[project @ 1996-01-08 20:28:12 by partain]
[ghc-hetmet.git] / glafp-utils / scripts / fastmake.prl
1 #! /usr/local/bin/perl
2 #
3 ($Pgm = $0) =~ s/.*\/([^\/]+)$/\1/;
4 $Usage = "\n" . <<EOUSAGE;
5 Usage:
6     $Pgm [-? or -help] [-k] [-n] [-v] [-t] dir/module-target(s)
7
8 This script runs `make' to build the requested target, WITHOUT
9 including the dependencies generated by `mkdependHS' (i.e., all those
10 derived from import declarations).
11
12 With a -t flag, it also sets the modification time of the resulting
13 .hi file (one target only, please) to some EARLY date, so that changes
14 to that interface will not trigger much useless recompilation.
15
16 Typical uses, for module "Bar" in directory "foo":
17
18 (1) You've changed "Bar" and you want to recompile it; you know that
19     other module interfaces are stable, so you'd rather do without all
20     of `make''s prognostications:
21
22     $Pgm foo/Bar.s
23
24 (2) You've ADDED a new function to "Bar"; you want to recompile that
25     module, BUT NOT TRIGGER LOTS OF FURTHER COMPILATION because of the
26     "changed" interface file:
27
28     $Pgm -t foo/Bar.s
29
30 USE AT YOUR OWN RISK: you can make a big mess with this script!
31 EOUSAGE
32
33 $Makefile = 'Makefile';
34 $Tmpfile  = "/tmp/Makefile$$";
35 chop($Arch = `uname -a`);
36 $SleazyTouch = '/usr/5bin/touch';
37 $DoTouch = 0;
38 $Verbose = 0;
39 $MakeFlags = '';
40
41 sub rm_temp_file {
42     print STDERR "rm $Tmpfile\n" if $Verbose;
43     unlink $Tmpfile;
44     exit(1);
45 }
46 $SIG{'INT'}  = 'rm_temp_file';
47 $SIG{'QUIT'} = 'rm_temp_file';
48
49 $Target = '';
50 $DirMod = '';   # the dir/module-file to make
51
52 # process ARGV
53 while ($_ = $ARGV[0]) {
54     shift(@ARGV);
55     if (/^-\?$/ || /^-help$/) {
56         print $Usage;
57         exit 1;
58     } elsif (/^-v$/) {
59         $Verbose = 1;
60     } elsif (/^-t$/) {
61         $Do_touch = 1;
62     } elsif (/^-k$/) {
63         $MakeFlags .= ' -k';
64     } elsif (/^-n$/) {
65         $MakeFlags .= ' -n';
66     } elsif (/^-d$/) {
67         $MakeFlags .= ' -d';
68     } elsif (/^-/) {
69         print STDERR "$Pgm: unknown option: $_\n\n$Usage";
70         exit 1;
71     } elsif (/^([A-Z_]+)=(.+)/) {
72         $MakeFlags .= " $1=\"$2\"";
73
74     } elsif ($Do_touch) { # the module file
75         $Target = $_;
76         if ( /([^\/]+\/[^\/\.]+)\.[a-z]+/ ) {
77             $DirMod = $1;
78         } else {
79             print STDERR "$Pgm: argument not of the form: directory/Module.suffix: $_\n\n$Usage";
80             exit 1;
81         }
82     } else {    # accumulate as "Target"...
83         $Target .= " $_";
84     }
85 }
86
87 if ($Do_touch && $Target =~ / /) {
88     print STDERR "$Pgm: too many arguments\n\n$Usage";
89     exit 1;
90 }
91
92 open(INF, "<$Makefile") || die "Can't open $Makefile for input\n";
93
94 open(OUTF,">$Tmpfile") || die "Can't open $Tmpfile for output\n";
95 select(OUTF);
96
97 $_ = <INF>;
98
99 # copy through until ...
100 while ( $_ && ! /^# DO NOT DELETE: Beginning of Haskell dependencies/ ) {
101     print $_;
102     $_ = <INF>;
103 }
104
105 # now copy through 'til the end, omitting the %.{o,s,hc} : %.hi dependencies
106 while ( $_ ) {
107     print $_ if ! /^\S+ : \S+\.hi$/;
108     $_ = <INF>;
109 }
110
111 close(INF);
112 close(OUTF);
113
114 if ($Arch ne "sun3") {
115     $Make = 'make JMAKE=jmake LIT2PGM=lit2pgm LIT2LATEX=lit2latex LIT2TEXI=lit2texi MKDEPENDLIT=mkdependlit MAKEINFO=makeinfo POSTMAKEINFO=postmakeinfo';
116 } else {
117     $Make = 'make';
118 }
119 print STDERR "$Make $MakeFlags -f $Tmpfile $Target; rm $Tmpfile\n" if $Verbose;
120
121 system( "$Make $MakeFlags -f $Tmpfile $Target; rm $Tmpfile" );
122
123 if ($Do_touch) {
124     print STDERR "$SleazyTouch -m 01010101 $DirMod\.hi\n" if $Verbose;
125     system( "$SleazyTouch -m 01010101 $DirMod\.hi" );
126 }