summaryrefslogtreecommitdiff
path: root/infrastructure/makeparcels.pl.in
blob: ed2a01aac33a41a553fe62d31f729d8c0619a3cf (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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
#!@PERL@

use strict;
use lib 'infrastructure';
use BoxPlatform;

my @parcels;
my %parcel_contents;

sub starts_with ($$)
{
	my ($string,$expected) = @_;
	return substr($string, 0, length $expected) eq $expected;
}

sub os_matches ($)
{
	my ($prefix_string) = @_;
	my @prefixes = split m'\,', $prefix_string;
	foreach my $prefix (@prefixes)
	{
		return 1 if starts_with($build_os,  $prefix);
		return 1 if starts_with($target_os, $prefix);
	}
	return 0;
}

my $copy_command = "cp -p";

if ($build_os eq 'CYGWIN')
{
	$copy_command = "cp -pu"; # faster
}

open PARCELS,"parcels.txt" or die "Can't open parcels file";
{
	my $cur_parcel = '';
	while(<PARCELS>)
	{
		chomp; s/#.+\Z//; s/\s+\Z//; s/\s+/ /g;
		next unless m/\S/;
		
		# omit bits on some platforms?
		next if m/\AEND-OMIT/;
		if(m/\AOMIT:(.+)/)
		{
			if (os_matches($1))
			{
				while(<PARCELS>)
				{
					last if m/\AEND-OMIT/;	
				}
			}
			next;
		}

		if (m'\AONLY:(.+)')
		{
			if (not os_matches($1))
			{
				while (<PARCELS>)
				{
					last if m'\AEND-ONLY';
				}
			}
			next;
		}
		next if (m'\AEND-ONLY');

		if (m'\AEXCEPT:(.+)')
		{
			if (os_matches($1))
			{
				while (<PARCELS>)
				{
					last if m'\AEND-EXCEPT';
				}
			}
			next;
		}
		next if (m'\AEND-EXCEPT');
		
		# new parcel, or a new parcel definition?
		if(m/\A\s+(.+)\Z/)
		{
			push @{$parcel_contents{$cur_parcel}},$1
		}
		else
		{
			$cur_parcel = $_;
			push @parcels,$_;
		}
	}
}
close PARCELS;

# create parcels directory
mkdir "parcels",0755;
mkdir "parcels/scripts",0755;

# write master makefile

open MAKE,">Makefile" or die "Can't open master Makefile for writing";

print MAKE <<__E;
#
# AUTOMATICALLY GENERATED FILE
#    do not edit!
#
#

MAKE = $make_command

__E

print MAKE "all:\t",join(' ',map {"build-".$_} @parcels),"\n\n";

print MAKE <<__END_OF_FRAGMENT;
test:	release/common/test

release/common/test:
	./runtest.pl ALL release

.PHONY: docs
docs:
	cd docs; \$(MAKE)

__END_OF_FRAGMENT

my $release_flag = BoxPlatform::make_flag('RELEASE');
my @clean_deps;

for my $parcel (@parcels)
{
	my $version = BoxPlatform::parcel_root($parcel);
	my $target  = BoxPlatform::parcel_target($parcel);
	my $dir     = BoxPlatform::parcel_dir($parcel);
	my @parcel_deps;

	# Need to use BSD install on Solaris
	my $install_bin = $build_os eq 'SunOS' ? '/usr/ucb/install' : 'install';

	unless ($target_windows)
	{
		open SCRIPT,">parcels/scripts/install-$parcel" or die
			"Can't open installer script for $parcel for writing";
		print SCRIPT "#!/bin/sh\n\n";
	}

	for(@{$parcel_contents{$parcel}})
	{
		my @args = split /\s+/;

		my ($type,$name,$dest) = @args;
		my $optional = 0;
		my $install  = 1;

		if ($type eq 'optional')
		{
			$optional = 1;
			shift @args;
			($type,$name,$dest) = @args;
		}

		if ($type eq 'noinstall')
		{
			$install = 0;
			shift @args;
			($type,$name,$dest) = @args;
		}

		if($type eq 'bin')
		{
			my $exeext = $platform_exe_ext;
			print MAKE <<EOF;
$dir/$name$exeext: release/bin/$name/$name$exeext
	mkdir -p $dir
	$copy_command release/bin/$name/$name$exeext $dir

.PHONY: release/bin/$name/$name$exeext
release/bin/$name/$name$exeext:
	(cd bin/$name; \$(MAKE) $release_flag)

EOF
			push @parcel_deps, "$dir/$name$exeext";
		}
		elsif ($type eq 'script')
		{
			my $fullpath = $name;
			my $filename = $name;
			# remove path from script name
			$filename =~ s{.*/}{};

			print MAKE <<EOF;
$dir/$filename: $fullpath
	mkdir -p $dir
EOF

			if ($optional)
			{
				print MAKE "\ttest -r $fullpath " .
					"&& $copy_command $fullpath $dir || true\n";
			}
			else
			{
				print MAKE "\t$copy_command $fullpath $dir\n";
			}

			print MAKE "\n";

			push @parcel_deps, "$dir/$filename";
		}
		elsif($type eq 'man')
		{
			print MAKE <<EOF;
$dir/${name}.gz: docs/man/${name}.gz
	mkdir -p $dir
	$copy_command docs/man/${name}.gz $dir

EOF
			# Releases have the docs pre-made, but users
			# may want to rebuild them for some reason.
			print MAKE <<EOF;
.PHONY: docs/man/${name}.gz
docs/man/${name}.gz:
	cd docs; \$(MAKE) man/${name}.gz

EOF
			push @parcel_deps, "$dir/${name}.gz";
		}
		elsif($type eq 'html')
		{
			print MAKE <<EOF;
$dir/docs/${name}.html: docs/htmlguide/man-html/${name}.html
	mkdir -p $dir/docs
	$copy_command docs/htmlguide/man-html/${name}.html $dir/docs

EOF
			# Releases have the docs pre-made, but users
			# may want to rebuild them for some reason.
			print MAKE <<EOF;
.PHONY: docs/htmlguide/man-html/${name}.html
docs/htmlguide/man-html/${name}.html:
	cd docs; \$(MAKE) htmlguide/man-html/${name}.html

EOF
			push @parcel_deps, "$dir/docs/${name}.html";
		}
		elsif ($type eq 'subdir')
		{
			shift @args;
			my $subdir = shift @args;
			print MAKE <<EOF;
.PHONY: $name-build $name-clean

$name-build:
	cd $subdir; \$(MAKE) @args

$name-clean:
	cd $name; \$(MAKE) clean
EOF
			push @parcel_deps, "$name-build";
			push @clean_deps,  "$name-clean";
		}
	}

	print MAKE <<EOF;
build-$parcel:	$target

$target: @parcel_deps
	test -d $dir || mkdir $dir
EOF
	
	for(@{$parcel_contents{$parcel}})
	{
		my @args = split /\s+/;

		my ($type,$name,$dest) = @args;

		my $optional = 0;
		my $install  = 1;

		if ($type eq 'optional')
		{
			$optional = 1;
			shift @args;
			($type,$name,$dest) = @args;
		}

		if ($type eq 'noinstall')
		{
			$install = 0;
			shift @args;
			($type,$name,$dest) = @args;
		}

		if ($type eq 'script')
		{
			# remove path from script name
			$name =~ s{.*/}{};
		}

		if ($type eq 'html')
		{
			$dest = "share/doc/@PACKAGE_TARNAME@";
			$name = "docs/$name.html";
		}

		if ($type eq 'man')
		{
			$name =~ /([0-9])$/;
			$dest = "man/man$1";
			$name =~ s/$/\.gz/;
		}

		if ($install and not $target_windows and not $type eq "subdir")
		{
			my $local_install_dir = $install_into_dir;
			if (defined $dest)
			{
				if ($dest =~ m,^/,)
				{
					# Don't add $prefix if $dest is a literal path
					$local_install_dir = $dest;
				}
				else
				{
					$local_install_dir = "@prefix@/$dest";
				}
			}
			print SCRIPT "mkdir -p " .
				"\${DESTDIR}$local_install_dir/\n";
			print SCRIPT "$install_bin $name " .
				"\${DESTDIR}$local_install_dir\n";
		}
	}

	unless ($target_windows)
	{	
		close SCRIPT;
		chmod 0755,"parcels/scripts/install-$parcel";
	}
	
	my $root = BoxPlatform::parcel_root($parcel);

	unless ($target_windows)
	{
		print MAKE "\tcp parcels/scripts/install-$parcel $dir\n";
	}

	print MAKE "\t(cd parcels; tar cf - $root | gzip -9 - > $root.tgz )\n";
	
	print MAKE "\n";

	unless ($target_windows)
	{	
		print MAKE "install-$parcel:\n";
		print MAKE "\t(cd $dir; ./install-$parcel)\n\n";
	}
}

print MAKE <<EOF;
install:
	cat local/install.msg

clean: @clean_deps
	cd docs; \$(MAKE) clean
EOF

if ($build_os eq 'CYGWIN')
{
	print MAKE "\tfind release debug       -type f | xargs -r rm\n";
	print MAKE "\tfind . -name 'autogen_*' -type f | xargs -r rm\n";
}
else
{
	print MAKE "\tfind release debug       -type f -exec rm {} \\;\n";
	print MAKE "\tfind . -name 'autogen_*' -type f -exec rm {} \\;\n";
}

for my $parcel (@parcels)
{
	print MAKE "\trm -r ", BoxPlatform::parcel_dir($parcel),    "\n";
	print MAKE "\trm    ", BoxPlatform::parcel_target($parcel), "\n";
}

close MAKE;

open INSTALLMSG,">local/install.msg" or die "Can't open install message file for writing";
print INSTALLMSG <<__E;

Parcels need to be installed separately, and as root. Type one of the following:

__E

for(@parcels)
{
	print INSTALLMSG "    $make_command install-".$_."\n";
}
print INSTALLMSG "\n";

close INSTALLMSG;