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