summaryrefslogtreecommitdiff
path: root/glafp-utils/fastmake/fastmake.prl
blob: 730e6a41a5aa3c5806dc46e1781b61fa3e5b3fbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#! /usr/local/bin/perl
#
($Pgm = $0) =~ s/.*\/([^\/]+)$/\1/;
$Usage = "\n" . <<EOUSAGE;
Usage:
    $Pgm [-? or -help] [-k] [-n] [-v] [-t] dir/module-target(s)

This script runs `make' to build the requested target, WITHOUT
including the dependencies generated by `mkdependHS' (i.e., all those
derived from import declarations).

With a -t flag, it also sets the modification time of the resulting
.hi file (one target only, please) to some EARLY date, so that changes
to that interface will not trigger much useless recompilation.

Typical uses, for module "Bar" in directory "foo":

(1) You've changed "Bar" and you want to recompile it; you know that
    other module interfaces are stable, so you'd rather do without all
    of `make''s prognostications:

    $Pgm foo/Bar.s

(2) You've ADDED a new function to "Bar"; you want to recompile that
    module, BUT NOT TRIGGER LOTS OF FURTHER COMPILATION because of the
    "changed" interface file:

    $Pgm -t foo/Bar.s

USE AT YOUR OWN RISK: you can make a big mess with this script!
EOUSAGE

$Makefile = 'Makefile';
if ( $ENV{'TMPDIR'} ) { # where to make tmp file names
    $Tmpfile = $ENV{'TMPDIR'} . "/Makefile$$";
} else {
    $Tmpfile  = "$(TMPDIR)/Makefile$$";
    $ENV{'TMPDIR'} = '$(TMPDIR)'; # set the env var as well
}
$SleazyTouch = '/usr/5bin/touch';
$DoTouch = 0;
$Verbose = 0;
$MakeFlags = '';

sub rm_temp_file {
    print STDERR "rm $Tmpfile\n" if $Verbose;
    unlink $Tmpfile;
    exit(1);
}
$SIG{'INT'}  = 'rm_temp_file';
$SIG{'QUIT'} = 'rm_temp_file';

$Target = '';
$DirMod = '';	# the dir/module-file to make

# process ARGV
while ($_ = $ARGV[0]) {
    shift(@ARGV);
    if (/^-\?$/ || /^-help$/) {
	print $Usage;
	exit 1;
    } elsif (/^-v$/) {
	$Verbose = 1;
    } elsif (/^-t$/) {
	$Do_touch = 1;
    } elsif (/^-k$/) {
	$MakeFlags .= ' -k';
    } elsif (/^-n$/) {
	$MakeFlags .= ' -n';
    } elsif (/^-d$/) {
	$MakeFlags .= ' -d';
    } elsif (/^-/) {
	print STDERR "$Pgm: unknown option: $_\n\n$Usage";
	exit 1;
    } elsif (/^([A-Z_]+)=(.+)/) {
	$MakeFlags .= " $1=\"$2\"";

    } elsif ($Do_touch) { # the module file
	$Target = $_;
	if ( /([^\/]+\/[^\/\.]+)\.[a-z]+/ ) {
	    $DirMod = $1;
	} else {
	    print STDERR "$Pgm: argument not of the form: directory/Module.suffix: $_\n\n$Usage";
	    exit 1;
	}
    } else {	# accumulate as "Target"...
	$Target .= " $_";
    }
}

if ($Do_touch && $Target =~ / /) {
    print STDERR "$Pgm: too many arguments\n\n$Usage";
    exit 1;
}

open(INF, "<$Makefile") || die "Can't open $Makefile for input\n";

open(OUTF,">$Tmpfile") || die "Can't open $Tmpfile for output\n";
select(OUTF);

$_ = <INF>;

# copy through until ...
while ( $_ && ! /^# DO NOT DELETE: Beginning of Haskell dependencies/ ) {
    print $_;
    $_ = <INF>;
}

# now copy through 'til the end, omitting the %.{o,s,hc} : %.hi dependencies
while ( $_ ) {
    print $_ if ! /^\S+ : \S+\.hi$/;
    $_ = <INF>;
}

close(INF);
close(OUTF);

$Make = 'make JMAKE=jmake LIT2PGM=lit2pgm LIT2LATEX=lit2latex LIT2TEXI=lit2texi MKDEPENDLIT=mkdependlit MAKEINFO=makeinfo POSTMAKEINFO=postmakeinfo';

print STDERR "$Make $MakeFlags -f $Tmpfile $Target; rm $Tmpfile\n" if $Verbose;

system( "$Make $MakeFlags -f $Tmpfile $Target; rm $Tmpfile" );

if ($Do_touch) {
    print STDERR "$SleazyTouch -m 01010101 $DirMod\.hi\n" if $Verbose;
    system( "$SleazyTouch -m 01010101 $DirMod\.hi" );
}