730e6a41a5aa3c5806dc46e1781b61fa3e5b3fbe
[ghc-hetmet.git] / glafp-utils / fastmake / 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 if ( $ENV{'TMPDIR'} ) { # where to make tmp file names
35     $Tmpfile = $ENV{'TMPDIR'} . "/Makefile$$";
36 } else {
37     $Tmpfile  = "$(TMPDIR)/Makefile$$";
38     $ENV{'TMPDIR'} = '$(TMPDIR)'; # set the env var as well
39 }
40 $SleazyTouch = '/usr/5bin/touch';
41 $DoTouch = 0;
42 $Verbose = 0;
43 $MakeFlags = '';
44
45 sub rm_temp_file {
46     print STDERR "rm $Tmpfile\n" if $Verbose;
47     unlink $Tmpfile;
48     exit(1);
49 }
50 $SIG{'INT'}  = 'rm_temp_file';
51 $SIG{'QUIT'} = 'rm_temp_file';
52
53 $Target = '';
54 $DirMod = '';   # the dir/module-file to make
55
56 # process ARGV
57 while ($_ = $ARGV[0]) {
58     shift(@ARGV);
59     if (/^-\?$/ || /^-help$/) {
60         print $Usage;
61         exit 1;
62     } elsif (/^-v$/) {
63         $Verbose = 1;
64     } elsif (/^-t$/) {
65         $Do_touch = 1;
66     } elsif (/^-k$/) {
67         $MakeFlags .= ' -k';
68     } elsif (/^-n$/) {
69         $MakeFlags .= ' -n';
70     } elsif (/^-d$/) {
71         $MakeFlags .= ' -d';
72     } elsif (/^-/) {
73         print STDERR "$Pgm: unknown option: $_\n\n$Usage";
74         exit 1;
75     } elsif (/^([A-Z_]+)=(.+)/) {
76         $MakeFlags .= " $1=\"$2\"";
77
78     } elsif ($Do_touch) { # the module file
79         $Target = $_;
80         if ( /([^\/]+\/[^\/\.]+)\.[a-z]+/ ) {
81             $DirMod = $1;
82         } else {
83             print STDERR "$Pgm: argument not of the form: directory/Module.suffix: $_\n\n$Usage";
84             exit 1;
85         }
86     } else {    # accumulate as "Target"...
87         $Target .= " $_";
88     }
89 }
90
91 if ($Do_touch && $Target =~ / /) {
92     print STDERR "$Pgm: too many arguments\n\n$Usage";
93     exit 1;
94 }
95
96 open(INF, "<$Makefile") || die "Can't open $Makefile for input\n";
97
98 open(OUTF,">$Tmpfile") || die "Can't open $Tmpfile for output\n";
99 select(OUTF);
100
101 $_ = <INF>;
102
103 # copy through until ...
104 while ( $_ && ! /^# DO NOT DELETE: Beginning of Haskell dependencies/ ) {
105     print $_;
106     $_ = <INF>;
107 }
108
109 # now copy through 'til the end, omitting the %.{o,s,hc} : %.hi dependencies
110 while ( $_ ) {
111     print $_ if ! /^\S+ : \S+\.hi$/;
112     $_ = <INF>;
113 }
114
115 close(INF);
116 close(OUTF);
117
118 $Make = 'make JMAKE=jmake LIT2PGM=lit2pgm LIT2LATEX=lit2latex LIT2TEXI=lit2texi MKDEPENDLIT=mkdependlit MAKEINFO=makeinfo POSTMAKEINFO=postmakeinfo';
119
120 print STDERR "$Make $MakeFlags -f $Tmpfile $Target; rm $Tmpfile\n" if $Verbose;
121
122 system( "$Make $MakeFlags -f $Tmpfile $Target; rm $Tmpfile" );
123
124 if ($Do_touch) {
125     print STDERR "$SleazyTouch -m 01010101 $DirMod\.hi\n" if $Verbose;
126     system( "$SleazyTouch -m 01010101 $DirMod\.hi" );
127 }