ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/App-Staticperl/mkbundle
(Generate patch)

Comparing cvsroot/App-Staticperl/mkbundle (file contents):
Revision 1.6 by root, Tue Dec 7 09:27:54 2010 UTC vs.
Revision 1.10 by root, Thu Dec 9 09:51:32 2010 UTC

4# cannot load modules till after the tracer BEGIN block 4# cannot load modules till after the tracer BEGIN block
5 5
6our $VERBOSE = 1; 6our $VERBOSE = 1;
7our $STRIP = "pod"; # none, pod or ppi 7our $STRIP = "pod"; # none, pod or ppi
8our $PERL = 0; 8our $PERL = 0;
9our $APP;
9our $VERIFY = 0; 10our $VERIFY = 0;
10our $STATIC = 0; 11our $STATIC = 0;
11 12
12my $PREFIX = "bundle"; 13my $PREFIX = "bundle";
13my $PACKAGE = "static"; 14my $PACKAGE = "static";
15my %pm; 16my %pm;
16my %pmbin; 17my %pmbin;
17my @libs; 18my @libs;
18my @static_ext; 19my @static_ext;
19my $extralibs; 20my $extralibs;
21my @staticlibs;
22my @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;
88 or die "$autodir/$ix: $!"; 91 or die "$autodir/$ix: $!";
89 92
90 my $package; 93 my $package;
91 94
92 while (<$fh>) { 95 while (<$fh>) {
93 if (/^\s*sub\s+([^[:space:];]+)\s*;?\s*$/) { 96 if (/^\s*sub\s+ ([^[:space:];]+) \s* (?:\([^)]*\))? \s*;?\s*$/x) {
94 my $al = "auto/$package/$1.al"; 97 my $al = "auto/$package/$1.al";
95 my $inc = find_inc $al; 98 my $inc = find_inc $al;
96 99
97 defined $inc or die "$al: autoload file not found, but should be there.\n"; 100 defined $inc or die "$al: autoload file not found, but should be there.\n";
98 101
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
217sub cmd_staticlib {
218 push @staticlibs, $_
219 for split /\s+/, $_[0];
220}
221
214sub cmd_file { 222sub 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") {
246use Getopt::Long; 260use Getopt::Long;
247 261
248Getopt::Long::Configure ("bundling", "no_auto_abbrev", "no_ignore_case"); 262Getopt::Long::Configure ("bundling", "no_auto_abbrev", "no_ignore_case");
249 263
250GetOptions 264GetOptions
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
280die "cannot specify both --app and --perl\n"
281 if $PERL and defined $APP;
263 282
264my $data; 283my $data;
265my @index; 284my @index;
266my @order = sort { 285my @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
616static char *args[] = {
617 "staticperl",
618 "-e",
619 "0"
620};
621
622EOF 635EOF
623 636
624############################################################################# 637#############################################################################
625# xs_init 638# xs_init
626 639
665EOF 678EOF
666 679
667############################################################################# 680#############################################################################
668# optional perl_init/perl_destroy 681# optional perl_init/perl_destroy
669 682
670if ($PERL) { 683if ($APP) {
671 print $fh <<EOF; 684 print $fh <<EOF;
672 685
673int 686int
674main (int argc, char *argv []) 687main (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}
714EOF
715} elsif ($PERL) {
716 print $fh <<EOF;
717
718int
719main (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);
700staticperl_init (void) 745staticperl_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
764if ($PERL) { 819if ($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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines