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,
8 # Reads from information stored in
15 # miniperl.map (on OS/2)
16 # perl5.def (on OS/2; this is the old version of the file being made)
20 # plus long lists of function names hard-coded directly in this script and
21 # in the DATA section.
23 # Writes the result to STDOUT.
25 # Normally this script is invoked from a makefile (e.g. win32/Makefile),
26 # which redirects STDOUT to a suitable file, such as:
34 BEGIN { unshift @INC, "lib" }
38 use vars qw($PLATFORM $CCTYPE $FILETYPE $CONFIG_ARGS $ARCHNAME $PATCHLEVEL);
40 my (%define, %ordinal);
44 if ($flag =~ s/^CC_FLAGS=/ /) {
45 for my $fflag ($flag =~ /(?:^|\s)-D(\S+)/g) {
46 $fflag .= '=1' unless $fflag =~ /^(\w+)=/;
47 $define{$1} = $2 if $fflag =~ /^(\w+)=(.+)$/;
51 $define{$1} = 1 if ($flag =~ /^-D(\w+)$/);
52 $define{$1} = $2 if ($flag =~ /^-D(\w+)=(.+)$/);
53 $CCTYPE = $1 if ($flag =~ /^CCTYPE=(\w+)$/);
54 $PLATFORM = $1 if ($flag =~ /^PLATFORM=(\w+)$/);
55 if ($PLATFORM eq 'netware') {
56 $FILETYPE = $1 if ($flag =~ /^FILETYPE=(\w+)$/);
60 my @PLATFORM = qw(aix win32 wince os2 netware);
62 @PLATFORM{@PLATFORM} = ();
64 defined $PLATFORM || die "PLATFORM undefined, must be one of: @PLATFORM\n";
65 exists $PLATFORM{$PLATFORM} || die "PLATFORM must be one of: @PLATFORM\n";
67 if ($PLATFORM eq 'win32' or $PLATFORM eq 'wince' or $PLATFORM eq "aix") {
68 # Add the compile-time options that miniperl was built with to %define.
69 # On Win32 these are not the same options as perl itself will be built
70 # with since miniperl is built with a canned config (one of the win32/
71 # config_H.*) and none of the BUILDOPT's that are set in the makefiles,
72 # but they do include some #define's that are hard-coded in various
73 # source files and header files and don't include any BUILDOPT's that
74 # the user might have chosen to disable because the canned configs are
75 # minimal configs that don't include any of those options.
76 my $opts = ($PLATFORM eq 'wince' ? '-MCross' : ''); # for wince need Cross.pm to get Config.pm
78 $ENV{PERL5LIB} = join $Config{path_sep}, @INC;
79 my $cmd = "$^X $opts -V";
81 or die "Couldn't run [$cmd]: $!";
82 my($options) = $config =~ /^ Compile-time options: (.*?)\n^ \S/ms;
83 $options =~ s/\s+/ /g;
84 print STDERR "Options: ($options)\n";
85 foreach (split /\s+/, $options) {
90 my %exportperlmalloc =
92 Perl_malloc => "malloc",
94 Perl_realloc => "realloc",
95 Perl_calloc => "calloc",
98 my $exportperlmalloc = $PLATFORM eq 'os2';
100 my $config_sh = "config.sh";
101 my $config_h = "config.h";
102 my $intrpvar_h = "intrpvar.h";
103 my $perlvars_h = "perlvars.h";
104 my $global_sym = "global.sym";
105 my $globvar_sym = "globvar.sym";
106 my $perlio_sym = "perlio.sym";
109 if ($PLATFORM eq 'aix') {
112 elsif ($PLATFORM =~ /^win(?:32|ce)$/ || $PLATFORM eq 'netware') {
113 $CCTYPE = "MSVC" unless defined $CCTYPE;
114 foreach ($intrpvar_h, $perlvars_h, $global_sym, $globvar_sym, $perlio_sym) {
119 unless ($PLATFORM eq 'win32' || $PLATFORM eq 'wince' || $PLATFORM eq 'netware') {
120 open(CFG,$config_sh) || die "Cannot open $config_sh: $!\n";
122 if (/^(?:ccflags|optimize)='(.+)'$/) {
124 $define{$1} = 1 while /-D(\w+)/g;
126 if (/^(d_(?:mmap|sigaction))='(.+)'$/) {
129 if ($PLATFORM eq 'os2') {
130 $CONFIG_ARGS = $1 if /^config_args='(.+)'$/;
131 $ARCHNAME = $1 if /^archname='(.+)'$/;
132 $PATCHLEVEL = $1 if /^perl_patchlevel='(.+)'$/;
137 if ($PLATFORM eq 'win32' || $PLATFORM eq 'wince') {
138 open(CFG,"<..\\$config_sh") || die "Cannot open ..\\$config_sh: $!\n";
139 if ((join '', <CFG>) =~ /^static_ext='(.*)'$/m) {
145 open(CFG,$config_h) || die "Cannot open $config_h: $!\n";
147 $define{$1} = 1 if /^\s*#\s*define\s+(MYMALLOC)\b/;
148 $define{$1} = 1 if /^\s*#\s*define\s+(MULTIPLICITY)\b/;
149 $define{$1} = 1 if /^\s*#\s*define\s+(PERL_\w+)\b/;
150 $define{$1} = 1 if /^\s*#\s*define\s+(USE_\w+)\b/;
151 $define{$1} = 1 if /^\s*#\s*define\s+(HAS_\w+)\b/;
155 # perl.h logic duplication begins
157 if ($define{PERL_IMPLICIT_SYS}) {
158 $define{PL_OP_SLAB_ALLOC} = 1;
161 if ($define{USE_ITHREADS}) {
162 if (!$define{MULTIPLICITY}) {
163 $define{MULTIPLICITY} = 1;
167 $define{PERL_IMPLICIT_CONTEXT} ||=
168 $define{USE_ITHREADS} ||
169 $define{MULTIPLICITY} ;
171 if ($define{USE_ITHREADS} && $PLATFORM ne 'win32' && $^O ne 'darwin') {
172 $define{USE_REENTRANT_API} = 1;
175 # perl.h logic duplication ends
179 print STDERR "Defines: (" . join(' ', sort keys %define) . ")\n";
181 if ($PLATFORM =~ /^win(?:32|ce)$/) {
182 (my $dll = ($define{PERL_DLL} || "perl513")) =~ s/\.dll$//i;
183 print "LIBRARY $dll\n";
184 # The DESCRIPTION module definition file statement is not supported
186 if ($CCTYPE =~ /^(?:MSVC60|GCC|BORLAND)$/) {
187 print "DESCRIPTION 'Perl interpreter'\n";
190 if ($define{PERL_IMPLICIT_SYS}) {
191 output_symbol("perl_get_host_info");
192 output_symbol("perl_alloc_override");
194 if ($define{USE_ITHREADS} and $define{PERL_IMPLICIT_SYS}) {
195 output_symbol("perl_clone_host");
198 elsif ($PLATFORM eq 'os2') {
199 if (open my $fh, '<', 'perl5.def') {
201 last if /^\s*EXPORTS\b/;
204 $ordinal{$1} = $2 if /^\s*"(\w+)"\s*(?:=\s*"\w+"\s*)?\@(\d+)\s*$/;
205 # This allows skipping ordinals which were used in older versions
206 $sym_ord = $1 if /^\s*;\s*LAST_ORDINAL\s*=\s*(\d+)\s*$/;
208 $sym_ord < $_ and $sym_ord = $_ for values %ordinal; # Take the max
210 (my $v = $]) =~ s/(\d\.\d\d\d)(\d\d)$/$1_$2/;
211 $v .= '-thread' if $ARCHNAME =~ /-thread/;
212 (my $dll = $define{PERL_DLL}) =~ s/\.dll$//i;
213 $v .= "\@$PATCHLEVEL" if $PATCHLEVEL;
214 my $d = "DESCRIPTION '\@#perl5-porters\@perl.org:$v#\@ Perl interpreter, configured as $CONFIG_ARGS'";
215 $d = substr($d, 0, 249) . "...'" if length $d > 253;
217 LIBRARY '$dll' INITINSTANCE TERMINSTANCE
221 DATA LOADONCALL NONSHARED MULTIPLE
225 elsif ($PLATFORM eq 'aix') {
226 my $OSVER = `uname -v`;
228 my $OSREL = `uname -r`;
230 if ($OSVER > 4 || ($OSVER == 4 && $OSREL >= 3)) {
236 elsif ($PLATFORM eq 'netware') {
237 if ($FILETYPE eq 'def') {
238 print "LIBRARY perl513\n";
239 print "DESCRIPTION 'Perl interpreter for NetWare'\n";
242 if ($define{PERL_IMPLICIT_SYS}) {
243 output_symbol("perl_get_host_info");
244 output_symbol("perl_alloc_override");
245 output_symbol("perl_clone_host");
254 foreach my $symbol (@$list) {
261 foreach my $symbol (@$list) {
262 my $skipsym = $symbol;
264 if ($define{MULTIPLICITY}) {
265 $skipsym =~ s/^Perl_[GIT](\w+)_ptr$/PL_$1/;
267 emit_symbol($symbol) unless exists $skip{$skipsym};
271 if ($PLATFORM eq 'win32') {
295 Perl_init_thread_intern
329 if ($PLATFORM eq 'wince') {
344 PL_collation_standard
372 Perl_init_thread_intern
399 elsif ($PLATFORM eq 'aix') {
418 Perl_sys_intern_clear
430 if $define{'HAS_SIGNBIT'};
435 elsif ($PLATFORM eq 'os2') {
480 XS_Cwd_extLibpath_set
484 XS_Cwd_sys_is_absolute
485 XS_Cwd_sys_is_relative
487 XS_DynaLoader_mod2fname
488 XS_File__Copy_syscopy
492 Perl_Process_Messages
503 emit_symbols([qw(os2_cond_wait
508 if $define{'USE_5005THREADS'} or $define{'USE_ITHREADS'};
510 elsif ($PLATFORM eq 'netware') {
534 Perl_init_thread_intern
559 Perl_sys_intern_clear
567 Perl_PerlIO_setlinebuf
568 Perl_PerlIO_set_ptrcnt
574 Perl_PerlIO_get_bufsiz
587 unless ($define{'DEBUGGING'}) {
603 if ($define{'PERL_IMPLICIT_CONTEXT'}) {
609 if ($define{'PERL_IMPLICIT_SYS'}) {
630 unless ($define{'PERL_OLD_COPY_ON_WRITE'}) {
636 unless ($define{'USE_REENTRANT_API'}) {
642 if ($define{'MYMALLOC'}) {
651 if ($define{'USE_ITHREADS'}) {
668 Perl_malloc_good_size
674 if ($define{'PERL_USE_SAFE_PUTENV'}) {
680 unless ($define{'USE_ITHREADS'}) {
686 # USE_5005THREADS symbols. Kept as reference for easier removal
705 Perl_new_struct_thread
706 Perl_per_thread_magicals
714 unless ($define{'USE_ITHREADS'}) {
720 PL_sharedsv_space_mutex
726 Perl_clone_params_del
727 Perl_clone_params_new
751 Perl_sharedsv_thrcnt_dec
752 Perl_sharedsv_thrcnt_inc
754 Perl_stashpv_hvname_match
755 Perl_regdupe_internal
760 unless ($define{'PERL_IMPLICIT_CONTEXT'}) {
770 Perl_load_module_nocontext
773 Perl_warner_nocontext
774 Perl_newSVpvf_nocontext
775 Perl_sv_catpvf_nocontext
776 Perl_sv_setpvf_nocontext
777 Perl_sv_catpvf_mg_nocontext
778 Perl_sv_setpvf_mg_nocontext
784 unless ($define{'PERL_IMPLICIT_SYS'}) {
791 unless ($define{'FAKE_THREADS'}) {
792 skip_symbols [qw(PL_curthr)];
795 unless ($define{'PL_OP_SLAB_ALLOC'}) {
805 unless ($define{'PERL_DEBUG_READONLY_OPS'}) {
812 unless ($define{'THREADS_HAVE_PIDS'}) {
813 skip_symbols [qw(PL_ppid)];
816 unless ($define{'PERL_NEED_APPCTX'}) {
822 unless ($define{'PERL_NEED_TIMESBASE'}) {
828 unless ($define{'DEBUG_LEAKING_SCALARS'}) {
834 unless ($define{'DEBUG_LEAKING_SCALARS_FORK_DUMP'}) {
839 unless ($define{'PERL_DONT_CREATE_GVSV'}) {
844 if ($define{'SPRINTF_RETURNS_STRLEN'}) {
849 unless ($define{'PERL_USES_PL_PIDSTATUS'}) {
856 unless ($define{'PERL_TRACK_MEMPOOL'}) {
858 PL_memory_debug_header
862 if ($define{'PERL_MAD'}) {
888 Perl_xmldump_packsubs
902 unless ($define{'MULTIPLICITY'}) {
905 PL_interp_size_5_10_0
909 unless ($define{'PERL_GLOBAL_STRUCT'}) {
911 PL_global_struct_size
915 unless ($define{'PERL_GLOBAL_STRUCT_PRIVATE'}) {
922 unless ($define{'d_mmap'}) {
928 if ($define{'d_sigaction'}) {
935 # VMS does its own thing for these symbols.
936 skip_symbols [qw(PL_sig_handlers_initted
943 my $proc = shift || sub { "PL_$_[2]" };
944 open(VARS,$file) || die "Cannot open $file: $!\n";
947 # All symbols have a Perl_ prefix because that's what embed.h
948 # sticks in front of them. The A?I?S?C? is strictly speaking
950 push(@syms, &$proc($1,$2,$3)) if (/\bPERLVAR(A?I?S?C?)\(([IGT])(\w+)/);
956 if ($define{'PERL_GLOBAL_STRUCT'}) {
957 my $global = readvar($perlvars_h);
958 skip_symbols $global;
959 emit_symbol('Perl_GetVars');
960 emit_symbols [qw(PL_Vars PL_VarsPtr)] unless $CCTYPE eq 'GCC';
962 skip_symbols [qw(Perl_init_global_struct Perl_free_global_struct)];
965 # functions from *.sym files
967 my @syms = ($global_sym, $globvar_sym);
969 # Symbols that are the public face of the PerlIO layers implementation
970 # These are in _addition to_ the public face of the abstraction
971 # and need to be exported to allow XS modules to implement layers
985 PerlIOBase_setlinebuf
1000 PerlIOBuf_set_ptrcnt
1022 Perl_PerlIO_clearerr
1024 Perl_PerlIO_context_layers
1030 Perl_PerlIO_get_base
1031 Perl_PerlIO_get_bufsiz
1037 Perl_PerlIO_set_ptrcnt
1038 Perl_PerlIO_setlinebuf
1046 if ($PLATFORM eq 'netware') {
1047 push(@layer_syms,'PL_def_layerlist','PL_known_layers','PL_perlio');
1050 if ($define{'USE_PERLIO'}) {
1051 # Export the symols that make up the PerlIO abstraction, regardless
1052 # of its implementation - read from a file
1053 push @syms, $perlio_sym;
1055 # This part is then dependent on how the abstraction is implemented
1056 if ($define{'USE_SFIO'}) {
1057 # Old legacy non-stdio "PerlIO"
1058 skip_symbols \@layer_syms;
1059 skip_symbols [qw(perlsio_binmode)];
1060 # SFIO defines most of the PerlIO routines as macros
1061 # So undo most of what $perlio_sym has just done - d'oh !
1062 # Perhaps it would be better to list the ones which do exist
1107 Perl_PerlIO_clearerr
1114 Perl_PerlIO_get_base
1115 Perl_PerlIO_get_bufsiz
1121 Perl_PerlIO_set_ptrcnt
1122 Perl_PerlIO_setlinebuf
1135 # PerlIO with layers - export implementation
1136 emit_symbols \@layer_syms;
1137 emit_symbols [qw(perlsio_binmode)];
1139 if ($define{'USE_ITHREADS'}) {
1151 # Skip the PerlIO layer symbols - although
1152 # nothing should have exported them anyway.
1153 skip_symbols \@layer_syms;
1161 PL_perlio_fd_refcnt_size
1164 # Also do NOT add abstraction symbols from $perlio_sym
1165 # abstraction is done as #define to stdio
1166 # Remaining remnants that _may_ be functions
1167 # are handled in <DATA>
1170 for my $syms (@syms) {
1171 open (GLOBAL, "<$syms") || die "failed to open $syms: $!\n";
1173 next if (!/^[A-Za-z]/);
1174 # Functions have a Perl_ prefix
1175 # Variables have a PL_ prefix
1177 my $symbol = ($syms =~ /var\.sym$/i ? "PL_" : "");
1179 emit_symbol($symbol) unless exists $skip{$symbol};
1186 if ($define{'MULTIPLICITY'} && $define{PERL_GLOBAL_STRUCT}) {
1187 for my $f ($perlvars_h) {
1188 my $glob = readvar($f, sub { "Perl_" . $_[1] . $_[2] . "_ptr" });
1191 # XXX AIX seems to want the perlvars.h symbols, for some reason
1192 if ($PLATFORM eq 'aix' or $PLATFORM eq 'os2') { # OS/2 needs PL_thr_key
1193 my $glob = readvar($perlvars_h);
1198 unless ($define{'PERL_GLOBAL_STRUCT'}) {
1199 my $glob = readvar($perlvars_h);
1202 unless ($define{MULTIPLICITY}) {
1203 my $glob = readvar($intrpvar_h);
1211 return if $symbol !~ /^[A-Za-z_]/;
1212 return if $symbol =~ /^\#/;
1215 return if exists $skip{$symbol};
1216 emit_symbol($symbol);
1223 if ($PLATFORM =~ /^win(?:32|ce)$/) {
1224 foreach my $symbol (qw(
1287 win32_getprotobyname
1288 win32_getprotobynumber
1317 win32_open_osfhandle
1388 try_symbol($symbol);
1390 if ($CCTYPE eq "BORLAND") {
1391 try_symbol('_matherr');
1394 elsif ($PLATFORM eq 'os2') {
1395 my (%mapped, @missing);
1396 open MAP, 'miniperl.map' or die 'Cannot read miniperl.map';
1397 /^\s*[\da-f:]+\s+(\w+)/i and $mapped{$1}++ foreach <MAP>;
1398 close MAP or die 'Cannot close miniperl.map';
1400 @missing = grep { !exists $mapped{$_} }
1402 @missing = grep { !exists $exportperlmalloc{$_} } @missing;
1403 delete $export{$_} foreach @missing;
1405 elsif ($PLATFORM eq 'netware') {
1406 foreach my $symbol (qw(
1533 fnInsertHashListAddrs
1544 try_symbol($symbol);
1548 # records of type boot_module for statically linked modules (except Dynaloader)
1549 $static_ext =~ s/\//__/g;
1550 $static_ext =~ s/\bDynaLoader\b//;
1551 my @stat_mods = map {"boot_$_"} grep {/\S/} split /\s+/, $static_ext;
1552 foreach my $symbol (@stat_mods)
1554 try_symbol($symbol);
1557 try_symbol("init_Win32CORE") if $static_ext =~ /\bWin32CORE\b/;
1559 # Now all symbols should be defined because
1560 # next we are going to output them.
1562 foreach my $symbol (sort keys %export) {
1563 output_symbol($symbol);
1566 if ($PLATFORM eq 'os2') {
1571 Perl_OS2_handler_install
1573 ; LAST_ORDINAL=$sym_ord
1580 $export{$symbol} = 1;
1585 if ($PLATFORM =~ /^win(?:32|ce)$/) {
1586 $symbol = "_$symbol" if $CCTYPE eq 'BORLAND';
1587 print "\t$symbol\n";
1588 # XXX: binary compatibility between compilers is an exercise
1589 # in frustration :-(
1590 # if ($CCTYPE eq "BORLAND") {
1591 # # workaround Borland quirk by exporting both the straight
1592 # # name and a name with leading underscore. Note the
1593 # # alias *must* come after the symbol itself, if both
1594 # # are to be exported. (Linker bug?)
1595 # print "\t_$symbol\n";
1596 # print "\t$symbol = _$symbol\n";
1598 # elsif ($CCTYPE eq 'GCC') {
1599 # # Symbols have leading _ whole process is $%@"% slow
1600 # # so skip aliases for now
1601 # nprint "\t$symbol\n";
1604 # # for binary coexistence, export both the symbol and
1605 # # alias with leading underscore
1606 # print "\t$symbol\n";
1607 # print "\t_$symbol = $symbol\n";
1610 elsif ($PLATFORM eq 'os2') {
1611 printf qq( %-31s \@%s\n),
1612 qq("$symbol"), $ordinal{$symbol} || ++$sym_ord;
1613 printf qq( %-31s \@%s\n),
1614 qq("$exportperlmalloc{$symbol}" = "$symbol"),
1615 $ordinal{$exportperlmalloc{$symbol}} || ++$sym_ord
1616 if $exportperlmalloc and exists $exportperlmalloc{$symbol};
1618 elsif ($PLATFORM eq 'aix') {
1621 elsif ($PLATFORM eq 'netware') {
1622 print "\t$symbol,\n";
1628 # Oddities from PerlIO