… | |
… | |
8 | our $UNISTRIP = 1; # always on, try to strip unicore swash data |
8 | our $UNISTRIP = 1; # always on, try to strip unicore swash data |
9 | our $PERL = 0; |
9 | our $PERL = 0; |
10 | our $APP; |
10 | our $APP; |
11 | our $VERIFY = 0; |
11 | our $VERIFY = 0; |
12 | our $STATIC = 0; |
12 | our $STATIC = 0; |
|
|
13 | our $PACKLIST = 0; |
13 | |
14 | |
14 | our $OPTIMISE_SIZE = 0; # optimise for raw file size instead of for compression? |
15 | our $OPTIMISE_SIZE = 0; # optimise for raw file size instead of for compression? |
15 | |
16 | |
16 | our $CACHE; |
17 | our $CACHE; |
17 | our $CACHEVER = 1; # do not change unless you know what you are doing |
18 | our $CACHEVER = 1; # do not change unless you know what you are doing |
… | |
… | |
35 | |
36 | |
36 | $|=1; |
37 | $|=1; |
37 | |
38 | |
38 | our ($TRACER_W, $TRACER_R); |
39 | our ($TRACER_W, $TRACER_R); |
39 | |
40 | |
40 | sub find_inc($) { |
41 | sub find_incdir($) { |
41 | for (@INC) { |
42 | for (@INC) { |
42 | next if ref; |
43 | next if ref; |
43 | return $_ if -e "$_/$_[0]"; |
44 | return $_ if -e "$_/$_[0]"; |
44 | } |
45 | } |
45 | |
46 | |
46 | undef |
47 | undef |
47 | } |
48 | } |
48 | |
49 | |
|
|
50 | sub find_inc($) { |
|
|
51 | my $dir = find_incdir $_[0]; |
|
|
52 | |
|
|
53 | return "$dir/$_[0]" |
|
|
54 | if defined $dir; |
|
|
55 | |
|
|
56 | undef |
|
|
57 | } |
|
|
58 | |
49 | BEGIN { |
59 | BEGIN { |
50 | # create a loader process to detect @INC requests before we load any modules |
60 | # create a loader process to detect @INC requests before we load any modules |
51 | my ($W_TRACER, $R_TRACER); # used by tracer |
61 | my ($W_TRACER, $R_TRACER); # used by tracer |
52 | |
62 | |
53 | pipe $R_TRACER, $TRACER_W or die "pipe: $!"; |
63 | pipe $R_TRACER, $TRACER_W or die "pipe: $!"; |
… | |
… | |
55 | |
65 | |
56 | unless (fork) { |
66 | unless (fork) { |
57 | close $TRACER_R; |
67 | close $TRACER_R; |
58 | close $TRACER_W; |
68 | close $TRACER_W; |
59 | |
69 | |
|
|
70 | my $pkg = "pkg000000"; |
|
|
71 | |
60 | unshift @INC, sub { |
72 | unshift @INC, sub { |
61 | my $dir = find_inc $_[1] |
73 | my $dir = find_incdir $_[1] |
62 | or return; |
74 | or return; |
63 | |
75 | |
64 | syswrite $W_TRACER, "-\n$dir\n$_[1]\n"; |
76 | syswrite $W_TRACER, "-\n$dir\n$_[1]\n"; |
65 | |
77 | |
66 | open my $fh, "<:perlio", "$dir/$_[1]" |
78 | open my $fh, "<:perlio", "$dir/$_[1]" |
… | |
… | |
70 | }; |
82 | }; |
71 | |
83 | |
72 | while (<$R_TRACER>) { |
84 | while (<$R_TRACER>) { |
73 | if (/use (.*)$/) { |
85 | if (/use (.*)$/) { |
74 | my $mod = $1; |
86 | my $mod = $1; |
|
|
87 | my $pkg = ++$pkg; |
|
|
88 | my $eval = $mod = $mod =~ /[^A-Za-z0-9_:]/ |
75 | eval "require $mod"; |
89 | ? "require $mod" |
|
|
90 | : "{ package $pkg; use $mod; }"; |
|
|
91 | eval $eval; |
76 | warn "ERROR: $@ (while loading '$mod')\n" |
92 | warn "ERROR: $@ (while loading '$mod')\n" |
77 | if $@; |
93 | if $@; |
78 | syswrite $W_TRACER, "\n"; |
|
|
79 | } elsif (/eval (.*)$/) { |
94 | } elsif (/eval (.*)$/) { |
80 | my $eval = $1; |
95 | my $eval = $1; |
81 | eval $eval; |
96 | eval $eval; |
82 | warn "ERROR: $@ (in '$eval')\n" |
97 | warn "ERROR: $@ (in '$eval')\n" |
83 | if $@; |
98 | if $@; |
84 | } |
99 | } |
|
|
100 | |
|
|
101 | syswrite $W_TRACER, "\n"; |
85 | } |
102 | } |
86 | |
103 | |
87 | exit 0; |
104 | exit 0; |
88 | } |
105 | } |
89 | } |
106 | } |
90 | |
107 | |
91 | # module loading is now safe |
108 | # module loading is now safe |
92 | |
109 | |
93 | sub trace_module { |
110 | sub trace_parse { |
94 | syswrite $TRACER_W, "use $_[0]\n"; |
|
|
95 | |
|
|
96 | for (;;) { |
111 | for (;;) { |
97 | <$TRACER_R> =~ /^-$/ or last; |
112 | <$TRACER_R> =~ /^-$/ or last; |
98 | my $dir = <$TRACER_R>; chomp $dir; |
113 | my $dir = <$TRACER_R>; chomp $dir; |
99 | my $name = <$TRACER_R>; chomp $name; |
114 | my $name = <$TRACER_R>; chomp $name; |
100 | |
115 | |
101 | $pm{$name} = "$dir/$name"; |
116 | $pm{$name} = "$dir/$name"; |
|
|
117 | |
|
|
118 | print "+ found potential dependency $name\n" |
|
|
119 | if $VERBOSE >= 3; |
102 | } |
120 | } |
|
|
121 | } |
|
|
122 | |
|
|
123 | sub trace_module { |
|
|
124 | print "tracing module $_[0]\n" |
|
|
125 | if $VERBOSE >= 2; |
|
|
126 | |
|
|
127 | syswrite $TRACER_W, "use $_[0]\n"; |
|
|
128 | trace_parse; |
103 | } |
129 | } |
104 | |
130 | |
105 | sub trace_eval { |
131 | sub trace_eval { |
|
|
132 | print "tracing eval $_[0]\n" |
|
|
133 | if $VERBOSE >= 2; |
|
|
134 | |
106 | syswrite $TRACER_W, "eval $_[0]\n"; |
135 | syswrite $TRACER_W, "eval $_[0]\n"; |
|
|
136 | trace_parse; |
107 | } |
137 | } |
108 | |
138 | |
109 | sub trace_finish { |
139 | sub trace_finish { |
110 | close $TRACER_W; |
140 | close $TRACER_W; |
111 | close $TRACER_R; |
141 | close $TRACER_R; |
… | |
… | |
119 | use Digest::MD5; |
149 | use Digest::MD5; |
120 | |
150 | |
121 | sub cache($$$) { |
151 | sub cache($$$) { |
122 | my ($variant, $src, $filter) = @_; |
152 | my ($variant, $src, $filter) = @_; |
123 | |
153 | |
124 | if (length $CACHE and 2048 <= length $src) { |
154 | if (length $CACHE and 2048 <= length $src and defined $variant) { |
125 | my $file = "$CACHE/" . Digest::MD5::md5_hex "$CACHEVER\x00$variant\x00$src"; |
155 | my $file = "$CACHE/" . Digest::MD5::md5_hex "$CACHEVER\x00$variant\x00$src"; |
126 | |
156 | |
127 | if (open my $fh, "<:perlio", $file) { |
157 | if (open my $fh, "<:perlio", $file) { |
|
|
158 | print "using cache for $file\n" |
|
|
159 | if $VERBOSE >= 7; |
|
|
160 | |
128 | local $/; |
161 | local $/; |
129 | return <$fh>; |
162 | return <$fh>; |
130 | } |
163 | } |
131 | |
164 | |
132 | $src = $filter->($src); |
165 | $src = $filter->($src); |
|
|
166 | |
|
|
167 | print "creating cache entry $file\n" |
|
|
168 | if $VERBOSE >= 8; |
133 | |
169 | |
134 | if (open my $fh, ">:perlio", "$file~") { |
170 | if (open my $fh, ">:perlio", "$file~") { |
135 | if ((syswrite $fh, $src) == length $src) { |
171 | if ((syswrite $fh, $src) == length $src) { |
136 | close $fh; |
172 | close $fh; |
137 | rename "$file~", $file; |
173 | rename "$file~", $file; |
… | |
… | |
200 | my $path = "$_[0]/$_"; |
236 | my $path = "$_[0]/$_"; |
201 | |
237 | |
202 | if (-d "$path/.") { |
238 | if (-d "$path/.") { |
203 | $scan->($path); |
239 | $scan->($path); |
204 | } else { |
240 | } else { |
205 | next unless /\.(?:pm|pl)$/; |
|
|
206 | |
|
|
207 | $path = substr $path, $skip; |
241 | $path = substr $path, $skip; |
208 | push @tree, $path |
242 | push @tree, $path |
209 | unless exists $INCSKIP{$path}; |
243 | unless exists $INCSKIP{$path}; |
210 | } |
244 | } |
211 | } |
245 | } |
… | |
… | |
232 | } |
266 | } |
233 | |
267 | |
234 | ############################################################################# |
268 | ############################################################################# |
235 | |
269 | |
236 | sub cmd_boot { |
270 | sub cmd_boot { |
237 | $pm{"//boot"} = $_[0]; |
271 | $pm{"&&boot"} = $_[0]; |
238 | } |
272 | } |
239 | |
273 | |
240 | sub cmd_add { |
274 | sub cmd_add { |
241 | $_[0] =~ /^(.*)(?:\s+(\S+))$/ |
275 | $_[0] =~ /^(.*)(?:\s+(\S+))?$/ |
242 | or die "$_[0]: cannot parse"; |
276 | or die "$_[0]: cannot parse"; |
243 | |
277 | |
244 | my $file = $1; |
278 | my $file = $1; |
245 | my $as = defined $2 ? $2 : "/$1"; |
279 | my $as = defined $2 ? $2 : "&$1"; |
246 | |
280 | |
247 | $pm{$as} = $file; |
281 | $pm{$as} = $file; |
248 | $pmbin{$as} = 1 if $_[1]; |
282 | $pmbin{$as} = 1 if $_[1]; |
249 | } |
283 | } |
250 | |
284 | |
… | |
… | |
264 | |
298 | |
265 | for (get_inctrees) { |
299 | for (get_inctrees) { |
266 | my ($dir, $files) = @$_; |
300 | my ($dir, $files) = @$_; |
267 | |
301 | |
268 | $pm{$_} = "$dir/$_" |
302 | $pm{$_} = "$dir/$_" |
269 | for grep /$pattern/, @$files; |
303 | for grep /$pattern/ && /\.(pl|pm)$/, @$files; |
270 | } |
304 | } |
271 | } |
305 | } |
|
|
306 | |
|
|
307 | sub parse_argv; |
272 | |
308 | |
273 | sub cmd_file { |
309 | sub cmd_file { |
274 | open my $fh, "<", $_[0] |
310 | open my $fh, "<", $_[0] |
275 | or die "$_[0]: $!\n"; |
311 | or die "$_[0]: $!\n"; |
276 | |
312 | |
|
|
313 | local @ARGV; |
|
|
314 | |
277 | while (<$fh>) { |
315 | while (<$fh>) { |
278 | chomp; |
316 | chomp; |
|
|
317 | next unless /\S/; |
|
|
318 | next if /^\s*#/; |
|
|
319 | |
|
|
320 | s/^\s*-*/--/; |
279 | my ($cmd, $args) = split / /, $_, 2; |
321 | my ($cmd, $args) = split / /, $_, 2; |
280 | $cmd =~ s/^-+//; |
|
|
281 | |
322 | |
282 | if ($cmd eq "strip") { |
323 | push @ARGV, $cmd; |
283 | $STRIP = $args; |
324 | push @ARGV, $args if defined $args; |
284 | } elsif ($cmd eq "perl") { |
|
|
285 | $PERL = 1; |
|
|
286 | } elsif ($cmd eq "app") { |
|
|
287 | $APP = $args; |
|
|
288 | } elsif ($cmd eq "eval") { |
|
|
289 | trace_eval $_; |
|
|
290 | } elsif ($cmd eq "use") { |
|
|
291 | trace_module $_ |
|
|
292 | for split / /, $args; |
|
|
293 | } elsif ($cmd eq "staticlib") { |
|
|
294 | cmd_staticlib $args; |
|
|
295 | } elsif ($cmd eq "boot") { |
|
|
296 | cmd_boot $args; |
|
|
297 | } elsif ($cmd eq "static") { |
|
|
298 | $STATIC = 1; |
|
|
299 | } elsif ($cmd eq "add") { |
|
|
300 | cmd_add $args, 0; |
|
|
301 | } elsif ($cmd eq "addbin") { |
|
|
302 | cmd_add $args, 1; |
|
|
303 | } elsif ($cmd eq "incglob") { |
|
|
304 | cmd_incglob $args; |
|
|
305 | } elsif ($cmd eq "include") { |
|
|
306 | cmd_include $args, 1; |
|
|
307 | } elsif ($cmd eq "exclude") { |
|
|
308 | cmd_include $args, 0; |
|
|
309 | } elsif (/^\s*#/) { |
|
|
310 | # comment |
|
|
311 | } elsif (/\S/) { |
|
|
312 | die "$_: unsupported directive\n"; |
|
|
313 | } |
|
|
314 | } |
325 | } |
|
|
326 | |
|
|
327 | parse_argv; |
315 | } |
328 | } |
316 | |
329 | |
317 | use Getopt::Long; |
330 | use Getopt::Long; |
318 | |
331 | |
|
|
332 | sub parse_argv { |
|
|
333 | GetOptions |
|
|
334 | "strip=s" => \$STRIP, |
|
|
335 | "cache=s" => \$CACHE, # internal option |
|
|
336 | "verbose|v" => sub { ++$VERBOSE }, |
|
|
337 | "quiet|q" => sub { --$VERBOSE }, |
|
|
338 | "perl" => \$PERL, |
|
|
339 | "app=s" => \$APP, |
|
|
340 | "eval|e=s" => sub { trace_eval $_[1] }, |
|
|
341 | "use|M=s" => sub { trace_module $_[1] }, |
|
|
342 | "boot=s" => sub { cmd_boot $_[1] }, |
|
|
343 | "add=s" => sub { cmd_add $_[1], 0 }, |
|
|
344 | "addbin=s" => sub { cmd_add $_[1], 1 }, |
|
|
345 | "incglob=s" => sub { cmd_incglob $_[1] }, |
|
|
346 | "include|i=s" => sub { cmd_include $_[1], 1 }, |
|
|
347 | "exclude|x=s" => sub { cmd_include $_[1], 0 }, |
|
|
348 | "static!" => \$STATIC, |
|
|
349 | "usepacklists!" => \$PACKLIST, |
|
|
350 | "staticlib=s" => sub { cmd_staticlib $_[1] }, |
|
|
351 | "<>" => sub { cmd_file $_[0] }, |
|
|
352 | or exit 1; |
|
|
353 | } |
|
|
354 | |
319 | Getopt::Long::Configure ("bundling", "no_auto_abbrev", "no_ignore_case"); |
355 | Getopt::Long::Configure ("bundling", "no_auto_abbrev", "no_ignore_case"); |
320 | |
356 | |
321 | GetOptions |
357 | parse_argv; |
322 | "strip=s" => \$STRIP, |
|
|
323 | "cache=s" => \$CACHE, # internal option |
|
|
324 | "verbose|v" => sub { ++$VERBOSE }, |
|
|
325 | "quiet|q" => sub { --$VERBOSE }, |
|
|
326 | "perl" => \$PERL, |
|
|
327 | "app=s" => \$APP, |
|
|
328 | "eval|e=s" => sub { trace_eval $_[1] }, |
|
|
329 | "use|M=s" => sub { trace_module $_[1] }, |
|
|
330 | "boot=s" => sub { cmd_boot $_[1] }, |
|
|
331 | "add=s" => sub { cmd_add $_[1], 0 }, |
|
|
332 | "addbin=s" => sub { cmd_add $_[1], 1 }, |
|
|
333 | "incglob=s" => sub { cmd_incglob $_[1] }, |
|
|
334 | "include|i=s" => sub { cmd_include $_[1], 1 }, |
|
|
335 | "exclude|x=s" => sub { cmd_include $_[1], 0 }, |
|
|
336 | "static" => sub { $STATIC = 1 }, |
|
|
337 | "staticlib=s" => sub { cmd_staticlib $_[1] }, |
|
|
338 | "<>" => sub { cmd_file $_[0] }, |
|
|
339 | or exit 1; |
|
|
340 | |
358 | |
341 | die "cannot specify both --app and --perl\n" |
359 | die "cannot specify both --app and --perl\n" |
342 | if $PERL and defined $APP; |
360 | if $PERL and defined $APP; |
343 | |
361 | |
344 | # required for @INC loading, unfortunately |
362 | # required for @INC loading, unfortunately |
345 | trace_module "PerlIO::scalar"; |
363 | trace_module "PerlIO::scalar"; |
346 | |
364 | |
347 | ############################################################################# |
365 | ############################################################################# |
348 | # include/exclude apply |
366 | # apply include/exclude |
349 | |
367 | |
350 | { |
368 | { |
351 | my %pmi; |
369 | my %pmi; |
352 | |
370 | |
353 | for (@incext) { |
371 | for (@incext) { |
… | |
… | |
356 | my @match = grep /$glob/, keys %pm; |
374 | my @match = grep /$glob/, keys %pm; |
357 | |
375 | |
358 | if ($inc) { |
376 | if ($inc) { |
359 | # include |
377 | # include |
360 | @pmi{@match} = delete @pm{@match}; |
378 | @pmi{@match} = delete @pm{@match}; |
|
|
379 | |
|
|
380 | print "applying include $glob - protected ", (scalar @match), " files.\n" |
|
|
381 | if $VERBOSE >= 5; |
361 | } else { |
382 | } else { |
362 | # exclude |
383 | # exclude |
363 | delete @pm{@match}; |
384 | delete @pm{@match}; |
|
|
385 | |
|
|
386 | print "applying exclude $glob - removed ", (scalar @match), " files.\n" |
|
|
387 | if $VERBOSE >= 5; |
364 | } |
388 | } |
365 | } |
389 | } |
366 | |
390 | |
367 | my @pmi = keys %pmi; |
391 | my @pmi = keys %pmi; |
368 | @pm{@pmi} = delete @pmi{@pmi}; |
392 | @pm{@pmi} = delete @pmi{@pmi}; |
369 | } |
393 | } |
370 | |
394 | |
371 | ############################################################################# |
395 | ############################################################################# |
372 | # scan for AutoLoader and static archives |
396 | # scan for AutoLoader, static archives and other dependencies |
373 | |
397 | |
374 | sub scan_al { |
398 | sub scan_al { |
375 | my ($auto, $autodir) = @_; |
399 | my ($auto, $autodir) = @_; |
376 | |
400 | |
377 | my $ix = "$autodir/autosplit.ix"; |
401 | my $ix = "$autodir/autosplit.ix"; |
|
|
402 | |
|
|
403 | print "processing autoload index for '$auto'\n" |
|
|
404 | if $VERBOSE >= 6; |
378 | |
405 | |
379 | $pm{"$auto/autosplit.ix"} = $ix; |
406 | $pm{"$auto/autosplit.ix"} = $ix; |
380 | |
407 | |
381 | open my $fh, "<:perlio", $ix |
408 | open my $fh, "<:perlio", $ix |
382 | or die "$ix: $!"; |
409 | or die "$ix: $!"; |
… | |
… | |
388 | my $al = "auto/$package/$1.al"; |
415 | my $al = "auto/$package/$1.al"; |
389 | my $inc = find_inc $al; |
416 | my $inc = find_inc $al; |
390 | |
417 | |
391 | defined $inc or die "$al: autoload file not found, but should be there.\n"; |
418 | defined $inc or die "$al: autoload file not found, but should be there.\n"; |
392 | |
419 | |
393 | $pm{$al} = "$inc/$al"; |
420 | $pm{$al} = $inc; |
|
|
421 | print "found autoload function '$al'\n" |
|
|
422 | if $VERBOSE >= 6; |
394 | |
423 | |
395 | } elsif (/^\s*package\s+([^[:space:];]+)\s*;?\s*$/) { |
424 | } elsif (/^\s*package\s+([^[:space:];]+)\s*;?\s*$/) { |
396 | ($package = $1) =~ s/::/\//g; |
425 | ($package = $1) =~ s/::/\//g; |
397 | } elsif (/^\s*(?:#|1?\s*;?\s*$)/) { |
426 | } elsif (/^\s*(?:#|1?\s*;?\s*$)/) { |
398 | # nop |
427 | # nop |
399 | } else { |
428 | } else { |
400 | warn "$ix: unparsable line, please report: $_"; |
429 | warn "WARNING: $ix: unparsable line, please report: $_"; |
401 | } |
430 | } |
402 | } |
431 | } |
403 | } |
432 | } |
404 | |
433 | |
405 | for my $pm (keys %pm) { |
434 | for my $pm (keys %pm) { |
406 | if ($pm =~ /^(.*)\.pm$/) { |
435 | if ($pm =~ /^(.*)\.pm$/) { |
407 | my $auto = "auto/$1"; |
436 | my $auto = "auto/$1"; |
408 | my $autodir = find_inc $auto; |
437 | my $autodir = find_inc $auto; |
409 | |
438 | |
410 | if (defined $autodir && -d "$autodir/$auto") { |
439 | if (defined $autodir && -d $autodir) { |
411 | $autodir = "$autodir/$auto"; |
|
|
412 | |
|
|
413 | # AutoLoader |
440 | # AutoLoader |
414 | scan_al $auto, $autodir |
441 | scan_al $auto, $autodir |
415 | if -f "$autodir/autosplit.ix"; |
442 | if -f "$autodir/autosplit.ix"; |
416 | |
443 | |
417 | # extralibs.ld |
444 | # extralibs.ld |
418 | if (open my $fh, "<:perlio", "$autodir/extralibs.ld") { |
445 | if (open my $fh, "<:perlio", "$autodir/extralibs.ld") { |
|
|
446 | print "found extralibs for $pm\n" |
|
|
447 | if $VERBOSE >= 6; |
|
|
448 | |
419 | local $/; |
449 | local $/; |
420 | $extralibs .= " " . <$fh>; |
450 | $extralibs .= " " . <$fh>; |
421 | } |
451 | } |
422 | |
452 | |
423 | $pm =~ /([^\/]+).pm$/ or die "$pm: unable to match last component"; |
453 | $pm =~ /([^\/]+).pm$/ or die "$pm: unable to match last component"; |
424 | |
454 | |
425 | my $base = $1; |
455 | my $base = $1; |
426 | |
456 | |
427 | # static ext |
457 | # static ext |
428 | if (-f "$autodir/$base$Config{_a}") { |
458 | if (-f "$autodir/$base$Config{_a}") { |
|
|
459 | print "found static archive for $pm\n" |
|
|
460 | if $VERBOSE >= 3; |
|
|
461 | |
429 | push @libs, "$autodir/$base$Config{_a}"; |
462 | push @libs, "$autodir/$base$Config{_a}"; |
430 | push @static_ext, $pm; |
463 | push @static_ext, $pm; |
431 | } |
464 | } |
432 | |
465 | |
433 | # dynamic object |
466 | # dynamic object |
434 | die "ERROR: found shared object - can't link statically ($_)\n" |
467 | die "ERROR: found shared object - can't link statically ($_)\n" |
435 | if -f "$autodir/$base.$Config{dlext}"; |
468 | if -f "$autodir/$base.$Config{dlext}"; |
|
|
469 | |
|
|
470 | if ($PACKLIST && open my $fh, "<:perlio", "$autodir/.packlist") { |
|
|
471 | print "found .packlist for $pm\n" |
|
|
472 | if $VERBOSE >= 3; |
|
|
473 | |
|
|
474 | while (<$fh>) { |
|
|
475 | chomp; |
|
|
476 | s/ .*$//; # newer-style .packlists might contain key=value pairs |
|
|
477 | |
|
|
478 | # only include certain files (.al, .ix, .pm, .pl) |
|
|
479 | if (/\.(pm|pl|al|ix)$/) { |
|
|
480 | for my $inc (@INC) { |
|
|
481 | # in addition, we only add files that are below some @INC path |
|
|
482 | $inc =~ s/\/*$/\//; |
|
|
483 | |
|
|
484 | if ($inc eq substr $_, 0, length $inc) { |
|
|
485 | my $base = substr $_, length $inc; |
|
|
486 | $pm{$base} = $_; |
|
|
487 | |
|
|
488 | print "+ added .packlist dependency $base\n" |
|
|
489 | if $VERBOSE >= 3; |
|
|
490 | } |
|
|
491 | |
|
|
492 | last; |
|
|
493 | } |
|
|
494 | } |
|
|
495 | } |
|
|
496 | } |
436 | } |
497 | } |
437 | } |
498 | } |
438 | } |
499 | } |
439 | |
500 | |
440 | ############################################################################# |
501 | ############################################################################# |
|
|
502 | |
|
|
503 | print "processing bundle files (try more -v power if you get bored waiting here)...\n" |
|
|
504 | if $VERBOSE >= 1; |
441 | |
505 | |
442 | my $data; |
506 | my $data; |
443 | my @index; |
507 | my @index; |
444 | my @order = sort { |
508 | my @order = sort { |
445 | length $a <=> length $b |
509 | length $a <=> length $b |
… | |
… | |
470 | my $size = length $src; |
534 | my $size = length $src; |
471 | |
535 | |
472 | unless ($pmbin{$pm}) { # only do this unless the file is binary |
536 | unless ($pmbin{$pm}) { # only do this unless the file is binary |
473 | if ($pm =~ /^auto\/POSIX\/[^\/]+\.al$/) { |
537 | if ($pm =~ /^auto\/POSIX\/[^\/]+\.al$/) { |
474 | if ($src =~ /^ unimpl \"/m) { |
538 | if ($src =~ /^ unimpl \"/m) { |
475 | warn "$pm: skipping (not implemented anyways).\n" |
539 | print "$pm: skipping (raises runtime error only).\n" |
476 | if $VERBOSE >= 2; |
540 | if $VERBOSE >= 3; |
477 | next; |
541 | next; |
478 | } |
542 | } |
479 | } |
543 | } |
480 | |
544 | |
481 | $src = cache "$UNISTRIP,$OPTIMISE_SIZE,$STRIP", $src, sub { |
545 | $src = cache +($STRIP eq "ppi" ? "$UNISTRIP,$OPTIMISE_SIZE" : undef), $src, sub { |
482 | if ($UNISTRIP && $pm =~ /^unicore\/.*\.pl$/) { |
546 | if ($UNISTRIP && $pm =~ /^unicore\/.*\.pl$/) { |
|
|
547 | print "applying unicore stripping $pm\n" |
|
|
548 | if $VERBOSE >= 6; |
|
|
549 | |
483 | # special stripping for unicore swashes and properties |
550 | # special stripping for unicore swashes and properties |
484 | # much more could be done by going binary |
551 | # much more could be done by going binary |
485 | $src =~ s{ |
552 | $src =~ s{ |
486 | (^return\ <<'END';\n) (.*?\n) (END(?:\n|\Z)) |
553 | (^return\ <<'END';\n) (.*?\n) (END(?:\n|\Z)) |
487 | }{ |
554 | }{ |
… | |
… | |
600 | |
667 | |
601 | $src = $ppi->serialize; |
668 | $src = $ppi->serialize; |
602 | } else { |
669 | } else { |
603 | warn "WARNING: $pm{$pm}: PPI failed to parse this file\n"; |
670 | warn "WARNING: $pm{$pm}: PPI failed to parse this file\n"; |
604 | } |
671 | } |
605 | } elsif ($STRIP =~ /pod/i && $pm ne "Opcode.pm") { # opcode parses it's own pod |
672 | } elsif ($STRIP =~ /pod/i && $pm ne "Opcode.pm") { # opcode parses its own pod |
606 | require Pod::Strip; |
673 | require Pod::Strip; |
607 | |
674 | |
608 | my $stripper = Pod::Strip->new; |
675 | my $stripper = Pod::Strip->new; |
609 | |
676 | |
610 | my $out; |
677 | my $out; |
… | |
… | |
630 | # open my $fh, ">x" or die; print $fh $src;#d# |
697 | # open my $fh, ">x" or die; print $fh $src;#d# |
631 | # exit 1; |
698 | # exit 1; |
632 | # } |
699 | # } |
633 | } |
700 | } |
634 | |
701 | |
635 | print "adding $pm{$pm} (original size $size, stored size ", length $src, ")\n" |
702 | print "adding $pm (original size $size, stored size ", length $src, ")\n" |
636 | if $VERBOSE >= 2; |
703 | if $VERBOSE >= 2; |
637 | |
704 | |
638 | push @index, ((length $pm) << 25) | length $data; |
705 | push @index, ((length $pm) << 25) | length $data; |
639 | $data .= $pm . $src; |
706 | $data .= $pm . $src; |
640 | } |
707 | } |
641 | |
708 | |
642 | length $data < 2**25 |
709 | length $data < 2**25 |
643 | or die "bundle too large (only 32MB supported)\n"; |
710 | or die "ERROR: bundle too large (only 32MB supported)\n"; |
644 | |
711 | |
645 | my $varpfx = "bundle_" . substr +(Digest::MD5::md5_hex $data), 0, 16; |
712 | my $varpfx = "bundle_" . substr +(Digest::MD5::md5_hex $data), 0, 16; |
646 | |
713 | |
647 | ############################################################################# |
714 | ############################################################################# |
648 | # output |
715 | # output |
649 | |
716 | |
650 | print "generating $PREFIX.h... "; |
717 | print "generating $PREFIX.h... " |
|
|
718 | if $VERBOSE >= 1; |
651 | |
719 | |
652 | { |
720 | { |
653 | open my $fh, ">", "$PREFIX.h" |
721 | open my $fh, ">", "$PREFIX.h" |
654 | or die "$PREFIX.h: $!\n"; |
722 | or die "$PREFIX.h: $!\n"; |
655 | |
723 | |
… | |
… | |
661 | #include <XSUB.h> |
729 | #include <XSUB.h> |
662 | |
730 | |
663 | /* public API */ |
731 | /* public API */ |
664 | EXTERN_C PerlInterpreter *staticperl; |
732 | EXTERN_C PerlInterpreter *staticperl; |
665 | EXTERN_C void staticperl_xs_init (pTHX); |
733 | EXTERN_C void staticperl_xs_init (pTHX); |
666 | EXTERN_C void staticperl_init (void); |
734 | EXTERN_C void staticperl_init (XSINIT_t xs_init); /* argument can be 0 */ |
667 | EXTERN_C void staticperl_cleanup (void); |
735 | EXTERN_C void staticperl_cleanup (void); |
668 | |
736 | |
669 | EOF |
737 | EOF |
670 | } |
738 | } |
671 | |
739 | |
672 | print "\n"; |
740 | print "\n" |
|
|
741 | if $VERBOSE >= 1; |
673 | |
742 | |
674 | ############################################################################# |
743 | ############################################################################# |
675 | # output |
744 | # output |
676 | |
745 | |
677 | print "generating $PREFIX.c... "; |
746 | print "generating $PREFIX.c... " |
|
|
747 | if $VERBOSE >= 1; |
678 | |
748 | |
679 | open my $fh, ">", "$PREFIX.c" |
749 | open my $fh, ">", "$PREFIX.c" |
680 | or die "$PREFIX.c: $!\n"; |
750 | or die "$PREFIX.c: $!\n"; |
681 | |
751 | |
682 | print $fh <<EOF; |
752 | print $fh <<EOF; |
… | |
… | |
712 | printf $fh "0x%08x\n};\n", (length $data); |
782 | printf $fh "0x%08x\n};\n", (length $data); |
713 | |
783 | |
714 | print $fh "static const char $varpfx\_data [] =\n"; |
784 | print $fh "static const char $varpfx\_data [] =\n"; |
715 | dump_string $fh, $data; |
785 | dump_string $fh, $data; |
716 | |
786 | |
717 | print $fh ";\n\n";; |
787 | print $fh ";\n\n"; |
718 | |
788 | |
719 | ############################################################################# |
789 | ############################################################################# |
720 | # bootstrap |
790 | # bootstrap |
721 | |
791 | |
722 | # boot file for staticperl |
792 | # boot file for staticperl |
… | |
… | |
738 | $fh |
808 | $fh |
739 | }; |
809 | }; |
740 | } |
810 | } |
741 | '; |
811 | '; |
742 | |
812 | |
743 | $bootstrap .= "require '//boot';" |
813 | $bootstrap .= "require '&&boot';" |
744 | if exists $pm{"//boot"}; |
814 | if exists $pm{"&&boot"}; |
745 | |
815 | |
746 | $bootstrap =~ s/\s+/ /g; |
816 | $bootstrap =~ s/\s+/ /g; |
747 | $bootstrap =~ s/(\W) /$1/g; |
817 | $bootstrap =~ s/(\W) /$1/g; |
748 | $bootstrap =~ s/ (\W)/$1/g; |
818 | $bootstrap =~ s/ (\W)/$1/g; |
749 | |
819 | |
… | |
… | |
869 | print $fh " newXS (\"$pname\::$bootstrap\", boot_$cname, file);\n"; |
939 | print $fh " newXS (\"$pname\::$bootstrap\", boot_$cname, file);\n"; |
870 | } |
940 | } |
871 | |
941 | |
872 | print $fh <<EOF; |
942 | print $fh <<EOF; |
873 | Perl_av_create_and_unshift_one (&PL_preambleav, newSVpv (bootstrap, sizeof (bootstrap) - 1)); |
943 | Perl_av_create_and_unshift_one (&PL_preambleav, newSVpv (bootstrap, sizeof (bootstrap) - 1)); |
|
|
944 | |
|
|
945 | if (PL_oldname) |
|
|
946 | ((XSINIT_t)PL_oldname)(aTHX); |
874 | } |
947 | } |
875 | EOF |
948 | EOF |
876 | |
949 | |
877 | ############################################################################# |
950 | ############################################################################# |
878 | # optional perl_init/perl_destroy |
951 | # optional perl_init/perl_destroy |
879 | |
952 | |
880 | if ($APP) { |
953 | if ($APP) { |
|
|
954 | print $fh <<EOF; |
|
|
955 | |
|
|
956 | int |
|
|
957 | main (int argc, char *argv []) |
|
|
958 | { |
|
|
959 | extern char **environ; |
|
|
960 | int i, exitstatus; |
|
|
961 | char **args = malloc ((argc + 3) * sizeof (const char *)); |
|
|
962 | |
|
|
963 | args [0] = argv [0]; |
|
|
964 | args [1] = "-e"; |
|
|
965 | args [2] = "0"; |
|
|
966 | args [3] = "--"; |
|
|
967 | |
|
|
968 | for (i = 1; i < argc; ++i) |
|
|
969 | args [i + 3] = argv [i]; |
|
|
970 | |
|
|
971 | PERL_SYS_INIT3 (&argc, &argv, &environ); |
|
|
972 | staticperl = perl_alloc (); |
|
|
973 | perl_construct (staticperl); |
|
|
974 | |
|
|
975 | PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |
|
|
976 | |
|
|
977 | exitstatus = perl_parse (staticperl, staticperl_xs_init, argc + 3, args, environ); |
|
|
978 | free (args); |
|
|
979 | if (!exitstatus) |
|
|
980 | perl_run (staticperl); |
|
|
981 | |
|
|
982 | exitstatus = perl_destruct (staticperl); |
|
|
983 | perl_free (staticperl); |
|
|
984 | PERL_SYS_TERM (); |
|
|
985 | |
|
|
986 | return exitstatus; |
|
|
987 | } |
|
|
988 | EOF |
|
|
989 | } elsif ($PERL) { |
881 | print $fh <<EOF; |
990 | print $fh <<EOF; |
882 | |
991 | |
883 | int |
992 | int |
884 | main (int argc, char *argv []) |
993 | main (int argc, char *argv []) |
885 | { |
994 | { |
886 | extern char **environ; |
995 | extern char **environ; |
887 | int exitstatus; |
996 | int exitstatus; |
888 | |
997 | |
|
|
998 | PERL_SYS_INIT3 (&argc, &argv, &environ); |
|
|
999 | staticperl = perl_alloc (); |
|
|
1000 | perl_construct (staticperl); |
|
|
1001 | |
|
|
1002 | PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |
|
|
1003 | |
|
|
1004 | exitstatus = perl_parse (staticperl, staticperl_xs_init, argc, argv, environ); |
|
|
1005 | if (!exitstatus) |
|
|
1006 | perl_run (staticperl); |
|
|
1007 | |
|
|
1008 | exitstatus = perl_destruct (staticperl); |
|
|
1009 | perl_free (staticperl); |
|
|
1010 | PERL_SYS_TERM (); |
|
|
1011 | |
|
|
1012 | return exitstatus; |
|
|
1013 | } |
|
|
1014 | EOF |
|
|
1015 | } else { |
|
|
1016 | print $fh <<EOF; |
|
|
1017 | |
|
|
1018 | EXTERN_C void |
|
|
1019 | staticperl_init (XSINIT_t xs_init) |
|
|
1020 | { |
889 | static char *args[] = { |
1021 | static char *args[] = { |
890 | "staticperl", |
1022 | "staticperl", |
891 | "-e", |
1023 | "-e", |
892 | "0" |
1024 | "0" |
893 | }; |
1025 | }; |
894 | |
1026 | |
895 | PERL_SYS_INIT3 (&argc, &argv, &environ); |
|
|
896 | staticperl = perl_alloc (); |
|
|
897 | perl_construct (staticperl); |
|
|
898 | |
|
|
899 | PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |
|
|
900 | |
|
|
901 | exitstatus = perl_parse (staticperl, staticperl_xs_init, sizeof (args) / sizeof (*args), args, environ); |
|
|
902 | if (!exitstatus) |
|
|
903 | perl_run (staticperl); |
|
|
904 | |
|
|
905 | exitstatus = perl_destruct (staticperl); |
|
|
906 | perl_free (staticperl); |
|
|
907 | PERL_SYS_TERM (); |
|
|
908 | |
|
|
909 | return exitstatus; |
|
|
910 | } |
|
|
911 | EOF |
|
|
912 | } elsif ($PERL) { |
|
|
913 | print $fh <<EOF; |
|
|
914 | |
|
|
915 | int |
|
|
916 | main (int argc, char *argv []) |
|
|
917 | { |
|
|
918 | extern char **environ; |
|
|
919 | int exitstatus; |
|
|
920 | |
|
|
921 | PERL_SYS_INIT3 (&argc, &argv, &environ); |
|
|
922 | staticperl = perl_alloc (); |
|
|
923 | perl_construct (staticperl); |
|
|
924 | |
|
|
925 | PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |
|
|
926 | |
|
|
927 | exitstatus = perl_parse (staticperl, staticperl_xs_init, argc, argv, environ); |
|
|
928 | if (!exitstatus) |
|
|
929 | perl_run (staticperl); |
|
|
930 | |
|
|
931 | exitstatus = perl_destruct (staticperl); |
|
|
932 | perl_free (staticperl); |
|
|
933 | PERL_SYS_TERM (); |
|
|
934 | |
|
|
935 | return exitstatus; |
|
|
936 | } |
|
|
937 | EOF |
|
|
938 | } else { |
|
|
939 | print $fh <<EOF; |
|
|
940 | |
|
|
941 | EXTERN_C void |
|
|
942 | staticperl_init (void) |
|
|
943 | { |
|
|
944 | extern char **environ; |
1027 | extern char **environ; |
945 | int argc = sizeof (args) / sizeof (args [0]); |
1028 | int argc = sizeof (args) / sizeof (args [0]); |
946 | char **argv = args; |
1029 | char **argv = args; |
947 | |
|
|
948 | static char *args[] = { |
|
|
949 | "staticperl", |
|
|
950 | "-e", |
|
|
951 | "0" |
|
|
952 | }; |
|
|
953 | |
1030 | |
954 | PERL_SYS_INIT3 (&argc, &argv, &environ); |
1031 | PERL_SYS_INIT3 (&argc, &argv, &environ); |
955 | staticperl = perl_alloc (); |
1032 | staticperl = perl_alloc (); |
956 | perl_construct (staticperl); |
1033 | perl_construct (staticperl); |
957 | PL_origalen = 1; |
1034 | PL_origalen = 1; |
958 | PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |
1035 | PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |
|
|
1036 | PL_oldname = (char *)xs_init; |
959 | perl_parse (staticperl, staticperl_xs_init, argc, argv, environ); |
1037 | perl_parse (staticperl, staticperl_xs_init, argc, argv, environ); |
960 | |
1038 | |
961 | perl_run (staticperl); |
1039 | perl_run (staticperl); |
962 | } |
1040 | } |
963 | |
1041 | |
… | |
… | |
970 | PERL_SYS_TERM (); |
1048 | PERL_SYS_TERM (); |
971 | } |
1049 | } |
972 | EOF |
1050 | EOF |
973 | } |
1051 | } |
974 | |
1052 | |
975 | print -s "$PREFIX.c", " octets (", (length $data) , " data octets).\n\n"; |
1053 | print -s "$PREFIX.c", " octets (", (length $data) , " data octets).\n\n" |
|
|
1054 | if $VERBOSE >= 1; |
976 | |
1055 | |
977 | ############################################################################# |
1056 | ############################################################################# |
978 | # libs, cflags |
1057 | # libs, cflags |
979 | |
1058 | |
980 | { |
1059 | { |
981 | print "generating $PREFIX.ccopts... "; |
1060 | print "generating $PREFIX.ccopts... " |
|
|
1061 | if $VERBOSE >= 1; |
982 | |
1062 | |
983 | my $str = "$Config{ccflags} $Config{optimize} $Config{cppflags} -I$Config{archlibexp}/CORE"; |
1063 | my $str = "$Config{ccflags} $Config{optimize} $Config{cppflags} -I$Config{archlibexp}/CORE"; |
984 | $str =~ s/([\(\)])/\\$1/g; |
1064 | $str =~ s/([\(\)])/\\$1/g; |
985 | |
|
|
986 | print "$str\n\n"; |
|
|
987 | |
1065 | |
988 | open my $fh, ">$PREFIX.ccopts" |
1066 | open my $fh, ">$PREFIX.ccopts" |
989 | or die "$PREFIX.ccopts: $!"; |
1067 | or die "$PREFIX.ccopts: $!"; |
990 | print $fh $str; |
1068 | print $fh $str; |
|
|
1069 | |
|
|
1070 | print "$str\n\n" |
|
|
1071 | if $VERBOSE >= 1; |
991 | } |
1072 | } |
992 | |
1073 | |
993 | { |
1074 | { |
994 | print "generating $PREFIX.ldopts... "; |
1075 | print "generating $PREFIX.ldopts... "; |
995 | |
1076 | |
… | |
… | |
1003 | for (@staticlibs) { |
1084 | for (@staticlibs) { |
1004 | $str =~ s/(^|\s) (-l\Q$_\E) ($|\s)/$1-Wl,-Bstatic $2 -Wl,-Bdynamic$3/gx; |
1085 | $str =~ s/(^|\s) (-l\Q$_\E) ($|\s)/$1-Wl,-Bstatic $2 -Wl,-Bdynamic$3/gx; |
1005 | } |
1086 | } |
1006 | |
1087 | |
1007 | $str =~ s/([\(\)])/\\$1/g; |
1088 | $str =~ s/([\(\)])/\\$1/g; |
1008 | |
|
|
1009 | print "$str\n\n"; |
|
|
1010 | |
1089 | |
1011 | open my $fh, ">$PREFIX.ldopts" |
1090 | open my $fh, ">$PREFIX.ldopts" |
1012 | or die "$PREFIX.ldopts: $!"; |
1091 | or die "$PREFIX.ldopts: $!"; |
1013 | print $fh $str; |
1092 | print $fh $str; |
|
|
1093 | |
|
|
1094 | print "$str\n\n" |
|
|
1095 | if $VERBOSE >= 1; |
1014 | } |
1096 | } |
1015 | |
1097 | |
1016 | if ($PERL or defined $APP) { |
1098 | if ($PERL or defined $APP) { |
1017 | $APP = "perl" unless defined $APP; |
1099 | $APP = "perl" unless defined $APP; |
1018 | |
1100 | |
1019 | print "generating $APP...\n"; |
1101 | print "building $APP...\n" |
|
|
1102 | if $VERBOSE >= 1; |
1020 | |
1103 | |
1021 | system "$Config{cc} \$(cat bundle.ccopts\) -o \Q$APP\E bundle.c \$(cat bundle.ldopts\)"; |
1104 | system "$Config{cc} \$(cat bundle.ccopts\) -o \Q$APP\E bundle.c \$(cat bundle.ldopts\)"; |
1022 | |
1105 | |
1023 | # unlink "$PREFIX.$_" |
1106 | unlink "$PREFIX.$_" |
1024 | # for qw(ccopts ldopts c h); |
1107 | for qw(ccopts ldopts c h); |
1025 | |
1108 | |
1026 | print "\n"; |
1109 | print "\n" |
|
|
1110 | if $VERBOSE >= 1; |
1027 | } |
1111 | } |
1028 | |
1112 | |