-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmake.pl
executable file
·1109 lines (1024 loc) · 28 KB
/
make.pl
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
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/perl
#-------------------------------------------------------------------------------
# make.pl
#
# Copyright (C) 2006-2011 Oliver Hamann.
#
# Homepage: http://eaglemode.sourceforge.net/
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License version 3 as published by the
# Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License version 3 for
# more details.
#
# You should have received a copy of the GNU General Public License version 3
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#-------------------------------------------------------------------------------
use strict;
use warnings;
use Config;
use Cwd;
use File::Basename;
use File::Copy;
use File::Path;
use File::Spec::Functions;
use IO::Handle;
#================================== Constants ==================================
my $ProjectName = 'eaglemode';
my $ProjectTitle = 'Eagle Mode';
my $ProjectComment = 'Zoomable user interface with plugin applications';
my $ProjectIcon = 'res/icons/eaglemode48.png';
my $ProjectCategories = 'System;FileManager;';
my $UniccDir = catfile("makers","unicc");
my $UtilsDir = catfile("makers","utils");
my $PackersDir = catfile("makers","packers");
my $MakersDir = "makers";
my $MakersEnding = ".maker.pm";
my $DefaultsMaker = "defaults";
my $BuildingDoneFile = catfile("obj","building_done");
my $DefaultInstallDirectory = catfile(
($Config{'osname'} eq 'MSWin32') ?
eval(
"use Win32::TieRegistry;".
"\$Registry->{'HKEY_LOCAL_MACHINE\\\\Software\\\\Microsoft\\\\'.".
" 'Windows\\\\CurrentVersion\\\\\\\\ProgramFilesDir'}"
)
:
'/usr/local'
,
$ProjectName
);
my $DirectorySeparator=substr(catfile("x","y"),1,1);
my $CLEAN_FLAG = 1<<0;
my $INSTALL_FLAG = 1<<1;
my $EXEC_FLAG = 1<<2;
my $PRIVATE_FLAG = 1<<3;
my $NOBACKUP_FLAG = 1<<4;
#================================== Functions ==================================
sub Help
# Print help text.
# Arguments: none
# Returns: none
{
print(
"Usage:\n".
" perl $0 build [<option>=<value>]...\n".
" Compile and link.\n".
" Options:\n".
" compiler=<name> (default: gnu)\n".
" Which compiler and linker to be used. For more information, please\n".
" read the Compilers section at the end of doc/html/MakeSystem.html.\n".
" projects=all|[not:]<name>[,<name>]... (default: all)\n".
" Which projects to be built. The keyword \"not:\" means to build all\n".
" but the given projects (except through dependencies).\n".
" continue=ask|yes|no (default: ask)\n".
" What to do when there is an error in building a project which is\n".
" not essential.\n".
" debug=yes|no (default: no)\n".
" Whether to have debug information in the binaries.\n".
" cpus=<n> (default: 1)\n".
" Number of CPUs to be used. More precisely, it is the maximum\n".
" number of source files to be compiled in parallel.\n".
" Further options may be defined by the maker scripts (see below).\n".
" perl $0 show-extra-options\n".
" Print a list of extra options for the build command, defined by the\n".
" maker scripts.\n".
" perl $0 install [<option>=<value>]...\n".
" Install the binaries and their required files.\n".
" Options:\n".
" dir=<target directory> (default: $DefaultInstallDirectory)\n".
" Set the target directory. \n".
" menu=yes|no (default: no)\n".
" Whether to create a desktop start menu entry. This creates\n".
" the file /usr/\[local/\]share/applications/$ProjectName.desktop.\n".
" bin=yes|no (default: no)\n".
" Whether to create a binary in path. This creates\n".
" the file /usr/\[local/\]bin/$ProjectName.\n".
" root=<root directory> (default: <empty>)\n".
" A directory prefix which shall be prepended to the paths of all\n".
" installed files and directories without adapting the contents of\n".
" files generated by the menu and bin options. This is an advanced\n".
" option for packagers.\n".
" simulate=yes|no (default: no)\n".
" If this is set to yes, installation is not really performed, but\n".
" it is shown what would be installed.\n".
" perl $0 pack <type>\n".
" Create a binary or source package for distribution and/or installation.\n".
" This does NOT require to call build before. Possible types are:\n".
" deb - Debian package.\n".
" ebuild - Gentoo build file.\n".
" exe - Windows setup executable.\n".
" lzm - Slax package.\n".
" rpm - Red Hat package.\n".
" tgz - Slackware package.\n".
" tar.bz2, tar.gz or zip - Source package.\n".
" The packages are created in a subdirectory named \"packages\".\n".
" perl $0 clean [<option>=<value>]...\n".
" Delete generated files.\n".
" Options:\n".
" level=0|1 (default: 1)\n".
" 0 - Delete generated files which are not needed for installation\n".
" and execution.\n".
" 1 - Delete all generated files.\n".
" simulate=yes|no (default: no)\n".
" If this is set to yes, deletion is not really performed, but it is\n".
" shown what would be deleted.\n".
" perl $0 list [<option>=<value>]...\n".
" Print a list of files and directories.\n".
" Options:\n".
" filter=[+|-<flag>[+|-<flag>...]] (default: <no filter>)\n".
" Only list files that have certain flags set (+) or unset (-).\n".
" Possible flags are: clean, install, exec, private, nobackup.\n".
" listdirs=yes|no (default: no)\n".
" Whether to include directories in the listing.\n".
" includeparent=yes|no (default: no)\n".
" Whether to include the name of the parent directory in the paths.\n".
" perl $0 help\n".
" Print this help.\n"
);
}
sub LoadAllMakers
# Load all the maker files ("do" them).
# Arguments: none
# Returns: @ - array of the names of all the makers.
{
my $elen=length($MakersEnding);
my @names=();
my $dh;
# Get all names of makers, without MakersEnding.
opendir($dh,$MakersDir);
while (defined(my $s=readdir($dh))) {
if (substr($s,-$elen,$elen) eq $MakersEnding) {
push(@names,substr($s,0,length($s)-$elen));
}
}
closedir($dh);
# Sort the makers by name (but see more below). This is just to avoid
# random order.
@names=sort(@names);
# Do the maker files.
for (my $i=0; $i<@names; $i++) {
my $path=catfile($MakersDir,"$names[$i]$MakersEnding");
do("$path");
if ($@) {
die("$@");
}
}
# Bring the essential makers to the beginning so that they are called
# first. This avoids wasting time with unessential things before failing
# by something essential.
for (my $i=0, my $j=0; $i<@names; $i++) {
if ($names[$i]->IsEssential()) {
if ($i>$j) { splice(@names,$j,0,splice(@names,$i,1)); }
$j++;
}
}
return @names;
}
sub AD_Recurse
# Helper function for ApplyDependencies.
# Arguments:
# \@ - Reference to the resulting array of makers.
# \@ - Reference to a hash table with states for all makers
# (0=it exists, 1=on stack, 2=in result).
# @ - The maker to add.
# Returns: none
{
my $resultRef=shift;
my $stateRef=shift;
my $maker=shift;
if (!exists($$stateRef{$maker})) {
die("Unknown project '$maker', stopped");
}
elsif ($$stateRef{$maker} eq 0) {
$$stateRef{$maker}=1;
my @dependencies=$maker->GetDependencies();
for (my $i=0; $i<@dependencies; $i++) {
AD_Recurse($resultRef,$stateRef,$dependencies[$i]);
}
push(@$resultRef,$maker);
$$stateRef{$maker}=2;
}
elsif ($$stateRef{$maker} eq 1) {
die("Circular dependencies with project '$maker', stopped");
}
}
sub ApplyDependencies
# Apply the dependencies on a set of makers. The defaults maker is
# automatically included.
# Arguments:
# \@ - Reference to array of all loaded makers (read only).
# @ - Array of target makers.
# Returns:
# @ - Sorted array of makers to be executed.
{
my $allRef=shift;
my @makers=@_;
my @result=();
my %state=();
for (my $i=0; $i<@$allRef; $i++) {
$state{$$allRef[$i]}=0;
}
AD_Recurse(\@result,\%state,$DefaultsMaker);
for (my $i=0; $i<@makers; $i++) {
AD_Recurse(\@result,\%state,$makers[$i]);
}
return @result;
}
sub GetFileHandlingRules
# Get the file handling rules from the makers in a translated form.
# Arguments:
# \@ - Reference to array of all loaded makers with the dependencies
# already applied (read only).
# Returns:
# @ - An array of references to rules: Each rule is an array of three
# things: a flag mask for the and-operation, a flag mask for the
# or-operation and the regex-pattern.
{
my $allMakersRef=shift;
my @rules=();
for (my $i=0; $i<@$allMakersRef; $i++) {
my $maker=$$allMakersRef[$i];
my @origRules=$maker->GetFileHandlingRules();
for (my $j=0; $j<@origRules; $j++) {
my $origRule=$origRules[$j];
my $k=index($origRule,':');
if ($k <= 0) {
die("No colon in file handling rule '$origRule' from project '$maker', stopped");
}
my $pattern=substr($origRule,$k+1);
my $ops=substr($origRule,0,$k);
my $andMask=0xff;
my $orMask=0;
do {
my $eat;
if ($ops =~ /^\+clean/) {
$orMask|=$CLEAN_FLAG;
$eat=6;
}
elsif ($ops =~ /^-clean/) {
$andMask&=(~$CLEAN_FLAG);
$eat=6;
}
elsif ($ops =~ /^\+install/) {
$orMask|=$INSTALL_FLAG;
$eat=8;
}
elsif ($ops =~ /^-install/) {
$andMask&=(~$INSTALL_FLAG);
$eat=8;
}
elsif ($ops =~ /^\+exec/) {
$orMask|=$EXEC_FLAG;
$eat=5;
}
elsif ($ops =~ /^-exec/) {
$andMask&=(~$EXEC_FLAG);
$eat=5;
}
elsif ($ops =~ /^\+private/) {
$orMask|=$PRIVATE_FLAG;
$eat=8;
}
elsif ($ops =~ /^-private/) {
$andMask&=(~$PRIVATE_FLAG);
$eat=8;
}
elsif ($ops =~ /^\+nobackup/) {
$orMask|=$NOBACKUP_FLAG;
$eat=9;
}
elsif ($ops =~ /^-nobackup/) {
$andMask&=(~$NOBACKUP_FLAG);
$eat=9;
}
else {
die("Error in file handling rule '$origRule' from project '$maker', stopped");
}
$ops=substr($ops,$eat);
} while (length($ops) != 0);
push(@rules,[$andMask,$orMask,$pattern]);
}
}
return @rules;
}
sub GetFileHandling
# Get the handling flags for a file.
# Arguments:
# \@ - Reference to the file handling rules returned by
# GetFileHandlingRules (read only).
# @ - The relative path of the file.
# Returns:
# $ - Combination of the flags $CLEAN_FLAG, $INSTALL_FLAG, $EXEC_FLAG,
# $PRIVATE_FLAG and $NOBACKUP_FLAG.
{
my $rulesRef=shift;
my $path=shift;
# Translate the directory separators to '/' in the path (only for the
# pattern matching).
if ($DirectorySeparator ne '/') {
for (my $i=0; $i>=0;) {
$i=index($path,$DirectorySeparator,$i);
if ($i>=0) {
$path=
substr($path,0,$i).
'/'.
substr($path,$i+length($DirectorySeparator))
;
}
}
}
# Apply the rules.
my $flags=0;
for (my $i=0; $i<@$rulesRef; $i++) {
my $rule=$$rulesRef[$i];
if ($path =~ $$rule[2]) {
$flags &= $$rule[0];
$flags |= $$rule[1];
}
}
return $flags;
}
sub GetExtraBuildOptions
# Get the extra build options from the makers.
# Arguments:
# \@ - Reference to array of all loaded makers (read only).
# Returns:
# @ - An array of references: each element is an array of four
# things: option name, default value, description and maker name.
{
my $allMakersRef=shift;
my @allOpts=();
for (my $i=0; $i<@$allMakersRef; $i++) {
my $maker=$$allMakersRef[$i];
my @opts=$maker->GetExtraBuildOptions();
for (my $j=0; $j<@opts; $j++) {
my $opt=$opts[$j];
push(@allOpts,[$$opt[0],$$opt[1],$$opt[2],$maker]);
}
}
return @allOpts;
}
sub IsDirectoryEmpty
# Check whether a directory is empty.
# Arguments:
# $ - The directory.
# Returns:
# $ - 1 if empty, 0 if not.
{
my $dir=shift;
my $dh;
opendir($dh,$dir);
while (defined(my $name=readdir($dh))) {
if ($name ne "." and $name ne "..") {
closedir($dh);
return 0;
}
}
closedir($dh);
return 1;
}
sub ReadDirectoryTree
# Read a directory tree and return a sorted array of all paths.
# Arguments:
# Optional: $ - The directory to be read.
# Optional: $ - A prefix to be prepended to the resulting paths.
# Optional: $ - Whether to have children before parents in the list.
# Returns:
# @ - Sorted array of all paths.
{
my $dir=shift;
if (!defined($dir)) { $dir="."; }
my $prefix=shift;
if (!defined($prefix)) { $prefix=""; }
my $childrenBeforeParents=shift;
if (!defined($childrenBeforeParents)) { $childrenBeforeParents=0; }
my $dh;
opendir($dh,$dir);
my @names=sort(readdir($dh));
closedir($dh);
my @result=();
for (my $i=0; $i<@names; $i++) {
my $name=$names[$i];
if ($name ne "." and $name ne "..") {
if ($childrenBeforeParents == 0) {
push(@result,$prefix.$name);
}
my $subDir=catfile($dir,$name);
if (-d($subDir)) {
my $subPrefix=$prefix.$name.$DirectorySeparator;
push(
@result,
ReadDirectoryTree($subDir,$subPrefix,$childrenBeforeParents)
);
}
if ($childrenBeforeParents != 0) {
push(@result,$prefix.$name);
}
}
}
return @result;
}
sub Build
# Perform the build command.
# Arguments:
# @ - The options.
# Results: none
{
# Load the makers.
my @allMakers=LoadAllMakers();
# Prepare default options.
my %options=(
'compiler', 'gnu',
'projects', 'all',
'continue', 'ask',
'debug', 'no',
'cpus', 1
);
my @extraOpts=GetExtraBuildOptions(\@allMakers);
for (my $i=0; $i<@extraOpts; $i++) {
$options{$extraOpts[$i]->[0]}=$extraOpts[$i]->[1];
}
# Parse option arguments.
for (my $i=0; $i<@_; $i++) {
my $e=index($_[$i],"=");
if ($e<0) {
die("Not a valid option: '$_[$i]', stopped");
}
my $name=substr($_[$i],0,$e);
my $value=substr($_[$i],$e+1);
if (!defined($options{$name})) {
die("Unknown option name '$name', stopped");
}
$options{$name}=$value;
}
# Perform some checks on the options.
if ($options{'continue'} !~ /^(ask|yes|no)$/) {
die("Illegal value for option 'continue', stopped");
}
if ($options{'debug'} !~ /^(yes|no)$/) {
die("Illegal value for option 'debug', stopped");
}
# Add an option for the path of the unicc directory.
$options{'unicc'}=$UniccDir;
# Add an option for the unicc call.
$options{'unicc_call'}=[
'perl', catfile($UniccDir,'unicc.pl'),
'--compiler', $options{'compiler'},
'--cpus', $options{'cpus'},
$options{'debug'} eq 'yes' ? ("--debug") : ()
];
# Add an option for the path of the utils directory.
$options{'utils'}=$UtilsDir;
# Parse the 'projects' option and fill the array @makers.
my @makers=();
my $projects=$options{'projects'};
if ($projects eq 'all') {
@makers=@allMakers;
}
else {
my $not=0;
if (index($projects,'not:')==0) {
$not=1;
@makers=@allMakers;
$projects=substr($projects,4);
}
while (length($projects)>0) {
my $i=index($projects,',');
my $n;
if ($i<0) {
$n=$projects;
$projects='';
}
else {
$n=substr($projects,0,$i);
$projects=substr($projects,$i+1);
}
for ($i=@allMakers-1; ; $i--) {
if ($i<0) { die("Unknown project \"$n\", stopped"); }
if ($allMakers[$i] eq $n) { last; }
}
if ($not) {
for ($i=@makers-1; $i>=0; $i--) {
if ($makers[$i] eq $n) { splice(@makers,$i,1); }
}
}
else {
push(@makers,$n);
}
}
}
# Apply dependencies on the array of makers.
@makers=ApplyDependencies(\@allMakers,@makers);
# Remove the "building done" file (created again on success more below).
if (-e($BuildingDoneFile)) {
unlink($BuildingDoneFile);
}
my @failedNonEssentialMakers=();
# Loop for the makers.
for (my $i=0; $i<@makers; $i++) {
my $maker=$makers[$i];
# Print a header.
print("### $maker ###\n");
# Call the maker and check the result.
# Remember that ...->Build(%options) automatically prepends an
# argument which should be ignored by the implementation.
my $result;
eval { $result=$maker->Build(%options); };
if ($@) {
print(STDERR $@);
$result=0;
}
if ($result==0) {
if ($maker->IsEssential()) {
print(
"---\n".
"Building $maker failed!\n"
);
exit(1);
}
elsif ($options{"continue"} eq "no") {
print(
"---\n".
"Building $maker failed, but that project is not so essential.\n".
"So if you did not mean to stop at this point, restart with option\n".
"\"continue=ask\" or \"continue=yes\".\n"
);
exit(1);
}
elsif ($options{"continue"} eq "yes") {
push(@failedNonEssentialMakers,$maker);
}
else {
push(@failedNonEssentialMakers,$maker);
print(
"---\n".
"Building $maker failed, but that project is not so essential.\n".
"So if you don't know how to solve the problem, then you could\n".
"continue the overall building now, and live without the features\n".
"the project provides. Continue? [y(es)/n(o)/a(lways)]: "
);
for (my $again=1; $again eq 1;) {
STDOUT->flush();
my $ln=readline(*STDIN);
$.=0; # for that a call to die will not print an input line number.
if ($ln =~ /^\s*[nN]/) {
exit(1);
}
elsif ($ln =~ /^\s*[yY]/) {
$again=0;
}
elsif ($ln =~ /^\s*[aA]/) {
$options{"continue"}="yes";
$again=0;
}
elsif ($ln =~ /^\s*[rR]/) {
# *** secret option: "retry" ***
# I'm not satisfied with this, because:
# - The maker scripts are not reloaded (no effect if edited).
# - It's only for non-essential projects...
pop(@failedNonEssentialMakers);
$i--;
$again=0;
}
else {
print("Say yes, no or always: ");
}
}
}
}
}
# Create a file as an internal hint that installation is allowed now.
my $fh;
open($fh,">",$BuildingDoneFile);
close($fh);
# Print final messages.
if (@failedNonEssentialMakers != 0) {
print(
"---\n".
"Building succeeded! (But you will have to live without:"
);
for (my $i=0; $i<@failedNonEssentialMakers; $i++) {
if ($i>0) { print(","); }
print(" $failedNonEssentialMakers[$i]");
}
print(")\n");
}
else {
print(
"---\n".
"Building succeeded!\n"
);
}
if ($Config{'osname'} eq "cygwin") {
print(
"\n".
"*************************************************************************\n".
"*** VERY IMPORTANT: By all means, before starting the program, please ***\n".
"*** rebase all the Cygwin DLLs together with the DLLs built by this ***\n".
"*** project (subdirectory 'lib'). If you do not know how to do that, ***\n".
"*** get familiar with the Cygwin program 'rebaseall'. ***\n".
"*************************************************************************\n".
"\n"
);
}
}
sub ShowExtraOptions
# Perform the show-extra-options command.
# Arguments: none
# Results: none
{
my @allMakers=LoadAllMakers();
my @lst=GetExtraBuildOptions(\@allMakers);
my $maker="";
for (my $i=0; $i<@lst; $i++) {
if ($maker ne $lst[$i]->[3]) {
$maker=$lst[$i]->[3];
print("### $maker ###\n");
}
print("$lst[$i]->[2]\n");
}
}
sub Install
# Perform the install command.
# Arguments:
# @ - The options.
# Results: none
{
my $dir=$DefaultInstallDirectory;
my $haveMenu=0;
my $haveBin=0;
my $rootPrefix="";
my $simulate=0;
for (my $i=0; $i<@_; $i++) {
my $e=index($_[$i],"=");
if ($e<0) {
die("Not a valid option: '$_[$i]', stopped");
}
my $name=substr($_[$i],0,$e);
my $value=substr($_[$i],$e+1);
if ($name eq 'dir') {
$dir=$value;
}
elsif ($name eq 'menu') {
if ($value eq 'no') { $haveMenu=0; }
elsif ($value eq 'yes') {
if ($Config{'osname'} eq 'MSWin32') {
die "The menu option is not yet supported for this operating system, stopped";
}
$haveMenu=1;
}
else { die("Illegal value for option 'menu', stopped"); }
}
elsif ($name eq 'bin') {
if ($value eq 'no') { $haveBin=0; }
elsif ($value eq 'yes') {
if ($Config{'osname'} eq 'MSWin32') {
die "The bin option is not yet supported for this operating system, stopped";
}
$haveBin=1;
}
else { die("Illegal value for option 'bin', stopped"); }
}
elsif ($name eq 'root') {
$rootPrefix=$value;
}
elsif ($name eq 'simulate') {
if ($value eq 'no') { $simulate=0; }
elsif ($value eq 'yes') { $simulate=1; }
else { die("Illegal value for option 'simulate', stopped"); }
}
else {
die("Unknown option name '$name', stopped");
}
}
my @rawMakers=LoadAllMakers();
my @makers=ApplyDependencies(\@rawMakers,@rawMakers);
my @rules=GetFileHandlingRules(\@makers);
my @allPaths=ReadDirectoryTree();
if (!-e($BuildingDoneFile)) {
die("Please run 'perl $0 build' first.\n");
}
my $outDir=$rootPrefix.$dir;
if (!-e($outDir)) {
print("Making directory $outDir\n");
if ($simulate == 0) {
if (!mkpath($outDir,0,0755)) {
die "Failed to create directory \"$outDir\": $!";
}
}
}
for (my $i=0; $i<@allPaths; $i++) {
my $path=$allPaths[$i];
my $flags=GetFileHandling(\@rules,$path);
if (($flags&$INSTALL_FLAG)!=0) {
my $tgtPath=catfile($outDir,$path);
if (-d($path)) {
if (!-e($tgtPath)) {
print("Making directory $tgtPath\n");
if ($simulate == 0) {
if (!mkpath($tgtPath,0,0755)) {
die "Failed to create directory \"$tgtPath\": $!";
}
}
}
}
else {
print("Installing file $tgtPath\n");
if ($simulate == 0) {
if (!copy($path,$tgtPath)) {
die "Failed to copy \"$path\" to \"$tgtPath\": $!";
}
my $mode;
if (($flags&$EXEC_FLAG)!=0) {
$mode=0755;
}
else {
$mode=0644;
}
if (!chmod($mode,$tgtPath)) {
die "Failed to chmod \"$tgtPath\": $!";
}
}
}
}
}
if ($haveMenu) {
my $menuDir;
if (index($dir,"/usr/local/")==0) { $menuDir="/usr/local/share/applications"; }
else { $menuDir="/usr/share/applications"; }
$menuDir=$rootPrefix.$menuDir;
my $menuFile=catfile($menuDir,$ProjectName.'.desktop');
if (!-e($menuDir)) {
print("Making directory $menuDir\n");
if ($simulate == 0) {
if (!mkpath($menuDir,0,0755)) {
die "Failed to create directory \"$menuDir\": $!";
}
}
}
print("Installing file $menuFile\n");
if ($simulate == 0) {
my $fh;
open($fh,">",$menuFile);
print($fh
"[Desktop Entry]\n".
"Name=$ProjectTitle\n".
"Comment=$ProjectComment\n".
"Exec=$dir/$ProjectName.sh\n".
"Icon=$dir/$ProjectIcon\n".
"Terminal=false\n".
"Type=Application\n".
"Categories=$ProjectCategories\n".
"StartupNotify=true\n"
);
close($fh);
if (!chmod(0644,$menuFile)) {
die "Failed to chmod \"$menuFile\": $!";
}
}
}
if ($haveBin) {
my $binDir;
if (index($dir,"/usr/local/")==0) { $binDir="/usr/local/bin"; }
else { $binDir="/usr/bin"; }
$binDir=$rootPrefix.$binDir;
my $binFile=catfile($binDir,$ProjectName);
if (!-e($binDir)) {
print("Making directory $binDir\n");
if ($simulate == 0) {
if (!mkpath($binDir,0,0755)) {
die "Failed to create directory \"$binDir\": $!";
}
}
}
print("Installing file $binFile\n");
if ($simulate == 0) {
my $fh;
open($fh,">",$binFile);
print($fh
"#!/bin/sh\n".
"exec \"$dir/$ProjectName.sh\" \"\$@\"\n"
);
close($fh);
if (!chmod(0755,$binFile)) {
die "Failed to chmod \"$binFile\": $!";
}
}
}
}
sub Pack
# Perform the pack command.
{
my $type=shift;
if (!defined($type)) {
print(STDERR "You must specify a package type.\n");
exit(1);
}
$type=~tr/./-/;
my $path=catfile($PackersDir,'pack_'.$type.'_private.pl');
if (!-e $path) { $path=catfile($PackersDir,'pack_'.$type.'.pl'); }
system("perl",$path,@_)==0 || exit(1);
}
sub Clean
# Perform the clean command.
# Arguments:
# @ - The options.
# Results: none
{
my $level=1;
my $simulate=0;
for (my $i=0; $i<@_; $i++) {
my $e=index($_[$i],"=");
if ($e<0) {
die("Not a valid option: '$_[$i]', stopped");
}
my $name=substr($_[$i],0,$e);
my $value=substr($_[$i],$e+1);
if ($name eq 'level') {
if ($value eq '0') { $level=0; }
elsif ($value eq '1') { $level=1; }
else { die("Illegal value for option 'level', stopped"); }
}
elsif ($name eq 'simulate') {
if ($value eq 'no') { $simulate=0; }
elsif ($value eq 'yes') { $simulate=1; }
else { die("Illegal value for option 'simulate', stopped"); }
}
else {
die("Unknown option name '$name', stopped");
}
}
my @rawMakers=LoadAllMakers();
my @makers=ApplyDependencies(\@rawMakers,@rawMakers);
my @rules=GetFileHandlingRules(\@makers);
my @allPaths=ReadDirectoryTree(".","",1);
if ($level>=1 and -e($BuildingDoneFile)) {
print("Removing $BuildingDoneFile\n");
if ($simulate == 0) {
unlink($BuildingDoneFile) || die($!);
}
}
for (my $i=0; $i<@allPaths; $i++) {
my $path=$allPaths[$i];
my $flags=GetFileHandling(\@rules,$path);
if (
($flags&$CLEAN_FLAG)!=0 and
(($flags&$INSTALL_FLAG)==0 or $level>=1) and
$path ne $BuildingDoneFile
) {
if (-d($path)) {
if (IsDirectoryEmpty($path)==1) {
print("Removing $path\n");
if ($simulate == 0) {
rmdir($path) || die($!);
}
}
}
else {
print("Removing $path\n");
if ($simulate == 0) {
unlink($path) || die($!);
}
}
}
}
}
sub List
# Perform the list command.
# Arguments:
# @ - The options.
# Results: none
{
my $filterSet=0;
my $filterUnset=0;
my $listdirs=0;
my $includeparent=0;
for (my $i=0; $i<@_; $i++) {
my $e=index($_[$i],"=");
if ($e<0) {
die("Not a valid option: '$_[$i]', stopped");
}
my $name=substr($_[$i],0,$e);
my $value=substr($_[$i],$e+1);
if ($name eq 'filter') {
$filterSet=0;
$filterUnset=0;
while (length($value) != 0) {
my $op;
if ($value =~ /^\+/) {
$op=1;
}
elsif ($value =~ /^-/) {
$op=0;
}
else {
die("Illegal value for option 'filter', stopped");
}