[project @ 1999-07-14 13:26:48 by simonmar]
[ghc-hetmet.git] / ghc / utils / mkdependHS / mkdependHS.prl
index 2dca4db..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,11 +84,13 @@ $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");
 @File_suffix = ();
-$ghc_version_info = ${ProjectVersionInt};
 
 $Import_dirs = '.';
 %Syslibs = ();
@@ -101,6 +103,12 @@ $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"; }
+$SIG{'INT'}  = 'quit_upon_signal';
+$SIG{'QUIT'} = 'quit_upon_signal';
 
 &mangle_command_line_args();
 
@@ -109,10 +117,6 @@ if ( $Status ) {
     exit(1);
 }
 
-push(@Defines,
-     ( #OLD: "-D__HASKELL1__=$Haskell_1",
-      "-D__GLASGOW_HASKELL__=$ghc_version_info"));
-
 @Import_dirs  = split(/:/,$Import_dirs);
 @Include_dirs = split(/\s+/,$Include_dirs); # still has -I's in it
 
@@ -127,9 +131,14 @@ if (!$Include_prelude) {
 }
 
 foreach $lib ( @Syslibs ) {
-    local($dir) = 
-      ($INSTALLING) ? "${InstLibDirGhc}/imports/${lib}" 
-                   : "${TopPwd}/ghc/lib/${lib}";
+    local($dir);
+
+    if ( $lib eq 'win32' && ! $INSTALLING ) {
+      $dir = "${TopPwd}/hslibs/${lib}/src";
+    } else {
+      $dir = ($INSTALLING) ? "${InstLibDirGhc}/imports/${lib}" 
+                          : "${TopPwd}/ghc/lib/${lib}";
+    }
     if (!$Include_prelude) {
        push(@Ignore_dirs,$dir);
     } else {
@@ -156,11 +165,6 @@ print STDERR "Include_dirs=@Include_dirs\n" if $Verbose;
 
 @Depend_lines = ();
 
-# Delete temp. file if script is halted.
-sub quit_upon_signal { print STDERR "Deleting $Tmp_prefix.hs .. \n"; unlink "$Tmp_prefix.hs"; }
-$SIG{'INT'}  = 'quit_upon_signal';
-$SIG{'QUIT'} = 'quit_upon_signal';
-
 foreach $sf (@Src_files) {
 
     # just like lit-inputter
@@ -184,10 +188,11 @@ foreach $sf (@Src_files) {
     } else {
        $file_to_read = "$Tmp_prefix.hs";
        local($to_do) = "$Unlit $sf $file_to_read";
-       &run_something($to_do, 'unlit');
+       &run_something($to_do, $sf, 'unlit');
     }
     &slurp_file_for_imports($file_to_read, $sf);
 
+    # Delete the temporary.
     if ( $sf =~ /\.l(hs|y)$/ ) {
        unlink "$Tmp_prefix.hs";
     }
@@ -219,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 ($!)";
@@ -249,6 +254,8 @@ sub mangle_command_line_args {
            push(@Syslibs, &grab_arg_arg($_,''));
        } elsif ( /^-fglasgow-exts$/ ) {
            push(@Syslibs, 'exts');
+       } elsif ( /^-concurrent$/ ) {
+           push(@Syslibs, 'concurrent');
        } elsif ($Dashdashes_seen != 1) { # not between -- ... --
            if ( /^-v$/ ) {
                $Verbose++;
@@ -267,7 +274,7 @@ sub mangle_command_line_args {
             
            } elsif ( /^-(x|-exclude-module=)(.*)/ ) { 
                local($thing) = &grab_arg_arg($1,$2);
-               $IgnoreMe{$thing} = 'y';
+               $IgnoreMe{$thing} = 'Y';
            } elsif ( /^-(X|-exclude-directory=)(.*)/ ) { 
                foreach $d ( split(/:/,&grab_arg_arg($1, $2)) ) {
                    push(@Ignore_dirs,"$d");
@@ -350,7 +357,7 @@ sub preprocess_import_dirs {
             next unless /(.*)\.(hi|l?hs|l?y)$/;
             #don't tag it twice or overwrite it with a diff. value
             next if $IgnoreMe{$1};
-            print STDERR "Module $d/$1.$2 will be ignored\n" if $Verbose;
+            print STDERR "Module $d will be ignored\n" if $Verbose;
 
             $IgnoreMe{$1} = 'y';
         }
@@ -360,12 +367,21 @@ sub preprocess_import_dirs {
 
 sub slurp_file_for_imports {
     local($file_to_read, $orig_src_file) = @_;
-    local($follow_file);
+    local($follow_file,$read_from_file);
+    local($cleanup)=0;
 
     local($last_seen_dir) = $orig_src_file;
     $last_seen_dir =~ s/\/[^\/]+$//; # strip to dir name
     $last_seen_dir = '.' if ($last_seen_dir eq $orig_src_file);
 
+    local($mod_name) = $orig_src_file;
+
+    $mod_name =~ s/.*\/([^\/]+)$/$1/g;
+    $mod_name =~ s/^([^.]+)\.(.*)$/$1/;
+
+    print STDERR "Warning: processing module $mod_name, which I was supposed to ignore.\n"
+       if ( $IgnoreMe{$mod_name} eq 'Y' && $Warnings );
+
     &process_dependency('import',0,'Prelude') if ($Include_prelude);
 
     # we mangle #include's so they will also leave something
@@ -373,13 +389,17 @@ 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 |";
+#       $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');
+       $read_from_file="${file_to_read}.i";
+       $cleanup=1;
     } else {
+       $read_from_file="${file_to_read}";
        $open_cmd = $file_to_read;
     }
     print STDERR "$open_cmd\n" if $Verbose;
 
-    open(SRCFILE, $open_cmd) || die "$Pgm: Can't open $file_to_read: $!\n";
+    open(SRCFILE, $read_from_file) || die "$Pgm: Can't open $file_to_read: $!\n";
 
     while (<SRCFILE>) {
         #
@@ -396,6 +416,10 @@ sub slurp_file_for_imports {
        &process_dependency($todo,$source,$modname);
     }
     close(SRCFILE) || exit(1);
+    # remove temporary file, if any.
+    if ($cleanup) {
+          unlink("$read_from_file");
+    }
 }
 
 #
@@ -404,7 +428,11 @@ sub process_dependency {
   local($todo,$source,$modname) = @_;
 
   if ($todo eq 'import') {
-    if ( $ModuleIn{$modname} ) {
+    if ( $IgnoreMe{$modname} eq 'Y' ) {
+         # user specifically asked for this module
+        # to be ignored.
+        $follow_file = '__ignore__';
+    } elsif ( $ModuleIn{$modname} ) {
         $follow_file = "$ModuleIn{$modname}/$modname.hi";
     } else { # hard way
        $follow_file =
@@ -438,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) {
@@ -507,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;
@@ -576,7 +613,7 @@ sub find_in_Include_dirs {
 
 # out of the driver, actually
 sub run_something {
-    local($str_to_do, $tidy_name) = @_;
+    local($str_to_do, $file_to_read, $tidy_name) = @_;
 
     print STDERR "\n$tidy_name:\n\t" if $Verbose;
     print STDERR "$str_to_do\n" if $Verbose;
@@ -584,8 +621,8 @@ sub run_something {
     local($return_val) = system($str_to_do) >> 8;
 
     if ($return_val != 0) {
-       local($die_msg) = "$Pgm: execution of the $tidy_name had trouble";
-       $die_msg .= " (program not found)" if $return_val == 255;
+       local($die_msg) = "$Pgm: Running $tidy_name ( on $file_to_read ) failed";
+        $die_msg .= " program not found: $str_to_do " if $return_val == 255;
        $die_msg .= " ($!)" if $Verbose && $! != 0;
        $die_msg .= "\n";
        print STDERR $die_msg;