From aea784af873f089a40af71849d83f59008562a58 Mon Sep 17 00:00:00 2001 From: Ian Lynagh Date: Wed, 9 Dec 2009 12:39:29 +0000 Subject: [PATCH] Eliminate mkdependC We now just call gcc to get the dependencies directly --- compiler/ghc.mk | 18 ++-- ghc.mk | 5 +- ghc/ghc.mk | 14 ++- includes/RtsFlags.h | 3 + includes/ghc.mk | 4 +- mk/config.mk.in | 2 - mk/tree.mk | 1 - rts/ghc.mk | 12 +-- rules/build-dependencies.mk | 50 +++++++-- rules/build-package.mk | 2 +- rules/build-prog.mk | 4 +- utils/mkdependC/Makefile | 15 --- utils/mkdependC/ghc.mk | 23 ---- utils/mkdependC/mkdependC.prl | 236 ----------------------------------------- 14 files changed, 76 insertions(+), 313 deletions(-) delete mode 100644 utils/mkdependC/Makefile delete mode 100644 utils/mkdependC/ghc.mk delete mode 100644 utils/mkdependC/mkdependC.prl diff --git a/compiler/ghc.mk b/compiler/ghc.mk index f2a4fc5..abc3788 100644 --- a/compiler/ghc.mk +++ b/compiler/ghc.mk @@ -29,6 +29,12 @@ endef compiler_CONFIG_HS = compiler/main/Config.hs +# This is just to avoid generating a warning when generating deps +# involving RtsFlags.h +compiler_stage1_MKDEPENDC_OPTS = -DMAKING_GHC_BUILD_SYSTEM_DEPENDENCIES +compiler_stage2_MKDEPENDC_OPTS = -DMAKING_GHC_BUILD_SYSTEM_DEPENDENCIES +compiler_stage3_MKDEPENDC_OPTS = -DMAKING_GHC_BUILD_SYSTEM_DEPENDENCIES + ifneq "$(BINDIST)" "YES" compiler/stage1/package-data.mk : $(compiler_CONFIG_HS) compiler/stage2/package-data.mk : $(compiler_CONFIG_HS) @@ -453,13 +459,13 @@ ifeq "$(stage)" "3" $(eval $(call build-package,compiler,stage3,2)) endif -$(compiler_stage1_depfile) : compiler/stage1/$(PLATFORM_H) -$(compiler_stage2_depfile) : compiler/stage2/$(PLATFORM_H) -$(compiler_stage3_depfile) : compiler/stage3/$(PLATFORM_H) +$(compiler_stage1_depfile_haskell) : compiler/stage1/$(PLATFORM_H) +$(compiler_stage2_depfile_haskell) : compiler/stage2/$(PLATFORM_H) +$(compiler_stage3_depfile_haskell) : compiler/stage3/$(PLATFORM_H) -$(compiler_stage1_depfile) : $(includes_H_CONFIG) $(includes_H_PLATFORM) $(includes_GHCCONSTANTS) $(includes_DERIVEDCONSTANTS) $(PRIMOP_BITS) -$(compiler_stage2_depfile) : $(includes_H_CONFIG) $(includes_H_PLATFORM) $(includes_GHCCONSTANTS) $(includes_DERIVEDCONSTANTS) $(PRIMOP_BITS) -$(compiler_stage3_depfile) : $(includes_H_CONFIG) $(includes_H_PLATFORM) $(includes_GHCCONSTANTS) $(includes_DERIVEDCONSTANTS) $(PRIMOP_BITS) +$(compiler_stage1_depfile_haskell) : $(includes_H_CONFIG) $(includes_H_PLATFORM) $(includes_GHCCONSTANTS) $(includes_DERIVEDCONSTANTS) $(PRIMOP_BITS) +$(compiler_stage2_depfile_haskell) : $(includes_H_CONFIG) $(includes_H_PLATFORM) $(includes_GHCCONSTANTS) $(includes_DERIVEDCONSTANTS) $(PRIMOP_BITS) +$(compiler_stage3_depfile_haskell) : $(includes_H_CONFIG) $(includes_H_PLATFORM) $(includes_GHCCONSTANTS) $(includes_DERIVEDCONSTANTS) $(PRIMOP_BITS) # Every Constants.o object file depends on includes/GHCConstants.h: $(eval $(call compiler-hs-dependency,Constants,$(includes_GHCCONSTANTS) includes/HaskellConstants.hs)) diff --git a/ghc.mk b/ghc.mk index 56be5fa..f5d0d9d 100644 --- a/ghc.mk +++ b/ghc.mk @@ -486,7 +486,6 @@ BUILD_DIRS = ifneq "$(BINDIST)" "YES" BUILD_DIRS += \ - $(GHC_MKDEPENDC_DIR) \ $(GHC_MKDIRHIER_DIR) endif @@ -682,8 +681,8 @@ compiler/stage1/package-data.mk : \ # These are necessary because the bootstrapping compiler may not know # about cross-package dependencies: -$(compiler_stage1_depfile) : $(BOOT_LIBS) -$(ghc_stage1_depfile) : $(compiler_stage1_v_LIB) +$(compiler_stage1_depfile_haskell) : $(BOOT_LIBS) +$(ghc_stage1_depfile_haskell) : $(compiler_stage1_v_LIB) # A few careful dependencies between bootstrapping packages. When we # can rely on the stage 0 compiler being able to generate diff --git a/ghc/ghc.mk b/ghc/ghc.mk index a3973bf..1f0b287 100644 --- a/ghc/ghc.mk +++ b/ghc/ghc.mk @@ -18,6 +18,14 @@ ghc_stage1_HC_OPTS = $(GhcStage1HcOpts) ghc_stage2_HC_OPTS = $(GhcStage2HcOpts) ghc_stage3_HC_OPTS = $(GhcStage3HcOpts) +ghc_stage2_CC_OPTS = -Iincludes +ghc_stage3_CC_OPTS = -Iincludes + +ghc_stage1_C_FILES_NODEPS = ghc/hschooks.c + +ghc_stage2_MKDEPENDC_OPTS = -DMAKING_GHC_BUILD_SYSTEM_DEPENDENCIES +ghc_stage3_MKDEPENDC_OPTS = -DMAKING_GHC_BUILD_SYSTEM_DEPENDENCIES + ifeq "$(GhcWithInterpreter)" "YES" ghc_stage2_HC_OPTS += -DGHCI ghc_stage3_HC_OPTS += -DGHCI @@ -118,9 +126,9 @@ ghc/stage2/build/tmp/$(ghc_stage2_PROG) : $(compiler_stage2_v_LIB) ghc/stage3/build/tmp/$(ghc_stage3_PROG) : $(compiler_stage3_v_LIB) # Modules here import HsVersions.h, so we need ghc_boot_platform.h -$(ghc_stage1_depfile) : compiler/stage1/$(PLATFORM_H) -$(ghc_stage2_depfile) : compiler/stage2/$(PLATFORM_H) -$(ghc_stage3_depfile) : compiler/stage3/$(PLATFORM_H) +$(ghc_stage1_depfile_haskell) : compiler/stage1/$(PLATFORM_H) +$(ghc_stage2_depfile_haskell) : compiler/stage2/$(PLATFORM_H) +$(ghc_stage3_depfile_haskell) : compiler/stage3/$(PLATFORM_H) all_ghc_stage1 : $(GHC_STAGE1) all_ghc_stage2 : $(GHC_STAGE2) diff --git a/includes/RtsFlags.h b/includes/RtsFlags.h index 778fccf..a6b4d2c 100644 --- a/includes/RtsFlags.h +++ b/includes/RtsFlags.h @@ -1,2 +1,5 @@ +#ifndef MAKING_GHC_BUILD_SYSTEM_DEPENDENCIES #warning RtsFlags.h is DEPRECATED; please just #include "Rts.h" +#endif + #include "Rts.h" diff --git a/includes/ghc.mk b/includes/ghc.mk index ef98e74..14a99f8 100644 --- a/includes/ghc.mk +++ b/includes/ghc.mk @@ -129,7 +129,7 @@ includes_dist-derivedconstants_PROG = mkDerivedConstants$(exeext) $(eval $(call build-prog,includes,dist-derivedconstants,0)) -$(includes_dist-derivedconstants_depfile) : $(includes_H_CONFIG) $(includes_H_PLATFORM) $(wildcard includes/*.h) $(wildcard rts/*.h) +$(includes_dist-derivedconstants_depfile_c_asm) : $(includes_H_CONFIG) $(includes_H_PLATFORM) $(wildcard includes/*.h) $(wildcard rts/*.h) includes/dist-derivedconstants/build/mkDerivedConstants.o : $(includes_H_CONFIG) $(includes_H_PLATFORM) ifneq "$(BINDIST)" "YES" @@ -159,7 +159,7 @@ includes_dist-ghcconstants_CC_OPTS = -DGEN_HASKELL $(eval $(call build-prog,includes,dist-ghcconstants,0)) ifneq "$(BINDIST)" "YES" -$(includes_dist-ghcconstants_depfile) : $(includes_H_CONFIG) $(includes_H_PLATFORM) $(wildcard includes/*.h) $(wildcard rts/*.h) +$(includes_dist-ghcconstants_depfile_c_asm) : $(includes_H_CONFIG) $(includes_H_PLATFORM) $(wildcard includes/*.h) $(wildcard rts/*.h) includes/dist-ghcconstants/build/mkDerivedConstants.o : $(includes_H_CONFIG) $(includes_H_PLATFORM) diff --git a/mk/config.mk.in b/mk/config.mk.in index 07b0c79..a400af9 100644 --- a/mk/config.mk.in +++ b/mk/config.mk.in @@ -409,7 +409,6 @@ GHC_GENPRIMOP_PGM = genprimopcode$(exeext) GHC_GENAPPLY_PGM = genapply$(exeext) GHC_CABAL_PGM = ghc-cabal$(exeext) GHC_PKG_PGM = ghc-pkg$(exeext) -GHC_MKDEPENDC_PGM = mkdependC GHC_LTX_PGM = ltx$(exeext) GHC_MKDIRHIER_PGM = mkdirhier GHC_LNDIR_PGM = lndir @@ -433,7 +432,6 @@ LNDIR = $(GHC_LNDIR_DIR)/$(GHC_LNDIR_PGM) UNLIT = $(INPLACE_LIB)/$(GHC_UNLIT_PGM) TOUCHY = $(INPLACE_LIB)/$(GHC_TOUCHY_PGM) MKDIRHIER = $(INPLACE_BIN)/$(GHC_MKDIRHIER_PGM) -MKDEPENDC = $(INPLACE_BIN)/$(GHC_MKDEPENDC_PGM) GHC_CABAL_INPLACE = $(INPLACE_BIN)/$(GHC_CABAL_PGM) GENAPPLY_INPLACE = $(INPLACE_BIN)/$(GHC_GENAPPLY_PGM) GHC_PKG_INPLACE = $(INPLACE_BIN)/$(GHC_PKG_PGM) diff --git a/mk/tree.mk b/mk/tree.mk index 9fb305f..6fab460 100644 --- a/mk/tree.mk +++ b/mk/tree.mk @@ -23,7 +23,6 @@ GHC_RTS_DIR = rts GHC_DRIVER_DIR = driver GHC_COMPAT_DIR = compat -GHC_MKDEPENDC_DIR = $(GHC_UTILS_DIR)/mkdependC GHC_LTX_DIR = $(GHC_UTILS_DIR)/ltx GHC_LNDIR_DIR = $(GHC_UTILS_DIR)/lndir GHC_MKDIRHIER_DIR = $(GHC_UTILS_DIR)/mkdirhier diff --git a/rts/ghc.mk b/rts/ghc.mk index 20a3356..c3d7eb6 100644 --- a/rts/ghc.mk +++ b/rts/ghc.mk @@ -18,6 +18,7 @@ rts_dist_HC = $(GHC_STAGE1) # merge GhcLibWays and GhcRTSWays but strip out duplicates rts_WAYS = $(GhcLibWays) $(filter-out $(GhcLibWays),$(GhcRTSWays)) +rts_dist_WAYS = $(rts_WAYS) ALL_RTS_LIBS = rts/dist/build/libHSrtsmain.a \ $(foreach way,$(rts_WAYS),rts/dist/build/libHSrts$($(way)_libsuf)) @@ -354,15 +355,8 @@ endif # ----------------------------------------------------------------------------- # dependencies -# Hack: we define every way-related option here, so that we get (hopefully) -# a superset of the dependencies. To do this properly, we should generate -# a different set of dependencies for each way. Further hack: PROFILING and -# TICKY_TICKY can't be used together, so we omit TICKY_TICKY for now. -rts_MKDEPENDC_OPTS += -DPROFILING -DTHREADED_RTS -DDEBUG -rts_MKDEPENDC_OPTS += -Irts/sm - rts_WAYS_DASHED = $(subst $(space),,$(patsubst %,-%,$(strip $(rts_WAYS)))) -rts_dist_depfile = rts/dist/build/.depend$(rts_WAYS_DASHED) +rts_dist_depfile_base = rts/dist/build/.depend$(rts_WAYS_DASHED) rts_dist_C_SRCS = $(rts_C_SRCS) $(rts_thr_EXTRA_C_SRCS) rts_dist_S_SRCS = $(rts_S_SRCS) @@ -370,7 +364,7 @@ rts_dist_C_FILES = $(rts_C_SRCS) $(rts_thr_EXTRA_C_SRCS) $(rts_S_SRCS) $(eval $(call build-dependencies,rts,dist)) -$(rts_dist_depfile) : libffi/dist-install/build/ffi.h +$(rts_dist_depfile_c_asm) : libffi/dist-install/build/ffi.h #----------------------------------------------------------------------------- # libffi stuff diff --git a/rules/build-dependencies.mk b/rules/build-dependencies.mk index dfb98d2..a2bae25 100644 --- a/rules/build-dependencies.mk +++ b/rules/build-dependencies.mk @@ -10,35 +10,48 @@ # # ----------------------------------------------------------------------------- - define build-dependencies # args: $1 = dir, $2 = distdir +$1_$2_depfile_haskell = $$($1_$2_depfile_base).haskell +$1_$2_depfile_c_asm = $$($1_$2_depfile_base).c_asm + +$1_$2_C_FILES_DEPS = $$(filter-out $$($1_$2_C_FILES_NODEPS),$$($1_$2_C_FILES)) + ifeq "$$($1_$2_ghc_ge_609)" "YES" -$1_$2_MKDEPENDHS_FLAGS = -include-pkg-deps -dep-makefile $$($1_$2_depfile) $$(foreach way,$$(filter-out v,$$($1_$2_WAYS)),-dep-suffix $$(way)) +$1_$2_MKDEPENDHS_FLAGS = -include-pkg-deps -dep-makefile $$($1_$2_depfile_haskell).tmp $$(foreach way,$$(filter-out v,$$($1_$2_WAYS)),-dep-suffix $$(way)) else -$1_$2_MKDEPENDHS_FLAGS = -optdep--include-pkg-deps -optdep-f -optdep$$($1_$2_depfile) $$(foreach way,$$(filter-out v,$$($1_$2_WAYS)),-optdep-s -optdep$$(way)) +$1_$2_MKDEPENDHS_FLAGS = -optdep--include-pkg-deps -optdep-f -optdep$$($1_$2_depfile_haskell).tmp $$(foreach way,$$(filter-out v,$$($1_$2_WAYS)),-optdep-s -optdep$$(way)) endif ifneq "$$($1_$2_NO_BUILD_DEPS)" "YES" -$$($1_$2_depfile) : $$(MKDEPENDC) $$($1_$2_HS_SRCS) $$($1_$2_HS_BOOT_SRCS) $$($1_$2_HC_MK_DEPEND_DEP) $$($1_$2_C_FILES) $$($1_$2_S_FILES) | $$$$(dir $$$$@)/. +$$($1_$2_depfile_haskell) : $$($1_$2_HS_SRCS) $$($1_$2_HS_BOOT_SRCS) $$($1_$2_HC_MK_DEPEND_DEP) | $$$$(dir $$$$@)/. "$$(RM)" $$(RM_OPTS) $$@.tmp touch $$@.tmp -ifneq "$$($1_$2_C_SRCS)$$($1_$2_S_SRCS)" "" - "$$(MKDEPENDC)" -f $$($1_$2_depfile).tmp $$($1_MKDEPENDC_OPTS) $$(foreach way,$$($1_WAYS),-s $$(way)) -- $$($1_$2_v_ALL_CC_OPTS) -- $$($1_$2_C_FILES) $$($1_$2_S_FILES) - sed -e "s|$1/\([^ :]*o[ :]\)|$1/$2/build/\1|g" -e "s|$$(TOP)/||" -e "s|$2/build/$2/build|$2/build|g" <$$($1_$2_depfile).tmp >$$($1_$2_depfile) -endif ifneq "$$($1_$2_HS_SRCS)" "" "$$($1_$2_HC_MK_DEPEND)" -M $$($1_$2_MKDEPENDHS_FLAGS) \ $$(filter-out -split-objs, $$($1_$2_v_ALL_HC_OPTS)) \ $$($1_$2_HS_SRCS) endif - echo "$1_$2_depfile_EXISTS = YES" >> $$@ + echo "$1_$2_depfile_haskell_EXISTS = YES" >> $$@.tmp ifneq "$$($1_$2_SLASH_MODS)" "" for dir in $$(sort $$(foreach mod,$$($1_$2_SLASH_MODS),$1/$2/build/$$(dir $$(mod)))); do \ if test ! -d $$$$dir; then mkdir -p $$$$dir; fi \ done endif + mv $$@.tmp $$@ + +$$($1_$2_depfile_c_asm) : $$($1_$2_C_FILES_DEPS) $$($1_$2_S_FILES) | $$$$(dir $$$$@)/. + "$$(RM)" $$(RM_OPTS) $$@.tmp + touch $$@.tmp +ifneq "$$(strip $$($1_$2_C_FILES_DEPS)$$($1_$2_S_FILES))" "" + $$(foreach f,$$($1_$2_C_FILES_DEPS) $$($1_$2_S_FILES), \ + $$(foreach w,$$($1_$2_WAYS), \ + $$(call addCFileDeps,$1,$2,$$($1_$2_depfile_c_asm),$$f,$$w))) + "$$(RM)" $$(RM_OPTS) $$@.bit +endif + echo "$1_$2_depfile_c_asm_EXISTS = YES" >> $$@.tmp + mv $$@.tmp $$@ endif # $1_$2_NO_BUILD_DEPS @@ -46,10 +59,11 @@ endif # $1_$2_NO_BUILD_DEPS # munge the dependencies it generates to refer to the correct targets. # Seems as good a place as any to attach the unlit dependency -$$($1_$2_depfile) : $$(UNLIT) +$$($1_$2_depfile_haskell) : $$(UNLIT) ifneq "$$(NO_INCLUDE_DEPS)" "YES" -include $$($1_$2_depfile) +include $$($1_$2_depfile_haskell) +include $$($1_$2_depfile_c_asm) else ifeq "$$(DEBUG)" "YES" $$(warning not building dependencies in $1) @@ -57,3 +71,17 @@ endif endif endef + +define addCFileDeps + +# $1 = dir +# $2 = distdir +# $3 = depfile +# $4 = file +# $5 = way +# The formatting of this definition (e.g. the blank line above) is +# important, in order to get make to generate the right makefile code. + $(CPP) $($1_$2_MKDEPENDC_OPTS) $($1_$2_$5_ALL_CC_OPTS) $($(basename $4)_CC_OPTS) -MM $4 -MF $3.bit + sed -e "1s|\.o|\.$($5_osuf)|" -e "1s|^|$(dir $4)|" -e "1s|$1/|$1/$2/build/|" -e "s|$(TOP)/||g" -e "s|$2/build/$2/build|$2/build|g" $3.bit >> $3.tmp +endef + diff --git a/rules/build-package.mk b/rules/build-package.mk index 9e1ab7a..4005c73 100644 --- a/rules/build-package.mk +++ b/rules/build-package.mk @@ -119,7 +119,7 @@ $(call includes-sources,$1,$2) # We must use a different dependency file if $(GhcLibWays) changes, so # encode the ways into the name of the file. $1_$2_WAYS_DASHED = $$(subst $$(space),,$$(patsubst %,-%,$$(strip $$($1_$2_WAYS)))) -$1_$2_depfile = $1/$2/build/.depend$$($1_$2_WAYS_DASHED) +$1_$2_depfile_base = $1/$2/build/.depend$$($1_$2_WAYS_DASHED) $(call build-dependencies,$1,$2) diff --git a/rules/build-prog.mk b/rules/build-prog.mk index 0e8a897..b88a2bb 100644 --- a/rules/build-prog.mk +++ b/rules/build-prog.mk @@ -72,12 +72,14 @@ endif else ifneq "$$(BINDIST)" "YES" +$1_$2_WAYS = v + $(call hs-sources,$1,$2) $(call c-sources,$1,$2) # --- DEPENDENCIES -$1_$2_depfile = $1/$2/build/.depend +$1_$2_depfile_base = $1/$2/build/.depend $(call build-dependencies,$1,$2) diff --git a/utils/mkdependC/Makefile b/utils/mkdependC/Makefile deleted file mode 100644 index 91a213c..0000000 --- a/utils/mkdependC/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -# ----------------------------------------------------------------------------- -# -# (c) 2009 The University of Glasgow -# -# This file is part of the GHC build system. -# -# To understand how the build system works and how to modify it, see -# http://hackage.haskell.org/trac/ghc/wiki/Building/Architecture -# http://hackage.haskell.org/trac/ghc/wiki/Building/Modifying -# -# ----------------------------------------------------------------------------- - -dir = utils/mkdependC -TOP = ../.. -include $(TOP)/mk/sub-makefile.mk diff --git a/utils/mkdependC/ghc.mk b/utils/mkdependC/ghc.mk deleted file mode 100644 index 229e3ee..0000000 --- a/utils/mkdependC/ghc.mk +++ /dev/null @@ -1,23 +0,0 @@ -# ----------------------------------------------------------------------------- -# -# (c) 2009 The University of Glasgow -# -# This file is part of the GHC build system. -# -# To understand how the build system works and how to modify it, see -# http://hackage.haskell.org/trac/ghc/wiki/Building/Architecture -# http://hackage.haskell.org/trac/ghc/wiki/Building/Modifying -# -# ----------------------------------------------------------------------------- - -$(MKDEPENDC) : utils/mkdependC/mkdependC.prl | $$(dir $$@)/. - "$(RM)" $(RM_OPTS) $@ - echo '#!$(PERL)' >> $@ - echo '$$DEFAULT_TMPDIR = "$(DEFAULT_TMPDIR)";' >> $@ - echo '$$CPP = "$(CPP)";' >> $@ - echo '$$BUILDPLATFORM = "$(BUILDPLATFORM)";' >> $@ - cat utils/mkdependC/mkdependC.prl >> $@ - $(EXECUTABLE_FILE) $@ - -$(eval $(call all-target,utils/mkdependC,$(MKDEPENDC))) -$(eval $(call clean-target,utils/mkdependC,,$(MKDEPENDC))) diff --git a/utils/mkdependC/mkdependC.prl b/utils/mkdependC/mkdependC.prl deleted file mode 100644 index e1f8f39..0000000 --- a/utils/mkdependC/mkdependC.prl +++ /dev/null @@ -1,236 +0,0 @@ -# -# This perl script template assumes that definitions for -# the following variables are prepended: -# -# DEFAULT_TMPDIR CPP BUILDPLATFORM -# -# ToDo: strip out all the .h junk -# - -use File::Temp qw/ tempfile tempdir /;; - -($Pgm = $0) =~ s/.*\/([^\/]+)$/\1/; -$Usage = "usage: $Pgm: not done yet\n"; - -$Status = 0; # just used for exit() status -$Verbose = 0; -$Dashdashes_seen = 0; - -$Begin_magic_str = "# DO NOT DELETE: Beginning of C dependencies"; -$End_magic_str = "# DO NOT DELETE: End of C dependencies"; -$Obj_suffix = 'o'; -@Defines = (); -$Include_dirs = ''; -$Makefile = ''; -@Src_files = (); -@File_suffix = (); -$baseName=''; -$ignore_output='> /dev/null'; - -if ( ${BUILDPLATFORM} eq "i386-unknown-mingw32" ) { - # Assuming the underlying perl uses cmd to exec system() calls. - $ignore_output = ">nul"; -} - -if ( $ENV{'TMPDIR'} ) { # where to make tmp file names - $Tmp_prefix = $ENV{'TMPDIR'} . "/mkdependC$$"; -} else { - $Tmp_prefix ="${DEFAULT_TMPDIR}/mkdependC$$"; - $ENV{'TMPDIR'} = "${DEFAULT_TMPDIR}"; # set the env var as well -} - -$tempfile = ''; - -sub quit_upon_signal { - if (-f $tempfile) { - print STDERR "Deleting $tempfile .. \n"; - unlink $tempfile; - } -} -$SIG{'INT'} = 'quit_upon_signal'; -$SIG{'QUIT'} = 'quit_upon_signal'; - -&mangle_command_line_args(); - -if ( ! $Makefile && -f 'makefile' ) { - $Makefile = 'makefile'; -} elsif ( ! $Makefile && -f 'Makefile') { - $Makefile = 'Makefile'; -} elsif ( ! $Makefile) { - die "$Pgm: no makefile or Makefile found\n"; -} - -@Depend_lines = (); - -print STDERR "Include_dirs=$Include_dirs\n" if $Verbose; - -foreach $sf (@Src_files) { - # just like lit-inputter - # except it puts each file through CPP and - # a de-commenter (not implemented); - # builds up @Depend_lines - print STDERR "Here we go for source file: $sf\n" if $Verbose; - ($baseName = $sf) =~ s/\.(c|hc)$//; - - &slurp_file($sf, 'fh00'); -} - -# Tiresome EOL termination issues -if ( ${BUILDPLATFORM} eq "i386-unknown-mingw32" ) { - $Begin_magic_str = $Begin_magic_str . "\r\n"; - $End_magic_str = $End_magic_str . "\r\n"; -} else { - $Begin_magic_str = $Begin_magic_str . "\n"; - $End_magic_str = $End_magic_str . "\n"; -} - -# OK, mangle the Makefile -unlink("$Makefile.bak"); -rename($Makefile,"$Makefile.bak"); -# now copy Makefile.bak into Makefile, rm'ing old dependencies -# and adding the new -open(OMKF,"< $Makefile.bak") || die "$Pgm: can't open $Makefile.bak: $!\n"; -open(NMKF,"> $Makefile") || die "$Pgm: can't open $Makefile: $!\n"; -binmode(OMKF); # Do not add stupid ^M's to the output on Win32 -binmode(NMKF); # Do not add stupid ^M's to the output on Win32 - -select(NMKF); -$_ = ; -while ($_ && $_ ne $Begin_magic_str) { # copy through, 'til Begin_magic_str - print $_; - $_ = ; -} -while ($_ && $_ ne $End_magic_str) { # delete 'til End_magic_str - $_ = ; -} -# insert dependencies -print $Begin_magic_str; -print @Depend_lines; -print $End_magic_str; -while () { # copy the rest through - print $_; -} -close(NMKF); -close(OMKF); -exit 0; - -sub mangle_command_line_args { - while($_ = $ARGV[0]) { - shift(@ARGV); - - if ( /^--$/ ) { - $Dashdashes_seen++; - - } elsif ( /^(-optc)?(-D.*)/ ) { # recognized wherever they occur - push(@Defines, $2); - } elsif ( /^(-optc)?(-I.*)/ ) { - $Include_dirs .= " $2"; - } elsif ( /^(-optc)?(-isystem.*)/ ) { - $Include_dirs .= " $2"; - - } elsif ($Dashdashes_seen != 1) { # not between -- ... -- - if ( /^-v$/ ) { - $Verbose++; - } elsif ( /^-f/ ) { - $Makefile = &grab_arg_arg($_); - } elsif ( /^-o/ ) { - $Obj_suffix = &grab_arg_arg($_); - } elsif ( /^-s/ ) { - local($suff) = &grab_arg_arg($_); - push(@File_suffix, $suff); - } elsif ( /^-bs/ ) { - $Begin_magic_str = &grab_arg_arg($_); - } elsif ( /^-es/ ) { - $End_magic_str = &grab_arg_arg($_); - } elsif ( /^-w/ ) { - $Width = &grab_arg_arg($_); - } elsif ( /^-/ ) { - print STDERR "$Pgm: unknown option ignored: $_\n"; - } else { - push(@Src_files, $_); - } - - } elsif ($Dashdashes_seen == 1) { # where we ignore unknown options - push(@Src_files,$_) if ! /^-/; - } - } -} - -sub grab_arg_arg { - local($option) = @_; - local($rest_of_arg); - - ($rest_of_arg = $option) =~ s/^-.//; - - if ($rest_of_arg) { - return($rest_of_arg); - } elsif ($#ARGV >= 0) { - local($temp) = $ARGV[0]; shift(@ARGV); - return($temp); - } else { - die "$Pgm: no argument following $option option\n"; - } -} - -sub slurp_file { # follows an example in the `open' item in perl man page - local($fname,$fhandle) = @_; - local($depend,$dep); # tmp - local(@Deps); - - $fhandle++; # a string increment - - $fname = &tidy_dir_names($fname); - - ($fh, $tempfile) = tempfile(DIR => '.', SUFFIX => '.d'); - close $fh; - - # ${CPP} better be 'gcc -E', or the -x option will fail... - # ..and the -MM & -MMD. - $result = system("${CPP} -MM -MMD $Include_dirs @Defines -x c $fname -o $tempfile $ignore_output"); - - if ($result != 0) { - # On the cheesy side..we do want to know what went wrong, so - # re-run the command. - $result = system("${CPP} -MM -MMD $Include_dirs @Defines -x c $fname -o $tempfile"); - if ($result != 0) { - unlink($tempfile); - exit($result); - } - }; - - local($dep_contents)=''; - local($deps)=''; - open($fhandle, $tempfile) || die "$Pgm: Can't open $tempfile: $!\n"; - - while (<$fhandle>) { - chop; - $dep_contents .= $_; - } - ($deps = $dep_contents) =~ s|^[^:]+:(.*)$|$1|g; - $deps =~ s| \\| |g; - - @Deps = split(/ +/, $deps); - - $depend = "$baseName.$Obj_suffix"; - foreach $suff (@File_suffix) { - $depend .= " $baseName.${suff}_$Obj_suffix"; - } - - foreach $dep (@Deps) { - push(@Depend_lines, "$depend: $dep\n") if $dep ne ''; - } - - close($fhandle); - unlink($tempfile); - $tempfile = ''; # for quit_upon_signal -} - -sub tidy_dir_names { # rm various pernicious dir-name combinations... - local($str) = @_; - - $str =~ s|/[^/.][^/]*/\.\.||g; # nuke: //.. - $str =~ s|/\.[^.][^/]*/\.\.||g; # nuke: /./.. (and others) - $str =~ s|"||g; - $str =~ s| \./| |; - $str; -} -- 1.7.10.4