This repository was archived by the owner on Mar 4, 2020. It is now read-only.
forked from jdlbot/jdlbot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuildit.pl
More file actions
executable file
·122 lines (94 loc) · 3.45 KB
/
buildit.pl
File metadata and controls
executable file
·122 lines (94 loc) · 3.45 KB
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
#!/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;
use File::Copy::Recursive qw(fcopy rcopy dircopy);
use Path::Class;
use File::Path qw(make_path remove_tree);
use File::Find;
use Cwd;
my $modulesToAdd = "-M UNIVERSAL -M Moose::Meta::Object::Trait -M Package::Stash::XS -M URI::Find";
my $filesToAdd = "";
my $copyTo = (dir( cwd , 'build', 'current' ))->stringify;
my $copyFrom = (dir( cwd ))->stringify;
my $path_sep = '\/';
print "Copying source files into build/current\n\n";
my $assetsList = "";
$filesToAdd .= " -a assets.list";
find( { wanted => sub {
if( $_ !~ /^\./ ){
if( -f (file($copyFrom , $File::Find::name))->stringify ){
my $toName = $File::Find::name;
$toName =~ s/^src$path_sep//;
print "$toName\n";
rcopy( (file($copyFrom , $File::Find::name))->stringify , (file($copyTo , $toName))->stringify );
$filesToAdd .= " -a $toName";
if ($toName =~ /^assets/) {
$assetsList .= "$toName\n"
}
}
}
} , no_chdir => 0 }, 'src');
my $builddir = (dir('build', 'current'))->stringify;
if ( ! -d $builddir ){
make_path($builddir);
}
my $assetsListFile = (file($copyTo,'assets.list'))->stringify;
open (my $fh, '>', $assetsListFile) or die "Could not open file '$assetsList' $!";
print $fh $assetsList;
close($fh);
if ( $^O =~ /MSWin/ ){
use Win32::Exe;
print "\nWindows build.\n\n";
copy((file('build', 'win', 'jdlbot.ico'))->stringify, (file($builddir, 'jdlbot.ico'))->stringify);
my $librariesToAdd = '-l libeay32__.dll -l ssleay32__.dll -l zlib1__.dll';
chdir($builddir);
my $result = `pp -M attributes $librariesToAdd $filesToAdd $modulesToAdd -o jdlbotServer.exe jdlbotServer.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('jdlbotServer.exe');
# $exe->set_single_group_icon('jdlbot.ico');
# $exe->write;
print $result;
if ( $? != 0 ){ die "Build failed.\n"; }
chdir('..\..');
my $distdir = 'dist';
if ( ! -d $distdir ){
make_path($distdir);
}
fcopy((file($builddir , 'jdlbotServer.exe'))->stringify, (file('dist', 'jdlbotServer.exe'))->stringify);
`explorer dist`;
print "Build successful.\n";
} elsif ( $^O eq 'darwin' ){
print "\nMac OS X build.\n\n";
chdir($builddir);
my $libxml = '-l /usr/lib/libxml2.dylib';
if( `which brew` ){
my $brew_xml_dir = `brew --cellar libxml2`;
$brew_xml_dir =~ s/\n|\r//g;
if( -d "$brew_xml_dir" ){
$brew_xml_dir = `brew --prefix libxml2`;
$brew_xml_dir =~ s/\n|\r//g;
$libxml = "-l $brew_xml_dir/lib/libxml2.dylib";
}
}
my $result = `pp $libxml $filesToAdd $modulesToAdd -o jdlbotServer jdlbotServer.pl`;
print $result;
if ( $? != 0 ){ die "Build failed.\n"; }
chdir('../..');
my $distdir = 'dist';
if ( ! -d $distdir ){
make_path($distdir);
}
dircopy((dir('build', 'mac', 'jDlBot.app'))->stringify,(dir('dist', 'jDlBot.app'))->stringify );
fcopy((file('build', 'current', 'jdlbotServer'))->stringify, (file('dist', 'jDlBot.app', 'Contents', 'Resources', 'jdlbotServer'))->stringify);
`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";
remove_tree($builddir, {keep_root => 1});
print "Done.\n";
exit(0);