haskell-cabal.eclass 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  1. # Copyright 1999-2015 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. # @ECLASS: haskell-cabal.eclass
  4. # @MAINTAINER:
  5. # Haskell herd <haskell@gentoo.org>
  6. # @AUTHOR:
  7. # Original author: Andres Loeh <kosmikus@gentoo.org>
  8. # Original author: Duncan Coutts <dcoutts@gentoo.org>
  9. # @BLURB: for packages that make use of the Haskell Common Architecture for Building Applications and Libraries (cabal)
  10. # @DESCRIPTION:
  11. # Basic instructions:
  12. #
  13. # Before inheriting the eclass, set CABAL_FEATURES to
  14. # reflect the tools and features that the package makes
  15. # use of.
  16. #
  17. # Currently supported features:
  18. # haddock -- for documentation generation
  19. # hscolour -- generation of colourised sources
  20. # hoogle -- generation of documentation search index
  21. # profile -- if package supports to build profiling-enabled libraries
  22. # bootstrap -- only used for the cabal package itself
  23. # lib -- the package installs libraries
  24. # nocabaldep -- don't add dependency on cabal.
  25. # only used for packages that _must_ not pull the dependency
  26. # on cabal, but still use this eclass (e.g. haskell-updater).
  27. # ghcdeps -- constraint dependency on package to ghc onces
  28. # only used for packages that use libghc internally and _must_
  29. # not pull upper versions
  30. # test-suite -- add support for cabal test-suites (introduced in Cabal-1.8)
  31. inherit eutils ghc-package multilib toolchain-funcs
  32. # @ECLASS-VARIABLE: CABAL_EXTRA_CONFIGURE_FLAGS
  33. # @DESCRIPTION:
  34. # User-specified additional parameters passed to 'setup configure'.
  35. # example: /etc/portage/make.conf:
  36. # CABAL_EXTRA_CONFIGURE_FLAGS="--enable-shared --enable-executable-dynamic"
  37. : ${CABAL_EXTRA_CONFIGURE_FLAGS:=}
  38. # @ECLASS-VARIABLE: CABAL_EXTRA_BUILD_FLAGS
  39. # @DESCRIPTION:
  40. # User-specified additional parameters passed to 'setup build'.
  41. # example: /etc/portage/make.conf: CABAL_EXTRA_BUILD_FLAGS=-v
  42. : ${CABAL_EXTRA_BUILD_FLAGS:=}
  43. # @ECLASS-VARIABLE: GHC_BOOTSTRAP_FLAGS
  44. # @DESCRIPTION:
  45. # User-specified additional parameters for ghc when building
  46. # _only_ 'setup' binary bootstrap.
  47. # example: /etc/portage/make.conf: GHC_BOOTSTRAP_FLAGS=-dynamic to make
  48. # linking 'setup' faster.
  49. : ${GHC_BOOTSTRAP_FLAGS:=}
  50. # @ECLASS-VARIABLE: CABAL_EXTRA_TEST_FLAGS
  51. # @DESCRIPTION:
  52. # User-specified additional parameters passed to 'setup test'.
  53. # example: /etc/portage/make.conf:
  54. # CABAL_EXTRA_TEST_FLAGS="-v3 --show-details=streaming"
  55. : ${CABAL_EXTRA_TEST_FLAGS:=}
  56. # @ECLASS-VARIABLE: CABAL_DEBUG_LOOSENING
  57. # @DESCRIPTION:
  58. # Show debug output for 'cabal_chdeps' function if set.
  59. # Needs working 'diff'.
  60. : ${CABAL_DEBUG_LOOSENING:=}
  61. HASKELL_CABAL_EXPF="pkg_setup src_compile src_test src_install pkg_postinst pkg_postrm"
  62. # 'dev-haskell/cabal' passes those options with ./configure-based
  63. # configuration, but most packages don't need/don't accept it:
  64. # #515362, #515362
  65. QA_CONFIGURE_OPTIONS+=" --with-compiler --with-hc --with-hc-pkg --with-gcc"
  66. case "${EAPI:-0}" in
  67. 2|3|4|5|6) HASKELL_CABAL_EXPF+=" src_configure" ;;
  68. *) ;;
  69. esac
  70. EXPORT_FUNCTIONS ${HASKELL_CABAL_EXPF}
  71. for feature in ${CABAL_FEATURES}; do
  72. case ${feature} in
  73. haddock) CABAL_USE_HADDOCK=yes;;
  74. hscolour) CABAL_USE_HSCOLOUR=yes;;
  75. hoogle) CABAL_USE_HOOGLE=yes;;
  76. profile) CABAL_USE_PROFILE=yes;;
  77. bootstrap) CABAL_BOOTSTRAP=yes;;
  78. lib) CABAL_HAS_LIBRARIES=yes;;
  79. nocabaldep) CABAL_FROM_GHC=yes;;
  80. ghcdeps) CABAL_GHC_CONSTRAINT=yes;;
  81. test-suite) CABAL_TEST_SUITE=yes;;
  82. # does nothing, removed 2016-09-04
  83. bin) ;;
  84. *) CABAL_UNKNOWN="${CABAL_UNKNOWN} ${feature}";;
  85. esac
  86. done
  87. if [[ -n "${CABAL_USE_HADDOCK}" ]]; then
  88. IUSE="${IUSE} doc"
  89. # don't require depend on itself to build docs.
  90. # ebuild bootstraps docs from just built binary
  91. #
  92. # starting from ghc-7.10.2 we install haddock bundled with
  93. # ghc to keep links to base and ghc library, otherwise
  94. # newer haddock versions change index format and can't
  95. # read index files for packages coming with ghc.
  96. [[ ${CATEGORY}/${PN} = "dev-haskell/haddock" ]] || \
  97. DEPEND="${DEPEND} doc? ( || ( dev-haskell/haddock >=dev-lang/ghc-7.10.2 ) )"
  98. fi
  99. if [[ -n "${CABAL_USE_HSCOLOUR}" ]]; then
  100. IUSE="${IUSE} hscolour"
  101. DEPEND="${DEPEND} hscolour? ( dev-haskell/hscolour )"
  102. fi
  103. if [[ -n "${CABAL_USE_HOOGLE}" ]]; then
  104. # enabled only in ::haskell
  105. #IUSE="${IUSE} hoogle"
  106. CABAL_USE_HOOGLE=
  107. fi
  108. if [[ -n "${CABAL_USE_PROFILE}" ]]; then
  109. IUSE="${IUSE} profile"
  110. fi
  111. if [[ -n "${CABAL_TEST_SUITE}" ]]; then
  112. IUSE="${IUSE} test"
  113. fi
  114. # returns the version of cabal currently in use.
  115. # Rarely it's handy to pin cabal version from outside.
  116. : ${_CABAL_VERSION_CACHE:=""}
  117. cabal-version() {
  118. if [[ -z "${_CABAL_VERSION_CACHE}" ]]; then
  119. if [[ "${CABAL_BOOTSTRAP}" ]]; then
  120. # We're bootstrapping cabal, so the cabal version is the version
  121. # of this package itself.
  122. _CABAL_VERSION_CACHE="${PV}"
  123. elif [[ "${CABAL_FROM_GHC}" ]]; then
  124. _CABAL_VERSION_CACHE="$(ghc-cabal-version)"
  125. else
  126. # We ask portage, not ghc, so that we only pick up
  127. # portage-installed cabal versions.
  128. _CABAL_VERSION_CACHE="$(ghc-extractportageversion dev-haskell/cabal)"
  129. fi
  130. fi
  131. echo "${_CABAL_VERSION_CACHE}"
  132. }
  133. cabal-bootstrap() {
  134. local setupmodule
  135. local cabalpackage
  136. local setup_bootstrap_args=()
  137. if [[ -f "${S}/Setup.lhs" ]]; then
  138. setupmodule="${S}/Setup.lhs"
  139. elif [[ -f "${S}/Setup.hs" ]]; then
  140. setupmodule="${S}/Setup.hs"
  141. else
  142. eqawarn "No Setup.lhs or Setup.hs found. Either add Setup.hs to package or call cabal-mksetup from ebuild"
  143. cabal-mksetup
  144. setupmodule="${S}/Setup.hs"
  145. fi
  146. # We build the setup program using the latest version of
  147. # cabal that we have installed
  148. cabalpackage=Cabal-$(cabal-version)
  149. einfo "Using cabal-$(cabal-version)."
  150. if $(ghc-supports-threaded-runtime); then
  151. # Cabal has a bug that deadlocks non-threaded RTS:
  152. # https://bugs.gentoo.org/537500
  153. # https://github.com/haskell/cabal/issues/2398
  154. setup_bootstrap_args+=(-threaded)
  155. fi
  156. make_setup() {
  157. set -- -package "${cabalpackage}" --make "${setupmodule}" \
  158. $(ghc-make-args) \
  159. "${setup_bootstrap_args[@]}" \
  160. ${HCFLAGS} \
  161. ${GHC_BOOTSTRAP_FLAGS} \
  162. "$@" \
  163. -o setup
  164. echo $(ghc-getghc) "$@"
  165. $(ghc-getghc) "$@"
  166. }
  167. if $(ghc-supports-shared-libraries); then
  168. # # some custom build systems might use external libraries,
  169. # # for which we don't have shared libs, so keep static fallback
  170. # bug #411789, http://hackage.haskell.org/trac/ghc/ticket/5743#comment:3
  171. # http://hackage.haskell.org/trac/ghc/ticket/7062
  172. # http://hackage.haskell.org/trac/ghc/ticket/3072
  173. # ghc does not set RPATH for extralibs, thus we do it ourselves by hands
  174. einfo "Prepending $(ghc-libdir) to LD_LIBRARY_PATH"
  175. if [[ ${CHOST} != *-darwin* ]]; then
  176. LD_LIBRARY_PATH="$(ghc-libdir)${LD_LIBRARY_PATH:+:}${LD_LIBRARY_PATH}"
  177. export LD_LIBRARY_PATH
  178. else
  179. DYLD_LIBRARY_PATH="$(ghc-libdir)${DYLD_LIBRARY_PATH:+:}${DYLD_LIBRARY_PATH}"
  180. export DYLD_LIBRARY_PATH
  181. fi
  182. { make_setup -dynamic "$@" && ./setup --help >/dev/null; } ||
  183. make_setup "$@" || die "compiling ${setupmodule} failed"
  184. else
  185. make_setup "$@" || die "compiling ${setupmodule} failed"
  186. fi
  187. }
  188. cabal-mksetup() {
  189. local setupdir=${1:-${S}}
  190. local setup_src=${setupdir}/Setup.hs
  191. rm -vf "${setupdir}"/Setup.{lhs,hs}
  192. elog "Creating 'Setup.hs' for 'Simple' build type."
  193. echo 'import Distribution.Simple; main = defaultMain' \
  194. > "${setup_src}" || die "failed to create default Setup.hs"
  195. }
  196. cabal-hscolour() {
  197. set -- hscolour "$@"
  198. echo ./setup "$@"
  199. ./setup "$@" || die "setup hscolour failed"
  200. }
  201. cabal-haddock() {
  202. set -- haddock "$@"
  203. echo ./setup "$@"
  204. ./setup "$@" || die "setup haddock failed"
  205. }
  206. cabal-hoogle() {
  207. ewarn "hoogle USE flag requires doc USE flag, building without hoogle"
  208. }
  209. cabal-hscolour-haddock() {
  210. # --hyperlink-source implies calling 'setup hscolour'
  211. set -- haddock --hyperlink-source
  212. echo ./setup "$@"
  213. ./setup "$@" --hyperlink-source || die "setup haddock --hyperlink-source failed"
  214. }
  215. cabal-hoogle-haddock() {
  216. set -- haddock --hoogle
  217. echo ./setup "$@"
  218. ./setup "$@" || die "setup haddock --hoogle failed"
  219. }
  220. cabal-hoogle-hscolour-haddock() {
  221. cabal-hscolour-haddock
  222. cabal-hoogle-haddock
  223. }
  224. cabal-hoogle-hscolour() {
  225. ewarn "hoogle USE flag requires doc USE flag, building without hoogle"
  226. cabal-hscolour
  227. }
  228. cabal-die-if-nonempty() {
  229. local breakage_type=$1
  230. shift
  231. [[ "${#@}" == 0 ]] && return 0
  232. eerror "Detected ${breakage_type} packages: ${@}"
  233. die "//==-- Please, run 'haskell-updater' to fix ${breakage_type} packages --==//"
  234. }
  235. cabal-show-brokens() {
  236. elog "ghc-pkg check: 'checking for other broken packages:'"
  237. # pretty-printer
  238. $(ghc-getghcpkg) check 2>&1 \
  239. | egrep -v '^Warning: haddock-(html|interfaces): ' \
  240. | egrep -v '^Warning: include-dirs: ' \
  241. | head -n 20
  242. cabal-die-if-nonempty 'broken' \
  243. $($(ghc-getghcpkg) check --simple-output)
  244. }
  245. cabal-show-old() {
  246. cabal-die-if-nonempty 'outdated' \
  247. $("${EPREFIX}"/usr/sbin/haskell-updater --quiet --upgrade --list-only)
  248. }
  249. cabal-show-brokens-and-die() {
  250. cabal-show-brokens
  251. cabal-show-old
  252. die "$@"
  253. }
  254. cabal-configure() {
  255. local cabalconf=()
  256. has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
  257. if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then
  258. # We use the bundled with GHC version if exists
  259. # Haddock is very picky about index files
  260. # it generates for ghc's base and other packages.
  261. local p=${EPREFIX}/usr/bin/haddock-ghc-$(ghc-version)
  262. if [[ -f $p ]]; then
  263. cabalconf+=(--with-haddock="${p}")
  264. else
  265. cabalconf+=(--with-haddock=${EPREFIX}/usr/bin/haddock)
  266. fi
  267. fi
  268. if [[ -n "${CABAL_USE_PROFILE}" ]] && use profile; then
  269. cabalconf+=(--enable-library-profiling)
  270. fi
  271. if [[ -n "${CABAL_TEST_SUITE}" ]]; then
  272. cabalconf+=($(use_enable test tests))
  273. fi
  274. if [[ -n "${CABAL_GHC_CONSTRAINT}" ]]; then
  275. cabalconf+=($(cabal-constraint "ghc"))
  276. fi
  277. cabalconf+=(--ghc-options="$(ghc-make-args)")
  278. local option
  279. for option in ${HCFLAGS}
  280. do
  281. cabalconf+=(--ghc-option="$option")
  282. done
  283. # toolchain
  284. cabalconf+=(--with-ar="$(tc-getAR)")
  285. # Building GHCi libs on ppc64 causes "TOC overflow".
  286. if use ppc64; then
  287. cabalconf+=(--disable-library-for-ghci)
  288. fi
  289. # currently cabal does not respect CFLAGS and LDFLAGS on it's own (bug #333217)
  290. # so translate LDFLAGS to ghc parameters (without filtering)
  291. local flag
  292. for flag in $CFLAGS; do cabalconf+=(--ghc-option="-optc$flag"); done
  293. for flag in $LDFLAGS; do cabalconf+=(--ghc-option="-optl$flag"); done
  294. # disable executable stripping for the executables, as portage will
  295. # strip by itself, and pre-stripping gives a QA warning.
  296. # cabal versions previous to 1.4 does not strip executables, and does
  297. # not accept the flag.
  298. # this fixes numerous bugs, amongst them;
  299. # bug #251881, bug #251882, bug #251884, bug #251886, bug #299494
  300. cabalconf+=(--disable-executable-stripping)
  301. cabalconf+=(--docdir="${EPREFIX}"/usr/share/doc/${PF})
  302. # As of Cabal 1.2, configure is quite quiet. For diagnostic purposes
  303. # it's better if the configure chatter is in the build logs:
  304. cabalconf+=(--verbose)
  305. # We build shared version of our Cabal where ghc ships it's shared
  306. # version of it. We will link ./setup as dynamic binary againt Cabal later.
  307. [[ ${CATEGORY}/${PN} == "dev-haskell/cabal" ]] && \
  308. $(ghc-supports-shared-libraries) && \
  309. cabalconf+=(--enable-shared)
  310. if $(ghc-supports-shared-libraries); then
  311. # Experimental support for dynamically linked binaries.
  312. # We are enabling it since 7.10.1_rc3
  313. if version_is_at_least "7.10.0.20150316" "$(ghc-version)"; then
  314. # we didn't enable it before as it was not stable on all arches
  315. cabalconf+=(--enable-shared)
  316. # Known to break on ghc-7.8/Cabal-1.18
  317. # https://ghc.haskell.org/trac/ghc/ticket/9625
  318. cabalconf+=(--enable-executable-dynamic)
  319. fi
  320. fi
  321. # --sysconfdir appeared in Cabal-1.18+
  322. if ./setup configure --help | grep -q -- --sysconfdir; then
  323. cabalconf+=(--sysconfdir="${EPREFIX}"/etc)
  324. fi
  325. # appeared in Cabal-1.18+ (see '--disable-executable-stripping')
  326. if ./setup configure --help | grep -q -- --disable-library-stripping; then
  327. cabalconf+=(--disable-library-stripping)
  328. fi
  329. set -- configure \
  330. --ghc --prefix="${EPREFIX}"/usr \
  331. --with-compiler="$(ghc-getghc)" \
  332. --with-hc-pkg="$(ghc-getghcpkg)" \
  333. --prefix="${EPREFIX}"/usr \
  334. --libdir="${EPREFIX}"/usr/$(get_libdir) \
  335. --libsubdir=${P}/ghc-$(ghc-version) \
  336. --datadir="${EPREFIX}"/usr/share/ \
  337. --datasubdir=${P}/ghc-$(ghc-version) \
  338. "${cabalconf[@]}" \
  339. ${CABAL_CONFIGURE_FLAGS} \
  340. ${CABAL_EXTRA_CONFIGURE_FLAGS} \
  341. "$@"
  342. echo ./setup "$@"
  343. ./setup "$@" || cabal-show-brokens-and-die "setup configure failed"
  344. }
  345. cabal-build() {
  346. set -- build ${CABAL_EXTRA_BUILD_FLAGS} "$@"
  347. echo ./setup "$@"
  348. ./setup "$@" \
  349. || die "setup build failed"
  350. }
  351. cabal-copy() {
  352. has "${EAPI:-0}" 0 1 2 && ! use prefix && ED=${D}
  353. set -- copy --destdir="${D}" "$@"
  354. echo ./setup "$@"
  355. ./setup "$@" || die "setup copy failed"
  356. # cabal is a bit eager about creating dirs,
  357. # so remove them if they are empty
  358. rmdir "${ED}/usr/bin" 2> /dev/null
  359. }
  360. cabal-pkg() {
  361. # This does not actually register since we're using true instead
  362. # of ghc-pkg. So it just leaves the .conf file and we can
  363. # register that ourselves (if it exists).
  364. if [[ -n ${CABAL_HAS_LIBRARIES} ]]; then
  365. # Newer cabal can generate a package conf for us:
  366. ./setup register --gen-pkg-config="${T}/${P}.conf"
  367. ghc-install-pkg "${T}/${P}.conf"
  368. fi
  369. }
  370. # Some cabal libs are bundled along with some versions of ghc
  371. # eg filepath-1.0 comes with ghc-6.6.1
  372. # by putting CABAL_CORE_LIB_GHC_PV="6.6.1" in an ebuild we are declaring that
  373. # when building with this version of ghc, the ebuild is a dummy that is it will
  374. # install no files since the package is already included with ghc.
  375. # However portage still records the dependency and we can upgrade the package
  376. # to a later one that's not included with ghc.
  377. # You can also put a space separated list, eg CABAL_CORE_LIB_GHC_PV="6.6 6.6.1".
  378. # Those versions are taken as-is from ghc `--numeric-version`.
  379. # Package manager versions are also supported:
  380. # CABAL_CORE_LIB_GHC_PV="7.10.* PM:7.8.4-r1".
  381. cabal-is-dummy-lib() {
  382. local bin_ghc_version=$(ghc-version)
  383. local pm_ghc_version=$(ghc-pm-version)
  384. for version in ${CABAL_CORE_LIB_GHC_PV}; do
  385. [[ "${bin_ghc_version}" == ${version} ]] && return 0
  386. [[ "${pm_ghc_version}" == ${version} ]] && return 0
  387. done
  388. return 1
  389. }
  390. # exported function: check if cabal is correctly installed for
  391. # the currently active ghc (we cannot guarantee this with portage)
  392. haskell-cabal_pkg_setup() {
  393. if [[ -n ${CABAL_HAS_LIBRARIES} ]]; then
  394. [[ ${RDEPEND} == *dev-lang/ghc* ]] || eqawarn "QA Notice: A library does not have runtime dependency on dev-lang/ghc."
  395. fi
  396. if [[ -n "${CABAL_UNKNOWN}" ]]; then
  397. eqawarn "QA Notice: Unknown entry in CABAL_FEATURES: ${CABAL_UNKNOWN}"
  398. fi
  399. if cabal-is-dummy-lib; then
  400. einfo "${P} is included in ghc-${CABAL_CORE_LIB_GHC_PV}, nothing to install."
  401. fi
  402. }
  403. haskell-cabal_src_configure() {
  404. cabal-is-dummy-lib && return
  405. pushd "${S}" > /dev/null || die
  406. cabal-bootstrap
  407. cabal-configure "$@"
  408. popd > /dev/null || die
  409. }
  410. # exported function: nice alias
  411. cabal_src_configure() {
  412. haskell-cabal_src_configure "$@"
  413. }
  414. # exported function: cabal-style bootstrap configure and compile
  415. cabal_src_compile() {
  416. # it's a common mistake when one bumps ebuild to EAPI="2" (and upper)
  417. # and forgets to separate src_compile() to src_configure()/src_compile().
  418. # Such error leads to default src_configure and we lose all passed flags.
  419. if ! has "${EAPI:-0}" 0 1; then
  420. local passed_flag
  421. for passed_flag in "$@"; do
  422. [[ ${passed_flag} == --flags=* ]] && \
  423. eqawarn "QA Notice: Cabal option '${passed_flag}' has effect only in src_configure()"
  424. done
  425. fi
  426. cabal-is-dummy-lib && return
  427. has src_configure ${HASKELL_CABAL_EXPF} || haskell-cabal_src_configure "$@"
  428. cabal-build
  429. if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then
  430. if [[ -n "${CABAL_USE_HSCOLOUR}" ]] && use hscolour; then
  431. if [[ -n "${CABAL_USE_HOOGLE}" ]] && use hoogle; then
  432. # hoogle, hscolour and haddock
  433. cabal-hoogle-hscolour-haddock
  434. else
  435. # haddock and hscolour
  436. cabal-hscolour-haddock
  437. fi
  438. else
  439. if [[ -n "${CABAL_USE_HOOGLE}" ]] && use hoogle; then
  440. # hoogle and haddock
  441. cabal-hoogle-haddock
  442. else
  443. # just haddock
  444. cabal-haddock
  445. fi
  446. fi
  447. else
  448. if [[ -n "${CABAL_USE_HSCOLOUR}" ]] && use hscolour; then
  449. if [[ -n "${CABAL_USE_HOOGLE}" ]] && use hoogle; then
  450. # hoogle and hscolour
  451. cabal-hoogle-hscolour
  452. else
  453. # just hscolour
  454. cabal-hscolour
  455. fi
  456. else
  457. if [[ -n "${CABAL_USE_HOOGLE}" ]] && use hoogle; then
  458. # just hoogle
  459. cabal-hoogle
  460. fi
  461. fi
  462. fi
  463. }
  464. haskell-cabal_src_compile() {
  465. pushd "${S}" > /dev/null || die
  466. cabal_src_compile "$@"
  467. popd > /dev/null || die
  468. }
  469. haskell-cabal_src_test() {
  470. local cabaltest=()
  471. pushd "${S}" > /dev/null || die
  472. if cabal-is-dummy-lib; then
  473. einfo ">>> No tests for dummy library: ${CATEGORY}/${PF}"
  474. else
  475. einfo ">>> Test phase [cabal test]: ${CATEGORY}/${PF}"
  476. # '--show-details=streaming' appeared in Cabal-1.20
  477. if ./setup test --help | grep -q -- "'streaming'"; then
  478. cabaltest+=(--show-details=streaming)
  479. fi
  480. set -- test \
  481. "${cabaltest[@]}" \
  482. ${CABAL_TEST_FLAGS} \
  483. ${CABAL_EXTRA_TEST_FLAGS} \
  484. "$@"
  485. echo ./setup "$@"
  486. ./setup "$@" || die "cabal test failed"
  487. fi
  488. popd > /dev/null || die
  489. }
  490. # exported function: cabal-style copy and register
  491. cabal_src_install() {
  492. has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
  493. if ! cabal-is-dummy-lib; then
  494. cabal-copy
  495. cabal-pkg
  496. fi
  497. # create a dummy local package conf file for haskell-updater
  498. # if it does not exist (dummy libraries and binaries w/o libraries)
  499. local ghc_confdir_with_prefix="$(ghc-confdir)"
  500. # remove EPREFIX
  501. dodir ${ghc_confdir_with_prefix#${EPREFIX}}
  502. local hint_db="${D}/$(ghc-confdir)"
  503. local hint_file="${hint_db}/${PF}.conf"
  504. mkdir -p "${hint_db}" || die
  505. touch "${hint_file}" || die
  506. }
  507. haskell-cabal_src_install() {
  508. pushd "${S}" > /dev/null || die
  509. cabal_src_install
  510. popd > /dev/null || die
  511. }
  512. haskell-cabal_pkg_postinst() {
  513. ghc-package_pkg_postinst
  514. }
  515. haskell-cabal_pkg_postrm() {
  516. ghc-package_pkg_postrm
  517. }
  518. # @FUNCTION: cabal_flag
  519. # @DESCRIPTION:
  520. # ebuild.sh:use_enable() taken as base
  521. #
  522. # Usage examples:
  523. #
  524. # CABAL_CONFIGURE_FLAGS=$(cabal_flag gui)
  525. # leads to "--flags=gui" or "--flags=-gui" (useflag 'gui')
  526. #
  527. # CABAL_CONFIGURE_FLAGS=$(cabal_flag gtk gui)
  528. # also leads to "--flags=gui" or " --flags=-gui" (useflag 'gtk')
  529. #
  530. cabal_flag() {
  531. if [[ -z "$1" ]]; then
  532. echo "!!! cabal_flag() called without a parameter." >&2
  533. echo "!!! cabal_flag() <USEFLAG> [<cabal_flagname>]" >&2
  534. return 1
  535. fi
  536. local UWORD=${2:-$1}
  537. if use "$1"; then
  538. echo "--flags=${UWORD}"
  539. else
  540. echo "--flags=-${UWORD}"
  541. fi
  542. return 0
  543. }
  544. # @FUNCTION: cabal_chdeps
  545. # @DESCRIPTION:
  546. # Allows easier patching of $CABAL_FILE (${S}/${PN}.cabal by default)
  547. # depends
  548. #
  549. # Accepts argument list as pairs of substitutions: <from-string> <to-string>...
  550. #
  551. # Dies on error.
  552. #
  553. # Usage examples:
  554. #
  555. # src_prepare() {
  556. # cabal_chdeps \
  557. # 'base >= 4.2 && < 4.6' 'base >= 4.2 && < 4.7' \
  558. # 'containers ==0.4.*' 'containers >= 0.4 && < 0.6'
  559. #}
  560. # or
  561. # src_prepare() {
  562. # CABAL_FILE=${S}/${MY_PN}.cabal cabal_chdeps \
  563. # 'base >= 4.2 && < 4.6' 'base >= 4.2 && < 4.7'
  564. # CABAL_FILE=${S}/${MY_PN}-tools.cabal cabal_chdeps \
  565. # 'base == 3.*' 'base >= 4.2 && < 4.7'
  566. #}
  567. #
  568. cabal_chdeps() {
  569. local cabal_fn=${MY_PN:-${PN}}.cabal
  570. local cf=${CABAL_FILE:-${S}/${cabal_fn}}
  571. local from_ss # ss - substring
  572. local to_ss
  573. local orig_c # c - contents
  574. local new_c
  575. [[ -f $cf ]] || die "cabal file '$cf' does not exist"
  576. orig_c=$(< "$cf")
  577. while :; do
  578. from_pat=$1
  579. to_str=$2
  580. [[ -n ${from_pat} ]] || break
  581. [[ -n ${to_str} ]] || die "'${from_str}' does not have 'to' part"
  582. einfo "CHDEP: '${from_pat}' -> '${to_str}'"
  583. # escape pattern-like symbols
  584. from_pat=${from_pat//\*/\\*}
  585. from_pat=${from_pat//\[/\\[}
  586. new_c=${orig_c//${from_pat}/${to_str}}
  587. if [[ -n $CABAL_DEBUG_LOOSENING ]]; then
  588. echo "${orig_c}" >"${T}/${cf}".pre
  589. echo "${new_c}" >"${T}/${cf}".post
  590. diff -u "${T}/${cf}".{pre,post}
  591. fi
  592. [[ "${orig_c}" == "${new_c}" ]] && die "no trigger for '${from_pat}'"
  593. orig_c=${new_c}
  594. shift
  595. shift
  596. done
  597. echo "${new_c}" > "$cf" ||
  598. die "failed to update"
  599. }
  600. # @FUNCTION: cabal-constraint
  601. # @DESCRIPTION:
  602. # Allowes to set contraint to the libraries that are
  603. # used by specified package
  604. cabal-constraint() {
  605. while read p v ; do
  606. echo "--constraint \"$p == $v\""
  607. done < $(ghc-pkgdeps ${1})
  608. }
  609. # @FUNCTION: replace-hcflags
  610. # @USAGE: <old> <new>
  611. # @DESCRIPTION:
  612. # Replace the <old> flag with <new> in HCFLAGS. Accepts shell globs for <old>.
  613. # The implementation is picked from flag-o-matic.eclass:replace-flags()
  614. replace-hcflags() {
  615. [[ $# != 2 ]] && die "Usage: replace-hcflags <old flag> <new flag>"
  616. local f new=()
  617. for f in ${HCFLAGS} ; do
  618. # Note this should work with globs like -O*
  619. if [[ ${f} == ${1} ]]; then
  620. einfo "HCFLAGS: replacing '${f}' to '${2}'"
  621. f=${2}
  622. fi
  623. new+=( "${f}" )
  624. done
  625. export HCFLAGS="${new[*]}"
  626. return 0
  627. }