b4b599d1115e28edaeeb42346bce08669185cf8c
[ghc.git] / utils / ghc-cabal / ghc.mk
1 # -----------------------------------------------------------------------------
2 #
3 # (c) 2009 The University of Glasgow
4 #
5 # This file is part of the GHC build system.
6 #
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
10 #
11 # -----------------------------------------------------------------------------
12
13 # Bootstrapping ghc-cabal
14
15 # Euch, hideous hack:
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)"
20
21 $(GHC_CABAL_INPLACE) : $(GHC_CABAL_DIR)/dist/build/tmp/ghc-cabal$(exeext) | $$(dir $$@)/.
22 "$(CP)" $< $@
23
24 $(GHC_CABAL_DIR)/dist/build/tmp/ghc-cabal$(exeext): $(GHC_CABAL_DIR)/ghc-cabal.hs | $$(dir $$@)/. bootstrapping/.
25 "$(GHC)" $(SRC_HC_OPTS) --make $(GHC_CABAL_DIR)/ghc-cabal.hs -o $@ \
26 -Wall $(WERROR) \
27 -DCABAL_VERSION=$(CABAL_VERSION) \
28 -odir bootstrapping \
29 -hidir bootstrapping \
30 -ilibraries/Cabal \
31 -ilibraries/filepath \
32 -ilibraries/hpc
33 touch $@
34
35 # touch is required, because otherwise if mkdirhier is newer, we
36 # repeatedly rebuild ghc-cabal.
37
38 $(eval $(call clean-target,$(GHC_CABAL_DIR),dist,\
39 $(GHC_CABAL_DIR)/dist bootstrapping))
40
41 $(eval $(call all-target,$(GHC_CABAL_DIR),$(GHC_CABAL_INPLACE)))
42
43 # -----------------------------------------------------------------------------
44 # dummy-ghc
45
46 # This is a tiny program to fool Cabal's configure that we have a
47 # stage1 GHC, which lets us configure all the packages before we've
48 # build stage1.
49
50 $(GHC_CABAL_DIR)_dist-dummy-ghc_MODULES = dummy-ghc
51 $(GHC_CABAL_DIR)_dist-dummy-ghc_PROG = dummy-ghc$(exeext)
52
53 # depend on project.mk, so we pick up the new version number if it changes.
54 $(GHC_CABAL_DIR)/dist-dummy-ghc/build/dummy-ghc.hs : $(GHC_CABAL_DIR)/ghc.mk $(MKDIRHIER) mk/project.mk compiler/main/DynFlags.hs
55 "$(MKDIRHIER)" $(dir $@)
56 "$(RM)" $(RM_OPTS) $@
57 echo 'import System.Environment' >> $@
58 echo 'import System.Cmd' >> $@
59 echo 'import System.Exit' >> $@
60 echo 'main :: IO ()' >> $@
61 echo 'main = do args <- getArgs' >> $@
62 echo ' case args of' >> $@
63 echo ' ["--numeric-version"] ->' >> $@
64 echo ' putStrLn "$(ProjectVersion)"' >> $@
65 echo ' ["--supported-languages"] ->' >> $@
66 echo ' mapM_ putStrLn extensions' >> $@
67 echo ' _ ->' >> $@
68 echo ' do e <- rawSystem "$(GHC_STAGE0)" args' >> $@
69 echo ' exitWith e' >> $@
70 # This unpleasant sed script grabs the lines between the
71 # xFlags ::
72 # line and the
73 # ]
74 # line of compiler/main/DynFlags.hs, and if they look like
75 # ( "PostfixOperators", ...
76 # then it translates them into
77 # ["PostfixOperators"] ++
78 echo 'extensions :: [String]' >> $@
79 echo 'extensions =' >> $@
80 sed '/^xFlags/,/]/{/^ (/{s/^[^"]*"/ ["/; s/"[^"]*$$/"] ++/; p}}; d' compiler/main/DynFlags.hs >> $@
81 echo ' []' >> $@
82
83 # We don't build dummy-ghc with Cabal, so we need to pass -package
84 # flags manually
85 utils/ghc-cabal_dist-dummy-ghc_HC_OPTS = -package process
86 $(eval $(call build-prog,utils/ghc-cabal,dist-dummy-ghc,0))
87