-
Notifications
You must be signed in to change notification settings - Fork 28
/
buildit.pl
executable file
·136 lines (106 loc) · 3.51 KB
/
buildit.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
#!/usr/bin/env perl
# Building with pp does NOT WORK with perl v5.10.0
# v5.10.0 will produce strange behavior in PAR applications
# Use Perl v5.10.1 and above only.
use File::Copy::Recursive qw(dircopy);
use Path::Class;
use Cwd;
use Data::Dumper;
my $filesToAdd = "";
my $copyTo = dir( cwd, 'build', 'current' );
$copyTo->mkpath();
my $copyFrom = dir(cwd);
print "Copying source files into build/current\n\n";
my $assetsList = "";
my $templatesList = "";
$filesToAdd .= " -a assets.list -a templates.list";
my $src_dir = dir('src');
$src_dir->recurse(
callback => sub {
my ($source) = @_;
my @components = $source->components();
shift @components;
if ( -d $source ) {
( dir( $copyTo, @components ) )->mkpath();
} elsif ( -f $source && $source->basename() !~ /^\./ ) {
my $file = file(@components);
$source->copy_to( file( $copyTo, $file ) );
$file = $file->as_foreign('Unix');
print $file. "\n";
$filesToAdd .= " -a " . qq($file);
if ( $file =~ /^assets/ ) {
$assetsList .= "$file\n";
} elsif ( $file =~ /^templates/ ) {
$templatesList .= "$file\n";
}
}
}
);
( file( $copyTo, 'assets.list' ) )->spew($assetsList);
( file( $copyTo, 'templates.list' ) )->spew($templatesList);
my $lib_dir = dir( $copyTo, 'lib' );
$lib_dir->mkpath();
if ( $^O =~ /MSWin/ ) {
use Win32::Exe;
print "\nWindows build.\n\n";
( file( 'build', 'win', 'ttmp32gme.ico' ) )->copy_to( file( $copyTo, 'ttmp32gme.ico' ) );
( dir( 'lib', 'win' ) )->recurse(
callback => sub {
my ($source) = @_;
my $name = $source->basename();
if ( -f $source && $name !~ /^\./ ) {
$source->copy_to( file( $lib_dir, $name ) );
print 'lib/' . $name . "\n";
$filesToAdd .= " -a " . qq(lib/$name);
}
}
);
chdir($copyTo);
my $addDlls = '-l libxml2-2__.dll -l libiconv-2__.dll -l zlib1__.dll -l liblzma-5__.dll';
my $result = `pp -M Win32API::File -c $addDlls $filesToAdd -o ttmp32gme.exe ttmp32gme.pl`;
# newer versions of pp don't support the --icon option any more, use Win32::Exe to manually replace the icon:
# $exe = Win32::Exe->new('ttmp32gme.exe');
# $exe->set_single_group_icon('ttmp32gme.ico');
# $exe->write;
print $result;
if ( $? != 0 ) { die "Build failed.\n"; }
chdir('..\..');
my $distdir = dir('dist');
$distdir->mkpath();
( file( $copyTo, 'ttmp32gme.exe' ) )->copy_to( file( $distdir, 'ttmp32gme.exe' ) );
`explorer dist`;
print "Build successful.\n";
} elsif ( $^O eq 'darwin' ) {
print "\nMac OS X build.\n\n";
( dir( 'lib', 'mac' ) )->recurse(
callback => sub {
my ($source) = @_;
my $name = $source->basename();
if ( -f $source && $name !~ /^\./ ) {
$source->copy_to( file( $lib_dir, $name ) );
print 'lib/' . $name . "\n";
$filesToAdd .= ' -a ' . 'lib/' . $name;
}
}
);
chdir($copyTo);
my $result = `/usr/local/bin/pp -c $filesToAdd -o mp32gme ttmp32gme.pl`;
print $result;
if ( $? != 0 ) { die "Build failed.\n"; }
chdir('../..');
my $distdir = dir('dist');
$distdir->mkpath();
my $app_dir = dir( $distdir, 'ttmp32gme.app' );
dircopy( ( dir( 'build', 'mac', 'ttmp32gme.app' ) )->stringify, ($app_dir)->stringify );
( file( $copyTo, 'mp32gme' ) )->copy_to( file( $app_dir, 'Contents', 'Resources', 'ttmp32gme' ) );
`open dist`;
print "Build successful.\n";
} else {
print
"Unsupported platform. Try installing the required perl modules and running the script out of the src folder.\n"
. "Maybe even send in a patch with a build script for your platform.\n";
}
print "Cleaning build folders.\n";
$copyTo->rmtree();
print "Done.\n";
exit(0);