… | |
… | |
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: $!"; |
… | |
… | |
56 | unless (fork) { |
66 | unless (fork) { |
57 | close $TRACER_R; |
67 | close $TRACER_R; |
58 | close $TRACER_W; |
68 | close $TRACER_W; |
59 | |
69 | |
60 | unshift @INC, sub { |
70 | unshift @INC, sub { |
61 | my $dir = find_inc $_[1] |
71 | my $dir = find_incdir $_[1] |
62 | or return; |
72 | or return; |
63 | |
73 | |
64 | syswrite $W_TRACER, "-\n$dir\n$_[1]\n"; |
74 | syswrite $W_TRACER, "-\n$dir\n$_[1]\n"; |
65 | |
75 | |
66 | open my $fh, "<:perlio", "$dir/$_[1]" |
76 | open my $fh, "<:perlio", "$dir/$_[1]" |
… | |
… | |
73 | if (/use (.*)$/) { |
83 | if (/use (.*)$/) { |
74 | my $mod = $1; |
84 | my $mod = $1; |
75 | eval "require $mod"; |
85 | eval "require $mod"; |
76 | warn "ERROR: $@ (while loading '$mod')\n" |
86 | warn "ERROR: $@ (while loading '$mod')\n" |
77 | if $@; |
87 | if $@; |
78 | syswrite $W_TRACER, "\n"; |
|
|
79 | } elsif (/eval (.*)$/) { |
88 | } elsif (/eval (.*)$/) { |
80 | my $eval = $1; |
89 | my $eval = $1; |
81 | eval $eval; |
90 | eval $eval; |
82 | warn "ERROR: $@ (in '$eval')\n" |
91 | warn "ERROR: $@ (in '$eval')\n" |
83 | if $@; |
92 | if $@; |
84 | } |
93 | } |
|
|
94 | |
|
|
95 | syswrite $W_TRACER, "\n"; |
85 | } |
96 | } |
86 | |
97 | |
87 | exit 0; |
98 | exit 0; |
88 | } |
99 | } |
89 | } |
100 | } |
90 | |
101 | |
91 | # module loading is now safe |
102 | # module loading is now safe |
92 | |
103 | |
93 | sub trace_module { |
104 | sub trace_parse { |
94 | syswrite $TRACER_W, "use $_[0]\n"; |
|
|
95 | |
|
|
96 | for (;;) { |
105 | for (;;) { |
97 | <$TRACER_R> =~ /^-$/ or last; |
106 | <$TRACER_R> =~ /^-$/ or last; |
98 | my $dir = <$TRACER_R>; chomp $dir; |
107 | my $dir = <$TRACER_R>; chomp $dir; |
99 | my $name = <$TRACER_R>; chomp $name; |
108 | my $name = <$TRACER_R>; chomp $name; |
100 | |
109 | |
101 | $pm{$name} = "$dir/$name"; |
110 | $pm{$name} = "$dir/$name"; |
|
|
111 | |
|
|
112 | print "+ found potential dependency $name\n" |
|
|
113 | if $VERBOSE >= 3; |
102 | } |
114 | } |
|
|
115 | } |
|
|
116 | |
|
|
117 | sub trace_module { |
|
|
118 | print "tracing module $_[0]\n" |
|
|
119 | if $VERBOSE >= 2; |
|
|
120 | |
|
|
121 | syswrite $TRACER_W, "use $_[0]\n"; |
|
|
122 | trace_parse; |
103 | } |
123 | } |
104 | |
124 | |
105 | sub trace_eval { |
125 | sub trace_eval { |
|
|
126 | print "tracing eval $_[0]\n" |
|
|
127 | if $VERBOSE >= 2; |
|
|
128 | |
106 | syswrite $TRACER_W, "eval $_[0]\n"; |
129 | syswrite $TRACER_W, "eval $_[0]\n"; |
|
|
130 | trace_parse; |
107 | } |
131 | } |
108 | |
132 | |
109 | sub trace_finish { |
133 | sub trace_finish { |
110 | close $TRACER_W; |
134 | close $TRACER_W; |
111 | close $TRACER_R; |
135 | close $TRACER_R; |
… | |
… | |
119 | use Digest::MD5; |
143 | use Digest::MD5; |
120 | |
144 | |
121 | sub cache($$$) { |
145 | sub cache($$$) { |
122 | my ($variant, $src, $filter) = @_; |
146 | my ($variant, $src, $filter) = @_; |
123 | |
147 | |
124 | if (length $CACHE and 2048 <= length $src) { |
148 | if (length $CACHE and 2048 <= length $src and defined $variant) { |
125 | my $file = "$CACHE/" . Digest::MD5::md5_hex "$CACHEVER\x00$variant\x00$src"; |
149 | my $file = "$CACHE/" . Digest::MD5::md5_hex "$CACHEVER\x00$variant\x00$src"; |
126 | |
150 | |
127 | if (open my $fh, "<:perlio", $file) { |
151 | if (open my $fh, "<:perlio", $file) { |
|
|
152 | print "using cache for $file\n" |
|
|
153 | if $VERBOSE >= 7; |
|
|
154 | |
128 | local $/; |
155 | local $/; |
129 | return <$fh>; |
156 | return <$fh>; |
130 | } |
157 | } |
131 | |
158 | |
132 | $src = $filter->($src); |
159 | $src = $filter->($src); |
|
|
160 | |
|
|
161 | print "creating cache entry $file\n" |
|
|
162 | if $VERBOSE >= 8; |
133 | |
163 | |
134 | if (open my $fh, ">:perlio", "$file~") { |
164 | if (open my $fh, ">:perlio", "$file~") { |
135 | if ((syswrite $fh, $src) == length $src) { |
165 | if ((syswrite $fh, $src) == length $src) { |
136 | close $fh; |
166 | close $fh; |
137 | rename "$file~", $file; |
167 | rename "$file~", $file; |
… | |
… | |
268 | $pm{$_} = "$dir/$_" |
298 | $pm{$_} = "$dir/$_" |
269 | for grep /$pattern/, @$files; |
299 | for grep /$pattern/, @$files; |
270 | } |
300 | } |
271 | } |
301 | } |
272 | |
302 | |
|
|
303 | sub parse_argv; |
|
|
304 | |
273 | sub cmd_file { |
305 | sub cmd_file { |
274 | open my $fh, "<", $_[0] |
306 | open my $fh, "<", $_[0] |
275 | or die "$_[0]: $!\n"; |
307 | or die "$_[0]: $!\n"; |
276 | |
308 | |
|
|
309 | local @ARGV; |
|
|
310 | |
277 | while (<$fh>) { |
311 | while (<$fh>) { |
278 | chomp; |
312 | chomp; |
|
|
313 | next unless /\S/; |
|
|
314 | next if /^\s*#/; |
|
|
315 | |
|
|
316 | s/^\s*-*/--/; |
279 | my ($cmd, $args) = split / /, $_, 2; |
317 | my ($cmd, $args) = split / /, $_, 2; |
280 | $cmd =~ s/^-+//; |
|
|
281 | |
318 | |
282 | if ($cmd eq "strip") { |
319 | push @ARGV, $cmd; |
283 | $STRIP = $args; |
320 | 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 | } |
321 | } |
|
|
322 | |
|
|
323 | parse_argv; |
315 | } |
324 | } |
316 | |
325 | |
317 | use Getopt::Long; |
326 | use Getopt::Long; |
318 | |
327 | |
|
|
328 | sub parse_argv { |
|
|
329 | GetOptions |
|
|
330 | "strip=s" => \$STRIP, |
|
|
331 | "cache=s" => \$CACHE, # internal option |
|
|
332 | "verbose|v" => sub { ++$VERBOSE }, |
|
|
333 | "quiet|q" => sub { --$VERBOSE }, |
|
|
334 | "perl" => \$PERL, |
|
|
335 | "app=s" => \$APP, |
|
|
336 | "eval|e=s" => sub { trace_eval $_[1] }, |
|
|
337 | "use|M=s" => sub { trace_module $_[1] }, |
|
|
338 | "boot=s" => sub { cmd_boot $_[1] }, |
|
|
339 | "add=s" => sub { cmd_add $_[1], 0 }, |
|
|
340 | "addbin=s" => sub { cmd_add $_[1], 1 }, |
|
|
341 | "incglob=s" => sub { cmd_incglob $_[1] }, |
|
|
342 | "include|i=s" => sub { cmd_include $_[1], 1 }, |
|
|
343 | "exclude|x=s" => sub { cmd_include $_[1], 0 }, |
|
|
344 | "static!" => \$STATIC, |
|
|
345 | "usepacklist!" => \$PACKLIST, |
|
|
346 | "staticlib=s" => sub { cmd_staticlib $_[1] }, |
|
|
347 | "<>" => sub { cmd_file $_[0] }, |
|
|
348 | or exit 1; |
|
|
349 | } |
|
|
350 | |
319 | Getopt::Long::Configure ("bundling", "no_auto_abbrev", "no_ignore_case"); |
351 | Getopt::Long::Configure ("bundling", "no_auto_abbrev", "no_ignore_case"); |
320 | |
352 | |
321 | GetOptions |
353 | 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 | |
354 | |
341 | die "cannot specify both --app and --perl\n" |
355 | die "cannot specify both --app and --perl\n" |
342 | if $PERL and defined $APP; |
356 | if $PERL and defined $APP; |
343 | |
357 | |
344 | # required for @INC loading, unfortunately |
358 | # required for @INC loading, unfortunately |
… | |
… | |
356 | my @match = grep /$glob/, keys %pm; |
370 | my @match = grep /$glob/, keys %pm; |
357 | |
371 | |
358 | if ($inc) { |
372 | if ($inc) { |
359 | # include |
373 | # include |
360 | @pmi{@match} = delete @pm{@match}; |
374 | @pmi{@match} = delete @pm{@match}; |
|
|
375 | |
|
|
376 | print "applying include $glob - protected ", (scalar @match), " files.\n" |
|
|
377 | if $VERBOSE >= 5; |
361 | } else { |
378 | } else { |
362 | # exclude |
379 | # exclude |
363 | delete @pm{@match}; |
380 | delete @pm{@match}; |
|
|
381 | |
|
|
382 | print "applying exclude $glob - excluded ", (scalar @match), " files.\n" |
|
|
383 | if $VERBOSE >= 5; |
364 | } |
384 | } |
365 | } |
385 | } |
366 | |
386 | |
367 | my @pmi = keys %pmi; |
387 | my @pmi = keys %pmi; |
368 | @pm{@pmi} = delete @pmi{@pmi}; |
388 | @pm{@pmi} = delete @pmi{@pmi}; |
… | |
… | |
373 | |
393 | |
374 | sub scan_al { |
394 | sub scan_al { |
375 | my ($auto, $autodir) = @_; |
395 | my ($auto, $autodir) = @_; |
376 | |
396 | |
377 | my $ix = "$autodir/autosplit.ix"; |
397 | my $ix = "$autodir/autosplit.ix"; |
|
|
398 | |
|
|
399 | print "processing autoload index for '$auto'\n" |
|
|
400 | if $VERBOSE >= 6; |
378 | |
401 | |
379 | $pm{"$auto/autosplit.ix"} = $ix; |
402 | $pm{"$auto/autosplit.ix"} = $ix; |
380 | |
403 | |
381 | open my $fh, "<:perlio", $ix |
404 | open my $fh, "<:perlio", $ix |
382 | or die "$ix: $!"; |
405 | or die "$ix: $!"; |
… | |
… | |
388 | my $al = "auto/$package/$1.al"; |
411 | my $al = "auto/$package/$1.al"; |
389 | my $inc = find_inc $al; |
412 | my $inc = find_inc $al; |
390 | |
413 | |
391 | defined $inc or die "$al: autoload file not found, but should be there.\n"; |
414 | defined $inc or die "$al: autoload file not found, but should be there.\n"; |
392 | |
415 | |
393 | $pm{$al} = "$inc/$al"; |
416 | $pm{$al} = $inc; |
|
|
417 | print "found autoload function '$al'\n" |
|
|
418 | if $VERBOSE >= 6; |
394 | |
419 | |
395 | } elsif (/^\s*package\s+([^[:space:];]+)\s*;?\s*$/) { |
420 | } elsif (/^\s*package\s+([^[:space:];]+)\s*;?\s*$/) { |
396 | ($package = $1) =~ s/::/\//g; |
421 | ($package = $1) =~ s/::/\//g; |
397 | } elsif (/^\s*(?:#|1?\s*;?\s*$)/) { |
422 | } elsif (/^\s*(?:#|1?\s*;?\s*$)/) { |
398 | # nop |
423 | # nop |
399 | } else { |
424 | } else { |
400 | warn "$ix: unparsable line, please report: $_"; |
425 | warn "WARNING: $ix: unparsable line, please report: $_"; |
401 | } |
426 | } |
402 | } |
427 | } |
403 | } |
428 | } |
404 | |
429 | |
405 | for my $pm (keys %pm) { |
430 | for my $pm (keys %pm) { |
406 | if ($pm =~ /^(.*)\.pm$/) { |
431 | if ($pm =~ /^(.*)\.pm$/) { |
407 | my $auto = "auto/$1"; |
432 | my $auto = "auto/$1"; |
408 | my $autodir = find_inc $auto; |
433 | my $autodir = find_inc $auto; |
409 | |
434 | |
410 | if (defined $autodir && -d "$autodir/$auto") { |
435 | if (defined $autodir && -d $autodir) { |
411 | $autodir = "$autodir/$auto"; |
|
|
412 | |
|
|
413 | # AutoLoader |
436 | # AutoLoader |
414 | scan_al $auto, $autodir |
437 | scan_al $auto, $autodir |
415 | if -f "$autodir/autosplit.ix"; |
438 | if -f "$autodir/autosplit.ix"; |
416 | |
439 | |
417 | # extralibs.ld |
440 | # extralibs.ld |
418 | if (open my $fh, "<:perlio", "$autodir/extralibs.ld") { |
441 | if (open my $fh, "<:perlio", "$autodir/extralibs.ld") { |
|
|
442 | print "found extralibs for $pm\n" |
|
|
443 | if $VERBOSE >= 6; |
|
|
444 | |
419 | local $/; |
445 | local $/; |
420 | $extralibs .= " " . <$fh>; |
446 | $extralibs .= " " . <$fh>; |
421 | } |
447 | } |
422 | |
448 | |
423 | $pm =~ /([^\/]+).pm$/ or die "$pm: unable to match last component"; |
449 | $pm =~ /([^\/]+).pm$/ or die "$pm: unable to match last component"; |
424 | |
450 | |
425 | my $base = $1; |
451 | my $base = $1; |
426 | |
452 | |
427 | # static ext |
453 | # static ext |
428 | if (-f "$autodir/$base$Config{_a}") { |
454 | if (-f "$autodir/$base$Config{_a}") { |
|
|
455 | print "found static archive for $pm\n" |
|
|
456 | if $VERBOSE >= 3; |
|
|
457 | |
429 | push @libs, "$autodir/$base$Config{_a}"; |
458 | push @libs, "$autodir/$base$Config{_a}"; |
430 | push @static_ext, $pm; |
459 | push @static_ext, $pm; |
431 | } |
460 | } |
432 | |
461 | |
433 | # dynamic object |
462 | # dynamic object |
434 | die "ERROR: found shared object - can't link statically ($_)\n" |
463 | die "ERROR: found shared object - can't link statically ($_)\n" |
435 | if -f "$autodir/$base.$Config{dlext}"; |
464 | if -f "$autodir/$base.$Config{dlext}"; |
|
|
465 | |
|
|
466 | if ($PACKLIST && open my $fh, "<:perlio", "$autodir/.packlist") { |
|
|
467 | print "found .packlist for $pm\n" |
|
|
468 | if $VERBOSE >= 3; |
|
|
469 | |
|
|
470 | while (<$fh>) { |
|
|
471 | chomp; |
|
|
472 | |
|
|
473 | # only include certain files (.al, .ix, .pm, .pl) |
|
|
474 | if (/\.(pm|pl|al|ix)$/) { |
|
|
475 | for my $inc (@INC) { |
|
|
476 | # in addition, we only add files that are below some @INC path |
|
|
477 | $inc =~ s/\/*$/\//; |
|
|
478 | |
|
|
479 | if ($inc eq substr $_, 0, length $inc) { |
|
|
480 | my $base = substr $_, length $inc; |
|
|
481 | $pm{$base} = $_; |
|
|
482 | |
|
|
483 | print "+ added .packlist dependency $base\n" |
|
|
484 | if $VERBOSE >= 3; |
|
|
485 | } |
|
|
486 | |
|
|
487 | last; |
|
|
488 | } |
|
|
489 | } |
|
|
490 | } |
|
|
491 | } |
436 | } |
492 | } |
437 | } |
493 | } |
438 | } |
494 | } |
439 | |
495 | |
440 | ############################################################################# |
496 | ############################################################################# |
|
|
497 | |
|
|
498 | print "processing bundle files (try more -v power if you get bored waiting here)...\n" |
|
|
499 | if $VERBOSE >= 1; |
441 | |
500 | |
442 | my $data; |
501 | my $data; |
443 | my @index; |
502 | my @index; |
444 | my @order = sort { |
503 | my @order = sort { |
445 | length $a <=> length $b |
504 | length $a <=> length $b |
… | |
… | |
470 | my $size = length $src; |
529 | my $size = length $src; |
471 | |
530 | |
472 | unless ($pmbin{$pm}) { # only do this unless the file is binary |
531 | unless ($pmbin{$pm}) { # only do this unless the file is binary |
473 | if ($pm =~ /^auto\/POSIX\/[^\/]+\.al$/) { |
532 | if ($pm =~ /^auto\/POSIX\/[^\/]+\.al$/) { |
474 | if ($src =~ /^ unimpl \"/m) { |
533 | if ($src =~ /^ unimpl \"/m) { |
475 | warn "$pm: skipping (not implemented anyways).\n" |
534 | print "$pm: skipping (only raises runtime error).\n" |
476 | if $VERBOSE >= 2; |
535 | if $VERBOSE >= 3; |
477 | next; |
536 | next; |
478 | } |
537 | } |
479 | } |
538 | } |
480 | |
539 | |
481 | $src = cache "$UNISTRIP,$OPTIMISE_SIZE,$STRIP", $src, sub { |
540 | $src = cache +($STRIP eq "ppi" ? "$UNISTRIP,$OPTIMISE_SIZE" : undef), $src, sub { |
482 | if ($UNISTRIP && $pm =~ /^unicore\/.*\.pl$/) { |
541 | if ($UNISTRIP && $pm =~ /^unicore\/.*\.pl$/) { |
|
|
542 | print "applying unicore stripping $pm\n" |
|
|
543 | if $VERBOSE >= 6; |
|
|
544 | |
483 | # special stripping for unicore swashes and properties |
545 | # special stripping for unicore swashes and properties |
484 | # much more could be done by going binary |
546 | # much more could be done by going binary |
485 | $src =~ s{ |
547 | $src =~ s{ |
486 | (^return\ <<'END';\n) (.*?\n) (END(?:\n|\Z)) |
548 | (^return\ <<'END';\n) (.*?\n) (END(?:\n|\Z)) |
487 | }{ |
549 | }{ |
… | |
… | |
630 | # open my $fh, ">x" or die; print $fh $src;#d# |
692 | # open my $fh, ">x" or die; print $fh $src;#d# |
631 | # exit 1; |
693 | # exit 1; |
632 | # } |
694 | # } |
633 | } |
695 | } |
634 | |
696 | |
635 | print "adding $pm{$pm} (original size $size, stored size ", length $src, ")\n" |
697 | print "adding $pm (original size $size, stored size ", length $src, ")\n" |
636 | if $VERBOSE >= 2; |
698 | if $VERBOSE >= 2; |
637 | |
699 | |
638 | push @index, ((length $pm) << 25) | length $data; |
700 | push @index, ((length $pm) << 25) | length $data; |
639 | $data .= $pm . $src; |
701 | $data .= $pm . $src; |
640 | } |
702 | } |
641 | |
703 | |
642 | length $data < 2**25 |
704 | length $data < 2**25 |
643 | or die "bundle too large (only 32MB supported)\n"; |
705 | or die "ERROR: bundle too large (only 32MB supported)\n"; |
644 | |
706 | |
645 | my $varpfx = "bundle_" . substr +(Digest::MD5::md5_hex $data), 0, 16; |
707 | my $varpfx = "bundle_" . substr +(Digest::MD5::md5_hex $data), 0, 16; |
646 | |
708 | |
647 | ############################################################################# |
709 | ############################################################################# |
648 | # output |
710 | # output |
649 | |
711 | |
650 | print "generating $PREFIX.h... "; |
712 | print "generating $PREFIX.h... " |
|
|
713 | if $VERBOSE >= 1; |
651 | |
714 | |
652 | { |
715 | { |
653 | open my $fh, ">", "$PREFIX.h" |
716 | open my $fh, ">", "$PREFIX.h" |
654 | or die "$PREFIX.h: $!\n"; |
717 | or die "$PREFIX.h: $!\n"; |
655 | |
718 | |
… | |
… | |
667 | EXTERN_C void staticperl_cleanup (void); |
730 | EXTERN_C void staticperl_cleanup (void); |
668 | |
731 | |
669 | EOF |
732 | EOF |
670 | } |
733 | } |
671 | |
734 | |
672 | print "\n"; |
735 | print "\n" |
|
|
736 | if $VERBOSE >= 1; |
673 | |
737 | |
674 | ############################################################################# |
738 | ############################################################################# |
675 | # output |
739 | # output |
676 | |
740 | |
677 | print "generating $PREFIX.c... "; |
741 | print "generating $PREFIX.c... " |
|
|
742 | if $VERBOSE >= 1; |
678 | |
743 | |
679 | open my $fh, ">", "$PREFIX.c" |
744 | open my $fh, ">", "$PREFIX.c" |
680 | or die "$PREFIX.c: $!\n"; |
745 | or die "$PREFIX.c: $!\n"; |
681 | |
746 | |
682 | print $fh <<EOF; |
747 | print $fh <<EOF; |
… | |
… | |
712 | printf $fh "0x%08x\n};\n", (length $data); |
777 | printf $fh "0x%08x\n};\n", (length $data); |
713 | |
778 | |
714 | print $fh "static const char $varpfx\_data [] =\n"; |
779 | print $fh "static const char $varpfx\_data [] =\n"; |
715 | dump_string $fh, $data; |
780 | dump_string $fh, $data; |
716 | |
781 | |
717 | print $fh ";\n\n";; |
782 | print $fh ";\n\n"; |
718 | |
783 | |
719 | ############################################################################# |
784 | ############################################################################# |
720 | # bootstrap |
785 | # bootstrap |
721 | |
786 | |
722 | # boot file for staticperl |
787 | # boot file for staticperl |
… | |
… | |
970 | PERL_SYS_TERM (); |
1035 | PERL_SYS_TERM (); |
971 | } |
1036 | } |
972 | EOF |
1037 | EOF |
973 | } |
1038 | } |
974 | |
1039 | |
975 | print -s "$PREFIX.c", " octets (", (length $data) , " data octets).\n\n"; |
1040 | print -s "$PREFIX.c", " octets (", (length $data) , " data octets).\n\n" |
|
|
1041 | if $VERBOSE >= 1; |
976 | |
1042 | |
977 | ############################################################################# |
1043 | ############################################################################# |
978 | # libs, cflags |
1044 | # libs, cflags |
979 | |
1045 | |
980 | { |
1046 | { |
981 | print "generating $PREFIX.ccopts... "; |
1047 | print "generating $PREFIX.ccopts... " |
|
|
1048 | if $VERBOSE >= 1; |
982 | |
1049 | |
983 | my $str = "$Config{ccflags} $Config{optimize} $Config{cppflags} -I$Config{archlibexp}/CORE"; |
1050 | my $str = "$Config{ccflags} $Config{optimize} $Config{cppflags} -I$Config{archlibexp}/CORE"; |
984 | $str =~ s/([\(\)])/\\$1/g; |
1051 | $str =~ s/([\(\)])/\\$1/g; |
985 | |
|
|
986 | print "$str\n\n"; |
|
|
987 | |
1052 | |
988 | open my $fh, ">$PREFIX.ccopts" |
1053 | open my $fh, ">$PREFIX.ccopts" |
989 | or die "$PREFIX.ccopts: $!"; |
1054 | or die "$PREFIX.ccopts: $!"; |
990 | print $fh $str; |
1055 | print $fh $str; |
|
|
1056 | |
|
|
1057 | print "$str\n\n" |
|
|
1058 | if $VERBOSE >= 1; |
991 | } |
1059 | } |
992 | |
1060 | |
993 | { |
1061 | { |
994 | print "generating $PREFIX.ldopts... "; |
1062 | print "generating $PREFIX.ldopts... "; |
995 | |
1063 | |
… | |
… | |
1003 | for (@staticlibs) { |
1071 | for (@staticlibs) { |
1004 | $str =~ s/(^|\s) (-l\Q$_\E) ($|\s)/$1-Wl,-Bstatic $2 -Wl,-Bdynamic$3/gx; |
1072 | $str =~ s/(^|\s) (-l\Q$_\E) ($|\s)/$1-Wl,-Bstatic $2 -Wl,-Bdynamic$3/gx; |
1005 | } |
1073 | } |
1006 | |
1074 | |
1007 | $str =~ s/([\(\)])/\\$1/g; |
1075 | $str =~ s/([\(\)])/\\$1/g; |
1008 | |
|
|
1009 | print "$str\n\n"; |
|
|
1010 | |
1076 | |
1011 | open my $fh, ">$PREFIX.ldopts" |
1077 | open my $fh, ">$PREFIX.ldopts" |
1012 | or die "$PREFIX.ldopts: $!"; |
1078 | or die "$PREFIX.ldopts: $!"; |
1013 | print $fh $str; |
1079 | print $fh $str; |
|
|
1080 | |
|
|
1081 | print "$str\n\n" |
|
|
1082 | if $VERBOSE >= 1; |
1014 | } |
1083 | } |
1015 | |
1084 | |
1016 | if ($PERL or defined $APP) { |
1085 | if ($PERL or defined $APP) { |
1017 | $APP = "perl" unless defined $APP; |
1086 | $APP = "perl" unless defined $APP; |
1018 | |
1087 | |
1019 | print "generating $APP...\n"; |
1088 | print "building $APP...\n" |
|
|
1089 | if $VERBOSE >= 1; |
1020 | |
1090 | |
1021 | system "$Config{cc} \$(cat bundle.ccopts\) -o \Q$APP\E bundle.c \$(cat bundle.ldopts\)"; |
1091 | system "$Config{cc} \$(cat bundle.ccopts\) -o \Q$APP\E bundle.c \$(cat bundle.ldopts\)"; |
1022 | |
1092 | |
1023 | # unlink "$PREFIX.$_" |
1093 | unlink "$PREFIX.$_" |
1024 | # for qw(ccopts ldopts c h); |
1094 | for qw(ccopts ldopts c h); |
1025 | |
1095 | |
1026 | print "\n"; |
1096 | print "\n" |
|
|
1097 | if $VERBOSE >= 1; |
1027 | } |
1098 | } |
1028 | |
1099 | |