1- -- Note: to bootstrap uuagc with a commandline uuagc,
2- -- pass the -DEXTERNAL_UUAGC to GHC
3- -- when building setup.hs. This can be accomplished using
4- -- cabal install with --ghc-options="-DEXTERNAL_UUAGC".
5- --
6- -- When this option is used, a cabal flag will be set so
7- -- that the Haskell sources will be regenerated from
8- -- the attribute grammar sources
9- --
10- -- Note: it would be nicer if this behavior could be enabled
11- -- with a configure flag. However, a compiled Setup.hs is
12- -- required in order to perform 'configure', so configure
13- -- flags are regarded too late in the process.
14- -- Also note that this Setup.hs has conditional package
15- -- requirements depending on what code is used.
16-
171{-# OPTIONS_GHC -fno-warn-warnings-deprecations #-}
18- {-# LANGUAGE CPP #-}
192module Main where
203
21- #ifdef EXTERNAL_UUAGC
224import System.Environment (getArgs )
23- import Distribution.Simple (defaultMainWithHooksArgs )
5+ import Distribution.Simple (defaultMainWithHooksArgs , UserHooks (.. ), simpleUserHooks )
6+ import Distribution.Simple.LocalBuildInfo (flagAssignment )
247import Distribution.Simple.UUAGC (uuagcUserHook )
8+ import Distribution.Types.Flag (lookupFlagAssignment , mkFlagName )
9+ import Debug.Trace
2510
2611main :: IO ()
27- main = args >>= defaultMainWithHooksArgs uuagcUserHook
28-
29- args :: IO [String ]
30- args = do
31- as <- getArgs
32- let addFlags | " configure" `elem` as = (" --flags=bootstrap_external" : )
33- | otherwise = id
34- return (addFlags as)
35- #else
36- import Distribution.Simple (defaultMain , defaultMainWithHooksArgs )
37-
38- main :: IO ()
39- main = defaultMain
40- #endif
12+ main = do
13+ args <- getArgs
14+ defaultMainWithHooksArgs hooks args
15+ where
16+ hooks = uuagcUserHook { buildHook = myBuildHook }
17+ myBuildHook pd lbi uh bf
18+ | lookupFlagAssignment (mkFlagName " bootstrap_external" ) (flagAssignment lbi) == Just True
19+ = buildHook uuagcUserHook pd lbi uh bf
20+ | otherwise
21+ = buildHook simpleUserHooks pd lbi uh bf
0 commit comments