996
|
1 #!/usr/bin/perl -w
|
|
2
|
|
3 eval 'exec perl -S $0 ${1+"$@"}'
|
|
4 if 0;
|
|
5
|
|
6 # This script will create the Makefile to build and install CLC-INTERCAL
|
|
7
|
|
8 # This file is part of CLC-INTERCAL 1.-94.-2
|
|
9
|
|
10 # Copyright (c) 2008 Claudio Calvelli, all rights reserved.
|
|
11
|
|
12 # CLC-INTERCAL is copyrighted software. However, permission to use, modify,
|
|
13 # and distribute it is granted provided that the conditions set out in the
|
|
14 # licence agreement are met. See files README and COPYING in the distribution.
|
|
15
|
|
16 use vars qw($VERSION $PERVERSION);
|
|
17 ($VERSION) = ($PERVERSION = "CLC-INTERCAL Makefile.PL 1.-94.-2") =~ /\s(\S+)$/;
|
|
18
|
|
19 use strict;
|
|
20 use Cwd;
|
|
21 use ExtUtils::MakeMaker;
|
|
22
|
|
23 BEGIN { $ENV{CLC_INTERCAL_PATH} = '' }
|
|
24
|
|
25 my @A = map {
|
|
26 /'/ and die "Try not to use single quotes...\n";
|
|
27 "'$_'"
|
|
28 } @ARGV;
|
|
29
|
|
30 # find out what packages are included in this
|
|
31 my $ddsh_suffix = 'ddsh';
|
|
32 my $tar_suffix = 'tar';
|
|
33 my $gz_suffix = 'gz';
|
|
34
|
|
35 open(MANIFEST, '<', 'MANIFEST')
|
|
36 or die "Sorry, I can't work without a MANIFEST\n";
|
|
37 my $base = undef;
|
|
38 my @extras = ();
|
|
39 my @other_tar = ();
|
|
40 my @other_ddsh = ();
|
|
41 my @other_echo = ();
|
|
42 while (<MANIFEST>) {
|
|
43 if (/^(.*)\.($ddsh_suffix|$tar_suffix)\.$gz_suffix\s+(\S+)$/) {
|
|
44 my ($name, $suffix, $path) = ($1, $2, $3);
|
|
45 "$name$suffix$path" =~ /[\s'"]/ and die "Invalid file name, please inform maintainer\n";
|
|
46 if ($name =~ /\bBase\b/) {
|
|
47 $base and die "Something is wrong... Base is provided by $name and $base->[0]\n";
|
|
48 $base = [$name, $suffix, $path];
|
|
49 } else {
|
|
50 push @extras, [$name, $suffix, $path];
|
|
51 }
|
|
52 push @other_echo, "\$(ECHO) '$name.$ddsh_suffix.$gz_suffix $path' >> .ddsh/MANIFEST";
|
|
53 } elsif (/^(\S+)/) {
|
|
54 push @other_tar, "\$(CP) $1 .tar/CLC-INTERCAL-%v/$1";
|
|
55 push @other_ddsh, "\$(CP) $1 .ddsh/$1" if $1 ne 'MANIFEST';
|
|
56 push @other_echo, "\$(ECHO) $1 >> .ddsh/MANIFEST";
|
|
57 }
|
|
58 }
|
|
59 close MANIFEST;
|
|
60 $base or die "Something is wrong... Base package was not included\n";
|
|
61
|
|
62 # pretend to write a Makefile. so that we get all the constants
|
|
63 my $constants = '';
|
|
64 ExtUtils::MakeMaker::WriteEmptyMakefile(
|
|
65 NORECURS => 1,
|
|
66 );
|
|
67
|
|
68 # extract base package
|
|
69 extract(@$base);
|
|
70
|
|
71 $ENV{CLC_INTERCAL_PATH} = getcwd . '/' . $base->[2];
|
|
72
|
|
73 # extract other packages
|
|
74 for my $extra (@extras) {
|
|
75 extract(@$extra);
|
|
76 }
|
|
77
|
|
78 # create a simple Makefile
|
|
79 my @targets = qw(all test clean realclean install tardist ddsh_dist);
|
|
80 my %beforepath = (
|
|
81 tardist => [
|
|
82 '$(RM_RF) .tar',
|
|
83 "\$(NOECHO) $^X -MExtUtils::Command -e mkpath .tar/CLC-INTERCAL-%v",
|
|
84 @other_tar,
|
|
85 ],
|
|
86 ddsh_dist => [
|
|
87 '$(RM_RF) .ddsh',
|
|
88 "\$(NOECHO) $^X -MExtUtils::Command -e mkpath .ddsh",
|
|
89 @other_echo,
|
|
90 @other_ddsh,
|
|
91 ],
|
|
92 );
|
|
93 my %afterpath = (
|
|
94 clean => [
|
|
95 '$(RM_F) Makefile.old',
|
|
96 '$(MV) Makefile Makefile.old',
|
|
97 ],
|
|
98 realclean => '$(RM_F) Makefile',
|
|
99 tardist => [
|
|
100 'cd .tar && $(TAR) $(TARFLAGS) ../CLC-INTERCAL-%v.tar CLC-INTERCAL-%v',
|
|
101 '$(RM_F) CLC-INTERCAL-%v.tar.%g',
|
|
102 'gzip CLC-INTERCAL-%v.tar',
|
|
103 '$(RM_RF) .tar',
|
|
104 ],
|
|
105 ddsh_dist => [
|
|
106 "cd .ddsh && $^X -e 'require \"../$base->[2]/INTERCAL/Distribute.pm\";' \\",
|
|
107 "\t-e 'Language::INTERCAL::Distribute::makeddshdist()' \\",
|
|
108 "\t'' MANIFEST ../CLC-INTERCAL-%v.ddsh %v",
|
|
109 '$(RM_F) CLC-INTERCAL-%v.ddsh.%g',
|
|
110 'gzip CLC-INTERCAL-%v.ddsh',
|
|
111 '$(RM_RF) .ddsh',
|
|
112 ],
|
|
113 );
|
|
114 my %perpath = (
|
|
115 realclean => '$(RM_RF) %p',
|
|
116 tardist => '$(MV) "%p/CLC-INTERCAL-%n-%v.tar.%g" ".tar/CLC-INTERCAL-%v/%n.tar.%g"',
|
|
117 ddsh_dist => '$(MV) "%p/CLC-INTERCAL-%n-%v.ddsh.%g" ".ddsh/%n.ddsh.%g"',
|
|
118 );
|
|
119
|
|
120 open(MAKEFILE, '>', 'Makefile') or die "Makefile: $!\n";
|
|
121 print MAKEFILE "# Tool paths from MakeMaker...\n\n" or die "Makefile: $!\n";
|
|
122 print MAKEFILE $constants or die "Makefile: $!\n";
|
|
123 print MAKEFILE "\n\n# Generated by CLC-INTERCAL...\n\n" or die "Makefile: $!\n";
|
|
124 print MAKEFILE "SUBDIRS = \\\n" or die "Makefile: $!\n";
|
|
125 for my $pv (@extras) {
|
|
126 print MAKEFILE "\t$pv->[2]\\\n" or die "Makefile: $!\n";
|
|
127 }
|
|
128 print MAKEFILE "\t$base->[2]\n\n" or die "Makefile: $!\n";
|
|
129 print MAKEFILE "CLC_INTERCAL_PATH = $ENV{CLC_INTERCAL_PATH}\n\n" or die "Makefile: $!\n";
|
|
130 print MAKEFILE ".PHONY: @targets dist\n\n" or die "Makefile: $!\n";
|
|
131 for my $target (@targets) {
|
|
132 print MAKEFILE "$target :\n" or die "Makefile: $!\n";
|
|
133 if (exists $beforepath{$target}) {
|
|
134 my $s = $beforepath{$target};
|
|
135 my %rep = (
|
|
136 v => $VERSION,
|
|
137 g => $gz_suffix,
|
|
138 '%' => '%',
|
|
139 );
|
|
140 for my $c (ref $s ? @$s : $s) {
|
|
141 my $cv = $c;
|
|
142 $cv =~ s/%([vg%])/$rep{$1}/ge;
|
|
143 print MAKEFILE "\t$cv\n" or die "Makefile: $!\n";
|
|
144 }
|
|
145 }
|
|
146 my $env = '';
|
|
147 for my $pv ($base, @extras) {
|
|
148 my ($name, $suffix, $path) = @$pv;
|
|
149 print MAKEFILE "\tcd $path; $env\$(MAKE) $target\n" or die "Makefile: $!\n";
|
|
150 my %rep = (
|
|
151 p => $path,
|
|
152 n => $name,
|
|
153 s => $suffix,
|
|
154 v => $VERSION,
|
|
155 g => $gz_suffix,
|
|
156 '%' => '%',
|
|
157 );
|
|
158 if (exists $perpath{$target}) {
|
|
159 my $s = $perpath{$target};
|
|
160 for my $c (ref $s ? @$s : $s) {
|
|
161 my $cv = $c;
|
|
162 $cv =~ s/%([pnsgv%])/$rep{$1}/ge;
|
|
163 print MAKEFILE "\t$cv\n" or die "Makefile: $!\n";
|
|
164 }
|
|
165 }
|
|
166 $env = 'CLC_INTERCAL_PATH=\'$(CLC_INTERCAL_PATH)\' ';
|
|
167 }
|
|
168 if (exists $afterpath{$target}) {
|
|
169 my $s = $afterpath{$target};
|
|
170 my %rep = (
|
|
171 v => $VERSION,
|
|
172 g => $gz_suffix,
|
|
173 '%' => '%',
|
|
174 );
|
|
175 for my $c (ref $s ? @$s : $s) {
|
|
176 my $cv = $c;
|
|
177 $cv =~ s/%([vg%])/$rep{$1}/ge;
|
|
178 print MAKEFILE "\t$cv\n" or die "Makefile: $!\n";
|
|
179 }
|
|
180 }
|
|
181 print MAKEFILE "\n" or die "Makefile: $!\n";
|
|
182 }
|
|
183 print MAKEFILE "dist : ddsh_dist\n" or die "Makefile: $!\n";
|
|
184 print MAKEFILE "\n" or die "Makefile: $!\n";
|
|
185 close MAKEFILE or die "Makefile: $!\n";
|
|
186
|
|
187 sub extract {
|
|
188 my ($name, $suffix, $path) = @_;
|
|
189 my @unlink = ();
|
|
190 print "Uncompressing $name\n";
|
|
191 unlink "$name.$suffix";
|
|
192 system("gzip -dc '$name.$suffix.$gz_suffix' > $name.$suffix") == 0
|
|
193 or die "Uncompress failed: $!\n";
|
|
194 push @unlink, "$name.$suffix";
|
|
195 print "Extracting $name\n";
|
|
196 if ($suffix eq $ddsh_suffix) {
|
|
197 system('sh', "$name.$suffix") == 0
|
|
198 or die "Extraction failed: $!\n";
|
|
199 } elsif ($suffix eq $tar_suffix) {
|
|
200 system('tar', '-xf', "$name.$suffix") == 0
|
|
201 or die "Extraction failed: $!\n";
|
|
202 } else {
|
|
203 die "Internal error, suffix is not supposed to be $suffix\n";
|
|
204 }
|
|
205 unlink @unlink;
|
|
206 print "Running Makefile.PL for $name\n";
|
|
207 system("cd '$path' && $^X Makefile.PL @A") == 0
|
|
208 or die "Makefile.PL failed: $!\n";
|
|
209 }
|
|
210
|
|
211 sub MY::tools_other {
|
|
212 package MY;
|
|
213 my $i = shift->SUPER::tools_other(@_);
|
|
214 $constants .= $i;
|
|
215 $i;
|
|
216 }
|
|
217
|
|
218 sub MY::dist {
|
|
219 package MY;
|
|
220 my $i = shift->SUPER::dist(@_);
|
|
221 $constants .= $i;
|
|
222 $i;
|
|
223 }
|
|
224
|
|
225 1;
|