1 # -----------------------------------------------------------------------------
3 # (c) 2009 The University of Glasgow
5 # This file is part of the GHC build system.
7 # To understand how the build system works and how to modify it, see
8 # http://hackage.haskell.org/trac/ghc/wiki/Building/Architecture
9 # http://hackage.haskell.org/trac/ghc/wiki/Building/Modifying
11 # -----------------------------------------------------------------------------
13 # Bootstrapping ghc-cabal
16 # XXX This should be in a different Makefile
17 CABAL_DOTTED_VERSION := $(shell grep "^Version:" libraries/Cabal/Cabal.cabal | sed "s/^Version: //")
18 CABAL_VERSION := $(subst .,$(comma),$(CABAL_DOTTED_VERSION))
19 CABAL_CONSTRAINT := --constraint="Cabal == $(CABAL_DOTTED_VERSION)"
21 $(GHC_CABAL_INPLACE) : $(GHC_CABAL_DIR)/dist/build/tmp/ghc-cabal$(exeext) | $$(dir $$@)/.
24 $(GHC_CABAL_DIR)/dist/build/tmp/ghc-cabal$(exeext): $(wildcard libraries/Cabal/Distribution/*/*/*.hs)
25 $(GHC_CABAL_DIR)/dist/build/tmp/ghc-cabal$(exeext): $(wildcard libraries/Cabal/Distribution/*/*.hs)
26 $(GHC_CABAL_DIR)/dist/build/tmp/ghc-cabal$(exeext): $(wildcard libraries/Cabal/Distribution/*.hs)
28 $(GHC_CABAL_DIR)/dist/build/tmp/ghc-cabal$(exeext): $(GHC_CABAL_DIR)/ghc-cabal.hs | $$(dir $$@)/. bootstrapping/.
29 "$(GHC)" $(SRC_HC_OPTS) --make $(GHC_CABAL_DIR)/ghc-cabal.hs -o $@ \
30 -no-user-package-conf \
32 -DCABAL_VERSION=$(CABAL_VERSION) \
34 -hidir bootstrapping \
36 -ilibraries/filepath \
40 # touch is required, because otherwise if mkdirhier is newer, we
41 # repeatedly rebuild ghc-cabal.
43 $(eval $(call clean-target,$(GHC_CABAL_DIR),dist,\
44 $(GHC_CABAL_DIR)/dist bootstrapping))
46 $(eval $(call all-target,$(GHC_CABAL_DIR),$(GHC_CABAL_INPLACE)))
48 # -----------------------------------------------------------------------------
51 # This is a tiny program to fool Cabal's configure that we have a
52 # stage1 GHC, which lets us configure all the packages before we've
55 $(GHC_CABAL_DIR)_dist-dummy-ghc_MODULES = dummy-ghc
56 $(GHC_CABAL_DIR)_dist-dummy-ghc_PROG = dummy-ghc$(exeext)
58 # depend on project.mk, so we pick up the new version number if it changes.
59 $(GHC_CABAL_DIR)/dist-dummy-ghc/build/dummy-ghc.hs : $(GHC_CABAL_DIR)/ghc.mk $(MKDIRHIER) mk/project.mk compiler/main/DynFlags.hs
60 "$(MKDIRHIER)" $(dir $@)
62 echo 'import System.Environment' >> $@
63 echo 'import System.Cmd' >> $@
64 echo 'import System.Exit' >> $@
65 echo 'main :: IO ()' >> $@
66 echo 'main = do args <- getArgs' >> $@
67 echo ' case args of' >> $@
68 echo ' ["--numeric-version"] ->' >> $@
69 echo ' putStrLn "$(ProjectVersion)"' >> $@
70 echo ' ["--supported-languages"] ->' >> $@
71 echo ' mapM_ putStrLn extensions' >> $@
73 echo ' do e <- rawSystem "$(GHC_STAGE0)" args' >> $@
74 echo ' exitWith e' >> $@
75 # This unpleasant sed script grabs the lines between the
79 # line of compiler/main/DynFlags.hs, and if they look like
80 # ( "PostfixOperators", ...
81 # then it translates them into
82 # ["PostfixOperators", "NoPostfixOperators"] ++
83 # Tabs are a pain to handle portably with sed, so rather than worrying
84 # about them we just use tr to remove them all before we start.
85 echo 'extensions :: [String]' >> $@
86 echo 'extensions =' >> $@
87 '$(TR)' -d '\t' < compiler/main/DynFlags.hs | '$(SED)' '/^xFlags/,/]/s/^ *( *"\([^"]*\)"[^"]*/ ["\1", "No\1"] ++/p;d' >> $@
90 # We don't build dummy-ghc with Cabal, so we need to pass -package
92 utils/ghc-cabal_dist-dummy-ghc_HC_OPTS = -package process
93 $(eval $(call build-prog,utils/ghc-cabal,dist-dummy-ghc,0))