3 # Create the export list for perl.
5 # Needed by WIN32 and OS/2 for creating perl.dll,
6 # and by AIX for creating libperl.a when -Dusershrplib is in effect,
7 # and by MacOS Classic.
9 # reads global.sym, pp.sym, perlvars.h, intrpvar.h, thrdvar.h, config.h
10 # On OS/2 reads miniperl.map and the previous version of perl5.def as well
12 BEGIN { unshift @INC, "lib" }
15 use vars qw($PLATFORM $CCTYPE $FILETYPE $CONFIG_ARGS $ARCHNAME $PATCHLEVEL);
17 my (%define, %ordinal);
21 if ($flag =~ s/^CC_FLAGS=/ /) {
22 for my $fflag ($flag =~ /(?:^|\s)-D(\S+)/g) {
23 $fflag .= '=1' unless $fflag =~ /^(\w+)=/;
24 $define{$1} = $2 if $fflag =~ /^(\w+)=(.+)$/;
28 $define{$1} = 1 if ($flag =~ /^-D(\w+)$/);
29 $define{$1} = $2 if ($flag =~ /^-D(\w+)=(.+)$/);
30 $CCTYPE = $1 if ($flag =~ /^CCTYPE=(\w+)$/);
31 $PLATFORM = $1 if ($flag =~ /^PLATFORM=(\w+)$/);
32 if ($PLATFORM eq 'netware') {
33 $FILETYPE = $1 if ($flag =~ /^FILETYPE=(\w+)$/);
37 my @PLATFORM = qw(aix win32 wince os2 MacOS netware);
39 @PLATFORM{@PLATFORM} = ();
41 defined $PLATFORM || die "PLATFORM undefined, must be one of: @PLATFORM\n";
42 exists $PLATFORM{$PLATFORM} || die "PLATFORM must be one of: @PLATFORM\n";
44 if ($PLATFORM eq 'win32' or $PLATFORM eq 'wince' or $PLATFORM eq "aix") {
45 # Add the compile-time options that miniperl was built with to %define.
46 # On Win32 these are not the same options as perl itself will be built
47 # with since miniperl is built with a canned config (one of the win32/
48 # config_H.*) and none of the BUILDOPT's that are set in the makefiles,
49 # but they do include some #define's that are hard-coded in various
50 # source files and header files and don't include any BUILDOPT's that
51 # the user might have chosen to disable because the canned configs are
52 # minimal configs that don't include any of those options.
53 my $opts = ($PLATFORM eq 'wince' ? '-MCross' : ''); # for wince need Cross.pm to get Config.pm
54 my $config = `$^X $opts -Ilib -V`;
55 my($options) = $config =~ /^ Compile-time options: (.*?)\n^ \S/ms;
56 $options =~ s/\s+/ /g;
57 print STDERR "Options: ($options)\n";
58 foreach (split /\s+/, $options) {
63 my %exportperlmalloc =
65 Perl_malloc => "malloc",
67 Perl_realloc => "realloc",
68 Perl_calloc => "calloc",
71 my $exportperlmalloc = $PLATFORM eq 'os2';
73 my $config_sh = "config.sh";
74 my $config_h = "config.h";
75 my $thrdvar_h = "thrdvar.h";
76 my $intrpvar_h = "intrpvar.h";
77 my $perlvars_h = "perlvars.h";
78 my $global_sym = "global.sym";
79 my $pp_sym = "pp.sym";
80 my $globvar_sym = "globvar.sym";
81 my $perlio_sym = "perlio.sym";
84 if ($PLATFORM eq 'aix') {
87 elsif ($PLATFORM =~ /^win(?:32|ce)$/ || $PLATFORM eq 'netware') {
88 $CCTYPE = "MSVC" unless defined $CCTYPE;
89 foreach ($thrdvar_h, $intrpvar_h, $perlvars_h, $global_sym,
90 $pp_sym, $globvar_sym, $perlio_sym) {
94 elsif ($PLATFORM eq 'MacOS') {
95 foreach ($thrdvar_h, $intrpvar_h, $perlvars_h, $global_sym,
96 $pp_sym, $globvar_sym, $perlio_sym) {
101 unless ($PLATFORM eq 'win32' || $PLATFORM eq 'wince' || $PLATFORM eq 'MacOS' || $PLATFORM eq 'netware') {
102 open(CFG,$config_sh) || die "Cannot open $config_sh: $!\n";
104 if (/^(?:ccflags|optimize)='(.+)'$/) {
106 $define{$1} = 1 while /-D(\w+)/g;
108 if (/^(d_(?:mmap|sigaction))='(.+)'$/) {
111 if ($PLATFORM eq 'os2') {
112 $CONFIG_ARGS = $1 if /^config_args='(.+)'$/;
113 $ARCHNAME = $1 if /^archname='(.+)'$/;
114 $PATCHLEVEL = $1 if /^perl_patchlevel='(.+)'$/;
119 if ($PLATFORM eq 'win32' || $PLATFORM eq 'wince') {
120 open(CFG,"<..\\$config_sh") || die "Cannot open ..\\$config_sh: $!\n";
121 if ((join '', <CFG>) =~ /^static_ext='(.*)'$/m) {
127 open(CFG,$config_h) || die "Cannot open $config_h: $!\n";
129 $define{$1} = 1 if /^\s*#\s*define\s+(MYMALLOC)\b/;
130 $define{$1} = 1 if /^\s*#\s*define\s+(MULTIPLICITY)\b/;
131 $define{$1} = 1 if /^\s*#\s*define\s+(PERL_\w+)\b/;
132 $define{$1} = 1 if /^\s*#\s*define\s+(USE_\w+)\b/;
136 # perl.h logic duplication begins
138 if ($define{PERL_IMPLICIT_SYS}) {
139 $define{PL_OP_SLAB_ALLOC} = 1;
142 if ($define{USE_ITHREADS}) {
143 if (!$define{MULTIPLICITY}) {
144 $define{MULTIPLICITY} = 1;
148 $define{PERL_IMPLICIT_CONTEXT} ||=
149 $define{USE_ITHREADS} ||
150 $define{MULTIPLICITY} ;
152 if ($define{USE_ITHREADS} && $PLATFORM ne 'win32' && $^O ne 'darwin') {
153 $define{USE_REENTRANT_API} = 1;
156 # perl.h logic duplication ends
160 print STDERR "Defines: (" . join(' ', sort keys %define) . ")\n";
162 if ($PLATFORM =~ /^win(?:32|ce)$/) {
163 (my $dll = ($define{PERL_DLL} || "perl59")) =~ s/\.dll$//i;
164 print "LIBRARY $dll\n";
165 print "DESCRIPTION 'Perl interpreter'\n";
167 if ($define{PERL_IMPLICIT_SYS}) {
168 output_symbol("perl_get_host_info");
169 output_symbol("perl_alloc_override");
171 if ($define{USE_ITHREADS} and $define{PERL_IMPLICIT_SYS}) {
172 output_symbol("perl_clone_host");
175 elsif ($PLATFORM eq 'os2') {
176 if (open my $fh, '<', 'perl5.def') {
178 last if /^\s*EXPORTS\b/;
181 $ordinal{$1} = $2 if /^\s*"(\w+)"\s*(?:=\s*"\w+"\s*)?\@(\d+)\s*$/;
182 # This allows skipping ordinals which were used in older versions
183 $sym_ord = $1 if /^\s*;\s*LAST_ORDINAL\s*=\s*(\d+)\s*$/;
185 $sym_ord < $_ and $sym_ord = $_ for values %ordinal; # Take the max
187 (my $v = $]) =~ s/(\d\.\d\d\d)(\d\d)$/$1_$2/;
188 $v .= '-thread' if $ARCHNAME =~ /-thread/;
189 (my $dll = $define{PERL_DLL}) =~ s/\.dll$//i;
190 $v .= "\@$PATCHLEVEL" if $PATCHLEVEL;
191 my $d = "DESCRIPTION '\@#perl5-porters\@perl.org:$v#\@ Perl interpreter, configured as $CONFIG_ARGS'";
192 $d = substr($d, 0, 249) . "...'" if length $d > 253;
194 LIBRARY '$dll' INITINSTANCE TERMINSTANCE
198 DATA LOADONCALL NONSHARED MULTIPLE
202 elsif ($PLATFORM eq 'aix') {
203 my $OSVER = `uname -v`;
205 my $OSREL = `uname -r`;
207 if ($OSVER > 4 || ($OSVER == 4 && $OSREL >= 3)) {
213 elsif ($PLATFORM eq 'netware') {
214 if ($FILETYPE eq 'def') {
215 print "LIBRARY perl59\n";
216 print "DESCRIPTION 'Perl interpreter for NetWare'\n";
219 if ($define{PERL_IMPLICIT_SYS}) {
220 output_symbol("perl_get_host_info");
221 output_symbol("perl_alloc_override");
222 output_symbol("perl_clone_host");
231 foreach my $symbol (@$list) {
238 foreach my $symbol (@$list) {
239 my $skipsym = $symbol;
241 if ($define{MULTIPLICITY}) {
242 $skipsym =~ s/^Perl_[GIT](\w+)_ptr$/PL_$1/;
244 emit_symbol($symbol) unless exists $skip{$skipsym};
248 if ($PLATFORM eq 'win32') {
272 Perl_init_thread_intern
306 if ($PLATFORM eq 'wince') {
321 PL_collation_standard
349 Perl_init_thread_intern
376 elsif ($PLATFORM eq 'aix') {
395 Perl_sys_intern_clear
405 elsif ($PLATFORM eq 'os2') {
450 XS_Cwd_extLibpath_set
454 XS_Cwd_sys_is_absolute
455 XS_Cwd_sys_is_relative
457 XS_DynaLoader_mod2fname
458 XS_File__Copy_syscopy
462 Perl_Process_Messages
473 emit_symbols([qw(os2_cond_wait
478 if $define{'USE_5005THREADS'} or $define{'USE_ITHREADS'};
480 elsif ($PLATFORM eq 'MacOS') {
504 Perl_sys_intern_clear
508 elsif ($PLATFORM eq 'netware') {
532 Perl_init_thread_intern
557 Perl_sys_intern_clear
565 Perl_PerlIO_setlinebuf
566 Perl_PerlIO_set_ptrcnt
572 Perl_PerlIO_get_bufsiz
585 unless ($define{'DEBUGGING'}) {
602 if ($define{'PERL_IMPLICIT_CONTEXT'}) {
608 if ($define{'PERL_IMPLICIT_SYS'}) {
629 unless ($define{'PERL_OLD_COPY_ON_WRITE'}) {
635 unless ($define{'USE_REENTRANT_API'}) {
641 if ($define{'MYMALLOC'}) {
650 if ($define{'USE_ITHREADS'}) {
672 if ($define{'PERL_USE_SAFE_PUTENV'}) {
678 unless ($define{'USE_ITHREADS'}) {
684 # USE_5005THREADS symbols. Kept as reference for easier removal
703 Perl_new_struct_thread
704 Perl_per_thread_magicals
712 unless ($define{'USE_ITHREADS'}) {
718 PL_sharedsv_space_mutex
744 Perl_sharedsv_thrcnt_dec
745 Perl_sharedsv_thrcnt_inc
747 Perl_stashpv_hvname_match
748 Perl_regdupe_internal
753 unless ($define{'PERL_IMPLICIT_CONTEXT'}) {
764 Perl_load_module_nocontext
767 Perl_warner_nocontext
768 Perl_newSVpvf_nocontext
769 Perl_sv_catpvf_nocontext
770 Perl_sv_setpvf_nocontext
771 Perl_sv_catpvf_mg_nocontext
772 Perl_sv_setpvf_mg_nocontext
778 unless ($define{'PERL_IMPLICIT_SYS'}) {
785 unless ($define{'FAKE_THREADS'}) {
786 skip_symbols [qw(PL_curthr)];
789 unless ($define{'PL_OP_SLAB_ALLOC'}) {
799 unless ($define{'THREADS_HAVE_PIDS'}) {
800 skip_symbols [qw(PL_ppid)];
803 unless ($define{'PERL_NEED_APPCTX'}) {
809 unless ($define{'PERL_NEED_TIMESBASE'}) {
815 unless ($define{'DEBUG_LEAKING_SCALARS_FORK_DUMP'}) {
820 unless ($define{'PERL_DONT_CREATE_GVSV'}) {
825 if ($define{'SPRINTF_RETURNS_STRLEN'}) {
830 unless ($define{'PERL_USES_PL_PIDSTATUS'}) {
837 unless ($define{'PERL_TRACK_MEMPOOL'}) {
839 PL_memory_debug_header
843 if ($define{'PERL_MAD'}) {
869 Perl_xmldump_packsubs
883 unless ($define{'PERL_GLOBAL_STRUCT_PRIVATE'}) {
890 unless ($define{'d_mmap'}) {
896 if ($define{'d_sigaction'}) {
903 # VMS does its own thing for these symbols.
904 skip_symbols [qw(PL_sig_handlers_initted
911 my $proc = shift || sub { "PL_$_[2]" };
912 open(VARS,$file) || die "Cannot open $file: $!\n";
915 # All symbols have a Perl_ prefix because that's what embed.h
916 # sticks in front of them. The A?I?S?C? is strictly speaking
918 push(@syms, &$proc($1,$2,$3)) if (/\bPERLVAR(A?I?S?C?)\(([IGT])(\w+)/);
924 if ($define{'PERL_GLOBAL_STRUCT'}) {
925 my $global = readvar($perlvars_h);
926 skip_symbols $global;
927 emit_symbol('Perl_GetVars');
928 emit_symbols [qw(PL_Vars PL_VarsPtr)] unless $CCTYPE eq 'GCC';
930 skip_symbols [qw(Perl_init_global_struct Perl_free_global_struct)];
933 # functions from *.sym files
935 my @syms = ($global_sym, $globvar_sym); # $pp_sym is not part of the API
937 # Symbols that are the public face of the PerlIO layers implementation
938 # These are in _addition to_ the public face of the abstraction
939 # and need to be exported to allow XS modules to implement layers
953 PerlIOBase_setlinebuf
990 Perl_PerlIO_context_layers
997 Perl_PerlIO_get_bufsiz
1003 Perl_PerlIO_set_ptrcnt
1004 Perl_PerlIO_setlinebuf
1012 if ($PLATFORM eq 'netware') {
1013 push(@layer_syms,'PL_def_layerlist','PL_known_layers','PL_perlio');
1016 if ($define{'USE_PERLIO'}) {
1017 # Export the symols that make up the PerlIO abstraction, regardless
1018 # of its implementation - read from a file
1019 push @syms, $perlio_sym;
1021 # This part is then dependent on how the abstraction is implemented
1022 if ($define{'USE_SFIO'}) {
1023 # Old legacy non-stdio "PerlIO"
1024 skip_symbols \@layer_syms;
1025 skip_symbols [qw(perlsio_binmode)];
1026 # SFIO defines most of the PerlIO routines as macros
1027 # So undo most of what $perlio_sym has just done - d'oh !
1028 # Perhaps it would be better to list the ones which do exist
1073 Perl_PerlIO_clearerr
1080 Perl_PerlIO_get_base
1081 Perl_PerlIO_get_bufsiz
1087 Perl_PerlIO_set_ptrcnt
1088 Perl_PerlIO_setlinebuf
1101 # PerlIO with layers - export implementation
1102 emit_symbols \@layer_syms;
1103 emit_symbols [qw(perlsio_binmode)];
1105 if ($define{'USE_ITHREADS'}) {
1117 # Skip the PerlIO layer symbols - although
1118 # nothing should have exported them anyway.
1119 skip_symbols \@layer_syms;
1127 PL_perlio_fd_refcnt_size
1130 # Also do NOT add abstraction symbols from $perlio_sym
1131 # abstraction is done as #define to stdio
1132 # Remaining remnants that _may_ be functions
1133 # are handled in <DATA>
1136 for my $syms (@syms) {
1137 open (GLOBAL, "<$syms") || die "failed to open $syms: $!\n";
1139 next if (!/^[A-Za-z]/);
1140 # Functions have a Perl_ prefix
1141 # Variables have a PL_ prefix
1143 my $symbol = ($syms =~ /var\.sym$/i ? "PL_" : "");
1145 emit_symbol($symbol) unless exists $skip{$symbol};
1152 if ($define{'MULTIPLICITY'}) {
1153 for my $f ($perlvars_h, $intrpvar_h, $thrdvar_h) {
1154 my $glob = readvar($f, sub { "Perl_" . $_[1] . $_[2] . "_ptr" });
1157 # XXX AIX seems to want the perlvars.h symbols, for some reason
1158 if ($PLATFORM eq 'aix' or $PLATFORM eq 'os2') { # OS/2 needs PL_thr_key
1159 my $glob = readvar($perlvars_h);
1164 unless ($define{'PERL_GLOBAL_STRUCT'}) {
1165 my $glob = readvar($perlvars_h);
1168 unless ($define{'MULTIPLICITY'}) {
1169 my $glob = readvar($intrpvar_h);
1172 unless ($define{'MULTIPLICITY'}) {
1173 my $glob = readvar($thrdvar_h);
1181 return if $symbol !~ /^[A-Za-z_]/;
1182 return if $symbol =~ /^\#/;
1185 return if exists $skip{$symbol};
1186 emit_symbol($symbol);
1193 if ($PLATFORM =~ /^win(?:32|ce)$/) {
1194 foreach my $symbol (qw(
1256 win32_getprotobyname
1257 win32_getprotobynumber
1286 win32_open_osfhandle
1357 try_symbol($symbol);
1359 if ($CCTYPE eq "BORLAND") {
1360 try_symbol('_matherr');
1363 elsif ($PLATFORM eq 'os2') {
1364 my (%mapped, @missing);
1365 open MAP, 'miniperl.map' or die 'Cannot read miniperl.map';
1366 /^\s*[\da-f:]+\s+(\w+)/i and $mapped{$1}++ foreach <MAP>;
1367 close MAP or die 'Cannot close miniperl.map';
1369 @missing = grep { !exists $mapped{$_} }
1371 @missing = grep { !exists $exportperlmalloc{$_} } @missing;
1372 delete $export{$_} foreach @missing;
1374 elsif ($PLATFORM eq 'MacOS') {
1375 open MACSYMS, 'macperl.sym' or die 'Cannot read macperl.sym';
1383 elsif ($PLATFORM eq 'netware') {
1384 foreach my $symbol (qw(
1511 fnInsertHashListAddrs
1522 try_symbol($symbol);
1526 # records of type boot_module for statically linked modules (except Dynaloader)
1527 $static_ext =~ s/\//__/g;
1528 $static_ext =~ s/\bDynaLoader\b//;
1529 my @stat_mods = map {"boot_$_"} grep {/\S/} split /\s+/, $static_ext;
1530 foreach my $symbol (@stat_mods)
1532 try_symbol($symbol);
1535 # Now all symbols should be defined because
1536 # next we are going to output them.
1538 foreach my $symbol (sort keys %export) {
1539 output_symbol($symbol);
1542 if ($PLATFORM eq 'os2') {
1547 Perl_OS2_handler_install
1549 ; LAST_ORDINAL=$sym_ord
1556 $export{$symbol} = 1;
1561 if ($PLATFORM =~ /^win(?:32|ce)$/) {
1562 $symbol = "_$symbol" if $CCTYPE eq 'BORLAND';
1563 print "\t$symbol\n";
1564 # XXX: binary compatibility between compilers is an exercise
1565 # in frustration :-(
1566 # if ($CCTYPE eq "BORLAND") {
1567 # # workaround Borland quirk by exporting both the straight
1568 # # name and a name with leading underscore. Note the
1569 # # alias *must* come after the symbol itself, if both
1570 # # are to be exported. (Linker bug?)
1571 # print "\t_$symbol\n";
1572 # print "\t$symbol = _$symbol\n";
1574 # elsif ($CCTYPE eq 'GCC') {
1575 # # Symbols have leading _ whole process is $%@"% slow
1576 # # so skip aliases for now
1577 # nprint "\t$symbol\n";
1580 # # for binary coexistence, export both the symbol and
1581 # # alias with leading underscore
1582 # print "\t$symbol\n";
1583 # print "\t_$symbol = $symbol\n";
1586 elsif ($PLATFORM eq 'os2') {
1587 printf qq( %-31s \@%s\n),
1588 qq("$symbol"), $ordinal{$symbol} || ++$sym_ord;
1589 printf qq( %-31s \@%s\n),
1590 qq("$exportperlmalloc{$symbol}" = "$symbol"),
1591 $ordinal{$exportperlmalloc{$symbol}} || ++$sym_ord
1592 if $exportperlmalloc and exists $exportperlmalloc{$symbol};
1594 elsif ($PLATFORM eq 'aix' || $PLATFORM eq 'MacOS') {
1597 elsif ($PLATFORM eq 'netware') {
1598 print "\t$symbol,\n";
1604 # Oddities from PerlIO