[project @ 1998-05-19 11:19:56 by simonm]
[ghc-hetmet.git] / ghc / utils / mkdependHS / mkdependHS.prl
index fe86282..2dca4db 100644 (file)
@@ -3,7 +3,7 @@
 #
 #  RAWCPP TMPDIR TOP_PWD
 #  libdir libexecdir datadir INSTALLING
-#  PROJECTVERSION SED 
+#  ProjectVersionInt SED 
 #
 # tries to work like mkdependC - capable of dealing with:
 #
@@ -35,6 +35,7 @@ mkdependHS-specific options (not between --'s):
     -w          No warnings
     -f blah    Use "blah" as the makefile, rather than "makefile"
                or "Makefile".
+    -cpp       Wash the input files through cpp(1).
     -o <osuf>  Use <osuf> as the "object file" suffix ( default: o)
     -s <suf>   Make extra dependencies for files with
                suffix <suf><osuf>; thus, "-o hc -s _a" will
@@ -49,7 +50,7 @@ mkdependHS-specific options (not between --'s):
                 don't generate any dependencies on modules therein.
     -Xdirs      same as --exclude-directory
     --include-prelude
-               Regard prelude library as unstable, i.e., generate dependencies
+               Regard prelude libraries as unstable, i.e., generate dependencies
                on prelude modules. This option is normally only used by the
                 various system libraries. If a -syslib option is used, dependencies
                 will also be generated on the library's interfaces.
@@ -66,6 +67,7 @@ $Warnings   = 1; # 1 => warn about duplicate interface files
 $Dashdashes_seen = 0;
 
 $Cpp = ${RAWCPP};
+$Cpp_flag_set = 0; # 1 => run cpp over input files.
 
 if ( $ENV{'TMPDIR'} ) { # where to make tmp file names
     $Tmp_prefix = $ENV{'TMPDIR'} . "/mkdependHS$$";
@@ -77,7 +79,6 @@ if ( $ENV{'TMPDIR'} ) { # where to make tmp file names
 $TopPwd                   = "${TOP_PWD}";
 $InstLibDirGhc     = "${libdir}";
 $InstLibExecDirGhc = "${libexecdir}";
-$InstHsLibDirGhc   = "${libdir}/hslibs";
 $InstDataDirGhc    = "${datadir}";
 
 $Unlit = ($INSTALLING) ? "${InstLibExecDirGhc}/unlit" 
@@ -87,7 +88,7 @@ $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 = int ( ${PROJECTVERSION} * 100 );
+$ghc_version_info = ${ProjectVersionInt};
 
 $Import_dirs = '.';
 %Syslibs = ();
@@ -117,11 +118,8 @@ push(@Defines,
 
 # set up array of ignored modules
 local(@dirs) = ($INSTALLING) ? 
-              ("$InstLibDirGhc/imports")
-            : ("$TopPwd/ghc/lib/ghc",
-               "$TopPwd/ghc/lib/required",
-               "$TopPwd/ghc/lib/glaExts",
-               "$TopPwd/ghc/lib/concurrent");
+              ("$InstLibDirGhc/imports/std")
+            : ("$TopPwd/ghc/lib/std");
 if (!$Include_prelude) {
     push(@Ignore_dirs, @dirs);
 } else {
@@ -130,12 +128,12 @@ if (!$Include_prelude) {
 
 foreach $lib ( @Syslibs ) {
     local($dir) = 
-      ($INSTALLING) ? "${InstHsLibDirGhc}/${lib}/imports" 
-                   : "${TopPwd}/hslibs/${lib}/src";
+      ($INSTALLING) ? "${InstLibDirGhc}/imports/${lib}" 
+                   : "${TopPwd}/ghc/lib/${lib}";
     if (!$Include_prelude) {
        push(@Ignore_dirs,$dir);
     } else {
-       push(@Import_dirs, @dirs);
+       push(@Import_dirs, $dir);
     }
 }
 
@@ -196,16 +194,15 @@ foreach $sf (@Src_files) {
 }
 
 
-# OK, mangle the Makefile
-unlink("$Makefile.bak");
-
 #
-# If no output file exist as yet, create one.
+# Create backup version of output file.
 # 
-if ( ! -f $Makefile.bak ) {
-   system("touch $Makefile.bak");
-} 
-if ( -f $Makefile ) {
+if ( ! -f $Makefile ) {
+   # truncate() may not be implemented, so we
+   # play it safe here.
+   local(*TRUNC);
+   open(TRUNC,"> $Makefile.bak") && close(TRUNC);
+} else {
    rename($Makefile,"$Makefile.bak");
 }
 # now copy Makefile.bak into Makefile, rm'ing old dependencies
@@ -222,7 +219,7 @@ while ($_ && $_ ne $End_magic_str) { # delete 'til End_magic_str
     $_ = <OMKF>;
 }
 # insert dependencies
-print $Begin_magic_str, @Depend_lines, $End_magic_str || die "Failed to write out dependencies ($!)";
+print "\n$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 ($!)";
@@ -240,12 +237,18 @@ sub mangle_command_line_args {
 
        } elsif ( /^-D(.*)/ ) { # recognized wherever they occur
            push(@Defines, $_);
-       } elsif ( /^-i(.*)/ ) { # ditto
-           $Import_dirs .= ":$1";
+       } elsif ( /^-cpp$/ ) { # recognized wherever they occur
+           $Cpp_flag_set =1; 
+       } elsif ( /^-i$/ ) {
+           $Import_dirs = ''; # import path cleared!
+       } elsif ( /^-i(.*)/ ) {
+           $Import_dirs = "$1:$Import_dirs";
        } elsif ( /^-I/ ) {
            $Include_dirs .= " $_";
        } elsif ( /^-syslib$/ ) {
            push(@Syslibs, &grab_arg_arg($_,''));
+       } elsif ( /^-fglasgow-exts$/ ) {
+           push(@Syslibs, 'exts');
        } elsif ($Dashdashes_seen != 1) { # not between -- ... --
            if ( /^-v$/ ) {
                $Verbose++;
@@ -283,10 +286,16 @@ sub mangle_command_line_args {
            } else {
                push(@Src_files, $_);
            }
-
-       } elsif ($Dashdashes_seen == 1) { # where we ignore unknown options
-           push(@Src_files, $_) if ! /^-/;
-       }
+        }
+        # Removed support for picking up plausible source file 
+        # names inside the ghc options chunk of the command
+        # line. It failed to deal with `option-value' stuff present
+        # on some invocations of ghc (e.g., "-ohi foo.baz").
+        #  -- sof 12/97
+       #
+       # } elsif ($Dashdashes_seen == 1) {
+       #     push(@Src_files, $_) if ! /^-/;
+       # }
     }
     @File_suffix = sort (@File_suffix);
 }
@@ -362,10 +371,15 @@ sub slurp_file_for_imports {
     # we mangle #include's so they will also leave something
     # behind to indicate the dependency on _them_
     
-    print STDERR "${SED} -e '/^# *include/{p;s/^# *include/!include/;};s/'\\''//g;s/\"//g' $file_to_read | $Cpp $Include_dirs -I$last_seen_dir @Defines |\n" if $Verbose;
+    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 |";
+    } else {
+       $open_cmd = $file_to_read;
+    }
+    print STDERR "$open_cmd\n" if $Verbose;
 
-    open(SRCFILE, "${SED} -e '/^# *include/{p;s/^# *include/!include/;};s/'\\''//g;s/\"//g' $file_to_read | $Cpp $Include_dirs -I$last_seen_dir @Defines |")
-       || die "$Pgm: Can't open $file_to_read: $!\n";
+    open(SRCFILE, $open_cmd) || die "$Pgm: Can't open $file_to_read: $!\n";
 
     while (<SRCFILE>) {
         #