1 | #!/opt/bin/perl |
1 | #!/opt/bin/perl |
2 | |
2 | |
3 | ############################################################################# |
3 | ############################################################################# |
4 | # cannot load modules till after the tracer BEGIN block |
4 | # cannot load modules till after the tracer BEGIN block |
5 | |
5 | |
6 | our $VERBOSE = 1; |
6 | our $VERBOSE = 1; |
7 | our $STRIP = "pod"; # none, pod or ppi |
7 | our $STRIP = "pod"; # none, pod or ppi |
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 | our $PACKLIST = 0; |
|
|
14 | our $IGNORE_ENV = 0; |
14 | |
15 | |
15 | our $OPTIMISE_SIZE = 0; # optimise for raw file size instead of for compression? |
16 | our $OPTIMISE_SIZE = 0; # optimise for raw file size instead of for compression? |
16 | |
17 | |
17 | our $CACHE; |
18 | our $CACHE; |
18 | our $CACHEVER = 1; # do not change unless you know what you are doing |
19 | our $CACHEVER = 1; # do not change unless you know what you are doing |
… | |
… | |
82 | }; |
83 | }; |
83 | |
84 | |
84 | while (<$R_TRACER>) { |
85 | while (<$R_TRACER>) { |
85 | if (/use (.*)$/) { |
86 | if (/use (.*)$/) { |
86 | my $mod = $1; |
87 | my $mod = $1; |
|
|
88 | my $eval; |
|
|
89 | |
|
|
90 | if ($mod =~ /^'.*'$/ or $mod =~ /^".*"$/) { |
|
|
91 | $eval = "require $mod"; |
|
|
92 | } elsif ($mod =~ y%/.%%) { |
|
|
93 | $eval = "require q\x00$mod\x00"; |
|
|
94 | } else { |
87 | my $pkg = ++$pkg; |
95 | my $pkg = ++$pkg; |
88 | my $eval = $mod = $mod =~ /[^A-Za-z0-9_:]/ |
|
|
89 | ? "require $mod" |
|
|
90 | : "{ package $pkg; use $mod; }"; |
96 | $eval = "{ package $pkg; use $mod; }"; |
|
|
97 | } |
|
|
98 | |
91 | eval $eval; |
99 | eval $eval; |
92 | warn "ERROR: $@ (while loading '$mod')\n" |
100 | warn "ERROR: $@ (while loading '$mod')\n" |
93 | if $@; |
101 | if $@; |
94 | } elsif (/eval (.*)$/) { |
102 | } elsif (/eval (.*)$/) { |
95 | my $eval = $1; |
103 | my $eval = $1; |
… | |
… | |
270 | sub cmd_boot { |
278 | sub cmd_boot { |
271 | $pm{"&&boot"} = $_[0]; |
279 | $pm{"&&boot"} = $_[0]; |
272 | } |
280 | } |
273 | |
281 | |
274 | sub cmd_add { |
282 | sub cmd_add { |
275 | $_[0] =~ /^(.*)(?:\s+(\S+))?$/ |
283 | $_[0] =~ /^(.*?)(?:\s+(\S+))?$/ |
276 | or die "$_[0]: cannot parse"; |
284 | or die "$_[0]: cannot parse"; |
277 | |
285 | |
278 | my $file = $1; |
286 | my $file = $1; |
279 | my $as = defined $2 ? $2 : "&$1"; |
287 | my $as = defined $2 ? $2 : $1; |
280 | |
288 | |
281 | $pm{$as} = $file; |
289 | $pm{$as} = $file; |
282 | $pmbin{$as} = 1 if $_[1]; |
290 | $pmbin{$as} = 1 if $_[1]; |
283 | } |
291 | } |
284 | |
292 | |
… | |
… | |
329 | |
337 | |
330 | use Getopt::Long; |
338 | use Getopt::Long; |
331 | |
339 | |
332 | sub parse_argv { |
340 | sub parse_argv { |
333 | GetOptions |
341 | GetOptions |
|
|
342 | "perl" => \$PERL, |
|
|
343 | "app=s" => \$APP, |
|
|
344 | |
|
|
345 | "verbose|v" => sub { ++$VERBOSE }, |
|
|
346 | "quiet|q" => sub { --$VERBOSE }, |
|
|
347 | |
334 | "strip=s" => \$STRIP, |
348 | "strip=s" => \$STRIP, |
335 | "cache=s" => \$CACHE, # internal option |
349 | "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] }, |
350 | "eval|e=s" => sub { trace_eval $_[1] }, |
341 | "use|M=s" => sub { trace_module $_[1] }, |
351 | "use|M=s" => sub { trace_module $_[1] }, |
342 | "boot=s" => sub { cmd_boot $_[1] }, |
352 | "boot=s" => sub { cmd_boot $_[1] }, |
343 | "add=s" => sub { cmd_add $_[1], 0 }, |
353 | "add=s" => sub { cmd_add $_[1], 0 }, |
344 | "addbin=s" => sub { cmd_add $_[1], 1 }, |
354 | "addbin=s" => sub { cmd_add $_[1], 1 }, |
345 | "incglob=s" => sub { cmd_incglob $_[1] }, |
355 | "incglob=s" => sub { cmd_incglob $_[1] }, |
346 | "include|i=s" => sub { cmd_include $_[1], 1 }, |
356 | "include|i=s" => sub { cmd_include $_[1], 1 }, |
347 | "exclude|x=s" => sub { cmd_include $_[1], 0 }, |
357 | "exclude|x=s" => sub { cmd_include $_[1], 0 }, |
|
|
358 | "usepacklists!" => \$PACKLIST, |
|
|
359 | |
348 | "static!" => \$STATIC, |
360 | "static!" => \$STATIC, |
349 | "usepacklists!" => \$PACKLIST, |
|
|
350 | "staticlib=s" => sub { cmd_staticlib $_[1] }, |
361 | "staticlib=s" => sub { cmd_staticlib $_[1] }, |
|
|
362 | "ignore-env" => \$IGNORE_ENV, |
|
|
363 | |
351 | "<>" => sub { cmd_file $_[0] }, |
364 | "<>" => sub { cmd_file $_[0] }, |
352 | or exit 1; |
365 | or exit 1; |
353 | } |
366 | } |
354 | |
367 | |
355 | Getopt::Long::Configure ("bundling", "no_auto_abbrev", "no_ignore_case"); |
368 | Getopt::Long::Configure ("bundling", "no_auto_abbrev", "no_ignore_case"); |
… | |
… | |
948 | EOF |
961 | EOF |
949 | |
962 | |
950 | ############################################################################# |
963 | ############################################################################# |
951 | # optional perl_init/perl_destroy |
964 | # optional perl_init/perl_destroy |
952 | |
965 | |
|
|
966 | if ($IGNORE_ENV) { |
|
|
967 | $IGNORE_ENV = <<EOF; |
|
|
968 | unsetenv ("PERL_UNICODE"); |
|
|
969 | unsetenv ("PERL_HASH_SEED_DEBUG"); |
|
|
970 | unsetenv ("PERL_DESTRUCT_LEVEL"); |
|
|
971 | unsetenv ("PERL_SIGNALS"); |
|
|
972 | unsetenv ("PERL_DEBUG_MSTATS"); |
|
|
973 | unsetenv ("PERL5OPT"); |
|
|
974 | unsetenv ("PERLIO_DEBUG"); |
|
|
975 | unsetenv ("PERLIO"); |
|
|
976 | unsetenv ("PERL_HASH_SEED"); |
|
|
977 | EOF |
|
|
978 | } else { |
|
|
979 | $IGNORE_ENV = ""; |
|
|
980 | } |
|
|
981 | |
953 | if ($APP) { |
982 | if ($APP) { |
954 | print $fh <<EOF; |
983 | print $fh <<EOF; |
955 | |
984 | |
956 | int |
985 | int |
957 | main (int argc, char *argv []) |
986 | main (int argc, char *argv []) |
… | |
… | |
966 | args [3] = "--"; |
995 | args [3] = "--"; |
967 | |
996 | |
968 | for (i = 1; i < argc; ++i) |
997 | for (i = 1; i < argc; ++i) |
969 | args [i + 3] = argv [i]; |
998 | args [i + 3] = argv [i]; |
970 | |
999 | |
|
|
1000 | $IGNORE_ENV |
971 | PERL_SYS_INIT3 (&argc, &argv, &environ); |
1001 | PERL_SYS_INIT3 (&argc, &argv, &environ); |
972 | staticperl = perl_alloc (); |
1002 | staticperl = perl_alloc (); |
973 | perl_construct (staticperl); |
1003 | perl_construct (staticperl); |
974 | |
1004 | |
975 | PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |
1005 | PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |
… | |
… | |
993 | main (int argc, char *argv []) |
1023 | main (int argc, char *argv []) |
994 | { |
1024 | { |
995 | extern char **environ; |
1025 | extern char **environ; |
996 | int exitstatus; |
1026 | int exitstatus; |
997 | |
1027 | |
|
|
1028 | $IGNORE_ENV |
998 | PERL_SYS_INIT3 (&argc, &argv, &environ); |
1029 | PERL_SYS_INIT3 (&argc, &argv, &environ); |
999 | staticperl = perl_alloc (); |
1030 | staticperl = perl_alloc (); |
1000 | perl_construct (staticperl); |
1031 | perl_construct (staticperl); |
1001 | |
1032 | |
1002 | PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |
1033 | PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |
… | |
… | |
1026 | |
1057 | |
1027 | extern char **environ; |
1058 | extern char **environ; |
1028 | int argc = sizeof (args) / sizeof (args [0]); |
1059 | int argc = sizeof (args) / sizeof (args [0]); |
1029 | char **argv = args; |
1060 | char **argv = args; |
1030 | |
1061 | |
|
|
1062 | $IGNORE_ENV |
1031 | PERL_SYS_INIT3 (&argc, &argv, &environ); |
1063 | PERL_SYS_INIT3 (&argc, &argv, &environ); |
1032 | staticperl = perl_alloc (); |
1064 | staticperl = perl_alloc (); |
1033 | perl_construct (staticperl); |
1065 | perl_construct (staticperl); |
1034 | PL_origalen = 1; |
1066 | PL_origalen = 1; |
1035 | PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |
1067 | PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |