# perl script expect the following variables to be prepended:
#
# RAWCPP TMPDIR TOP_PWD
-# libdir datadir INSTALLING
-# PROJECTVERSION SED
+# libdir libexecdir datadir INSTALLING
+# ProjectVersionInt SED
#
# tries to work like mkdependC - capable of dealing with:
#
-syslib <blah> This program uses this GHC system library; take
appropriate action (e.g., recognise when they are
"import"ing a module from that library).
- -fhaskell1.[2-9] Deal with the oddities associated with a
- particular version of Haskell 1.
mkdependHS-specific options (not between --'s):
-v Be verbose.
-v -v Be very verbose.
+ -w No warnings
-f blah Use "blah" as the makefile, rather than "makefile"
or "Makefile".
- -o <osuf> Use <osuf> as the "object file" suffix ( default: .o)
+ -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
- make dependencies both for .hc files and for _a.hc
+ suffix <suf><osuf>; thus, "-o hc -s _a" will
+ make dependencies both for .hc files and for .a_hc
files. (Useful in conjunction with NoFib "ways".)
--exclude-module=<file>
Regard <file> as "stable"; i.e., eXclude it from having
Regard : separated list of directories as containing stable,
don't generate any dependencies on modules therein.
-Xdirs same as --exclude-directory
+ --include-prelude
+ 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.
--include-module=<file>
Regard <file> as not "stable"; i.e., generate dependencies
on it (if any). This option is normally used in conjunction
EOUSAGE
-$Status = 0; # just used for exit() status
-$Verbose = 0; # 1 => verbose, 2 => very verbose
+$Status = 0; # just used for exit() status
+$Verbose = 0; # 1 => verbose, 2 => very verbose
+$Warnings = 1; # 1 => warn about duplicate interface files
$Dashdashes_seen = 0;
-# Try to guess how to run gcc's CPP directly -------------
-
-$OrigCpp = ${RAWCPP};
-if ( $OrigCpp !~ /(\S+)\s+(.*)/ ) {
- $Cpp = $OrigCpp;
-} else {
- $cmd = $1;
- $rest = $2;
- if ( -x $cmd ) { # cool
- $Cpp = $OrigCpp;
- } else { # oops; try to guess
- $GccV = `gcc -v 2>&1`;
- if ( $GccV =~ /Reading specs from (.*)\/specs/ ) {
- $Cpp = "$1/cpp $rest";
- } else {
- die "hscpp: don't know how to run cpp: $OrigCpp\n";
- }
- }
-}
+$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$$";
$ENV{'TMPDIR'} = "${TMPDIR}"; # set the env var as well
}
-$TopPwd = "${TOP_PWD}";
-$InstLibDirGhc = "${libdir}";
-$InstHsLibDirGhc = "${libdir}/hslibs";
-$InstDataDirGhc = "${datadir}";
+$TopPwd = "${TOP_PWD}";
+$InstLibDirGhc = "${libdir}";
+$InstLibExecDirGhc = "${libexecdir}";
+$InstDataDirGhc = "${datadir}";
-$Unlit = ($INSTALLING) ? "${InstLibDirGhc}/unlit" : "${TopPwd}/ghc/utils/unlit/unlit";
+$Unlit = ($INSTALLING) ? "${InstLibExecDirGhc}/unlit"
+ : "${TopPwd}/ghc/utils/unlit/unlit";
$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';
-$ghc_version_info = int ( ${PROJECTVERSION} * 100 );
+@Obj_suffix = ("o");
+@File_suffix = ();
+$ghc_version_info = ${ProjectVersionInt};
$Import_dirs = '.';
%Syslibs = ();
%LibIfaces = (); # known prelude/syslib ifaces; read from a file
-
%IgnoreMe = ();
# directories to considered stable.
-@Ignore_dirs = ($INSTALLING) ?
- ("$InstLibDirGhc/imports")
- : ("$TopPwd/ghc/lib/ghc",
- "$TopPwd/ghc/lib/required",
- "$TopPwd/ghc/lib/glaExts",
- "$TopPwd/ghc/lib/concurrent");
-
-$Haskell_1 = 3; # assume Haskell 1.3. Changed by -fhaskell-1.?
+@Ignore_dirs = ();
+
$Include_dirs = '-I.';
$Makefile = '';
@Src_files = ();
+$Include_prelude = 0;
&mangle_command_line_args();
-# set up array of ignored modules
-foreach $lib ( @Syslibs ) {
- local($dir) =
- ($INSTALLING) ? "${InstHsLibDirGhc}/${lib}/imports"
- : "${TopPwd}/hslibs/${lib}/src";
- push(@Ignore_dirs,$dir);
-}
-
if ( $Status ) {
print stderr $Usage;
exit(1);
}
push(@Defines,
- ("-D__HASKELL1__=$Haskell_1",
+ ( #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
+
+# set up array of ignored modules
+local(@dirs) = ($INSTALLING) ?
+ ("$InstLibDirGhc/imports/std")
+ : ("$TopPwd/ghc/lib/std");
+if (!$Include_prelude) {
+ push(@Ignore_dirs, @dirs);
+} else {
+ push(@Import_dirs, @dirs);
+}
+
+foreach $lib ( @Syslibs ) {
+ local($dir) =
+ ($INSTALLING) ? "${InstLibDirGhc}/imports/${lib}"
+ : "${TopPwd}/ghc/lib/${lib}";
+ if (!$Include_prelude) {
+ push(@Ignore_dirs,$dir);
+ } else {
+ push(@Import_dirs, $dir);
+ }
+}
+
+
# NB: We keep the scalar-variable equivalents to use in error messages
if ( ! $Makefile && -f 'makefile' ) {
@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
# except it puts each file through CPP and
# a de-commenter (not implemented);
# builds up @Depend_lines
print STDERR "Here we go for source file: $sf\n" if $Verbose;
($bf = $sf) =~ s/\.l?(hs|y)$//;
- #push(@Depend_lines, "$bf.$Obj_suffix $bf.hi : $sf\n");
- push(@Depend_lines, "$bf.$Obj_suffix : $sf\n");
- foreach $suff (@File_suffix) {
- push(@Depend_lines, "$bf.${suff}_$Obj_suffix : $sf\n");
- }
+ local($str)="";
+ foreach $obj (@Obj_suffix) {
+ $str .= "$bf.$obj ";
+ foreach $suff (@File_suffix) {
+ $str .= "$bf.${suff}_$obj ";
+ }
+ }
+ push(@Depend_lines, "$str: $sf\n");
# if it's a literate file, .lhs or .ly? (happy specs), then we de-literatize it:
if ( $sf !~ /\.l(hs|y)$/ ) {
$file_to_read = $sf;
}
}
-# 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
$_ = <OMKF>;
}
# insert dependencies
-print $Begin_magic_str;
-print @Depend_lines;
-print $End_magic_str;
+print "\n$Begin_magic_str", @Depend_lines, $End_magic_str || die "Failed to write out dependencies ($!)";
+
while (<OMKF>) { # copy the rest through
- print $_;
+ print $_ || die "Failed to write out dependencies ($!)";
}
close(NMKF) || exit(1);
close(OMKF) || exit(1);
} elsif ( /^-D(.*)/ ) { # recognized wherever they occur
push(@Defines, $_);
+ } elsif ( /^-cpp$/ ) { # recognized wherever they occur
+ $Cpp_flag_set =1;
+ } elsif ( /^-i$/ ) {
+ $Import_dirs = ''; # import path cleared!
} elsif ( /^-i(.*)/ ) {
- $Import_dirs .= ":$1";
+ $Import_dirs = "$1:$Import_dirs";
} elsif ( /^-I/ ) {
$Include_dirs .= " $_";
} elsif ( /^-syslib$/ ) {
push(@Syslibs, &grab_arg_arg($_,''));
- } elsif ( /^-fhaskell-1\.([2-9])/ ) {
- $Haskell_1 = $1;
+ } elsif ( /^-fglasgow-exts$/ ) {
+ push(@Syslibs, 'exts');
} elsif ($Dashdashes_seen != 1) { # not between -- ... --
if ( /^-v$/ ) {
$Verbose++;
+ } elsif ( /^-w$/ ) {
+ $Warnings = 0;
} elsif ( /^-f(.*)/ ) {
$Makefile = &grab_arg_arg('-f',$1);
} elsif ( /^-o(.*)/ ) {
- $Obj_suffix = &grab_arg_arg('-o',$1);
+ local($suff) = &grab_arg_arg('-o',$1);
+ # Weed out existing entry .. there must be a better way of doing this
+ # with arrays (non-assoc) ! -- sof
+ @Obj_suffix = grep(!/$suff/,@Obj_suffix);
+ push(@Obj_suffix, $suff);
#
# --exclude-module=mod => it's stable, trust me!
} elsif ( /^--include-module=(.*)/ ) {
local($thing) = &grab_arg_arg($1,$2);
$IgnoreMe{$thing} = 'n';
+ } elsif ( /^--include-prelude$/ ) {
+ $Include_prelude = 1;
} elsif ( /^-s(.*)/ ) {
local($suff) = &grab_arg_arg('-s',$1);
push(@File_suffix, $suff);
} 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);
}
next unless /(.*)\.hi$/;
$thing = $1;
if ($ModuleIn{$thing} && $ModuleIn{$thing} ne $d) {
- print STDERR "$Pgm: warning: $thing.hi appears in both $ModuleIn{$thing} and $d!\n";
+ print STDERR "$Pgm: warning: $thing.hi appears in both $ModuleIn{$thing} and $d!\n" if ($Warnings);
} else {
$ModuleIn{$thing} = $d;
}
$last_seen_dir =~ s/\/[^\/]+$//; # strip to dir name
$last_seen_dir = '.' if ($last_seen_dir eq $orig_src_file);
+ &process_dependency('import',0,'Prelude') if ($Include_prelude);
+
# 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>) {
#
$modname = $4;
next if $modname eq '';
- if ($todo eq 'import') {
- if ( $ModuleIn{$modname} ) {
- $follow_file = "$ModuleIn{$modname}/$modname.hi";
- } else { # hard way
- $follow_file
- = &find_in_Import_dirs($orig_src_file, $modname, $last_seen_dir );
- }
- } else {
- $follow_file
- = &find_in_Include_dirs($orig_src_file, $modname, $last_seen_dir);
- }
+ &process_dependency($todo,$source,$modname);
+ }
+ close(SRCFILE) || exit(1);
+}
- if (! $follow_file) { # it didnae find anything
- die "$orig_src_file: Couldn't handle: $_\n";
-
- } else { # it found something
- if ($follow_file ne '__ignore__') {
- local($int_file);
- $int_file = $follow_file;
-
- if ( $int_file !~ /\.(l?hs|hi|l?y)$/ ) {
- push(@Depend_lines, "$bf.$Obj_suffix : $int_file\n");
- foreach $suff (@File_suffix) {
- push(@Depend_lines, "$bf.${suff}_$Obj_suffix : $int_file\n");
- }
-
- } else {
- $int_file =~ s/\.l?hs$//;
- $int_file =~ s/\.l?y$//;
- $int_file =~ s/\.hi$//;
- local($source_dep);
-
- if ( $source && -f "$int_file.hs" ) {
- $source_dep = "$int_file.hs";
- push(@Depend_lines, "$bf.$Obj_suffix : $source_dep\n");
- } elsif ( $source && -f "$int_file.lhs" ) {
- $source_dep = "$int_file.lhs";
- push(@Depend_lines, "$bf.$Obj_suffix : $source_dep\n");
- } elsif ( $source && ( -f "$int_file.ly" || -f "$int_file.y" ) ) {
- $source_dep = "$int_file.hs";
- push(@Depend_lines, "$bf.$Obj_suffix : $source_dep\n");
- } else {
- if ( $source ) {
- print STDERR "Warning: could not find source file dependency $int_file.(hs|lhs|y|ly)\n";
- }
- push(@Depend_lines, "$bf.$Obj_suffix : $int_file.hi\n");
- }
-
- if ( ! $source ) {
- foreach $suff (@File_suffix) {
- push(@Depend_lines, "$bf.${suff}_$Obj_suffix : $int_file.${suff}_hi\n");
- }
- } else {
- foreach $suff (@File_suffix) {
- push(@Depend_lines, "$bf.${suff}_$Obj_suffix : $source_dep\n");
- }
- }
- }
+#
+# Handle
+sub process_dependency {
+ local($todo,$source,$modname) = @_;
+
+ if ($todo eq 'import') {
+ if ( $ModuleIn{$modname} ) {
+ $follow_file = "$ModuleIn{$modname}/$modname.hi";
+ } else { # hard way
+ $follow_file =
+ &find_in_Import_dirs($orig_src_file, $modname, $last_seen_dir, $source );
+ }
+ } else {
+ $follow_file
+ = &find_in_Include_dirs($orig_src_file, $modname, $last_seen_dir);
+ }
+
+ if (! $follow_file) { # it didnae find anything
+ die "$orig_src_file: Couldn't handle: $_\n";
+
+ } else { # it found something
+ if ($follow_file ne '__ignore__') {
+ local($int_file) = $follow_file;
+
+ if ( $int_file !~ /\.(l?hs|hi|l?y)$/ ) {
+ local($str) = "";
+ foreach $obj (@Obj_suffix) {
+ $str .= "$bf.$obj ";
+ foreach $suff (@File_suffix) {
+ $str .= "$bf.${suff}_$obj ";
+ }
}
+ push(@Depend_lines, "$str: $int_file\n");
+ } else {
+ $int_file =~ s/\.l?hs$//;
+ $int_file =~ s/\.l?y$//;
+ $int_file =~ s/\.hi$//;
+ local($source_dep);
+
+ if ( $source ) {
+ $source_dep = "$int_file.hi-boot";
+ } else {
+ local($str)="";
+ foreach $obj (@Obj_suffix) {
+ $str .= "$bf.$obj ";
+ }
+ push(@Depend_lines, "$str: $int_file.hi\n");
+ }
+
+ if ( ! $source ) {
+ foreach $suff (@File_suffix) {
+ local($str) = "";
+ foreach $obj (@Obj_suffix) {
+ $str .= "$bf.${suff}_$obj ";
+ }
+ push(@Depend_lines, "$str: $int_file.${suff}_hi\n");
+ }
+ } else {
+ local($str) = "";
+ foreach $obj (@Obj_suffix) {
+ $str .= "$bf.$obj ";
+ foreach $suff (@File_suffix) {
+ $str .= "$bf.${suff}_$obj ";
+ }
+ }
+ push(@Depend_lines, "$str: $source_dep\n");
+ }
}
- }
- close(SRCFILE) || exit(1);
+ }
+ }
}
# when we see something, we cache that fact ('y').
print STDERR "trying... $name_to_check\n" if $Verbose >= 2; # very verbose
return($name_to_check) if -f $name_to_check;
}
+
+ if ( $source ) {
+ $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;
+ }
}
if ($do_magical_check == 1) {
$name_to_check = "$last_seen_dir/$modname.hi";