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