Refactor gcc.c, pulling out the reusable code
[ghc-hetmet.git] / utils / ghc-cabal / ghc.mk
index 71232fb..f495048 100644 (file)
@@ -21,6 +21,10 @@ CABAL_CONSTRAINT := --constraint="Cabal == $(CABAL_DOTTED_VERSION)"
 $(GHC_CABAL_INPLACE) : $(GHC_CABAL_DIR)/dist/build/tmp/ghc-cabal$(exeext) | $$(dir $$@)/.
        "$(CP)" $< $@
 
+$(GHC_CABAL_DIR)/dist/build/tmp/ghc-cabal$(exeext): $(wildcard libraries/Cabal/Distribution/*/*/*.hs)
+$(GHC_CABAL_DIR)/dist/build/tmp/ghc-cabal$(exeext): $(wildcard libraries/Cabal/Distribution/*/*.hs)
+$(GHC_CABAL_DIR)/dist/build/tmp/ghc-cabal$(exeext): $(wildcard libraries/Cabal/Distribution/*.hs)
+
 $(GHC_CABAL_DIR)/dist/build/tmp/ghc-cabal$(exeext): $(GHC_CABAL_DIR)/ghc-cabal.hs | $$(dir $$@)/. bootstrapping/.
        "$(GHC)" $(SRC_HC_OPTS) --make $(GHC_CABAL_DIR)/ghc-cabal.hs -o $@ \
               -Wall $(WERROR) \
@@ -51,10 +55,36 @@ $(GHC_CABAL_DIR)_dist-dummy-ghc_MODULES = dummy-ghc
 $(GHC_CABAL_DIR)_dist-dummy-ghc_PROG    = dummy-ghc$(exeext)
 
 # depend on project.mk, so we pick up the new version number if it changes.
-$(GHC_CABAL_DIR)/dist-dummy-ghc/build/dummy-ghc.hs : $(GHC_CABAL_DIR)/ghc.mk mk/project.mk | $$(dir $$@)/.
-       echo "import System.Environment; import System.Cmd; import System.Exit" >$@
-       echo "main :: IO ()" >>$@
-       echo "main = do args <- getArgs; if args == [\"--numeric-version\"] then putStrLn \"$(ProjectVersion)\" else do e <- rawSystem \"$(GHC_STAGE0)\" args; exitWith e" >>$@
+$(GHC_CABAL_DIR)/dist-dummy-ghc/build/dummy-ghc.hs : $(GHC_CABAL_DIR)/ghc.mk $(MKDIRHIER) mk/project.mk compiler/main/DynFlags.hs
+       "$(MKDIRHIER)" $(dir $@)
+       "$(RM)" $(RM_OPTS) $@
+       echo 'import System.Environment'                                  >> $@
+       echo 'import System.Cmd'                                          >> $@
+       echo 'import System.Exit'                                         >> $@
+       echo 'main :: IO ()'                                              >> $@
+       echo 'main = do args <- getArgs'                                  >> $@
+       echo '          case args of'                                     >> $@
+       echo '              ["--numeric-version"] ->'                     >> $@
+       echo '                  putStrLn "$(ProjectVersion)"'             >> $@
+       echo '              ["--supported-languages"] ->'                 >> $@
+       echo '                  mapM_ putStrLn extensions'                >> $@
+       echo '              _ ->'                                         >> $@
+       echo '                  do e <- rawSystem "$(GHC_STAGE0)" args'   >> $@
+       echo '                     exitWith e'                            >> $@
+# This unpleasant sed script grabs the lines between the
+#      xFlags ::
+# line and the
+#   ]
+# line of compiler/main/DynFlags.hs, and if they look like
+#   ( "PostfixOperators", ...
+# then it translates them into
+#   ["PostfixOperators"] ++
+# Tabs are a pain to handle portably with sed, so rather than worrying
+# about them we just use tr to remove them all before we start.
+       echo 'extensions :: [String]'                                     >> $@
+       echo 'extensions ='                                               >> $@
+       '$(TR)' -d '\t' < compiler/main/DynFlags.hs | '$(SED)' '/^xFlags/,/]/s/^ *( *\("[^"]*"\)[^"]*/  [\1] ++/p;d' >> $@
+       echo '  []'                                                       >> $@
 
 # We don't build dummy-ghc with Cabal, so we need to pass -package
 # flags manually