summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--compiler/ghc.mk18
-rw-r--r--ghc.mk5
-rw-r--r--ghc/ghc.mk14
-rw-r--r--includes/RtsFlags.h3
-rw-r--r--includes/ghc.mk4
-rw-r--r--mk/config.mk.in2
-rw-r--r--mk/tree.mk1
-rw-r--r--rts/ghc.mk12
-rw-r--r--rules/build-dependencies.mk50
-rw-r--r--rules/build-package.mk2
-rw-r--r--rules/build-prog.mk4
-rw-r--r--utils/mkdependC/Makefile15
-rw-r--r--utils/mkdependC/ghc.mk23
-rw-r--r--utils/mkdependC/mkdependC.prl236
14 files changed, 76 insertions, 313 deletions
diff --git a/compiler/ghc.mk b/compiler/ghc.mk
index f2a4fc5310..abc3788705 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 56be5faf66..f5d0d9d7d6 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 a3973bf79d..1f0b287ca5 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 778fccf40a..a6b4d2cc80 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 ef98e74531..14a99f8611 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 07b0c79359..a400af902e 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 9fb305f347..6fab46022e 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 20a3356cf3..c3d7eb6e6b 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 dfb98d2c65..a2bae25963 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 9e1ab7acf2..4005c73179 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 0e8a89791b..b88a2bb557 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 91a213c022..0000000000
--- 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 229e3ee40e..0000000000
--- 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 e1f8f39fc0..0000000000
--- 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);
-$_ = <OMKF>;
-while ($_ && $_ ne $Begin_magic_str) { # copy through, 'til Begin_magic_str
- print $_;
- $_ = <OMKF>;
-}
-while ($_ && $_ ne $End_magic_str) { # delete 'til End_magic_str
- $_ = <OMKF>;
-}
-# insert dependencies
-print $Begin_magic_str;
-print @Depend_lines;
-print $End_magic_str;
-while (<OMKF>) { # 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: /<dir>/..
- $str =~ s|/\.[^.][^/]*/\.\.||g; # nuke: /./.. (and others)
- $str =~ s|"||g;
- $str =~ s| \./| |;
- $str;
-}