[project @ 1998-08-05 22:34: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     # append .exe if it's not there under cygwin32
15     $executable = "${executable}.exe" if $TargetPlatform eq 'i386-unknown-cygwin32' &&
16                                          $executable !~ /\...*$/ ; 
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 ) && ( ! -B $executable );
22     # perl apparently determines whether something is executable
23     # by looking at the file suffix under win32/cygwin32 !?!
24     # Hence, we try binary files if (! -x) fails.
25
26     # by this point, consistency strings (with commas) have become
27     # local symbols (with .'s)
28     $HsC_consist_options =~ s/,/./g;
29     $Cc_consist_options  =~ s/,/./g;
30
31     # now run `nm' and check all the version info
32     open(CONSIST, "$Nm -p $executable |") || &tidy_up_and_die(1,"$Pgm: can't run: $Nm\n");
33     while (<CONSIST>) {
34         chop;
35         next if ! /^[\da-fA-F]+\s+[tn]\s+(hsc|cc)\./;
36
37         if (/^[\da-fA-F]+\s+[tn]\s+(hsc|cc)\.(\S+)\.(\d+)\.(\d+)\.(.*)/) {
38             $phase = $1; $infile = $2;
39             $major_version = $3; $minor_version = $4;
40             $opts = $5;
41             if ($phase eq 'hsc') {
42                 $Status++,
43                 print STDERR "$Pgm: consistency error: major version not $HsC_major_version:\n$_\n"
44                     if $major_version != $HsC_major_version;
45                 print STDERR "$Pgm: consistency warning: minor version not $HsC_minor_version:\n$_\n"
46                     if $minor_version != $HsC_minor_version;
47                 $Status++,
48                 print STDERR "$Pgm: consistency error: not options $opts -- $HsC_consist_options:\n$_\n"
49                     if $opts ne $HsC_consist_options;
50
51             } else { # phase is cc ...
52                 $Status++,
53                 print STDERR "$Pgm: consistency error: major version not $Cc_major_version:\n$_\n"
54                     if $major_version != $Cc_major_version;
55                 print STDERR "$Pgm: consistency warning: minor version not $Cc_minor_version:\n$_\n"
56                     if $minor_version != $Cc_minor_version;
57
58                 $Status++,
59                 print STDERR "$Pgm: consistency error: not options $Cc_consist_options:\n$_\n"
60                     if $opts ne $Cc_consist_options;
61             }
62         } else {
63             print STDERR "$Pgm: consistency-checking: unrecognised `what' line:\n$_\n";
64         }
65     }
66     close(CONSIST) || &tidy_up_and_die(1,"Failed in running $Nm (consistency checking)\n");
67 }
68
69 # make "require"r happy...
70 1;
71 \end{code}