/[gentoo-x86]/eclass/haskell-cabal.eclass
Gentoo

Diff of /eclass/haskell-cabal.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.32 Revision 1.43
1# Copyright 1999-2012 Gentoo Foundation 1# Copyright 1999-2014 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License v2 2# Distributed under the terms of the GNU General Public License v2
3# $Header: /var/cvsroot/gentoo-x86/eclass/haskell-cabal.eclass,v 1.32 2012/04/19 17:33:19 slyfox Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/haskell-cabal.eclass,v 1.43 2014/02/11 19:00:06 slyfox Exp $
4 4
5# @ECLASS: haskell-cabal.eclass 5# @ECLASS: haskell-cabal.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# Haskell herd <haskell@gentoo.org> 7# Haskell herd <haskell@gentoo.org>
8# @AUTHOR: 8# @AUTHOR:
17# use of. 17# use of.
18# 18#
19# Currently supported features: 19# Currently supported features:
20# haddock -- for documentation generation 20# haddock -- for documentation generation
21# hscolour -- generation of colourised sources 21# hscolour -- generation of colourised sources
22# hoogle -- generation of documentation search index
22# alex -- lexer/scanner generator 23# alex -- lexer/scanner generator
23# happy -- parser generator 24# happy -- parser generator
24# c2hs -- C interface generator 25# c2hs -- C interface generator
25# cpphs -- C preprocessor clone written in Haskell 26# cpphs -- C preprocessor clone written in Haskell
26# profile -- if package supports to build profiling-enabled libraries 27# profile -- if package supports to build profiling-enabled libraries
30# nocabaldep -- don't add dependency on cabal. 31# nocabaldep -- don't add dependency on cabal.
31# only used for packages that _must_ not pull the dependency 32# only used for packages that _must_ not pull the dependency
32# on cabal, but still use this eclass (e.g. haskell-updater). 33# on cabal, but still use this eclass (e.g. haskell-updater).
33# test-suite -- add support for cabal test-suites (introduced in Cabal-1.8) 34# test-suite -- add support for cabal test-suites (introduced in Cabal-1.8)
34 35
35inherit ghc-package multilib 36inherit eutils ghc-package multilib multiprocessing
36 37
37# @ECLASS-VARIABLE: CABAL_EXTRA_CONFIGURE_FLAGS 38# @ECLASS-VARIABLE: CABAL_EXTRA_CONFIGURE_FLAGS
38# @DESCRIPTION: 39# @DESCRIPTION:
39# User-specified additional parameters passed to 'setup configure'. 40# User-specified additional parameters passed to 'setup configure'.
40# example: /etc/make.conf: CABAL_EXTRA_CONFIGURE_FLAGS=--enable-shared 41# example: /etc/portage/make.conf: CABAL_EXTRA_CONFIGURE_FLAGS=--enable-shared
41: ${CABAL_EXTRA_CONFIGURE_FLAGS:=} 42: ${CABAL_EXTRA_CONFIGURE_FLAGS:=}
42 43
43# @ECLASS-VARIABLE: CABAL_EXTRA_BUILD_FLAGS 44# @ECLASS-VARIABLE: CABAL_EXTRA_BUILD_FLAGS
44# @DESCRIPTION: 45# @DESCRIPTION:
45# User-specified additional parameters passed to 'setup build'. 46# User-specified additional parameters passed to 'setup build'.
46# example: /etc/make.conf: CABAL_EXTRA_BUILD_FLAGS=-v 47# example: /etc/portage/make.conf: CABAL_EXTRA_BUILD_FLAGS=-v
47: ${CABAL_EXTRA_BUILD_FLAGS:=} 48: ${CABAL_EXTRA_BUILD_FLAGS:=}
48 49
49# @ECLASS-VARIABLE: GHC_BOOTSTRAP_FLAGS 50# @ECLASS-VARIABLE: GHC_BOOTSTRAP_FLAGS
50# @DESCRIPTION: 51# @DESCRIPTION:
51# User-specified additional parameters for ghc when building 52# User-specified additional parameters for ghc when building
52# _only_ 'setup' binary bootstrap. 53# _only_ 'setup' binary bootstrap.
53# example: /etc/make.conf: GHC_BOOTSTRAP_FLAGS=-dynamic to make 54# example: /etc/portage/make.conf: GHC_BOOTSTRAP_FLAGS=-dynamic to make
54# linking 'setup' faster. 55# linking 'setup' faster.
55: ${GHC_BOOTSTRAP_FLAGS:=} 56: ${GHC_BOOTSTRAP_FLAGS:=}
56 57
58# @ECLASS-VARIABLE: CABAL_DEBUG_LOOSENING
59# @DESCRIPTION:
60# Show debug output for 'cabal_chdeps' function if set.
61# Needs working 'diff'.
62: ${CABAL_DEBUG_LOOSENING:=}
63
57HASKELL_CABAL_EXPF="pkg_setup src_compile src_test src_install" 64HASKELL_CABAL_EXPF="pkg_setup src_compile src_test src_install"
58 65
59case "${EAPI:-0}" in 66case "${EAPI:-0}" in
60 2|3|4) HASKELL_CABAL_EXPF+=" src_configure" ;; 67 2|3|4|5) HASKELL_CABAL_EXPF+=" src_configure" ;;
61 *) ;; 68 *) ;;
62esac 69esac
63 70
64EXPORT_FUNCTIONS ${HASKELL_CABAL_EXPF} 71EXPORT_FUNCTIONS ${HASKELL_CABAL_EXPF}
65 72
125fi 132fi
126if [[ -z "${CABAL_BOOTSTRAP}" && -z "${CABAL_FROM_GHC}" ]]; then 133if [[ -z "${CABAL_BOOTSTRAP}" && -z "${CABAL_FROM_GHC}" ]]; then
127 DEPEND="${DEPEND} >=dev-haskell/cabal-${CABAL_MIN_VERSION}" 134 DEPEND="${DEPEND} >=dev-haskell/cabal-${CABAL_MIN_VERSION}"
128fi 135fi
129 136
130# Libraries require GHC to be installed.
131if [[ -n "${CABAL_HAS_LIBRARIES}" ]]; then
132 RDEPEND="${RDEPEND} dev-lang/ghc"
133fi
134
135# returns the version of cabal currently in use 137# returns the version of cabal currently in use
136_CABAL_VERSION_CACHE="" 138_CABAL_VERSION_CACHE=""
137cabal-version() { 139cabal-version() {
138 if [[ -z "${_CABAL_VERSION_CACHE}" ]]; then 140 if [[ -z "${_CABAL_VERSION_CACHE}" ]]; then
139 if [[ "${CABAL_BOOTSTRAP}" ]]; then 141 if [[ "${CABAL_BOOTSTRAP}" ]]; then
185 $(ghc-getghc) "$@" 187 $(ghc-getghc) "$@"
186 } 188 }
187 if $(ghc-supports-shared-libraries); then 189 if $(ghc-supports-shared-libraries); then
188 # # some custom build systems might use external libraries, 190 # # some custom build systems might use external libraries,
189 # # for which we don't have shared libs, so keep static fallback 191 # # for which we don't have shared libs, so keep static fallback
190 # Disabled '-dynamic' as ghc does not embed RPATH to used extra-libraries:
191 # bug #411789, http://hackage.haskell.org/trac/ghc/ticket/5743#comment:3 192 # bug #411789, http://hackage.haskell.org/trac/ghc/ticket/5743#comment:3
192 # make_setup -dynamic "$@" || 193 # http://hackage.haskell.org/trac/ghc/ticket/7062
194 # http://hackage.haskell.org/trac/ghc/ticket/3072
195 # ghc does not set RPATH for extralibs, thus we do it ourselves by hands
196 einfo "Prepending $(ghc-libdir) to LD_LIBRARY_PATH"
197 if [[ ${CHOST} != *-darwin* ]]; then
198 LD_LIBRARY_PATH="$(ghc-libdir)${LD_LIBRARY_PATH:+:}${LD_LIBRARY_PATH}"
199 export LD_LIBRARY_PATH
200 else
201 DYLD_LIBRARY_PATH="$(ghc-libdir)${DYLD_LIBRARY_PATH:+:}${DYLD_LIBRARY_PATH}"
202 export DYLD_LIBRARY_PATH
203 fi
204 { make_setup -dynamic "$@" && ./setup --help >/dev/null; } ||
193 make_setup "$@" || die "compiling ${setupmodule} failed" 205 make_setup "$@" || die "compiling ${setupmodule} failed"
194 else 206 else
195 make_setup "$@" || die "compiling ${setupmodule} failed" 207 make_setup "$@" || die "compiling ${setupmodule} failed"
196 fi 208 fi
197} 209}
228 set -- haddock --hyperlink-source 240 set -- haddock --hyperlink-source
229 echo ./setup "$@" 241 echo ./setup "$@"
230 ./setup "$@" --hyperlink-source || die "setup haddock --hyperlink-source failed" 242 ./setup "$@" --hyperlink-source || die "setup haddock --hyperlink-source failed"
231} 243}
232 244
245cabal-die-if-nonempty() {
246 local breakage_type=$1
247 shift
248
249 [[ "${#@}" == 0 ]] && return 0
250 eerror "Detected ${breakage_type} packages: ${@}"
251 die "//==-- Please, run 'haskell-updater' to fix ${breakage_type} packages --==//"
252}
253
254cabal-show-brokens() {
255 # pretty-printer
256 $(ghc-getghcpkg) check 2>&1 \
257 | egrep -v '^Warning: haddock-(html|interfaces): ' \
258 | egrep -v '^Warning: include-dirs: '
259
260 cabal-die-if-nonempty 'broken' \
261 $($(ghc-getghcpkg) check --simple-output)
262}
263
264cabal-show-old() {
265 cabal-die-if-nonempty 'outdated' \
266 $("${EPREFIX}"/usr/sbin/haskell-updater --quiet --upgrade --list-only)
267}
268
269cabal-show-brokens-and-die() {
270 cabal-show-brokens
271 cabal-show-old
272
273 die "$@"
274}
275
233cabal-configure() { 276cabal-configure() {
277 local cabalconf=()
234 has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX= 278 has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
235 279
236 if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then 280 if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then
237 cabalconf="${cabalconf} --with-haddock=${EPREFIX}/usr/bin/haddock" 281 cabalconf+=(--with-haddock=${EPREFIX}/usr/bin/haddock)
238 fi 282 fi
239 if [[ -n "${CABAL_USE_PROFILE}" ]] && use profile; then 283 if [[ -n "${CABAL_USE_PROFILE}" ]] && use profile; then
240 cabalconf="${cabalconf} --enable-library-profiling" 284 cabalconf+=(--enable-library-profiling)
241 fi 285 fi
242 if [[ -n "${CABAL_USE_ALEX}" ]]; then 286 if [[ -n "${CABAL_USE_ALEX}" ]]; then
243 cabalconf="${cabalconf} --with-alex=${EPREFIX}/usr/bin/alex" 287 cabalconf+=(--with-alex=${EPREFIX}/usr/bin/alex)
244 fi 288 fi
245 289
246 if [[ -n "${CABAL_USE_HAPPY}" ]]; then 290 if [[ -n "${CABAL_USE_HAPPY}" ]]; then
247 cabalconf="${cabalconf} --with-happy=${EPREFIX}/usr/bin/happy" 291 cabalconf+=(--with-happy=${EPREFIX}/usr/bin/happy)
248 fi 292 fi
249 293
250 if [[ -n "${CABAL_USE_C2HS}" ]]; then 294 if [[ -n "${CABAL_USE_C2HS}" ]]; then
251 cabalconf="${cabalconf} --with-c2hs=${EPREFIX}/usr/bin/c2hs" 295 cabalconf+=(--with-c2hs=${EPREFIX}/usr/bin/c2hs)
252 fi 296 fi
253 if [[ -n "${CABAL_USE_CPPHS}" ]]; then 297 if [[ -n "${CABAL_USE_CPPHS}" ]]; then
254 cabalconf="${cabalconf} --with-cpphs=${EPREFIX}/usr/bin/cpphs" 298 cabalconf+=(--with-cpphs=${EPREFIX}/usr/bin/cpphs)
255 fi 299 fi
256 if [[ -n "${CABAL_TEST_SUITE}" ]]; then 300 if [[ -n "${CABAL_TEST_SUITE}" ]]; then
257 cabalconf="${cabalconf} $(use_enable test tests)" 301 cabalconf+=($(use_enable test tests))
258 fi 302 fi
259 303
260 local option 304 local option
261 for option in ${HCFLAGS} 305 for option in ${HCFLAGS}
262 do 306 do
263 cabalconf+=" --ghc-option=$option" 307 cabalconf+=(--ghc-option="$option")
264 done 308 done
309
310 # parallel on all available cores
311 if ghc-supports-parallel-make; then
312 local max_jobs=$(makeopts_jobs)
313
314 # limit to sort-of-sane value (same as Cabal)
315 [[ ${max_jobs} -gt 64 ]] && max_jobs=64
316
317 cabalconf+=(--ghc-option=-j"$max_jobs")
318 fi
265 319
266 # Building GHCi libs on ppc64 causes "TOC overflow". 320 # Building GHCi libs on ppc64 causes "TOC overflow".
267 if use ppc64; then 321 if use ppc64; then
268 cabalconf="${cabalconf} --disable-library-for-ghci" 322 cabalconf+=(--disable-library-for-ghci)
269 fi 323 fi
270 324
271 # currently cabal does not respect CFLAGS and LDFLAGS on it's own (bug #333217) 325 # currently cabal does not respect CFLAGS and LDFLAGS on it's own (bug #333217)
272 # so translate LDFLAGS to ghc parameters (without filtering) 326 # so translate LDFLAGS to ghc parameters (without filtering)
273 local flag 327 local flag
274 for flag in $LDFLAGS; do cabalconf="${cabalconf} --ghc-option=-optl$flag"; done 328 for flag in $LDFLAGS; do cabalconf+=(--ghc-option="-optl$flag"); done
275 329
276 # disable executable stripping for the executables, as portage will 330 # disable executable stripping for the executables, as portage will
277 # strip by itself, and pre-stripping gives a QA warning. 331 # strip by itself, and pre-stripping gives a QA warning.
278 # cabal versions previous to 1.4 does not strip executables, and does 332 # cabal versions previous to 1.4 does not strip executables, and does
279 # not accept the flag. 333 # not accept the flag.
280 # this fixes numerous bugs, amongst them; 334 # this fixes numerous bugs, amongst them;
281 # bug #251881, bug #251882, bug #251884, bug #251886, bug #299494 335 # bug #251881, bug #251882, bug #251884, bug #251886, bug #299494
282 cabalconf="${cabalconf} --disable-executable-stripping" 336 cabalconf+=(--disable-executable-stripping)
283 337
284 cabalconf="${cabalconf} --docdir=${EPREFIX}/usr/share/doc/${PF}" 338 cabalconf+=(--docdir="${EPREFIX}"/usr/share/doc/${PF})
285 # As of Cabal 1.2, configure is quite quiet. For diagnostic purposes 339 # As of Cabal 1.2, configure is quite quiet. For diagnostic purposes
286 # it's better if the configure chatter is in the build logs: 340 # it's better if the configure chatter is in the build logs:
287 cabalconf="${cabalconf} --verbose" 341 cabalconf+=(--verbose)
288 342
289 # We build shared version of our Cabal where ghc ships it's shared 343 # We build shared version of our Cabal where ghc ships it's shared
290 # version of it. We will link ./setup as dynamic binary againt Cabal later. 344 # version of it. We will link ./setup as dynamic binary againt Cabal later.
291 [[ ${CATEGORY}/${PN} == "dev-haskell/cabal" ]] && \ 345 [[ ${CATEGORY}/${PN} == "dev-haskell/cabal" ]] && \
292 $(ghc-supports-shared-libraries) && \ 346 $(ghc-supports-shared-libraries) && \
293 cabalconf="${cabalconf} --enable-shared" 347 cabalconf+=(--enable-shared)
348
349 if $(ghc-supports-shared-libraries); then
350 # maybe a bit lower
351 if $(ghc-supports-dynamic-by-default); then
352 cabalconf+=(--enable-shared)
353 fi
354 fi
355
356 # --sysconfdir appeared in Cabal-1.18+
357 if ./setup configure --help | grep -q -- --sysconfdir; then
358 cabalconf+=(--sysconfdir="${EPREFIX}"/etc)
359 fi
360
361 # appeared in Cabal-1.18+ (see '--disable-executable-stripping')
362 if ./setup configure --help | grep -q -- --disable-library-stripping; then
363 cabalconf+=(--disable-library-stripping)
364 fi
294 365
295 set -- configure \ 366 set -- configure \
296 --ghc --prefix="${EPREFIX}"/usr \ 367 --ghc --prefix="${EPREFIX}"/usr \
297 --with-compiler="$(ghc-getghc)" \ 368 --with-compiler="$(ghc-getghc)" \
298 --with-hc-pkg="$(ghc-getghcpkg)" \ 369 --with-hc-pkg="$(ghc-getghcpkg)" \
299 --prefix="${EPREFIX}"/usr \ 370 --prefix="${EPREFIX}"/usr \
300 --libdir="${EPREFIX}"/usr/$(get_libdir) \ 371 --libdir="${EPREFIX}"/usr/$(get_libdir) \
301 --libsubdir=${P}/ghc-$(ghc-version) \ 372 --libsubdir=${P}/ghc-$(ghc-version) \
302 --datadir="${EPREFIX}"/usr/share/ \ 373 --datadir="${EPREFIX}"/usr/share/ \
303 --datasubdir=${P}/ghc-$(ghc-version) \ 374 --datasubdir=${P}/ghc-$(ghc-version) \
304 ${cabalconf} \ 375 "${cabalconf[@]}" \
305 ${CABAL_CONFIGURE_FLAGS} \ 376 ${CABAL_CONFIGURE_FLAGS} \
306 ${CABAL_EXTRA_CONFIGURE_FLAGS} \ 377 ${CABAL_EXTRA_CONFIGURE_FLAGS} \
307 "$@" 378 "$@"
308 echo ./setup "$@" 379 echo ./setup "$@"
309 ./setup "$@" || die "setup configure failed" 380 ./setup "$@" || cabal-show-brokens-and-die "setup configure failed"
310} 381}
311 382
312cabal-build() { 383cabal-build() {
313 unset LANG LC_ALL LC_MESSAGES 384 unset LANG LC_ALL LC_MESSAGES
314 set -- build ${CABAL_EXTRA_BUILD_FLAGS} "$@" 385 set -- build ${CABAL_EXTRA_BUILD_FLAGS} "$@"
350# However portage still records the dependency and we can upgrade the package 421# However portage still records the dependency and we can upgrade the package
351# to a later one that's not included with ghc. 422# to a later one that's not included with ghc.
352# You can also put a space separated list, eg CABAL_CORE_LIB_GHC_PV="6.6 6.6.1". 423# You can also put a space separated list, eg CABAL_CORE_LIB_GHC_PV="6.6 6.6.1".
353cabal-is-dummy-lib() { 424cabal-is-dummy-lib() {
354 for version in ${CABAL_CORE_LIB_GHC_PV[*]}; do 425 for version in ${CABAL_CORE_LIB_GHC_PV[*]}; do
355 [[ "$(ghc-version)" == "$version" ]] && return 0 426 [[ "$(ghc-version)" == ${version} ]] && return 0
356 done 427 done
357 return 1 428 return 1
358} 429}
359 430
360# exported function: check if cabal is correctly installed for 431# exported function: check if cabal is correctly installed for
361# the currently active ghc (we cannot guarantee this with portage) 432# the currently active ghc (we cannot guarantee this with portage)
362haskell-cabal_pkg_setup() { 433haskell-cabal_pkg_setup() {
434 if [[ -n ${CABAL_HAS_LIBRARIES} ]]; then
435 [[ ${RDEPEND} == *dev-lang/ghc* ]] || eqawarn "QA Notice: A library does not have runtime dependency on dev-lang/ghc."
436 fi
363 if [[ -z "${CABAL_HAS_BINARIES}" ]] && [[ -z "${CABAL_HAS_LIBRARIES}" ]]; then 437 if [[ -z "${CABAL_HAS_BINARIES}" ]] && [[ -z "${CABAL_HAS_LIBRARIES}" ]]; then
364 eqawarn "QA Notice: Neither bin nor lib are in CABAL_FEATURES." 438 eqawarn "QA Notice: Neither bin nor lib are in CABAL_FEATURES."
365 fi 439 fi
366 if [[ -n "${CABAL_UNKNOWN}" ]]; then 440 if [[ -n "${CABAL_UNKNOWN}" ]]; then
367 eqawarn "QA Notice: Unknown entry in CABAL_FEATURES: ${CABAL_UNKNOWN}" 441 eqawarn "QA Notice: Unknown entry in CABAL_FEATURES: ${CABAL_UNKNOWN}"
459 local ghc_confdir_with_prefix="$(ghc-confdir)" 533 local ghc_confdir_with_prefix="$(ghc-confdir)"
460 # remove EPREFIX 534 # remove EPREFIX
461 dodir ${ghc_confdir_with_prefix#${EPREFIX}} 535 dodir ${ghc_confdir_with_prefix#${EPREFIX}}
462 local conf_file="${D}/$(ghc-confdir)/$(ghc-localpkgconf)" 536 local conf_file="${D}/$(ghc-confdir)/$(ghc-localpkgconf)"
463 [[ -e $conf_file ]] || echo '[]' > "$conf_file" || die 537 [[ -e $conf_file ]] || echo '[]' > "$conf_file" || die
538
539 # make sure installed packages do not destroy ghc's
540 # bundled packages
541 local initial_pkg_db=${ROOT}/$(ghc-libdir)/package.conf.d.initial
542 if [[ -e ${initial_pkg_db} ]]; then
543 local checked_pkg
544 for checked_pkg in $(ghc-listpkg "${conf_file}")
545 do
546 local initial_pkg
547 for initial_pkg in $(ghc-listpkg "${initial_pkg_db}"); do
548 if [[ ${checked_pkg} = ${initial_pkg} ]]; then
549 eerror "Package ${checked_pkg} is shipped with $(ghc-version)."
550 eerror "Ebuild author forgot CABAL_CORE_LIB_GHC_PV entry."
551 eerror "Found in ${initial_pkg_db}."
552 die
553 fi
554 done
555 done
556 fi
464} 557}
465 558
466haskell-cabal_src_install() { 559haskell-cabal_src_install() {
467 pushd "${S}" > /dev/null 560 pushd "${S}" > /dev/null
468 561
469 cabal_src_install 562 cabal_src_install
470 563
471 popd > /dev/null 564 popd > /dev/null
472} 565}
473 566
567# @FUNCTION: cabal_flag
568# @DESCRIPTION:
474# ebuild.sh:use_enable() taken as base 569# ebuild.sh:use_enable() taken as base
475# 570#
476# Usage examples: 571# Usage examples:
477# 572#
478# CABAL_CONFIGURE_FLAGS=$(cabal_flag gui) 573# CABAL_CONFIGURE_FLAGS=$(cabal_flag gui)
496 echo "--flags=-${UWORD}" 591 echo "--flags=-${UWORD}"
497 fi 592 fi
498 593
499 return 0 594 return 0
500} 595}
596
597# @FUNCTION: cabal_chdeps
598# @DESCRIPTION:
599# Allows easier patching of $CABAL_FILE (${S}/${PN}.cabal by default)
600# depends
601#
602# Accepts argument list as pairs of substitutions: <from-string> <to-string>...
603#
604# Dies on error.
605#
606# Usage examples:
607#
608# src_prepare() {
609# cabal_chdeps \
610# 'base >= 4.2 && < 4.6' 'base >= 4.2 && < 4.7' \
611# 'containers ==0.4.*' 'containers >= 0.4 && < 0.6'
612#}
613# or
614# src_prepare() {
615# CABAL_FILE=${S}/${MY_PN}.cabal cabal_chdeps \
616# 'base >= 4.2 && < 4.6' 'base >= 4.2 && < 4.7'
617# CABAL_FILE=${S}/${MY_PN}-tools.cabal cabal_chdeps \
618# 'base == 3.*' 'base >= 4.2 && < 4.7'
619#}
620#
621cabal_chdeps() {
622 local cf=${CABAL_FILE:-${S}/${PN}.cabal}
623 local from_ss # ss - substring
624 local to_ss
625 local orig_c # c - contents
626 local new_c
627
628 [[ -f $cf ]] || die "cabal file '$cf' does not exist"
629
630 orig_c=$(< "$cf")
631
632 while :; do
633 from_pat=$1
634 to_str=$2
635
636 [[ -n ${from_pat} ]] || break
637 [[ -n ${to_str} ]] || die "'${from_str}' does not have 'to' part"
638
639 einfo "CHDEP: '${from_pat}' -> '${to_str}'"
640
641 # escape pattern-like symbols
642 from_pat=${from_pat//\*/\\*}
643 from_pat=${from_pat//\[/\\[}
644
645 new_c=${orig_c//${from_pat}/${to_str}}
646
647 if [[ -n $CABAL_DEBUG_LOOSENING ]]; then
648 echo "${orig_c}" >"${T}/${cf}".pre
649 echo "${new_c}" >"${T}/${cf}".post
650 diff -u "${T}/${cf}".{pre,post}
651 fi
652
653 [[ "${orig_c}" == "${new_c}" ]] && die "no trigger for '${from_pat}'"
654 orig_c=${new_c}
655 shift
656 shift
657 done
658
659 echo "${new_c}" > "$cf" ||
660 die "failed to update"
661}
662
663# @FUNCTION: replace-hcflags
664# @USAGE: <old> <new>
665# @DESCRIPTION:
666# Replace the <old> flag with <new> in HCFLAGS. Accepts shell globs for <old>.
667# The implementation is picked from flag-o-matic.eclass:replace-flags()
668replace-hcflags() {
669 [[ $# != 2 ]] && die "Usage: replace-hcflags <old flag> <new flag>"
670
671 local f new=()
672 for f in ${HCFLAGS} ; do
673 # Note this should work with globs like -O*
674 if [[ ${f} == ${1} ]]; then
675 einfo "HCFLAGS: replacing '${f}' to '${2}'"
676 f=${2}
677 fi
678 new+=( "${f}" )
679 done
680 export HCFLAGS="${new[*]}"
681
682 return 0
683}

Legend:
Removed from v.1.32  
changed lines
  Added in v.1.43

  ViewVC Help
Powered by ViewVC 1.1.20