X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=glafp-utils%2FmkdependC%2FmkdependC.prl;h=b8f853ab039218ce308145965772f5e518953c65;hb=776afe7766a4fe991dbb5a38595900ebd95d4d5a;hp=7c524bd4d85117019c274ee9f292f9122b09f347;hpb=0941edb00f785a11c2cb9432b7e5bbf180d18269;p=ghc-hetmet.git diff --git a/glafp-utils/mkdependC/mkdependC.prl b/glafp-utils/mkdependC/mkdependC.prl index 7c524bd..b8f853a 100644 --- a/glafp-utils/mkdependC/mkdependC.prl +++ b/glafp-utils/mkdependC/mkdependC.prl @@ -1,8 +1,8 @@ # -# This stub of perl assumes that the following two -# variables are prepended: +# This perl script template assumes that definitions for +# the following variables are prepended: # -# TMPDIR CPP +# DEFAULT_TMPDIR CPP BUILDPLATFORM # # ToDo: strip out all the .h junk # @@ -21,12 +21,19 @@ $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 ="${TMPDIR}/mkdependC$$"; - $ENV{'TMPDIR'} = "${TMPDIR}"; # set the env var as well + $Tmp_prefix ="${DEFAULT_TMPDIR}/mkdependC$$"; + $ENV{'TMPDIR'} = "${DEFAULT_TMPDIR}"; # set the env var as well } $tempfile = ''; @@ -51,7 +58,6 @@ if ( ! $Makefile && -f 'makefile' ) { } @Depend_lines = (); -%Depend_seen = (); print STDERR "Include_dirs=$Include_dirs\n" if $Verbose; @@ -61,7 +67,7 @@ foreach $sf (@Src_files) { # a de-commenter (not implemented); # builds up @Depend_lines print STDERR "Here we go for source file: $sf\n" if $Verbose; - ($bf = $sf) =~ s/\.(c|hc)$//; + ($baseName = $sf) =~ s/\.(c|hc)$//; &slurp_file($sf, 'fh00'); } @@ -73,6 +79,9 @@ rename($Makefile,"$Makefile.bak"); # 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 @@ -100,10 +109,10 @@ sub mangle_command_line_args { if ( /^--$/ ) { $Dashdashes_seen++; - } elsif ( /^-D(.*)/ ) { # recognized wherever they occur - push(@Defines, $_); - } elsif ( /^-I/ ) { - $Include_dirs .= " $_"; + } elsif ( /^(-optc)?(-D.*)/ ) { # recognized wherever they occur + push(@Defines, $2); + } elsif ( /^(-optc)?(-I.*)/ ) { + $Include_dirs .= " $2"; } elsif ($Dashdashes_seen != 1) { # not between -- ... -- if ( /^-v$/ ) { @@ -151,65 +160,52 @@ sub grab_arg_arg { sub slurp_file { # follows an example in the `open' item in perl man page local($fname,$fhandle) = @_; - local($depend); # tmp + local($depend,$dep); # tmp + local(@Deps); + $fhandle++; # a string increment $fname = &tidy_dir_names($fname); - $tempfile = "$Tmp_prefix.i"; + ($tempfile = $fname) =~ s/\.[^\.]*$/\.d/; + $tempfile =~ s|.*/([^/]+)$|$1|g; # ${CPP} better be 'gcc -E', or the -x option will fail... - $result = system("${CPP} $Include_dirs @Defines -x c $fname -o $tempfile"); + # ..and the -MM & -MMD. + $result = system("${CPP} -MM -MMD $Include_dirs @Defines -x c $fname $ignore_output"); + if ($result != 0) { - unlink($tempfile); - exit($result); + # 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 "); + if ($result != 0) { + unlink($tempfile); + exit($result); + } }; + local($dep_contents)=''; + local($deps)=''; open($fhandle, $tempfile) || die "$Pgm: Can't open $tempfile: $!\n"; - line: while (<$fhandle>) { - next line if ! /^#/; - next line if /^#(ident|pragma)/; - chop; # rm trailing newline - - $_ = &tidy_dir_names($_); - - # strip junk off the front and back - $_ =~ s/^#\s+\d+\s+//; - $_ =~ s/[ 0-9]*$//; - - # a little bit of ad-hoc fiddling now: - # don't bother w/ dependencies on /usr/include stuff - # don't bother if it looks like a GCC built-in hdr file - # don't bother with funny yacc-ish files - # don't let a file depend on itself - next line if /^\/usr\/include/; - # Hack - the cygwin32 dir structupre is odd! - next line if /H-i386-cygwin32\/i386-cygwin32/; - next line if /H-i386-cygwin32\/lib\/gcc-lib\/i386-cygwin32/; - next line if /\/gcc-lib\/[^\/\n]+\/[\.0-9]+\/include\//; - next line if /\/gnu\/[^-\/]+-[^-\/]+-[^-\/]+\/include\//; - next line if /\/yaccpar/; - next line if /\/bison\.(simple|hairy)/; - next line if $_ eq $fname; - - print STDERR "$fname :: $_\n" if $Verbose; - - # ToDo: some sanity checks that we still have something reasonable? - - $int_file = $_; - $depend = "$bf.$Obj_suffix "; - foreach $suff (@File_suffix) { - $depend .= "$bf.${suff}_$Obj_suffix "; - } - $depend .= " : $int_file\n"; - - next line if $Depend_seen{$depend}; # already seen this one... - # OK, it's a new one. - $Depend_seen{$depend} = 1; - - push (@Depend_lines, $depend); + 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