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
13 use vars qw($PLATFORM $CCTYPE $FILETYPE $CONFIG_ARGS $ARCHNAME $PATCHLEVEL);
15 my (%define, %ordinal);
19 if ($flag =~ s/^CC_FLAGS=/ /) {
20 for my $fflag ($flag =~ /(?:^|\s)-D(\S+)/g) {
21 $fflag .= '=1' unless $fflag =~ /^(\w+)=/;
22 $define{$1} = $2 if $fflag =~ /^(\w+)=(.+)$/;
26 $define{$1} = 1 if ($flag =~ /^-D(\w+)$/);
27 $define{$1} = $2 if ($flag =~ /^-D(\w+)=(.+)$/);
28 $CCTYPE = $1 if ($flag =~ /^CCTYPE=(\w+)$/);
29 $PLATFORM = $1 if ($flag =~ /^PLATFORM=(\w+)$/);
30 if ($PLATFORM eq 'netware') {
31 $FILETYPE = $1 if ($flag =~ /^FILETYPE=(\w+)$/);
35 my @PLATFORM = qw(aix win32 wince os2 MacOS netware);
37 @PLATFORM{@PLATFORM} = ();
39 defined $PLATFORM || die "PLATFORM undefined, must be one of: @PLATFORM\n";
40 exists $PLATFORM{$PLATFORM} || die "PLATFORM must be one of: @PLATFORM\n";
42 if ($PLATFORM eq 'win32' or $PLATFORM eq 'wince' or $PLATFORM eq "aix") {
43 # Add the compile-time options that miniperl was built with to %define.
44 # On Win32 these are not the same options as perl itself will be built
45 # with since miniperl is built with a canned config (one of the win32/
46 # config_H.*) and none of the BUILDOPT's that are set in the makefiles,
47 # but they do include some #define's that are hard-coded in various
48 # source files and header files and don't include any BUILDOPT's that
49 # the user might have chosen to disable because the canned configs are
50 # minimal configs that don't include any of those options.
51 my $opts = ($PLATFORM eq 'wince' ? '-MCross' : ''); # for wince need Cross.pm to get Config.pm
52 my $config = `$^X $opts -Ilib -V`;
53 my($options) = $config =~ /^ Compile-time options: (.*?)\n^ \S/ms;
54 $options =~ s/\s+/ /g;
55 print STDERR "Options: ($options)\n";
56 foreach (split /\s+/, $options) {
61 my %exportperlmalloc =
63 Perl_malloc => "malloc",
65 Perl_realloc => "realloc",
66 Perl_calloc => "calloc",
69 my $exportperlmalloc = $PLATFORM eq 'os2';
71 my $config_sh = "config.sh";
72 my $config_h = "config.h";
73 my $thrdvar_h = "thrdvar.h";
74 my $intrpvar_h = "intrpvar.h";
75 my $perlvars_h = "perlvars.h";
76 my $global_sym = "global.sym";
77 my $pp_sym = "pp.sym";
78 my $globvar_sym = "globvar.sym";
79 my $perlio_sym = "perlio.sym";
82 if ($PLATFORM eq 'aix') {
85 elsif ($PLATFORM =~ /^win(?:32|ce)$/ || $PLATFORM eq 'netware') {
86 $CCTYPE = "MSVC" unless defined $CCTYPE;
87 foreach ($thrdvar_h, $intrpvar_h, $perlvars_h, $global_sym,
88 $pp_sym, $globvar_sym, $perlio_sym) {
92 elsif ($PLATFORM eq 'MacOS') {
93 foreach ($thrdvar_h, $intrpvar_h, $perlvars_h, $global_sym,
94 $pp_sym, $globvar_sym, $perlio_sym) {
99 unless ($PLATFORM eq 'win32' || $PLATFORM eq 'wince' || $PLATFORM eq 'MacOS' || $PLATFORM eq 'netware') {
100 open(CFG,$config_sh) || die "Cannot open $config_sh: $!\n";
102 if (/^(?:ccflags|optimize)='(.+)'$/) {
104 $define{$1} = 1 while /-D(\w+)/g;
106 if (/^(d_(?:mmap|sigaction))='(.+)'$/) {
109 if ($PLATFORM eq 'os2') {
110 $CONFIG_ARGS = $1 if /^config_args='(.+)'$/;
111 $ARCHNAME = $1 if /^archname='(.+)'$/;
112 $PATCHLEVEL = $1 if /^perl_patchlevel='(.+)'$/;
117 if ($PLATFORM eq 'win32' || $PLATFORM eq 'wince') {
118 open(CFG,"<..\\$config_sh") || die "Cannot open ..\\$config_sh: $!\n";
119 if ((join '', <CFG>) =~ /^static_ext='(.*)'$/m) {
125 open(CFG,$config_h) || die "Cannot open $config_h: $!\n";
127 $define{$1} = 1 if /^\s*#\s*define\s+(MYMALLOC)\b/;
128 $define{$1} = 1 if /^\s*#\s*define\s+(MULTIPLICITY)\b/;
129 $define{$1} = 1 if /^\s*#\s*define\s+(PERL_\w+)\b/;
130 $define{$1} = 1 if /^\s*#\s*define\s+(USE_\w+)\b/;
134 # perl.h logic duplication begins
136 if ($define{PERL_IMPLICIT_SYS}) {
137 $define{PL_OP_SLAB_ALLOC} = 1;
140 if ($define{USE_ITHREADS}) {
141 if (!$define{MULTIPLICITY}) {
142 $define{MULTIPLICITY} = 1;
146 $define{PERL_IMPLICIT_CONTEXT} ||=
147 $define{USE_ITHREADS} ||
148 $define{MULTIPLICITY} ;
150 if ($define{USE_ITHREADS} && $PLATFORM ne 'win32' && $^O ne 'darwin') {
151 $define{USE_REENTRANT_API} = 1;
154 # perl.h logic duplication ends
158 print STDERR "Defines: (" . join(' ', sort keys %define) . ")\n";
160 if ($PLATFORM =~ /^win(?:32|ce)$/) {
161 (my $dll = ($define{PERL_DLL} || "perl59")) =~ s/\.dll$//i;
162 print "LIBRARY $dll\n";
163 print "DESCRIPTION 'Perl interpreter'\n";
165 if ($define{PERL_IMPLICIT_SYS}) {
166 output_symbol("perl_get_host_info");
167 output_symbol("perl_alloc_override");
169 if ($define{USE_ITHREADS} and $define{PERL_IMPLICIT_SYS}) {
170 output_symbol("perl_clone_host");
173 elsif ($PLATFORM eq 'os2') {
174 if (open my $fh, '<', 'perl5.def') {
176 last if /^\s*EXPORTS\b/;
179 $ordinal{$1} = $2 if /^\s*"(\w+)"\s*(?:=\s*"\w+"\s*)?\@(\d+)\s*$/;
180 # This allows skipping ordinals which were used in older versions
181 $sym_ord = $1 if /^\s*;\s*LAST_ORDINAL\s*=\s*(\d+)\s*$/;
183 $sym_ord < $_ and $sym_ord = $_ for values %ordinal; # Take the max
185 (my $v = $]) =~ s/(\d\.\d\d\d)(\d\d)$/$1_$2/;
186 $v .= '-thread' if $ARCHNAME =~ /-thread/;
187 (my $dll = $define{PERL_DLL}) =~ s/\.dll$//i;
188 $v .= "\@$PATCHLEVEL" if $PATCHLEVEL;
189 my $d = "DESCRIPTION '\@#perl5-porters\@perl.org:$v#\@ Perl interpreter, configured as $CONFIG_ARGS'";
190 $d = substr($d, 0, 249) . "...'" if length $d > 253;
192 LIBRARY '$dll' INITINSTANCE TERMINSTANCE
196 DATA LOADONCALL NONSHARED MULTIPLE
200 elsif ($PLATFORM eq 'aix') {
201 my $OSVER = `uname -v`;
203 my $OSREL = `uname -r`;
205 if ($OSVER > 4 || ($OSVER == 4 && $OSREL >= 3)) {
211 elsif ($PLATFORM eq 'netware') {
212 if ($FILETYPE eq 'def') {
213 print "LIBRARY perl59\n";
214 print "DESCRIPTION 'Perl interpreter for NetWare'\n";
217 if ($define{PERL_IMPLICIT_SYS}) {
218 output_symbol("perl_get_host_info");
219 output_symbol("perl_alloc_override");
220 output_symbol("perl_clone_host");
229 foreach my $symbol (@$list) {
236 foreach my $symbol (@$list) {
237 my $skipsym = $symbol;
239 if ($define{MULTIPLICITY}) {
240 $skipsym =~ s/^Perl_[GIT](\w+)_ptr$/PL_$1/;
242 emit_symbol($symbol) unless exists $skip{$skipsym};
246 if ($PLATFORM eq 'win32') {
270 Perl_init_thread_intern
304 if ($PLATFORM eq 'wince') {
319 PL_collation_standard
347 Perl_init_thread_intern
374 elsif ($PLATFORM eq 'aix') {
393 Perl_sys_intern_clear
403 elsif ($PLATFORM eq 'os2') {
448 XS_Cwd_extLibpath_set
452 XS_Cwd_sys_is_absolute
453 XS_Cwd_sys_is_relative
455 XS_DynaLoader_mod2fname
456 XS_File__Copy_syscopy
460 Perl_Process_Messages
471 emit_symbols([qw(os2_cond_wait
476 if $define{'USE_5005THREADS'} or $define{'USE_ITHREADS'};
478 elsif ($PLATFORM eq 'MacOS') {
502 Perl_sys_intern_clear
506 elsif ($PLATFORM eq 'netware') {
530 Perl_init_thread_intern
555 Perl_sys_intern_clear
563 Perl_PerlIO_setlinebuf
564 Perl_PerlIO_set_ptrcnt
570 Perl_PerlIO_get_bufsiz
583 unless ($define{'DEBUGGING'}) {
600 if ($define{'PERL_IMPLICIT_CONTEXT'}) {
606 if ($define{'PERL_IMPLICIT_SYS'}) {
627 unless ($define{'PERL_OLD_COPY_ON_WRITE'}) {
634 unless ($define{'USE_REENTRANT_API'}) {
640 if ($define{'MYMALLOC'}) {
649 if ($define{'USE_ITHREADS'}) {
671 if ($define{'PERL_USE_SAFE_PUTENV'}) {
677 unless ($define{'USE_ITHREADS'}) {
683 # USE_5005THREADS symbols. Kept as reference for easier removal
702 Perl_new_struct_thread
703 Perl_per_thread_magicals
711 unless ($define{'USE_ITHREADS'}) {
717 PL_sharedsv_space_mutex
743 Perl_sharedsv_thrcnt_dec
744 Perl_sharedsv_thrcnt_inc
746 Perl_stashpv_hvname_match
747 Perl_regdupe_internal
751 unless ($define{'PERL_IMPLICIT_CONTEXT'}) {
762 Perl_load_module_nocontext
765 Perl_warner_nocontext
766 Perl_newSVpvf_nocontext
767 Perl_sv_catpvf_nocontext
768 Perl_sv_setpvf_nocontext
769 Perl_sv_catpvf_mg_nocontext
770 Perl_sv_setpvf_mg_nocontext
776 unless ($define{'PERL_IMPLICIT_SYS'}) {
783 unless ($define{'FAKE_THREADS'}) {
784 skip_symbols [qw(PL_curthr)];
787 unless ($define{'PL_OP_SLAB_ALLOC'}) {
797 unless ($define{'THREADS_HAVE_PIDS'}) {
798 skip_symbols [qw(PL_ppid)];
801 unless ($define{'PERL_NEED_APPCTX'}) {
807 unless ($define{'PERL_NEED_TIMESBASE'}) {
813 unless ($define{'DEBUG_LEAKING_SCALARS_FORK_DUMP'}) {
818 unless ($define{'PERL_DONT_CREATE_GVSV'}) {
823 if ($define{'SPRINTF_RETURNS_STRLEN'}) {
828 unless ($define{'PERL_USES_PL_PIDSTATUS'}) {
835 unless ($define{'PERL_TRACK_MEMPOOL'}) {
837 PL_memory_debug_header
841 if ($define{'PERL_MAD'}) {
867 Perl_xmldump_packsubs
881 unless ($define{'PERL_GLOBAL_STRUCT_PRIVATE'}) {
888 unless ($define{'d_mmap'}) {
894 if ($define{'d_sigaction'}) {
901 # VMS does its own thing for these symbols.
902 skip_symbols [qw(PL_sig_handlers_initted
909 my $proc = shift || sub { "PL_$_[2]" };
910 open(VARS,$file) || die "Cannot open $file: $!\n";
913 # All symbols have a Perl_ prefix because that's what embed.h
914 # sticks in front of them. The A?I?S?C? is strictly speaking
916 push(@syms, &$proc($1,$2,$3)) if (/\bPERLVAR(A?I?S?C?)\(([IGT])(\w+)/);
922 if ($define{'PERL_GLOBAL_STRUCT'}) {
923 my $global = readvar($perlvars_h);
924 skip_symbols $global;
925 emit_symbol('Perl_GetVars');
926 emit_symbols [qw(PL_Vars PL_VarsPtr)] unless $CCTYPE eq 'GCC';
928 skip_symbols [qw(Perl_init_global_struct Perl_free_global_struct)];
931 # functions from *.sym files
933 my @syms = ($global_sym, $globvar_sym); # $pp_sym is not part of the API
935 # Symbols that are the public face of the PerlIO layers implementation
936 # These are in _addition to_ the public face of the abstraction
937 # and need to be exported to allow XS modules to implement layers
951 PerlIOBase_setlinebuf
988 Perl_PerlIO_context_layers
995 Perl_PerlIO_get_bufsiz
1001 Perl_PerlIO_set_ptrcnt
1002 Perl_PerlIO_setlinebuf
1010 if ($PLATFORM eq 'netware') {
1011 push(@layer_syms,'PL_def_layerlist','PL_known_layers','PL_perlio');
1014 if ($define{'USE_PERLIO'}) {
1015 # Export the symols that make up the PerlIO abstraction, regardless
1016 # of its implementation - read from a file
1017 push @syms, $perlio_sym;
1019 # This part is then dependent on how the abstraction is implemented
1020 if ($define{'USE_SFIO'}) {
1021 # Old legacy non-stdio "PerlIO"
1022 skip_symbols \@layer_syms;
1023 skip_symbols [qw(perlsio_binmode)];
1024 # SFIO defines most of the PerlIO routines as macros
1025 # So undo most of what $perlio_sym has just done - d'oh !
1026 # Perhaps it would be better to list the ones which do exist
1071 Perl_PerlIO_clearerr
1078 Perl_PerlIO_get_base
1079 Perl_PerlIO_get_bufsiz
1085 Perl_PerlIO_set_ptrcnt
1086 Perl_PerlIO_setlinebuf
1099 # PerlIO with layers - export implementation
1100 emit_symbols \@layer_syms;
1101 emit_symbols [qw(perlsio_binmode)];
1103 if ($define{'USE_ITHREADS'}) {
1115 # Skip the PerlIO layer symbols - although
1116 # nothing should have exported them anyway.
1117 skip_symbols \@layer_syms;
1125 PL_perlio_fd_refcnt_size
1128 # Also do NOT add abstraction symbols from $perlio_sym
1129 # abstraction is done as #define to stdio
1130 # Remaining remnants that _may_ be functions
1131 # are handled in <DATA>
1134 for my $syms (@syms) {
1135 open (GLOBAL, "<$syms") || die "failed to open $syms: $!\n";
1137 next if (!/^[A-Za-z]/);
1138 # Functions have a Perl_ prefix
1139 # Variables have a PL_ prefix
1141 my $symbol = ($syms =~ /var\.sym$/i ? "PL_" : "");
1143 emit_symbol($symbol) unless exists $skip{$symbol};
1150 if ($define{'MULTIPLICITY'}) {
1151 for my $f ($perlvars_h, $intrpvar_h, $thrdvar_h) {
1152 my $glob = readvar($f, sub { "Perl_" . $_[1] . $_[2] . "_ptr" });
1155 # XXX AIX seems to want the perlvars.h symbols, for some reason
1156 if ($PLATFORM eq 'aix' or $PLATFORM eq 'os2') { # OS/2 needs PL_thr_key
1157 my $glob = readvar($perlvars_h);
1162 unless ($define{'PERL_GLOBAL_STRUCT'}) {
1163 my $glob = readvar($perlvars_h);
1166 unless ($define{'MULTIPLICITY'}) {
1167 my $glob = readvar($intrpvar_h);
1170 unless ($define{'MULTIPLICITY'}) {
1171 my $glob = readvar($thrdvar_h);
1179 return if $symbol !~ /^[A-Za-z_]/;
1180 return if $symbol =~ /^\#/;
1183 return if exists $skip{$symbol};
1184 emit_symbol($symbol);
1191 if ($PLATFORM =~ /^win(?:32|ce)$/) {
1192 foreach my $symbol (qw(
1254 win32_getprotobyname
1255 win32_getprotobynumber
1284 win32_open_osfhandle
1355 try_symbol($symbol);
1357 if ($CCTYPE eq "BORLAND") {
1358 try_symbol('_matherr');
1361 elsif ($PLATFORM eq 'os2') {
1362 my (%mapped, @missing);
1363 open MAP, 'miniperl.map' or die 'Cannot read miniperl.map';
1364 /^\s*[\da-f:]+\s+(\w+)/i and $mapped{$1}++ foreach <MAP>;
1365 close MAP or die 'Cannot close miniperl.map';
1367 @missing = grep { !exists $mapped{$_} }
1369 @missing = grep { !exists $exportperlmalloc{$_} } @missing;
1370 delete $export{$_} foreach @missing;
1372 elsif ($PLATFORM eq 'MacOS') {
1373 open MACSYMS, 'macperl.sym' or die 'Cannot read macperl.sym';
1381 elsif ($PLATFORM eq 'netware') {
1382 foreach my $symbol (qw(
1509 fnInsertHashListAddrs
1520 try_symbol($symbol);
1524 # records of type boot_module for statically linked modules (except Dynaloader)
1525 $static_ext =~ s/\//__/g;
1526 $static_ext =~ s/\bDynaLoader\b//;
1527 my @stat_mods = map {"boot_$_"} grep {/\S/} split /\s+/, $static_ext;
1528 foreach my $symbol (@stat_mods)
1530 try_symbol($symbol);
1533 # Now all symbols should be defined because
1534 # next we are going to output them.
1536 foreach my $symbol (sort keys %export) {
1537 output_symbol($symbol);
1540 if ($PLATFORM eq 'os2') {
1545 Perl_OS2_handler_install
1547 ; LAST_ORDINAL=$sym_ord
1554 $export{$symbol} = 1;
1559 if ($PLATFORM =~ /^win(?:32|ce)$/) {
1560 $symbol = "_$symbol" if $CCTYPE eq 'BORLAND';
1561 print "\t$symbol\n";
1562 # XXX: binary compatibility between compilers is an exercise
1563 # in frustration :-(
1564 # if ($CCTYPE eq "BORLAND") {
1565 # # workaround Borland quirk by exporting both the straight
1566 # # name and a name with leading underscore. Note the
1567 # # alias *must* come after the symbol itself, if both
1568 # # are to be exported. (Linker bug?)
1569 # print "\t_$symbol\n";
1570 # print "\t$symbol = _$symbol\n";
1572 # elsif ($CCTYPE eq 'GCC') {
1573 # # Symbols have leading _ whole process is $%@"% slow
1574 # # so skip aliases for now
1575 # nprint "\t$symbol\n";
1578 # # for binary coexistence, export both the symbol and
1579 # # alias with leading underscore
1580 # print "\t$symbol\n";
1581 # print "\t_$symbol = $symbol\n";
1584 elsif ($PLATFORM eq 'os2') {
1585 printf qq( %-31s \@%s\n),
1586 qq("$symbol"), $ordinal{$symbol} || ++$sym_ord;
1587 printf qq( %-31s \@%s\n),
1588 qq("$exportperlmalloc{$symbol}" = "$symbol"),
1589 $ordinal{$exportperlmalloc{$symbol}} || ++$sym_ord
1590 if $exportperlmalloc and exists $exportperlmalloc{$symbol};
1592 elsif ($PLATFORM eq 'aix' || $PLATFORM eq 'MacOS') {
1595 elsif ($PLATFORM eq 'netware') {
1596 print "\t$symbol,\n";
1602 # Oddities from PerlIO