X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=glafp-utils%2FmkdependC%2FmkdependC.prl;h=f7af53ac3c832b002a610a0bddb4d366f0a0e83c;hb=cbc7228335a0489362d8f5deadaecacc8731a4ce;hp=343818095b0c9c34eefb1d7ba5b483a702b933af;hpb=777a6a36a9cb3e693ee1486a20afdd98966497fd;p=ghc-hetmet.git diff --git a/glafp-utils/mkdependC/mkdependC.prl b/glafp-utils/mkdependC/mkdependC.prl index 3438180..f7af53a 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 # @@ -13,8 +13,8 @@ $Status = 0; # just used for exit() status $Verbose = 0; $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"; +$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 = ''; @@ -22,12 +22,18 @@ $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 = ''; @@ -66,6 +72,15 @@ foreach $sf (@Src_files) { &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"); @@ -73,6 +88,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 +118,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$/ ) { @@ -116,9 +134,9 @@ sub mangle_command_line_args { local($suff) = &grab_arg_arg($_); push(@File_suffix, $suff); } elsif ( /^-bs/ ) { - $Begin_magic_str = &grab_arg_arg($_) . "\n"; + $Begin_magic_str = &grab_arg_arg($_); } elsif ( /^-es/ ) { - $End_magic_str = &grab_arg_arg($_) . "\n"; + $End_magic_str = &grab_arg_arg($_); } elsif ( /^-w/ ) { $Width = &grab_arg_arg($_); } elsif ( /^-/ ) { @@ -163,10 +181,16 @@ sub slurp_file { # follows an example in the `open' item in perl man page # ${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"); + $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)='';