[project @ 1997-09-03 23:46:56 by sof]
[ghc-hetmet.git] / ghc / driver / ghc-consist.lprl
1 %************************************************************************
2 %*                                                                      *
3 \section[Driver-consistency-chk]{@chk_consistency_info@: Check an executable for consistency}
4 %*                                                                      *
5 %************************************************************************
6
7 \begin{code}
8 sub chk_consistency_info {
9     local($executable) = @_;
10     
11     local($major_version, $minor_version);
12     local($phase, $infile, $opts);
13
14     # append .exe if it's not there under cygwin32
15     $executable = "${executable}.exe" if $TargetPlatform eq 'i386-unknown-cygwin32' &&
16                                          $executable !~ /\.exe$/ ; 
17
18     print STDERR "Checking consistency of: $executable\n" if $Verbose;
19
20     &tidy_up_and_die(1, "Panic: no such executable: $executable\n")
21         if ! -x $executable;
22
23     # by this point, consistency strings (with commas) have become
24     # local symbols (with .'s)
25     $HsC_consist_options =~ s/,/./g;
26     $Cc_consist_options  =~ s/,/./g;
27
28     # now run `nm' and check all the version info
29     open(CONSIST, "$Nm -p $executable |") || &tidy_up_and_die(1,"$Pgm: can't run: $Nm\n");
30     while (<CONSIST>) {
31         chop;
32         next if ! /^[\da-fA-F]+\s+[tn]\s+(hsc|cc)\./;
33
34         if (/^[\da-fA-F]+\s+[tn]\s+(hsc|cc)\.(\S+)\.(\d+)\.(\d+)\.(.*)/) {
35             $phase = $1; $infile = $2;
36             $major_version = $3; $minor_version = $4;
37             $opts = $5;
38             if ($phase eq 'hsc') {
39                 $Status++,
40                 print STDERR "$Pgm: consistency error: major version not $HsC_major_version:\n$_\n"
41                     if $major_version != $HsC_major_version;
42                 print STDERR "$Pgm: consistency warning: minor version not $HsC_minor_version:\n$_\n"
43                     if $minor_version != $HsC_minor_version;
44                 $Status++,
45                 print STDERR "$Pgm: consistency error: not options $opts -- $HsC_consist_options:\n$_\n"
46                     if $opts ne $HsC_consist_options;
47
48             } else { # phase is cc ...
49                 $Status++,
50                 print STDERR "$Pgm: consistency error: major version not $Cc_major_version:\n$_\n"
51                     if $major_version != $Cc_major_version;
52                 print STDERR "$Pgm: consistency warning: minor version not $Cc_minor_version:\n$_\n"
53                     if $minor_version != $Cc_minor_version;
54
55                 $Status++,
56                 print STDERR "$Pgm: consistency error: not options $Cc_consist_options:\n$_\n"
57                     if $opts ne $Cc_consist_options;
58             }
59         } else {
60             print STDERR "$Pgm: consistency-checking: unrecognised `what' line:\n$_\n";
61         }
62     }
63     close(CONSIST) || &tidy_up_and_die(1,"Failed in running $Nm (consistency checking)\n");
64 }
65
66 # make "require"r happy...
67 1;
68 \end{code}