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

Comparing App-Staticperl/mkbundle (file contents):
Revision 1.16 by root, Thu Jan 20 21:32:47 2011 UTC vs.
Revision 1.34 by root, Mon Mar 12 21:45:10 2012 UTC

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
6our $VERBOSE = 1; 6our $VERBOSE = 1;
7our $STRIP = "pod"; # none, pod or ppi 7our $STRIP = "pod"; # none, pod or ppi
8our $UNISTRIP = 1; # always on, try to strip unicore swash data 8our $UNISTRIP = 1; # always on, try to strip unicore swash data
9our $PERL = 0; 9our $PERL = 0;
10our $APP; 10our $APP;
11our $VERIFY = 0; 11our $VERIFY = 0;
12our $STATIC = 0; 12our $STATIC = 0;
13our $PACKLIST = 0; 13our $PACKLIST = 0;
14our $IGNORE_ENV = 0;
15our $ALLOW_DYNAMIC = 0;
16our $HAVE_DYNAMIC; # maybe useful?
14 17
15our $OPTIMISE_SIZE = 0; # optimise for raw file size instead of for compression? 18our $OPTIMISE_SIZE = 0; # optimise for raw file size instead of for compression?
16 19
17our $CACHE; 20our $CACHE;
18our $CACHEVER = 1; # do not change unless you know what you are doing 21our $CACHEVER = 1; # do not change unless you know what you are doing
73 my $dir = find_incdir $_[1] 76 my $dir = find_incdir $_[1]
74 or return; 77 or return;
75 78
76 syswrite $W_TRACER, "-\n$dir\n$_[1]\n"; 79 syswrite $W_TRACER, "-\n$dir\n$_[1]\n";
77 80
78 open my $fh, "<:perlio", "$dir/$_[1]" 81 open my $fh, "<:raw:perlio", "$dir/$_[1]"
79 or warn "ERROR: $dir/$_[1]: $!\n"; 82 or warn "ERROR: $dir/$_[1]: $!\n";
80 83
81 $fh 84 $fh
82 }; 85 };
83 86
84 while (<$R_TRACER>) { 87 while (<$R_TRACER>) {
85 if (/use (.*)$/) { 88 if (/use (.*)$/) {
86 my $mod = $1; 89 my $mod = $1;
90 my $eval;
91
92 if ($mod =~ /^'.*'$/ or $mod =~ /^".*"$/) {
93 $eval = "require $mod";
94 } elsif ($mod =~ y%/.%%) {
95 $eval = "require q\x00$mod\x00";
96 } else {
87 my $pkg = ++$pkg; 97 my $pkg = ++$pkg;
88 eval "{ package $pkg; use $mod; }"; 98 $eval = "{ package $pkg; use $mod; }";
99 }
100
101 eval $eval;
89 warn "ERROR: $@ (while loading '$mod')\n" 102 warn "ERROR: $@ (while loading '$mod')\n"
90 if $@; 103 if $@;
91 } elsif (/eval (.*)$/) { 104 } elsif (/eval (.*)$/) {
92 my $eval = $1; 105 my $eval = $1;
93 eval $eval; 106 eval $eval;
149 my ($variant, $src, $filter) = @_; 162 my ($variant, $src, $filter) = @_;
150 163
151 if (length $CACHE and 2048 <= length $src and defined $variant) { 164 if (length $CACHE and 2048 <= length $src and defined $variant) {
152 my $file = "$CACHE/" . Digest::MD5::md5_hex "$CACHEVER\x00$variant\x00$src"; 165 my $file = "$CACHE/" . Digest::MD5::md5_hex "$CACHEVER\x00$variant\x00$src";
153 166
154 if (open my $fh, "<:perlio", $file) { 167 if (open my $fh, "<:raw:perlio", $file) {
155 print "using cache for $file\n" 168 print "using cache for $file\n"
156 if $VERBOSE >= 7; 169 if $VERBOSE >= 7;
157 170
158 local $/; 171 local $/;
159 return <$fh>; 172 return <$fh>;
162 $src = $filter->($src); 175 $src = $filter->($src);
163 176
164 print "creating cache entry $file\n" 177 print "creating cache entry $file\n"
165 if $VERBOSE >= 8; 178 if $VERBOSE >= 8;
166 179
167 if (open my $fh, ">:perlio", "$file~") { 180 if (open my $fh, ">:raw:perlio", "$file~") {
168 if ((syswrite $fh, $src) == length $src) { 181 if ((syswrite $fh, $src) == length $src) {
169 close $fh; 182 close $fh;
170 rename "$file~", $file; 183 rename "$file~", $file;
171 } 184 }
172 } 185 }
179 192
180sub dump_string { 193sub dump_string {
181 my ($fh, $data) = @_; 194 my ($fh, $data) = @_;
182 195
183 if (length $data) { 196 if (length $data) {
197 if ($^O eq "MSWin32") {
198 # 16 bit system, strings can't be longer than 64k. seriously.
199 print $fh "{\n";
184 for ( 200 for (
185 my $ofs = 0; 201 my $ofs = 0;
202 length (my $substr = substr $data, $ofs, 20);
203 $ofs += 20
204 ) {
205 $substr = join ",", map ord, split //, $substr;
206 print $fh " $substr,\n";
207 }
208 print $fh " 0 }\n";
209 } else {
210 for (
211 my $ofs = 0;
186 length (my $substr = substr $data, $ofs, 80); 212 length (my $substr = substr $data, $ofs, 80);
187 $ofs += 80 213 $ofs += 80
188 ) { 214 ) {
189 $substr =~ s/([^\x20-\x21\x23-\x5b\x5d-\x7e])/sprintf "\\%03o", ord $1/ge; 215 $substr =~ s/([^\x20-\x21\x23-\x5b\x5d-\x7e])/sprintf "\\%03o", ord $1/ge;
190 $substr =~ s/\?/\\?/g; # trigraphs... 216 $substr =~ s/\?/\\?/g; # trigraphs...
191 print $fh " \"$substr\"\n"; 217 print $fh " \"$substr\"\n";
218 }
192 } 219 }
193 } else { 220 } else {
194 print $fh " \"\"\n"; 221 print $fh " \"\"\n";
195 } 222 }
196} 223}
263} 290}
264 291
265############################################################################# 292#############################################################################
266 293
267sub cmd_boot { 294sub cmd_boot {
268 $pm{"//boot"} = $_[0]; 295 $pm{"!boot"} = $_[0];
269} 296}
270 297
271sub cmd_add { 298sub cmd_add {
272 $_[0] =~ /^(.*)(?:\s+(\S+))$/ 299 $_[0] =~ /^(.*?)(?:\s+(\S+))?$/
273 or die "$_[0]: cannot parse"; 300 or die "$_[0]: cannot parse";
274 301
275 my $file = $1; 302 my $file = $1;
276 my $as = defined $2 ? $2 : "/$1"; 303 my $as = defined $2 ? $2 : $1;
277 304
278 $pm{$as} = $file; 305 $pm{$as} = $file;
279 $pmbin{$as} = 1 if $_[1]; 306 $pmbin{$as} = 1 if $_[1];
280} 307}
281 308
326 353
327use Getopt::Long; 354use Getopt::Long;
328 355
329sub parse_argv { 356sub parse_argv {
330 GetOptions 357 GetOptions
358 "perl" => \$PERL,
359 "app=s" => \$APP,
360
361 "verbose|v" => sub { ++$VERBOSE },
362 "quiet|q" => sub { --$VERBOSE },
363
331 "strip=s" => \$STRIP, 364 "strip=s" => \$STRIP,
332 "cache=s" => \$CACHE, # internal option 365 "cache=s" => \$CACHE, # internal option
333 "verbose|v" => sub { ++$VERBOSE },
334 "quiet|q" => sub { --$VERBOSE },
335 "perl" => \$PERL,
336 "app=s" => \$APP,
337 "eval|e=s" => sub { trace_eval $_[1] }, 366 "eval|e=s" => sub { trace_eval $_[1] },
338 "use|M=s" => sub { trace_module $_[1] }, 367 "use|M=s" => sub { trace_module $_[1] },
339 "boot=s" => sub { cmd_boot $_[1] }, 368 "boot=s" => sub { cmd_boot $_[1] },
340 "add=s" => sub { cmd_add $_[1], 0 }, 369 "add=s" => sub { cmd_add $_[1], 0 },
341 "addbin=s" => sub { cmd_add $_[1], 1 }, 370 "addbin=s" => sub { cmd_add $_[1], 1 },
342 "incglob=s" => sub { cmd_incglob $_[1] }, 371 "incglob=s" => sub { cmd_incglob $_[1] },
343 "include|i=s" => sub { cmd_include $_[1], 1 }, 372 "include|i=s" => sub { cmd_include $_[1], 1 },
344 "exclude|x=s" => sub { cmd_include $_[1], 0 }, 373 "exclude|x=s" => sub { cmd_include $_[1], 0 },
374 "usepacklists!" => \$PACKLIST,
375
345 "static!" => \$STATIC, 376 "static!" => \$STATIC,
346 "usepacklists!" => \$PACKLIST,
347 "staticlib=s" => sub { cmd_staticlib $_[1] }, 377 "staticlib=s" => sub { cmd_staticlib $_[1] },
378 "allow-dynamic!"=> \$ALLOW_DYNAMIC,
379 "ignore-env" => \$IGNORE_ENV,
380
348 "<>" => sub { cmd_file $_[0] }, 381 "<>" => sub { cmd_file $_[0] },
349 or exit 1; 382 or exit 1;
350} 383}
351 384
352Getopt::Long::Configure ("bundling", "no_auto_abbrev", "no_ignore_case"); 385Getopt::Long::Configure ("bundling", "no_auto_abbrev", "no_ignore_case");
459 push @libs, "$autodir/$base$Config{_a}"; 492 push @libs, "$autodir/$base$Config{_a}";
460 push @static_ext, $pm; 493 push @static_ext, $pm;
461 } 494 }
462 495
463 # dynamic object 496 # dynamic object
464 die "ERROR: found shared object - can't link statically ($_)\n"
465 if -f "$autodir/$base.$Config{dlext}"; 497 if (-f "$autodir/$base.$Config{dlext}") {
498 if ($ALLOW_DYNAMIC) {
499 my $as = "!$auto/$base.$Config{dlext}";
500 $pm{$as} = "$autodir/$base.$Config{dlext}";
501 $pmbin{$as} = 1;
502
503 $HAVE_DYNAMIC = 1;
504
505 print "+ added dynamic object $as\n"
506 if $VERBOSE >= 3;
507 } else {
508 die "ERROR: found shared object '$autodir/$base.$Config{dlext}' but --allow-dynamic not given, aborting.\n"
509 }
510 }
466 511
467 if ($PACKLIST && open my $fh, "<:perlio", "$autodir/.packlist") { 512 if ($PACKLIST && open my $fh, "<:perlio", "$autodir/.packlist") {
468 print "found .packlist for $pm\n" 513 print "found .packlist for $pm\n"
469 if $VERBOSE >= 3; 514 if $VERBOSE >= 3;
470 515
518 or die "ERROR: $pm: path too long (only 128 octets supported)\n"; 563 or die "ERROR: $pm: path too long (only 128 octets supported)\n";
519 564
520 my $src = ref $path 565 my $src = ref $path
521 ? $$path 566 ? $$path
522 : do { 567 : do {
523 open my $pm, "<", $path 568 open my $pm, "<:raw:perlio", $path
524 or die "$path: $!"; 569 or die "$path: $!";
525 570
526 local $/; 571 local $/;
527 572
528 <$pm> 573 <$pm>
704} 749}
705 750
706length $data < 2**25 751length $data < 2**25
707 or die "ERROR: bundle too large (only 32MB supported)\n"; 752 or die "ERROR: bundle too large (only 32MB supported)\n";
708 753
709my $varpfx = "bundle_" . substr +(Digest::MD5::md5_hex $data), 0, 16; 754my $varpfx = "bundle";
710 755
711############################################################################# 756#############################################################################
712# output 757# output
713 758
714print "generating $PREFIX.h... " 759print "generating $PREFIX.h... "
717{ 762{
718 open my $fh, ">", "$PREFIX.h" 763 open my $fh, ">", "$PREFIX.h"
719 or die "$PREFIX.h: $!\n"; 764 or die "$PREFIX.h: $!\n";
720 765
721 print $fh <<EOF; 766 print $fh <<EOF;
722/* do not edit, automatically created by mkstaticbundle */ 767/* do not edit, automatically created by staticperl */
723 768
724#include <EXTERN.h> 769#include <EXTERN.h>
725#include <perl.h> 770#include <perl.h>
726#include <XSUB.h> 771#include <XSUB.h>
727 772
728/* public API */ 773/* public API */
729EXTERN_C PerlInterpreter *staticperl; 774EXTERN_C PerlInterpreter *staticperl;
730EXTERN_C void staticperl_xs_init (pTHX); 775EXTERN_C void staticperl_xs_init (pTHX);
731EXTERN_C void staticperl_init (void); 776EXTERN_C void staticperl_init (XSINIT_t xs_init); /* argument can be 0 */
732EXTERN_C void staticperl_cleanup (void); 777EXTERN_C void staticperl_cleanup (void);
733 778
734EOF 779EOF
735} 780}
736 781
745 790
746open my $fh, ">", "$PREFIX.c" 791open my $fh, ">", "$PREFIX.c"
747 or die "$PREFIX.c: $!\n"; 792 or die "$PREFIX.c: $!\n";
748 793
749print $fh <<EOF; 794print $fh <<EOF;
750/* do not edit, automatically created by mkstaticbundle */ 795/* do not edit, automatically created by staticperl */
751 796
752#include "bundle.h" 797#include "bundle.h"
753 798
754/* public API */ 799/* public API */
755PerlInterpreter *staticperl; 800PerlInterpreter *staticperl;
787# bootstrap 832# bootstrap
788 833
789# boot file for staticperl 834# boot file for staticperl
790# this file will be eval'ed at initialisation time 835# this file will be eval'ed at initialisation time
791 836
837# lines marked with "^D" are only used when $HAVE_DYNAMIC
792my $bootstrap = ' 838my $bootstrap = '
793BEGIN { 839BEGIN {
794 package ' . $PACKAGE . '; 840 package ' . $PACKAGE . ';
795 841
796 PerlIO::scalar->bootstrap; 842 # the path prefix to use when putting files into %INC
843 our $inc_prefix;
797 844
798 @INC = sub { 845 # the @INC hook to use when we have PerlIO::scalar available
846 my $perlio_inc = sub {
799 my $data = find "$_[1]" 847 my $data = find "$_[1]"
800 or return; 848 or return;
801 849
802 $INC{$_[1]} = $_[1]; 850 $INC{$_[1]} = "$inc_prefix$_[1]";
803 851
804 open my $fh, "<", \$data; 852 open my $fh, "<", \$data;
805 $fh 853 $fh
806 }; 854 };
855
856D if (defined &PerlIO::scalar::bootstrap) {
857 # PerlIO::scalar statically compiled in
858 PerlIO::scalar->bootstrap;
859 @INC = $perlio_inc;
860D } else {
861D # PerlIO::scalar not available, use slower method
862D @INC = sub {
863D # always check if PerlIO::scalar might now be available
864D if (defined &PerlIO::scalar::bootstrap) {
865D # switch to the faster perlio_inc hook
866D @INC = map { $_ == $_[0] ? $perlio_inc : $_ } @INC;
867D goto &$perlio_inc;
868D }
869D
870D my $data = find "$_[1]"
871D or return;
872D
873D $INC{$_[1]} = "$inc_prefix$_[1]";
874D
875D sub {
876D $data =~ /\G([^\n]*\n?)/g
877D or return;
878D
879D $_ = $1;
880D 1
881D }
882D };
883D }
807} 884}
808'; 885';
809 886
810$bootstrap .= "require '//boot';" 887$bootstrap .= "require '!boot';"
811 if exists $pm{"//boot"}; 888 if exists $pm{"!boot"};
812 889
890if ($HAVE_DYNAMIC) {
891 $bootstrap =~ s/^D/ /mg;
892} else {
893 $bootstrap =~ s/^D.*$//mg;
894}
895
896$bootstrap =~ s/#.*$//mg;
813$bootstrap =~ s/\s+/ /g; 897$bootstrap =~ s/\s+/ /g;
814$bootstrap =~ s/(\W) /$1/g; 898$bootstrap =~ s/(\W) /$1/g;
815$bootstrap =~ s/ (\W)/$1/g; 899$bootstrap =~ s/ (\W)/$1/g;
816 900
817print $fh "const char bootstrap [] = "; 901print $fh "const char bootstrap [] = ";
863 } 947 }
864 948
865 XSRETURN (0); 949 XSRETURN (0);
866 950
867 found: 951 found:
868 ST (0) = res; 952 ST (0) = sv_2mortal (res);
869 sv_2mortal (ST (0));
870 } 953 }
871 954
872 XSRETURN (1); 955 XSRETURN (1);
873} 956}
874 957
887 970
888 for (i = 0; i < $varpfx\_count; ++i) 971 for (i = 0; i < $varpfx\_count; ++i)
889 { 972 {
890 U32 idx = $varpfx\_index [i]; 973 U32 idx = $varpfx\_index [i];
891 974
892 PUSHs (newSVpvn ($varpfx\_data + (idx & 0x1FFFFFFU), idx >> 25)); 975 PUSHs (sv_2mortal (newSVpvn ($varpfx\_data + (idx & 0x1FFFFFFU), idx >> 25)));
893 } 976 }
894 } 977 }
895 978
896 XSRETURN ($varpfx\_count); 979 XSRETURN ($varpfx\_count);
897} 980}
905void 988void
906staticperl_xs_init (pTHX) 989staticperl_xs_init (pTHX)
907{ 990{
908EOF 991EOF
909 992
910@static_ext = ("DynaLoader", sort @static_ext); 993@static_ext = sort @static_ext;
911 994
912# prototypes 995# prototypes
913for (@static_ext) { 996for (@static_ext) {
914 s/\.pm$//; 997 s/\.pm$//;
915 (my $cname = $_) =~ s/\//__/g; 998 (my $cname = $_) =~ s/\//__/g;
929 s/\.pm$//; 1012 s/\.pm$//;
930 1013
931 (my $cname = $_) =~ s/\//__/g; 1014 (my $cname = $_) =~ s/\//__/g;
932 (my $pname = $_) =~ s/\//::/g; 1015 (my $pname = $_) =~ s/\//::/g;
933 1016
934 my $bootstrap = $pname eq "DynaLoader" ? "boot" : "bootstrap"; 1017 my $bootstrap = $pname eq "DynaLoader" ? "boot_DynaLoader" : "bootstrap";
935 1018
936 print $fh " newXS (\"$pname\::$bootstrap\", boot_$cname, file);\n"; 1019 print $fh " newXS (\"$pname\::$bootstrap\", boot_$cname, file);\n";
937} 1020}
938 1021
939print $fh <<EOF; 1022print $fh <<EOF;
1023 #ifdef _WIN32
1024 /* windows perls usually trail behind unix perls 8-10 years in exporting symbols */
1025
1026 if (!PL_preambleav)
1027 PL_preambleav = newAV ();
1028
1029 av_unshift (PL_preambleav, 1);
1030 av_store (PL_preambleav, 0, newSVpv (bootstrap, sizeof (bootstrap) - 1));
1031 #else
940 Perl_av_create_and_unshift_one (&PL_preambleav, newSVpv (bootstrap, sizeof (bootstrap) - 1)); 1032 Perl_av_create_and_unshift_one (&PL_preambleav, newSVpv (bootstrap, sizeof (bootstrap) - 1));
1033 #endif
1034
1035 if (PL_oldname)
1036 ((XSINIT_t)PL_oldname)(aTHX);
941} 1037}
942EOF 1038EOF
943 1039
944############################################################################# 1040#############################################################################
945# optional perl_init/perl_destroy 1041# optional perl_init/perl_destroy
946 1042
1043if ($IGNORE_ENV) {
1044 $IGNORE_ENV = <<EOF;
1045 unsetenv ("PERL_UNICODE");
1046 unsetenv ("PERL_HASH_SEED_DEBUG");
1047 unsetenv ("PERL_DESTRUCT_LEVEL");
1048 unsetenv ("PERL_SIGNALS");
1049 unsetenv ("PERL_DEBUG_MSTATS");
1050 unsetenv ("PERL5OPT");
1051 unsetenv ("PERLIO_DEBUG");
1052 unsetenv ("PERLIO");
1053 unsetenv ("PERL_HASH_SEED");
1054EOF
1055} else {
1056 $IGNORE_ENV = "";
1057}
1058
947if ($APP) { 1059if ($APP) {
1060 print $fh <<EOF;
1061
1062int
1063main (int argc, char *argv [])
1064{
1065 extern char **environ;
1066 int i, exitstatus;
1067 char **args = malloc ((argc + 3) * sizeof (const char *));
1068
1069 args [0] = argv [0];
1070 args [1] = "-e";
1071 args [2] = "0";
1072 args [3] = "--";
1073
1074 for (i = 1; i < argc; ++i)
1075 args [i + 3] = argv [i];
1076
1077$IGNORE_ENV
1078 PERL_SYS_INIT3 (&argc, &argv, &environ);
1079 staticperl = perl_alloc ();
1080 perl_construct (staticperl);
1081
1082 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
1083
1084 exitstatus = perl_parse (staticperl, staticperl_xs_init, argc + 3, args, environ);
1085 free (args);
1086 if (!exitstatus)
1087 perl_run (staticperl);
1088
1089 exitstatus = perl_destruct (staticperl);
1090 perl_free (staticperl);
1091 PERL_SYS_TERM ();
1092
1093 return exitstatus;
1094}
1095EOF
1096} elsif ($PERL) {
948 print $fh <<EOF; 1097 print $fh <<EOF;
949 1098
950int 1099int
951main (int argc, char *argv []) 1100main (int argc, char *argv [])
952{ 1101{
953 extern char **environ; 1102 extern char **environ;
954 int exitstatus; 1103 int exitstatus;
955 1104
1105$IGNORE_ENV
1106 PERL_SYS_INIT3 (&argc, &argv, &environ);
1107 staticperl = perl_alloc ();
1108 perl_construct (staticperl);
1109
1110 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
1111
1112 exitstatus = perl_parse (staticperl, staticperl_xs_init, argc, argv, environ);
1113 if (!exitstatus)
1114 perl_run (staticperl);
1115
1116 exitstatus = perl_destruct (staticperl);
1117 perl_free (staticperl);
1118 PERL_SYS_TERM ();
1119
1120 return exitstatus;
1121}
1122EOF
1123} else {
1124 print $fh <<EOF;
1125
1126EXTERN_C void
1127staticperl_init (XSINIT_t xs_init)
1128{
956 static char *args[] = { 1129 static char *args[] = {
957 "staticperl", 1130 "staticperl",
958 "-e", 1131 "-e",
959 "0" 1132 "0"
960 }; 1133 };
961 1134
962 PERL_SYS_INIT3 (&argc, &argv, &environ);
963 staticperl = perl_alloc ();
964 perl_construct (staticperl);
965
966 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
967
968 exitstatus = perl_parse (staticperl, staticperl_xs_init, sizeof (args) / sizeof (*args), args, environ);
969 if (!exitstatus)
970 perl_run (staticperl);
971
972 exitstatus = perl_destruct (staticperl);
973 perl_free (staticperl);
974 PERL_SYS_TERM ();
975
976 return exitstatus;
977}
978EOF
979} elsif ($PERL) {
980 print $fh <<EOF;
981
982int
983main (int argc, char *argv [])
984{
985 extern char **environ;
986 int exitstatus;
987
988 PERL_SYS_INIT3 (&argc, &argv, &environ);
989 staticperl = perl_alloc ();
990 perl_construct (staticperl);
991
992 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
993
994 exitstatus = perl_parse (staticperl, staticperl_xs_init, argc, argv, environ);
995 if (!exitstatus)
996 perl_run (staticperl);
997
998 exitstatus = perl_destruct (staticperl);
999 perl_free (staticperl);
1000 PERL_SYS_TERM ();
1001
1002 return exitstatus;
1003}
1004EOF
1005} else {
1006 print $fh <<EOF;
1007
1008EXTERN_C void
1009staticperl_init (void)
1010{
1011 extern char **environ; 1135 extern char **environ;
1012 int argc = sizeof (args) / sizeof (args [0]); 1136 int argc = sizeof (args) / sizeof (args [0]);
1013 char **argv = args; 1137 char **argv = args;
1014 1138
1015 static char *args[] = { 1139$IGNORE_ENV
1016 "staticperl",
1017 "-e",
1018 "0"
1019 };
1020
1021 PERL_SYS_INIT3 (&argc, &argv, &environ); 1140 PERL_SYS_INIT3 (&argc, &argv, &environ);
1022 staticperl = perl_alloc (); 1141 staticperl = perl_alloc ();
1023 perl_construct (staticperl); 1142 perl_construct (staticperl);
1024 PL_origalen = 1; 1143 PL_origalen = 1;
1025 PL_exit_flags |= PERL_EXIT_DESTRUCT_END; 1144 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
1145 PL_oldname = (char *)xs_init;
1026 perl_parse (staticperl, staticperl_xs_init, argc, argv, environ); 1146 perl_parse (staticperl, staticperl_xs_init, argc, argv, environ);
1027 1147
1028 perl_run (staticperl); 1148 perl_run (staticperl);
1029} 1149}
1030 1150
1037 PERL_SYS_TERM (); 1157 PERL_SYS_TERM ();
1038} 1158}
1039EOF 1159EOF
1040} 1160}
1041 1161
1162close $fh;
1163
1042print -s "$PREFIX.c", " octets (", (length $data) , " data octets).\n\n" 1164print -s "$PREFIX.c", " octets (", (length $data) , " data octets).\n\n"
1043 if $VERBOSE >= 1; 1165 if $VERBOSE >= 1;
1044 1166
1045############################################################################# 1167#############################################################################
1046# libs, cflags 1168# libs, cflags
1169
1170my $ccopts;
1047 1171
1048{ 1172{
1049 print "generating $PREFIX.ccopts... " 1173 print "generating $PREFIX.ccopts... "
1050 if $VERBOSE >= 1; 1174 if $VERBOSE >= 1;
1051 1175
1052 my $str = "$Config{ccflags} $Config{optimize} $Config{cppflags} -I$Config{archlibexp}/CORE"; 1176 $ccopts = "$Config{ccflags} $Config{optimize} $Config{cppflags} -I$Config{archlibexp}/CORE";
1053 $str =~ s/([\(\)])/\\$1/g; 1177 $ccopts =~ s/([\(\)])/\\$1/g;
1054 1178
1055 open my $fh, ">$PREFIX.ccopts" 1179 open my $fh, ">$PREFIX.ccopts"
1056 or die "$PREFIX.ccopts: $!"; 1180 or die "$PREFIX.ccopts: $!";
1057 print $fh $str; 1181 print $fh $ccopts;
1058 1182
1059 print "$str\n\n" 1183 print "$ccopts\n\n"
1060 if $VERBOSE >= 1; 1184 if $VERBOSE >= 1;
1061} 1185}
1186
1187my $ldopts;
1062 1188
1063{ 1189{
1064 print "generating $PREFIX.ldopts... "; 1190 print "generating $PREFIX.ldopts... ";
1065 1191
1066 my $str = $STATIC ? "-static " : ""; 1192 $ldopts = $STATIC ? "-static " : "";
1067 1193
1068 $str .= "$Config{ccdlflags} $Config{ldflags} @libs $Config{archlibexp}/CORE/$Config{libperl} $Config{perllibs}"; 1194 $ldopts .= "$Config{ccdlflags} $Config{ldflags} @libs $Config{archlibexp}/CORE/$Config{libperl} $Config{perllibs}";
1069 1195
1070 my %seen; 1196 my %seen;
1071 $str .= " $_" for grep !$seen{$_}++, ($extralibs =~ /(\S+)/g); 1197 $ldopts .= " $_" for reverse grep !$seen{$_}++, reverse +($extralibs =~ /(\S+)/g);
1072 1198
1073 for (@staticlibs) { 1199 for (@staticlibs) {
1074 $str =~ s/(^|\s) (-l\Q$_\E) ($|\s)/$1-Wl,-Bstatic $2 -Wl,-Bdynamic$3/gx; 1200 $ldopts =~ s/(^|\s) (-l\Q$_\E) ($|\s)/$1-Wl,-Bstatic $2 -Wl,-Bdynamic$3/gx;
1075 } 1201 }
1076 1202
1077 $str =~ s/([\(\)])/\\$1/g; 1203 $ldopts =~ s/([\(\)])/\\$1/g;
1078 1204
1079 open my $fh, ">$PREFIX.ldopts" 1205 open my $fh, ">$PREFIX.ldopts"
1080 or die "$PREFIX.ldopts: $!"; 1206 or die "$PREFIX.ldopts: $!";
1081 print $fh $str; 1207 print $fh $ldopts;
1082 1208
1083 print "$str\n\n" 1209 print "$ldopts\n\n"
1084 if $VERBOSE >= 1; 1210 if $VERBOSE >= 1;
1085} 1211}
1086 1212
1087if ($PERL or defined $APP) { 1213if ($PERL or defined $APP) {
1088 $APP = "perl" unless defined $APP; 1214 $APP = "perl" unless defined $APP;
1089 1215
1216 my $build = "$Config{cc} $ccopts -o \Q$APP\E$Config{_exe} bundle.c $ldopts";
1217
1090 print "building $APP...\n" 1218 print "build $APP...\n"
1091 if $VERBOSE >= 1; 1219 if $VERBOSE >= 1;
1092 1220
1093 system "$Config{cc} \$(cat bundle.ccopts\) -o \Q$APP\E bundle.c \$(cat bundle.ldopts\)"; 1221 print "$build\n"
1222 if $VERBOSE >= 2;
1223
1224 system $build;
1094 1225
1095 unlink "$PREFIX.$_" 1226 unlink "$PREFIX.$_"
1096 for qw(ccopts ldopts c h); 1227 for qw(ccopts ldopts c h);
1097 1228
1098 print "\n" 1229 print "\n"

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines