PageRenderTime 42ms CodeModel.GetById 20ms app.highlight 19ms RepoModel.GetById 1ms app.codeStats 0ms

/scripts/SDLpp.pl

http://github.com/PerlGameDev/SDL
Perl | 231 lines | 144 code | 55 blank | 32 comment | 28 complexity | f47e9f1da2dab1ca19057796b8ecb6d7 MD5 | raw file
  1
  2=pod
  3
  4=head1 NAME
  5
  6SDLpp - Package your SDL games
  7
  8=head1 SETUP
  9
 10 cpan Alien::SDL SDL
 11
 12 cpan Module::ScanDeps 
 13
 14version 0.97 needed
 15
 16 cpan PAR::Packer 
 17
 18version 1.004 needed
 19
 20pip http://strawberryperl.com/package/kmx/perl-modules-patched/PAR-1.000_patched.tar.gz
 21
 22=head1 USAGE
 23
 24  perl SDLpp.pl --output=a.exe  --input=script.pl --nclude=./lib --more=Foo::Bar,Bar::Foo 
 25
 26=head1 AUTHOR
 27
 28kthakore 
 29
 30=cut
 31
 32use strict;
 33use warnings;
 34use SDL;
 35use Alien::SDL;
 36use Getopt::Long;
 37use File::Spec;
 38use File::Find qw/finddepth/;
 39
 40use Data::Dumper;
 41use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
 42
 43#Checking if we have the pp installed
 44die 'Need PAR::Packer' if !( eval ' use PAR::Packer; 1' );
 45
 46#Default out put is a or a.exe for windows
 47my $output = 'a';
 48$output .= '.exe' if $^O =~ /win32/ig;
 49
 50my $libs = 'SDL,SDL-1.2,SDLmain';
 51
 52my $input;
 53
 54my $Include = '';
 55
 56my $extra = '';
 57
 58my $result = GetOptions(
 59	"output=s" => \$output,
 60	"libs=s"   => \$libs,
 61	"input=s"  => \$input,
 62	"nclude=s" => \$Include,
 63	"more=s"   => \$extra,
 64	"help"     => sub { usage() },
 65);
 66
 67$extra = '-M ' . $extra if $extra;
 68$extra =~ s/,/ \-M /g;
 69
 70my @sdl_libs = split ',', $libs;
 71
 72sub usage {
 73	print
 74		" perl SDLpp.pl --output=a.exe --libs=SDL,SDL_main,SDL_gfx  --input=script.pl --nclude=./lib --more=Foo::Bar,Bar::Foo \n"
 75		. " if --libs is not define only SDL,SDL-1.2,SDLmain libs are packaged \n";
 76
 77	exit;
 78}
 79
 80if ( !$input ) {
 81	warn 'Input needs to be specified.';
 82	usage;
 83}
 84
 85print "BUILDING PAR \n";
 86my $exclude_modules = '-X Alien::SDL::ConfigData -X SDL::ConfigData';
 87my $include_modules = '-M ExtUtils::CBuilder::Base -M Data::Dumper -M SDL -M Alien::SDL';
 88$include_modules .= " $extra" if $extra;
 89
 90my $out_par = $output . '.par';
 91my $par_cmd = "pp -B $exclude_modules $include_modules";
 92$par_cmd .= " -I $Include" if $Include;
 93$par_cmd .= " -p -o $out_par $input";
 94
 95print "\t $par_cmd \n";
 96
 97`$par_cmd` if !-e $out_par;
 98
 99print "PAR: $out_par\n" if -e $out_par;
100
101print "SEARCHING FOR ConfigData files \n";
102my $lib;
103my $AS_path;
104my $SD_path;
105
106finddepth( \&wanted, @INC );
107
108sub wanted {
109
110	if ( $_ =~ /ConfigData/ ) {
111		$AS_path = $File::Find::name
112			if $File::Find::name =~ 'Alien/SDL/ConfigData.pm';
113		$SD_path = $File::Find::name
114			if $File::Find::name =~ 'SDL/ConfigData.pm'
115				&& $File::Find::name !~ 'Alien/SDL/ConfigData.pm';
116
117		$lib = $File::Find::dir if ( $AS_path && $SD_path );
118	}
119}
120
121die "Cannot find lib/SDL/ConfigData.pm or lib/Alien/SDL/ConfigData.pm \n"
122	if ( !$AS_path || !$SD_path );
123
124print "Found ConfigData files in $lib \n";
125
126print "READING PAR FILE \n";
127
128my $par_file = Archive::Zip->new();
129unless ( $par_file->read($out_par) == AZ_OK ) {
130	die 'read error on ' . $out_par;
131}
132
133$par_file->addFile( $AS_path, 'lib/Alien/SDL/ConfigData.pm' );
134$par_file->addFile( $SD_path, 'lib/SDL/ConfigData.pm' );
135
136my $share = Alien::SDL::ConfigData->config('share_subdir');
137
138my @shares = $par_file->membersMatching($share);
139
140my $alien_sdl_auto = $shares[0]->fileName;
141
142$alien_sdl_auto =~ s/$share(\S+)// if $alien_sdl_auto;
143
144my @auto_folder = $par_file->membersMatching("$alien_sdl_auto(?!$share)");
145
146my @sdl_not_runtime = $par_file->membersMatching( $share . '/include' ); #TODO remove extra fluff in share_dri
147push @sdl_not_runtime, @auto_folder;                                     #remove non share dir stuff
148push @sdl_not_runtime, $par_file->membersMatching( $share . '/etc' );
149push @sdl_not_runtime, $par_file->membersMatching( $share . '/share' );
150push @sdl_not_runtime, $par_file->membersMatching( $share . '/lib' )
151	if $^O =~ /win32/ig;
152
153my @non              = ();
154my @sdl_libs_to_keep = ();
155
156foreach (@sdl_libs) {
157	if ( $^O =~ /win32/ig ) {
158		@non = $par_file->membersMatching( $share . "/bin(\\S+)" );
159
160		#push @sdl_not_runtime ,$par_file->membersMatching( $share."/bin(\\S+)(?!$_)" )
161	} else {
162		@non = $par_file->membersMatching( $share . "/lib(\\S+)" );
163	}
164
165	print "Removing non $_ shared objs \n";
166	my $lib_look = 'lib' . $_;
167	map {
168		my $n = $_->fileName;
169		if ( $n =~ /$lib_look\.(so|a|dll|dylib)/ ) {
170			push( @sdl_libs_to_keep, $_ );
171		}
172
173	} @non;
174
175}
176
177print "found $#sdl_libs_to_keep sdl libs to keep \n";
178my $regex_search = ']';
179map {
180	print "\t " . $_->fileName . "\n";
181	$regex_search .= ']' . $_->fileName
182} @sdl_libs_to_keep;
183
184$regex_search =~ s/\]\]//g;
185$regex_search =~ s/\]/\|/g;
186
187$regex_search = '(' . $regex_search . ')';
188
189map {
190	my $n    = $_->fileName;
191	my $star = ' ';
192
193	if ( $n !~ $regex_search ) {
194		push @sdl_not_runtime, $_;
195	}
196} @non;
197
198push @sdl_not_runtime, $par_file->membersMatching( $share . '/bin' )
199	unless $^O =~ /win32/ig;
200print "REMOVING NON RUNTIME $#sdl_not_runtime files from  \n";
201open( my $FH, '>', 'DeleteRecords.txt' ) or die $!;
202foreach (@sdl_not_runtime) {
203	if ( $_->fileName eq $alien_sdl_auto . $share ) {
204		print $FH "Not deleting " . $_->fileName . " \n";
205	} else {
206		$par_file->removeMember($_);
207		print $FH $_->fileName . "\n";
208	}
209
210}
211close $FH;
212
213my @config_members = $par_file->membersMatching('ConfigData.pm');
214
215foreach (@config_members) {
216	$_->desiredCompressionLevel(1);
217	$_->unixFileAttributes(0644);
218}
219
220unlink $out_par . '2';
221unless ( $par_file->writeToFileNamed( $out_par . '2' ) == AZ_OK ) {
222	die 'write error';
223}
224
225$par_cmd = "pp -o $output " . $out_par . "2";
226
227`$par_cmd`;
228
229print "MADE $output \n" if -e $output;
230unlink $out_par . '2';
231unlink $out_par;