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 | our $IGNORE_ENV = 0; |
15 | our $ALLOW_DLLS = 0; |
15 | our $ALLOW_DYNAMIC = 0; |
16 | our $HAVE_DLLS; # maybe useful? |
16 | our $HAVE_DYNAMIC; # maybe useful? |
17 | |
17 | |
18 | our $OPTIMISE_SIZE = 0; # optimise for raw file size instead of for compression? |
18 | our $OPTIMISE_SIZE = 0; # optimise for raw file size instead of for compression? |
19 | |
19 | |
20 | our $CACHE; |
20 | our $CACHE; |
21 | our $CACHEVER = 1; # do not change unless you know what you are doing |
21 | our $CACHEVER = 1; # do not change unless you know what you are doing |
… | |
… | |
192 | |
192 | |
193 | sub dump_string { |
193 | sub dump_string { |
194 | my ($fh, $data) = @_; |
194 | my ($fh, $data) = @_; |
195 | |
195 | |
196 | 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"; |
197 | for ( |
200 | for ( |
198 | 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; |
199 | length (my $substr = substr $data, $ofs, 80); |
212 | length (my $substr = substr $data, $ofs, 80); |
200 | $ofs += 80 |
213 | $ofs += 80 |
201 | ) { |
214 | ) { |
202 | $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; |
203 | $substr =~ s/\?/\\?/g; # trigraphs... |
216 | $substr =~ s/\?/\\?/g; # trigraphs... |
204 | print $fh " \"$substr\"\n"; |
217 | print $fh " \"$substr\"\n"; |
|
|
218 | } |
205 | } |
219 | } |
206 | } else { |
220 | } else { |
207 | print $fh " \"\"\n"; |
221 | print $fh " \"\"\n"; |
208 | } |
222 | } |
209 | } |
223 | } |
… | |
… | |
276 | } |
290 | } |
277 | |
291 | |
278 | ############################################################################# |
292 | ############################################################################# |
279 | |
293 | |
280 | sub cmd_boot { |
294 | sub cmd_boot { |
281 | $pm{"&&boot"} = $_[0]; |
295 | $pm{"!boot"} = $_[0]; |
282 | } |
296 | } |
283 | |
297 | |
284 | sub cmd_add { |
298 | sub cmd_add { |
285 | $_[0] =~ /^(.*?)(?:\s+(\S+))?$/ |
299 | $_[0] =~ /^(.*?)(?:\s+(\S+))?$/ |
286 | or die "$_[0]: cannot parse"; |
300 | or die "$_[0]: cannot parse"; |
… | |
… | |
359 | "exclude|x=s" => sub { cmd_include $_[1], 0 }, |
373 | "exclude|x=s" => sub { cmd_include $_[1], 0 }, |
360 | "usepacklists!" => \$PACKLIST, |
374 | "usepacklists!" => \$PACKLIST, |
361 | |
375 | |
362 | "static!" => \$STATIC, |
376 | "static!" => \$STATIC, |
363 | "staticlib=s" => sub { cmd_staticlib $_[1] }, |
377 | "staticlib=s" => sub { cmd_staticlib $_[1] }, |
364 | "allow-dlls" => \$ALLOW_DLLS, |
378 | "allow-dynamic!"=> \$ALLOW_DYNAMIC, |
365 | "ignore-env" => \$IGNORE_ENV, |
379 | "ignore-env" => \$IGNORE_ENV, |
366 | |
380 | |
367 | "<>" => sub { cmd_file $_[0] }, |
381 | "<>" => sub { cmd_file $_[0] }, |
368 | or exit 1; |
382 | or exit 1; |
369 | } |
383 | } |
… | |
… | |
479 | push @static_ext, $pm; |
493 | push @static_ext, $pm; |
480 | } |
494 | } |
481 | |
495 | |
482 | # dynamic object |
496 | # dynamic object |
483 | if (-f "$autodir/$base.$Config{dlext}") { |
497 | if (-f "$autodir/$base.$Config{dlext}") { |
484 | if ($ALLOW_DLLS) { |
498 | if ($ALLOW_DYNAMIC) { |
485 | my $as = "&fs/perl/$auto/$base.$Config{dlext}"; |
499 | my $as = "!$auto/$base.$Config{dlext}"; |
486 | $pm{$as} = "$autodir/$base.$Config{dlext}"; |
500 | $pm{$as} = "$autodir/$base.$Config{dlext}"; |
487 | $pmbin{$as} = 1; |
501 | $pmbin{$as} = 1; |
488 | |
502 | |
489 | $HAVE_DLLS = 1; |
503 | $HAVE_DYNAMIC = 1; |
490 | |
504 | |
491 | print "+ added dynamic object $auto/$base.$Config{dlext}\n" |
505 | print "+ added dynamic object $as\n" |
492 | if $VERBOSE >= 3; |
506 | if $VERBOSE >= 3; |
493 | } else { |
507 | } else { |
494 | die "ERROR: found shared object '$_' but --allow-dlls not given, aborting.\n" |
508 | die "ERROR: found shared object '$autodir/$base.$Config{dlext}' but --allow-dynamic not given, aborting.\n" |
495 | } |
509 | } |
496 | } |
510 | } |
497 | |
511 | |
498 | if ($PACKLIST && open my $fh, "<:perlio", "$autodir/.packlist") { |
512 | if ($PACKLIST && open my $fh, "<:perlio", "$autodir/.packlist") { |
499 | print "found .packlist for $pm\n" |
513 | print "found .packlist for $pm\n" |
… | |
… | |
818 | # bootstrap |
832 | # bootstrap |
819 | |
833 | |
820 | # boot file for staticperl |
834 | # boot file for staticperl |
821 | # this file will be eval'ed at initialisation time |
835 | # this file will be eval'ed at initialisation time |
822 | |
836 | |
823 | # lines marked with "^D" are only used when $HAVE_DLLS |
837 | # lines marked with "^D" are only used when $HAVE_DYNAMIC |
824 | my $bootstrap = ' |
838 | my $bootstrap = ' |
825 | BEGIN { |
839 | BEGIN { |
826 | package ' . $PACKAGE . '; |
840 | package ' . $PACKAGE . '; |
827 | |
841 | |
828 | # the path prefix to use when putting files into %INC |
842 | # the path prefix to use when putting files into %INC |
… | |
… | |
868 | D }; |
882 | D }; |
869 | D } |
883 | D } |
870 | } |
884 | } |
871 | '; |
885 | '; |
872 | |
886 | |
873 | $bootstrap .= "require '&&boot';" |
887 | $bootstrap .= "require '!boot';" |
874 | if exists $pm{"&&boot"}; |
888 | if exists $pm{"!boot"}; |
875 | |
889 | |
876 | if ($HAVE_DLLS) { |
890 | if ($HAVE_DYNAMIC) { |
877 | $bootstrap =~ s/^D/ /mg; |
891 | $bootstrap =~ s/^D/ /mg; |
878 | } else { |
892 | } else { |
879 | $bootstrap =~ s/^D.*$//mg; |
893 | $bootstrap =~ s/^D.*$//mg; |
880 | } |
894 | } |
881 | |
895 | |
… | |
… | |
1004 | |
1018 | |
1005 | print $fh " newXS (\"$pname\::$bootstrap\", boot_$cname, file);\n"; |
1019 | print $fh " newXS (\"$pname\::$bootstrap\", boot_$cname, file);\n"; |
1006 | } |
1020 | } |
1007 | |
1021 | |
1008 | print $fh <<EOF; |
1022 | print $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 |
1009 | 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 |
1010 | |
1034 | |
1011 | if (PL_oldname) |
1035 | if (PL_oldname) |
1012 | ((XSINIT_t)PL_oldname)(aTHX); |
1036 | ((XSINIT_t)PL_oldname)(aTHX); |
1013 | } |
1037 | } |
1014 | EOF |
1038 | EOF |
… | |
… | |
1133 | PERL_SYS_TERM (); |
1157 | PERL_SYS_TERM (); |
1134 | } |
1158 | } |
1135 | EOF |
1159 | EOF |
1136 | } |
1160 | } |
1137 | |
1161 | |
|
|
1162 | close $fh; |
|
|
1163 | |
1138 | print -s "$PREFIX.c", " octets (", (length $data) , " data octets).\n\n" |
1164 | print -s "$PREFIX.c", " octets (", (length $data) , " data octets).\n\n" |
1139 | if $VERBOSE >= 1; |
1165 | if $VERBOSE >= 1; |
1140 | |
1166 | |
1141 | ############################################################################# |
1167 | ############################################################################# |
1142 | # libs, cflags |
1168 | # libs, cflags |
|
|
1169 | |
|
|
1170 | my $ccopts; |
1143 | |
1171 | |
1144 | { |
1172 | { |
1145 | print "generating $PREFIX.ccopts... " |
1173 | print "generating $PREFIX.ccopts... " |
1146 | if $VERBOSE >= 1; |
1174 | if $VERBOSE >= 1; |
1147 | |
1175 | |
1148 | my $str = "$Config{ccflags} $Config{optimize} $Config{cppflags} -I$Config{archlibexp}/CORE"; |
1176 | $ccopts = "$Config{ccflags} $Config{optimize} $Config{cppflags} -I\"$Config{archlibexp}/CORE\""; |
1149 | $str =~ s/([\(\)])/\\$1/g; |
1177 | $ccopts =~ s/([\(\)])/\\$1/g; |
1150 | |
1178 | |
1151 | open my $fh, ">$PREFIX.ccopts" |
1179 | open my $fh, ">$PREFIX.ccopts" |
1152 | or die "$PREFIX.ccopts: $!"; |
1180 | or die "$PREFIX.ccopts: $!"; |
1153 | print $fh $str; |
1181 | print $fh $ccopts; |
1154 | |
1182 | |
1155 | print "$str\n\n" |
1183 | print "$ccopts\n\n" |
1156 | if $VERBOSE >= 1; |
1184 | if $VERBOSE >= 1; |
1157 | } |
1185 | } |
|
|
1186 | |
|
|
1187 | my $ldopts; |
1158 | |
1188 | |
1159 | { |
1189 | { |
1160 | print "generating $PREFIX.ldopts... "; |
1190 | print "generating $PREFIX.ldopts... "; |
1161 | |
1191 | |
1162 | my $str = $STATIC ? "-static " : ""; |
1192 | $ldopts = $STATIC ? "-static " : ""; |
1163 | |
1193 | |
1164 | $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}"; |
1165 | |
1195 | |
1166 | my %seen; |
1196 | my %seen; |
1167 | $str .= " $_" for grep !$seen{$_}++, ($extralibs =~ /(\S+)/g); |
1197 | $ldopts .= " $_" for reverse grep !$seen{$_}++, reverse ($extralibs =~ /(\S+)/g); |
1168 | |
1198 | |
1169 | for (@staticlibs) { |
1199 | for (@staticlibs) { |
1170 | $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; |
1171 | } |
1201 | } |
1172 | |
1202 | |
1173 | $str =~ s/([\(\)])/\\$1/g; |
1203 | $ldopts =~ s/([\(\)])/\\$1/g; |
1174 | |
1204 | |
1175 | open my $fh, ">$PREFIX.ldopts" |
1205 | open my $fh, ">$PREFIX.ldopts" |
1176 | or die "$PREFIX.ldopts: $!"; |
1206 | or die "$PREFIX.ldopts: $!"; |
1177 | print $fh $str; |
1207 | print $fh $ldopts; |
1178 | |
1208 | |
1179 | print "$str\n\n" |
1209 | print "$ldopts\n\n" |
1180 | if $VERBOSE >= 1; |
1210 | if $VERBOSE >= 1; |
1181 | } |
1211 | } |
1182 | |
1212 | |
1183 | if ($PERL or defined $APP) { |
1213 | if ($PERL or defined $APP) { |
1184 | $APP = "perl" unless defined $APP; |
1214 | $APP = "perl" unless defined $APP; |
1185 | |
1215 | |
|
|
1216 | my $build = "$Config{cc} $ccopts -o \Q$APP\E$Config{_exe} bundle.c $ldopts"; |
|
|
1217 | |
1186 | print "building $APP...\n" |
1218 | print "build $APP...\n" |
1187 | if $VERBOSE >= 1; |
1219 | if $VERBOSE >= 1; |
1188 | |
1220 | |
1189 | system "$Config{cc} \$(cat bundle.ccopts\) -o \Q$APP\E bundle.c \$(cat bundle.ldopts\)"; |
1221 | print "$build\n" |
|
|
1222 | if $VERBOSE >= 2; |
1190 | |
1223 | |
|
|
1224 | system $build; |
|
|
1225 | |
1191 | unlink "$PREFIX.$_" |
1226 | # unlink "$PREFIX.$_" |
1192 | for qw(ccopts ldopts c h); |
1227 | # for qw(ccopts ldopts c h); |
1193 | |
1228 | |
1194 | print "\n" |
1229 | print "\n" |
1195 | if $VERBOSE >= 1; |
1230 | if $VERBOSE >= 1; |
1196 | } |
1231 | } |
1197 | |
1232 | |