[project @ 1999-07-14 13:26:48 by simonmar]
[ghc-hetmet.git] / ghc / utils / mkdependHS / mkdependHS.prl
index 92500a3..3cd94bd 100644 (file)
@@ -1,9 +1,9 @@
 #
 # perl script expect the following variables to be prepended:
 #
-#  RAWCPP TMPDIR TOP_PWD
+#  RAWCPP TMPDIR TOP_PWD HscIfaceFileVersion
 #  libdir libexecdir datadir INSTALLING
-#  ProjectVersionInt SED 
+#  SED 
 #
 # tries to work like mkdependC - capable of dealing with:
 #
@@ -58,7 +58,7 @@ mkdependHS-specific options (not between --'s):
                 Regard <file> as not "stable"; i.e., generate dependencies
                 on it (if any). This option is normally used in conjunction 
                 with the --exclude-directory option.
-
+               
 EOUSAGE
 
 $Status     = 0; # just used for exit() status
@@ -84,6 +84,9 @@ $InstDataDirGhc    = "${datadir}";
 $Unlit = ($INSTALLING) ? "${InstLibExecDirGhc}/unlit" 
                       : "${TopPwd}/ghc/utils/unlit/unlit";
 
+$HiBootVersion = $HscIfaceFileVersion;
+$hi_boot_with_version = 0;
+
 $Begin_magic_str = "# DO NOT DELETE: Beginning of Haskell dependencies\n";
 $End_magic_str = "# DO NOT DELETE: End of Haskell dependencies\n";
 @Obj_suffix =  ("o");
@@ -100,6 +103,7 @@ $Include_dirs = '-I.';
 $Makefile = '';
 @Src_files = ();
 $Include_prelude = 0;
+@Defines = ();
 
 # Delete temp. file if script is halted.
 sub quit_upon_signal { print STDERR "Deleting $Tmp_prefix.hs .. \n"; unlink "$Tmp_prefix.hs"; }
@@ -113,10 +117,6 @@ if ( $Status ) {
     exit(1);
 }
 
-push(@Defines,
-     ( #OLD: "-D__HASKELL1__=$Haskell_1",
-      "-D__GLASGOW_HASKELL__=$ProjectVersionInt"));
-
 @Import_dirs  = split(/:/,$Import_dirs);
 @Include_dirs = split(/\s+/,$Include_dirs); # still has -I's in it
 
@@ -224,7 +224,7 @@ while ($_ && $_ ne $End_magic_str) { # delete 'til End_magic_str
     $_ = <OMKF>;
 }
 # insert dependencies
-print "\n$Begin_magic_str", @Depend_lines, $End_magic_str || die "Failed to write out dependencies ($!)";
+print "$Begin_magic_str", @Depend_lines, $End_magic_str || die "Failed to write out dependencies ($!)";
 
 while (<OMKF>) { # copy the rest through
     print $_ || die "Failed to write out dependencies ($!)";
@@ -390,7 +390,7 @@ sub slurp_file_for_imports {
     local ($open_cmd);
     if ($Cpp_flag_set) {
 #       $open_cmd = "${SED} -e '/^# *include/{p;s/^# *include/!include/;};s/'\\''//g;s/\"//g' $file_to_read | $Cpp $Include_dirs -I$last_seen_dir @Defines |";
-       &run_something("${SED} -e '/^# *include/{p;s/^# *include/!include/;};s/'\\''//g;s/\"//g' $file_to_read | $Cpp $Include_dirs -I$last_seen_dir @Defines 2>&1 > ${file_to_read}.i", $orig_src_file, 'cpp');
+       &run_something("${SED} -e '/^# *include/{p;s/^# *include/!include/;};s/'\\''//g;s/\"//g' $file_to_read | $Cpp $Include_dirs -I$last_seen_dir @Defines - 2>&1 > ${file_to_read}.i", $orig_src_file, 'cpp');
        $read_from_file="${file_to_read}.i";
        $cleanup=1;
     } else {
@@ -418,10 +418,7 @@ sub slurp_file_for_imports {
     close(SRCFILE) || exit(1);
     # remove temporary file, if any.
     if ($cleanup) {
-          # truncate() may not be implemented, so we
-          # play it safe here.
-          local(*TRUNC);
-          open(TRUNC,"> $read_from_file") && close(TRUNC);
+          unlink("$read_from_file");
     }
 }
 
@@ -469,7 +466,12 @@ sub process_dependency {
             local($source_dep);
 
             if ( $source ) {
-                $source_dep = "$int_file.hi-boot";
+               # if a version specific .hi-boot file exist, use it.
+               if ( -f "$int_file.hi-boot-${HiBootVersion}" ) {
+                          $source_dep = "$int_file.hi-boot-${HiBootVersion}";
+               } else {
+                  $source_dep = "$int_file.hi-boot";
+               }
             } else {
                local($str)="";
                foreach $obj (@Obj_suffix) {
@@ -538,6 +540,10 @@ sub find_in_Import_dirs {
         }
 
        if ( $source ) {
+           $name_to_check = "$import_dir/$modname.hi-boot-${HiBootVersion}";
+           print STDERR "trying... $name_to_check\n" if $Verbose >= 2; # very verbose
+           return($name_to_check) if -f $name_to_check;
+
            $name_to_check = "$import_dir/$modname.hi-boot";
            print STDERR "trying... $name_to_check\n" if $Verbose >= 2; # very verbose
            return($name_to_check) if -f $name_to_check;