… | |
… | |
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 $PERL = 0; |
8 | our $PERL = 0; |
|
|
9 | our $APP; |
9 | our $VERIFY = 0; |
10 | our $VERIFY = 0; |
10 | our $STATIC = 0; |
11 | our $STATIC = 0; |
11 | |
12 | |
12 | my $PREFIX = "bundle"; |
13 | my $PREFIX = "bundle"; |
13 | my $PACKAGE = "static"; |
14 | my $PACKAGE = "static"; |
… | |
… | |
15 | my %pm; |
16 | my %pm; |
16 | my %pmbin; |
17 | my %pmbin; |
17 | my @libs; |
18 | my @libs; |
18 | my @static_ext; |
19 | my @static_ext; |
19 | my $extralibs; |
20 | my $extralibs; |
|
|
21 | my @staticlibs; |
|
|
22 | my @incext; |
20 | |
23 | |
21 | @ARGV |
24 | @ARGV |
22 | or die "$0: use 'staticperl help' (or read the sources of staticperl)\n"; |
25 | or die "$0: use 'staticperl help' (or read the sources of staticperl)\n"; |
23 | |
26 | |
24 | $|=1; |
27 | $|=1; |
… | |
… | |
209 | |
212 | |
210 | $pm{$as} = $file; |
213 | $pm{$as} = $file; |
211 | $pmbin{$as} = 1 if $_[1]; |
214 | $pmbin{$as} = 1 if $_[1]; |
212 | } |
215 | } |
213 | |
216 | |
|
|
217 | sub cmd_staticlib { |
|
|
218 | push @staticlibs, $_ |
|
|
219 | for split /\s+/, $_[0]; |
|
|
220 | } |
|
|
221 | |
214 | sub cmd_file { |
222 | sub cmd_file { |
215 | open my $fh, "<", $_[0] |
223 | open my $fh, "<", $_[0] |
216 | or die "$_[0]: $!\n"; |
224 | or die "$_[0]: $!\n"; |
217 | |
225 | |
218 | while (<$fh>) { |
226 | while (<$fh>) { |
… | |
… | |
220 | my ($cmd, $args) = split / /, $_, 2; |
228 | my ($cmd, $args) = split / /, $_, 2; |
221 | $cmd =~ s/^-+//; |
229 | $cmd =~ s/^-+//; |
222 | |
230 | |
223 | if ($cmd eq "strip") { |
231 | if ($cmd eq "strip") { |
224 | $STRIP = $args; |
232 | $STRIP = $args; |
|
|
233 | } elsif ($cmd eq "perl") { |
|
|
234 | $PERL = 1; |
|
|
235 | } elsif ($cmd eq "app") { |
|
|
236 | $APP = $args; |
225 | } elsif ($cmd eq "eval") { |
237 | } elsif ($cmd eq "eval") { |
226 | trace_eval $_; |
238 | trace_eval $_; |
227 | } elsif ($cmd eq "use") { |
239 | } elsif ($cmd eq "use") { |
228 | trace_module $_ |
240 | trace_module $_ |
229 | for split / /, $args; |
241 | for split / /, $args; |
|
|
242 | } elsif ($cmd eq "staticlib") { |
|
|
243 | cmd_staticlib $args; |
230 | } elsif ($cmd eq "boot") { |
244 | } elsif ($cmd eq "boot") { |
231 | cmd_boot $args; |
245 | cmd_boot $args; |
232 | } elsif ($cmd eq "static") { |
246 | } elsif ($cmd eq "static") { |
233 | $STATIC = 1; |
247 | $STATIC = 1; |
234 | } elsif ($cmd eq "add") { |
248 | } elsif ($cmd eq "add") { |
… | |
… | |
246 | use Getopt::Long; |
260 | use Getopt::Long; |
247 | |
261 | |
248 | Getopt::Long::Configure ("bundling", "no_auto_abbrev", "no_ignore_case"); |
262 | Getopt::Long::Configure ("bundling", "no_auto_abbrev", "no_ignore_case"); |
249 | |
263 | |
250 | GetOptions |
264 | GetOptions |
251 | "strip=s" => \$STRIP, |
265 | "strip=s" => \$STRIP, |
252 | "verbose|v" => sub { ++$VERBOSE }, |
266 | "verbose|v" => sub { ++$VERBOSE }, |
253 | "quiet|q" => sub { --$VERBOSE }, |
267 | "quiet|q" => sub { --$VERBOSE }, |
254 | "perl" => \$PERL, |
268 | "perl" => \$PERL, |
|
|
269 | "app=s" => \$APP, |
255 | "eval|e=s" => sub { trace_eval $_[1] }, |
270 | "eval|e=s" => sub { trace_eval $_[1] }, |
256 | "use|M=s" => sub { trace_module $_[1] }, |
271 | "use|M=s" => sub { trace_module $_[1] }, |
257 | "boot=s" => sub { cmd_boot $_[1] }, |
272 | "boot=s" => sub { cmd_boot $_[1] }, |
258 | "add=s" => sub { cmd_add $_[1], 0 }, |
273 | "add=s" => sub { cmd_add $_[1], 0 }, |
259 | "addbin=s" => sub { cmd_add $_[1], 1 }, |
274 | "addbin=s" => sub { cmd_add $_[1], 1 }, |
260 | "static" => sub { $STATIC = 1 }, |
275 | "static" => sub { $STATIC = 1 }, |
|
|
276 | "staticlib=s" => sub { cmd_staticlib $_[1] }, |
261 | "<>" => sub { cmd_file $_[0] }, |
277 | "<>" => sub { cmd_file $_[0] }, |
262 | or exit 1; |
278 | or exit 1; |
|
|
279 | |
|
|
280 | die "cannot specify both --app and --perl\n" |
|
|
281 | if $PERL and defined $APP; |
263 | |
282 | |
264 | my $data; |
283 | my $data; |
265 | my @index; |
284 | my @index; |
266 | my @order = sort { |
285 | my @order = sort { |
267 | length $a <=> length $b |
286 | length $a <=> length $b |
… | |
… | |
611 | } |
630 | } |
612 | |
631 | |
613 | XSRETURN ($varpfx\_count); |
632 | XSRETURN ($varpfx\_count); |
614 | } |
633 | } |
615 | |
634 | |
616 | static char *args[] = { |
|
|
617 | "staticperl", |
|
|
618 | "-e", |
|
|
619 | "0" |
|
|
620 | }; |
|
|
621 | |
|
|
622 | EOF |
635 | EOF |
623 | |
636 | |
624 | ############################################################################# |
637 | ############################################################################# |
625 | # xs_init |
638 | # xs_init |
626 | |
639 | |
… | |
… | |
665 | EOF |
678 | EOF |
666 | |
679 | |
667 | ############################################################################# |
680 | ############################################################################# |
668 | # optional perl_init/perl_destroy |
681 | # optional perl_init/perl_destroy |
669 | |
682 | |
670 | if ($PERL) { |
683 | if ($APP) { |
671 | print $fh <<EOF; |
684 | print $fh <<EOF; |
672 | |
685 | |
673 | int |
686 | int |
674 | main (int argc, char *argv []) |
687 | main (int argc, char *argv []) |
675 | { |
688 | { |
676 | extern char **environ; |
689 | extern char **environ; |
677 | int exitstatus; |
690 | int exitstatus; |
|
|
691 | |
|
|
692 | static char *args[] = { |
|
|
693 | "staticperl", |
|
|
694 | "-e", |
|
|
695 | "0" |
|
|
696 | }; |
678 | |
697 | |
679 | PERL_SYS_INIT3 (&argc, &argv, &environ); |
698 | PERL_SYS_INIT3 (&argc, &argv, &environ); |
680 | staticperl = perl_alloc (); |
699 | staticperl = perl_alloc (); |
681 | perl_construct (staticperl); |
700 | perl_construct (staticperl); |
682 | |
701 | |
683 | PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |
702 | PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |
684 | |
703 | |
|
|
704 | exitstatus = perl_parse (staticperl, staticperl_xs_init, sizeof (args) / sizeof (*args), args, environ); |
|
|
705 | if (!exitstatus) |
|
|
706 | perl_run (staticperl); |
|
|
707 | |
|
|
708 | exitstatus = perl_destruct (staticperl); |
|
|
709 | perl_free (staticperl); |
|
|
710 | PERL_SYS_TERM (); |
|
|
711 | |
|
|
712 | return exitstatus; |
|
|
713 | } |
|
|
714 | EOF |
|
|
715 | } elsif ($PERL) { |
|
|
716 | print $fh <<EOF; |
|
|
717 | |
|
|
718 | int |
|
|
719 | main (int argc, char *argv []) |
|
|
720 | { |
|
|
721 | extern char **environ; |
|
|
722 | int exitstatus; |
|
|
723 | |
|
|
724 | PERL_SYS_INIT3 (&argc, &argv, &environ); |
|
|
725 | staticperl = perl_alloc (); |
|
|
726 | perl_construct (staticperl); |
|
|
727 | |
|
|
728 | PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |
|
|
729 | |
685 | exitstatus = perl_parse (staticperl, staticperl_xs_init, argc, argv, environ); |
730 | exitstatus = perl_parse (staticperl, staticperl_xs_init, argc, argv, environ); |
686 | if (!exitstatus) |
731 | if (!exitstatus) |
687 | perl_run (staticperl); |
732 | perl_run (staticperl); |
688 | |
733 | |
689 | exitstatus = perl_destruct (staticperl); |
734 | exitstatus = perl_destruct (staticperl); |
… | |
… | |
700 | staticperl_init (void) |
745 | staticperl_init (void) |
701 | { |
746 | { |
702 | extern char **environ; |
747 | extern char **environ; |
703 | int argc = sizeof (args) / sizeof (args [0]); |
748 | int argc = sizeof (args) / sizeof (args [0]); |
704 | char **argv = args; |
749 | char **argv = args; |
|
|
750 | |
|
|
751 | static char *args[] = { |
|
|
752 | "staticperl", |
|
|
753 | "-e", |
|
|
754 | "0" |
|
|
755 | }; |
705 | |
756 | |
706 | PERL_SYS_INIT3 (&argc, &argv, &environ); |
757 | PERL_SYS_INIT3 (&argc, &argv, &environ); |
707 | staticperl = perl_alloc (); |
758 | staticperl = perl_alloc (); |
708 | perl_construct (staticperl); |
759 | perl_construct (staticperl); |
709 | PL_origalen = 1; |
760 | PL_origalen = 1; |
… | |
… | |
743 | } |
794 | } |
744 | |
795 | |
745 | { |
796 | { |
746 | print "generating $PREFIX.ldopts... "; |
797 | print "generating $PREFIX.ldopts... "; |
747 | |
798 | |
748 | my $str = $STATIC ? "--static " : ""; |
799 | my $str = $STATIC ? "-static " : ""; |
749 | |
800 | |
750 | $str .= "$Config{ccdlflags} $Config{ldflags} @libs $Config{archlibexp}/CORE/$Config{libperl} $Config{perllibs}"; |
801 | $str .= "$Config{ccdlflags} $Config{ldflags} @libs $Config{archlibexp}/CORE/$Config{libperl} $Config{perllibs}"; |
751 | |
802 | |
752 | my %seen; |
803 | my %seen; |
753 | $str .= " $_" for grep !$seen{$_}++, ($extralibs =~ /(\S+)/g); |
804 | $str .= " $_" for grep !$seen{$_}++, ($extralibs =~ /(\S+)/g); |
|
|
805 | |
|
|
806 | for (@staticlibs) { |
|
|
807 | $str =~ s/(^|\s) (-l\Q$_\E) ($|\s)/$1-Wl,-Bstatic $2 -Wl,-Bdynamic$3/gx; |
|
|
808 | } |
754 | |
809 | |
755 | $str =~ s/([\(\)])/\\$1/g; |
810 | $str =~ s/([\(\)])/\\$1/g; |
756 | |
811 | |
757 | print "$str\n\n"; |
812 | print "$str\n\n"; |
758 | |
813 | |
759 | open my $fh, ">$PREFIX.ldopts" |
814 | open my $fh, ">$PREFIX.ldopts" |
760 | or die "$PREFIX.ldopts: $!"; |
815 | or die "$PREFIX.ldopts: $!"; |
761 | print $fh $str; |
816 | print $fh $str; |
762 | } |
817 | } |
763 | |
818 | |
764 | if ($PERL) { |
819 | if ($PERL or defined $APP) { |
|
|
820 | $APP = "perl" unless defined $APP; |
|
|
821 | |
|
|
822 | print "generating $APP...\n"; |
|
|
823 | |
765 | system "$Config{cc} \$(cat bundle.ccopts\) -o perl bundle.c \$(cat bundle.ldopts\)"; |
824 | system "$Config{cc} \$(cat bundle.ccopts\) -o \Q$APP\E bundle.c \$(cat bundle.ldopts\)"; |
766 | |
825 | |
767 | unlink "$PREFIX.$_" |
826 | unlink "$PREFIX.$_" |
768 | for qw(ccopts ldopts c h); |
827 | for qw(ccopts ldopts c h); |
769 | } |
828 | } |
770 | |
829 | |