X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=glafp-utils%2FmkdependC%2FmkdependC.prl;h=d879e7f4f767cbf9b2dac708098977bc142eb927;hb=7516738a036aac81e165d5e0a4973f1b1585a855;hp=b0c4f4f6a46b9b1f4d542b6abf2b6fe7dd15553b;hpb=1f1792c9d1db494bd5c7523c785d9cbaefcedbfe;p=ghc-hetmet.git diff --git a/glafp-utils/mkdependC/mkdependC.prl b/glafp-utils/mkdependC/mkdependC.prl index b0c4f4f..d879e7f 100644 --- a/glafp-utils/mkdependC/mkdependC.prl +++ b/glafp-utils/mkdependC/mkdependC.prl @@ -2,7 +2,7 @@ # This stub of perl assumes that the following two # variables are prepended: # -# TMPDIR CPP +# DEFAULT_TMPDIR CPP # # ToDo: strip out all the .h junk # @@ -15,23 +15,27 @@ $Dashdashes_seen = 0; $Begin_magic_str = "# DO NOT DELETE: Beginning of C dependencies\n"; $End_magic_str = "# DO NOT DELETE: End of C dependencies\n"; -$Obj_suffix = '.o'; +$Obj_suffix = 'o'; @Defines = (); $Include_dirs = ''; $Makefile = ''; @Src_files = (); +@File_suffix = (); +$baseName=''; 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 = ''; + sub quit_upon_signal { - if (-f "$Tmp_prefix.i") { - print STDERR "Deleting $Tmp_prefix.i .. \n"; - unlink "$Tmp_prefix.i"; + if (-f $tempfile) { + print STDERR "Deleting $tempfile .. \n"; + unlink $tempfile; } } $SIG{'INT'} = 'quit_upon_signal'; @@ -48,7 +52,6 @@ if ( ! $Makefile && -f 'makefile' ) { } @Depend_lines = (); -%Depend_seen = (); print STDERR "Include_dirs=$Include_dirs\n" if $Verbose; @@ -58,7 +61,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; - ($of = $sf) =~ s/\.(c|hc)$/$Obj_suffix/; + ($baseName = $sf) =~ s/\.(c|hc)$//; &slurp_file($sf, 'fh00'); } @@ -109,6 +112,9 @@ sub mangle_command_line_args { $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($_) . "\n"; } elsif ( /^-es/ ) { @@ -145,65 +151,49 @@ 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"); if ($result != 0) { unlink($tempfile); exit($result); }; - open($fhandle, $tempfile) || die "$Pgm: Can't open $fname: $!\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 bother with "literate" .h files (.lh); we'll just - # depend on the de-litified versions (which have better info) - # don't let a file depend on itself - next line if /^\/usr\/include/; - # Hack - the cygwin32 dir structure 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 /\.lh$/; - next line if $_ eq $fname; - - print STDERR "$fname :: $_\n" if $Verbose; - - # ToDo: some sanity checks that we still have something reasonable? - - $depend = "$of : $_\n"; - next line if $Depend_seen{$depend}; # already seen this one... - - # OK, it's a new one. - push (@Depend_lines, $depend); - $Depend_seen{$depend} = 1; + 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($tempname); - $tempname = ''; # for quit_upon_signal + unlink($tempfile); + $tempfile = ''; # for quit_upon_signal } sub tidy_dir_names { # rm various pernicious dir-name combinations...