cabal: Allow optional use of cpphs as a preprocessor

Pinging @peti.  This is needed on Darwin/Yosemite because clang's
preprocessor is broken there.
This commit is contained in:
John Wiegley 2015-01-08 11:55:11 -06:00
parent d0efcfa55e
commit 268da01677

View File

@ -1,13 +1,14 @@
# generic builder for Cabal packages # generic builder for Cabal packages
{ stdenv, fetchurl, lib, pkgconfig, ghc, Cabal, jailbreakCabal, glibcLocales { stdenv, fetchurl, lib, pkgconfig, ghc, Cabal, jailbreakCabal, glibcLocales
, gnugrep, coreutils, hscolour , gnugrep, coreutils, hscolour, cpphs
, enableLibraryProfiling ? false , enableLibraryProfiling ? false
, enableSharedLibraries ? false , enableSharedLibraries ? false
, enableSharedExecutables ? false , enableSharedExecutables ? false
, enableStaticLibraries ? true , enableStaticLibraries ? true
, enableCheckPhase ? stdenv.lib.versionOlder "7.4" ghc.version , enableCheckPhase ? stdenv.lib.versionOlder "7.4" ghc.version
, enableHyperlinkSource ? true , enableHyperlinkSource ? true
, enableCpphs ? false
, extension ? (self : super : {}) , extension ? (self : super : {})
}: }:
@ -56,6 +57,7 @@ assert !enableStaticLibraries -> versionOlder "7.7" ghc.version;
propagatedBuildInputs = filter (y : ! (y == null)) x.propagatedBuildInputs; propagatedBuildInputs = filter (y : ! (y == null)) x.propagatedBuildInputs;
propagatedUserEnvPkgs = filter (y : ! (y == null)) x.propagatedUserEnvPkgs; propagatedUserEnvPkgs = filter (y : ! (y == null)) x.propagatedUserEnvPkgs;
doCheck = enableCheckPhase && x.doCheck; doCheck = enableCheckPhase && x.doCheck;
useCpphs = enableCpphs && x.useCpphs;
hyperlinkSource = enableHyperlinkSource && x.hyperlinkSource; hyperlinkSource = enableHyperlinkSource && x.hyperlinkSource;
# Disable Darwin builds: <https://github.com/NixOS/nixpkgs/issues/2689>. # Disable Darwin builds: <https://github.com/NixOS/nixpkgs/issues/2689>.
meta = let meta = x.meta or {}; meta = let meta = x.meta or {};
@ -105,6 +107,7 @@ assert !enableStaticLibraries -> versionOlder "7.7" ghc.version;
extraBuildInputs = self.buildTools ++ extraBuildInputs = self.buildTools ++
(optionals self.doCheck self.testDepends) ++ (optionals self.doCheck self.testDepends) ++
(optional self.hyperlinkSource hscolour) ++ (optional self.hyperlinkSource hscolour) ++
(optional self.useCpphs cpphs) ++
(if self.pkgconfigDepends == [] then [] else [pkgconfig]) ++ (if self.pkgconfigDepends == [] then [] else [pkgconfig]) ++
(if self.isLibrary then [] else self.buildDepends ++ self.extraLibraries ++ self.pkgconfigDepends); (if self.isLibrary then [] else self.buildDepends ++ self.extraLibraries ++ self.pkgconfigDepends);
@ -153,6 +156,10 @@ assert !enableStaticLibraries -> versionOlder "7.7" ghc.version;
# and run any regression test suites the package might have # and run any regression test suites the package might have
doCheck = enableCheckPhase; doCheck = enableCheckPhase;
# force cpphs instead of the C compiler's preprocessor; sometimes
# needed due to clang's wacky behavior
useCpphs = false;
# pass the '--hyperlink-source' flag to ./Setup haddock # pass the '--hyperlink-source' flag to ./Setup haddock
hyperlinkSource = enableHyperlinkSource; hyperlinkSource = enableHyperlinkSource;
@ -231,6 +238,9 @@ assert !enableStaticLibraries -> versionOlder "7.7" ghc.version;
${optionalString (versionOlder "7.8" ghc.version && !self.isLibrary) '' ${optionalString (versionOlder "7.8" ghc.version && !self.isLibrary) ''
configureFlags+=" --ghc-option=-j$NIX_BUILD_CORES" configureFlags+=" --ghc-option=-j$NIX_BUILD_CORES"
''} ''}
${optionalString self.useCpphs ''
configureFlags+=" --ghc-option=-pgmPcpphs --ghc-option=-optP--cpp"
''}
${optionalString self.stdenv.isDarwin '' ${optionalString self.stdenv.isDarwin ''
configureFlags+=" --with-gcc=clang" configureFlags+=" --with-gcc=clang"
@ -259,7 +269,10 @@ assert !enableStaticLibraries -> versionOlder "7.7" ghc.version;
export GHC_PACKAGE_PATH=$(${ghc.GHCPackages}) export GHC_PACKAGE_PATH=$(${ghc.GHCPackages})
test -n "$noHaddock" || ./Setup haddock --html --hoogle \ test -n "$noHaddock" || ./Setup haddock --html --hoogle \
${optionalString (stdenv.lib.versionOlder "6.12" ghc.version) "--ghc-options=-optP-P"} \ ${optionalString (stdenv.lib.versionOlder "6.12" ghc.version) "--ghc-options=-optP-P"} \
${optionalString self.hyperlinkSource "--hyperlink-source"} ${optionalString self.hyperlinkSource "--hyperlink-source"} \
${optionalString self.useCpphs ''
--haddock-options="--optghc=-pgmPcpphs --optghc=-optP--cpp"
''}
eval "$postBuild" eval "$postBuild"
''; '';