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

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines