#
# 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:
#
to search for "import"ed modules
-I<dir> Add <dir> to list of directories to search for
.h files (i.e., usual meaning)
- -syslib <blah> This program uses this GHC system library; take
+ -package <blah> This program uses this GHC system library; take
appropriate action (e.g., recognise when they are
"import"ing a module from that library).
--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
+ various system libraries. If a -package 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
with the --exclude-directory option.
-
+
EOUSAGE
$Status = 0; # just used for exit() status
$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 = ();
# directories to considered stable.
@Ignore_dirs = ();
+%ModuleIn = ();
+
$Include_dirs = '-I.';
$Makefile = '';
@Src_files = ();
$Include_prelude = 0;
+@Defines = ();
+$ProcessingOptions=0;
+
+# 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();
+&mangle_command_line_args(@ARGV);
if ( $Status ) {
print stderr $Usage;
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
-# 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);
-
- 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 {
- push(@Import_dirs, $dir);
- }
-}
-
-
# NB: We keep the scalar-variable equivalents to use in error messages
+&gather_import_dirs();
+
if ( ! $Makefile && -f 'makefile' ) {
$Makefile = 'makefile';
} elsif ( ! $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
} 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";
}
$_ = <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 ($!)";
exit 0;
sub mangle_command_line_args {
- while($_ = $ARGV[0]) {
- shift(@ARGV);
+ local(@Args) = @_;
+
+ while($_ = $Args[0]) {
+ shift(@Args);
if ( /^--$/ ) {
$Dashdashes_seen++;
$Import_dirs = "$1:$Import_dirs";
} elsif ( /^-I/ ) {
$Include_dirs .= " $_";
- } elsif ( /^-syslib$/ ) {
- push(@Syslibs, &grab_arg_arg($_,''));
+ } elsif ( /^-syslib$/ ) { # deprecated, use -syslib
+ push(@Syslibs, &grab_arg_arg(*Args,$_,''));
+ } elsif ( /^-package$/ ) {
+ push(@Syslibs, &grab_arg_arg(*Args,$_,''));
} elsif ( /^-fglasgow-exts$/ ) {
- push(@Syslibs, 'exts');
+ push(@Syslibs, 'lang');
+ } elsif ( /^-concurrent$/ ) {
+ push(@Syslibs, 'concurrent');
+ } elsif (/^-#include(.*)/) {
+ &grab_arg_arg(*Args,$_,'');
} elsif ($Dashdashes_seen != 1) { # not between -- ... --
if ( /^-v$/ ) {
$Verbose++;
} elsif ( /^-w$/ ) {
$Warnings = 0;
- } elsif ( /^-f(.*)/ ) {
- $Makefile = &grab_arg_arg('-f',$1);
+ } elsif ( /^-f(.*)/ && !$ProcessingOptions ) {
+ $Makefile = &grab_arg_arg(*Args,'-f',$1);
} elsif ( /^-o(.*)/ ) {
- local($suff) = &grab_arg_arg('-o',$1);
+ local($suff) = &grab_arg_arg(*Args,'-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);
# --exclude-module=mod => it's stable, trust me!
} elsif ( /^-(x|-exclude-module=)(.*)/ ) {
- local($thing) = &grab_arg_arg($1,$2);
- $IgnoreMe{$thing} = 'y';
+ local($thing) = &grab_arg_arg(*Args,$1,$2);
+ $IgnoreMe{$thing} = 'Y';
} elsif ( /^-(X|-exclude-directory=)(.*)/ ) {
- foreach $d ( split(/:/,&grab_arg_arg($1, $2)) ) {
+ foreach $d ( split(/:/,&grab_arg_arg(*Args,$1, $2)) ) {
push(@Ignore_dirs,"$d");
}
} elsif ( /^--include-module=(.*)/ ) {
- local($thing) = &grab_arg_arg($1,$2);
+ local($thing) = &grab_arg_arg(*Args,$1,$2);
$IgnoreMe{$thing} = 'n';
} elsif ( /^--include-prelude$/ ) {
$Include_prelude = 1;
} elsif ( /^-s(.*)/ ) {
- local($suff) = &grab_arg_arg('-s',$1);
+ local($suff) = &grab_arg_arg(*Args,'-s',$1);
push(@File_suffix, $suff);
} elsif ( /^-/ ) {
- print STDERR "$Pgm: unknown option ignored: $_\n";
- $Status++;
+ if (!$ProcessingOptions) {
+ print STDERR "$Pgm: unknown option ignored: $_\n";
+ $Status++;
+ }
} else {
push(@Src_files, $_);
}
}
sub grab_arg_arg {
- local($option, $rest_of_arg) = @_;
+ local(*Args, $option, $rest_of_arg) = @_;
if ($rest_of_arg) {
return($rest_of_arg);
- } elsif ($#ARGV >= 0) {
- local($temp) = $ARGV[0]; shift(@ARGV);
+ } elsif ($#Args >= 0) {
+ local($temp) = $Args[0]; shift(@Args);
return($temp);
} else {
print STDERR "$Pgm: no argument following $option option\n";
}
}
+sub gather_import_dirs {
+
+ # 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);
+
+ # Yuck ^ 2
+ if ( $lib eq 'lang' && ! $INSTALLING ) {
+ push(@Import_dirs, "${TopPwd}/hslibs/${lib}/monads");
+ }
+ if ( $lib eq 'text' && ! $INSTALLING ) {
+ push(@Import_dirs, "${TopPwd}/hslibs/${lib}/html");
+ push(@Import_dirs, "${TopPwd}/hslibs/${lib}/haxml/lib");
+ }
+ if ( $lib eq 'data' && ! $INSTALLING ) {
+ push(@Import_dirs, "${TopPwd}/hslibs/${lib}/edison");
+ push(@Import_dirs, "${TopPwd}/hslibs/${lib}/edison/Assoc");
+ push(@Import_dirs, "${TopPwd}/hslibs/${lib}/edison/Coll");
+ push(@Import_dirs, "${TopPwd}/hslibs/${lib}/edison/Seq");
+ }
+ if ( $lib eq 'util' && ! $INSTALLING ) {
+ push(@Import_dirs, "${TopPwd}/hslibs/${lib}/check");
+ }
+
+ # Yuck ^ 3
+ if ( $lib eq 'win32' && ! $INSTALLING ) {
+ $dir = "${TopPwd}/hslibs/${lib}/src";
+ } elsif ( $lib eq 'com' && ! $INSTALLING ) {
+ $dir = "${TopPwd}/hdirect/lib";
+ } else {
+ $dir = ($INSTALLING) ? "${InstLibDirGhc}/imports/${lib}"
+ : "${TopPwd}/hslibs/${lib}";
+ }
+ if (!$Include_prelude) {
+ push(@Ignore_dirs,$dir);
+ } else {
+ push(@Import_dirs, $dir);
+ }
+ }
+}
+
+
+
sub preprocess_import_dirs {
# it's probably cheaper to find out what's in all
# the @Import_dirs before we start processing.
local($d, $thing);
local($_);
- %ModuleIn = ();
foreach $d ( @Import_dirs ) {
# Check to see if it can be ignored
for ($_ = readdir(DIR); $_; $_ = readdir(DIR)) {
next unless /(.*)\.hi$/;
$thing = $1;
- if ($ModuleIn{$thing} && $ModuleIn{$thing} ne $d) {
+ #
+ # dLL_ifs.hi is used to indicate whether a directory
+ # contains interface files whose object codes reside in a Win32 DLL.
+ #
+ if ($ModuleIn{$thing} && $ModuleIn{$thing} ne $d && $thing ne 'dLL_ifs') {
print STDERR "$Pgm: warning: $thing.hi appears in both $ModuleIn{$thing} and $d!\n" if ($Warnings);
} else {
$ModuleIn{$thing} = $d;
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';
}
local($follow_file,$read_from_file);
local($cleanup)=0;
+ local(@Old_Syslibs, $options);
+ local(@Old_Ignore_dirs);
+ local($found_options)=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);
+ #
+ # Check for {-# OPTIONS in the file-to-be-processed. If any syslib related options
+ # *only* are found, add them to the module search list (and take them off once
+ # we're through with this module.)
+ #
+
+ $options = &check_for_source_options($file_to_read);
+ if ($options ne "") {
+ @Old_Syslibs=@Syslibs;
+ $ProcessingOptions=1;
+ &mangle_command_line_args(split(/\s+/,$options));
+ if (@Old_Syslibs ne @Syslibs) {
+ $found_options=1;
+ @Old_Ignore_dirs = @Ignore_dirs;
+ &gather_import_dirs();
+ &preprocess_import_dirs();
+ }
+ }
+
# we mangle #include's so they will also leave something
# behind to indicate the dependency on _them_
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", 'Running cpp');
+ &run_something("${SED} -e '/^# *include/{p;s/^# *include/!include/;}' $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 {
next if $modname eq '';
&process_dependency($todo,$source,$modname);
}
+
+ if ($found_options) {
+ @Ignore_dirs = @Old_Ignore_dirs;
+ }
+
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");
}
}
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 =
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) {
}
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;
# 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;
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;
exit $return_val;
}
}
+
+# out of the driver too.
+sub check_for_source_options {
+ local($file) = @_;
+ local($comment_start,$comment_end);
+
+ # Assume it is a file containing Haskell source
+ $comment_start = "{-#";
+ $comment_end = "#-}";
+
+ open(FILE,$file) || return ""; # No big loss
+
+ while (<FILE>) {
+ if ( /^${comment_start} OPTIONS (.*)${comment_end}/ ) {
+ # return the options.
+ local($stuff) = $1;
+ print STDERR "Found OPTIONS $stuff in $file\n" if $Verbose;
+ close(FILE);
+ return $stuff;
+ }
+ elsif ( /^$/ ) { # ignore empty lines
+ ;
+ }
+ elsif ( /^#line.+$/ ) { # ignore comment lines (unused..ToDo: rm )
+ ;
+ }
+ elsif ( /^{-# LINE.+$/ ) { # ignore line pragmas
+ ;
+ }
+ else { # stop looking, something non-empty / not
+ # ${comment_start} OPTIONS .. ${comment_end} encountered.
+ close(FILE);return "";
+ }
+ }
+ close(FILE);
+ return "";
+}