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