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 -Duseshrplib is in effect,
7 # and by VMS for creating perlshr.exe.
9 # Reads from information stored in
11 # %Config::Config (ie config.sh)
16 # miniperl.map (on OS/2)
17 # perl5.def (on OS/2; this is the old version of the file being made)
21 # plus long lists of function names hard-coded directly in this script.
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 my %ARGS = (CCTYPE => 'MSVC');
42 sub process_cc_flags {
43 foreach (map {split /\s+/, $_} @_) {
44 $define{$1} = $2 // 1 if /^-D(\w+)(?:=(.+))?/;
50 if ($flag =~ /^(?:CC_FLAGS=)?(-D\w.*)/) {
52 } elsif ($flag =~ /^(CCTYPE|FILETYPE|PLATFORM|TARG_DIR)=(.+)$/) {
58 my @PLATFORM = qw(aix win32 wince os2 netware vms);
60 @PLATFORM{@PLATFORM} = ();
62 die "PLATFORM undefined, must be one of: @PLATFORM\n"
63 unless defined $ARGS{PLATFORM};
64 die "PLATFORM must be one of: @PLATFORM\n"
65 unless exists $PLATFORM{$ARGS{PLATFORM}};
68 # Is the following guard strictly necessary? Added during refactoring
69 # to keep the same behaviour when merging other code into here.
70 process_cc_flags(@Config{qw(ccflags optimize)})
71 if $ARGS{PLATFORM} ne 'win32' && $ARGS{PLATFORM} ne 'wince'
72 && $ARGS{PLATFORM} ne 'netware';
74 # Add the compile-time options that miniperl was built with to %define.
75 # On Win32 these are not the same options as perl itself will be built
76 # with since miniperl is built with a canned config (one of the win32/
77 # config_H.*) and none of the BUILDOPT's that are set in the makefiles,
78 # but they do include some #define's that are hard-coded in various
79 # source files and header files and don't include any BUILDOPT's that
80 # the user might have chosen to disable because the canned configs are
81 # minimal configs that don't include any of those options.
83 my @options = sort(Config::bincompat_options(), Config::non_bincompat_options());
84 print STDERR "Options: (@options)\n";
85 $define{$_} = 1 foreach @options;
87 my %exportperlmalloc =
89 Perl_malloc => "malloc",
91 Perl_realloc => "realloc",
92 Perl_calloc => "calloc",
95 my $exportperlmalloc = $ARGS{PLATFORM} eq 'os2';
97 my $config_h = "config.h";
98 my $intrpvar_h = "intrpvar.h";
99 my $perlvars_h = "perlvars.h";
100 my $global_sym = "global.sym";
101 my $globvar_sym = "globvar.sym";
102 my $perlio_sym = "perlio.sym";
104 if (exists $ARGS{TARG_DIR}) {
106 foreach $intrpvar_h, $perlvars_h, $global_sym, $globvar_sym, $perlio_sym;
109 open(CFG,$config_h) || die "Cannot open $config_h: $!\n";
111 $define{$1} = 1 if /^\s*\#\s*define\s+(MYMALLOC|MULTIPLICITY
112 |SPRINTF_RETURNS_STRLEN
113 |(?:PERL|USE|HAS)_\w+)\b/x;
117 # perl.h logic duplication begins
119 if ($define{PERL_IMPLICIT_SYS}) {
120 $define{PL_OP_SLAB_ALLOC} = 1;
123 if ($define{USE_ITHREADS}) {
124 if (!$define{MULTIPLICITY}) {
125 $define{MULTIPLICITY} = 1;
129 $define{PERL_IMPLICIT_CONTEXT} ||=
130 $define{USE_ITHREADS} ||
131 $define{MULTIPLICITY} ;
133 if ($define{USE_ITHREADS} && $ARGS{PLATFORM} ne 'win32' && $^O ne 'darwin') {
134 $define{USE_REENTRANT_API} = 1;
137 # perl.h logic duplication ends
139 print STDERR "Defines: (" . join(' ', sort keys %define) . ")\n";
144 if ($ARGS{PLATFORM} eq 'os2') {
145 if (open my $fh, '<', 'perl5.def') {
147 last if /^\s*EXPORTS\b/;
150 $ordinal{$1} = $2 if /^\s*"(\w+)"\s*(?:=\s*"\w+"\s*)?\@(\d+)\s*$/;
151 # This allows skipping ordinals which were used in older versions
152 $sym_ord = $1 if /^\s*;\s*LAST_ORDINAL\s*=\s*(\d+)\s*$/;
154 $sym_ord < $_ and $sym_ord = $_ for values %ordinal; # Take the max
159 # All platforms export boot_DynaLoader unconditionally.
160 my %export = ( boot_DynaLoader => 1 );
163 foreach my $symbol (@_) {
164 ++$export{$symbol} unless exists $skip{$symbol};
169 # $hash is the hash that we're adding to. For one of our callers, it will
170 # actually be the skip hash but that doesn't affect the intent of what
171 # we're doing, as in that case we skip adding something to the skip hash
172 # for the second time.
174 my ($file, $hash, $proc) = @_;
175 open my $vars, '<', $file or die die "Cannot open $file: $!\n";
178 # All symbols have a Perl_ prefix because that's what embed.h sticks
179 # in front of them. The A?I?S?C? is strictly speaking wrong.
180 next unless /\bPERLVAR(A?I?S?C?)\(([IGT])(\w+)/;
183 my $symbol = $proc ? &$proc($1,$2,$3) : $var;
184 ++$hash->{$symbol} unless exists $skip{$var};
188 if ($ARGS{PLATFORM} ne 'os2') {
189 ++$skip{$_} foreach qw(
203 if ($ARGS{PLATFORM} eq 'vms') {
204 ++$skip{PL_statusvalue_posix};
206 ++$skip{PL_statusvalue_vms};
207 if ($ARGS{PLATFORM} ne 'aix') {
208 ++$skip{$_} foreach qw(
220 if ($ARGS{PLATFORM} ne 'vms') {
221 # VMS does its own thing for these symbols.
222 ++$skip{$_} foreach qw(
223 PL_sig_handlers_initted
227 if ($ARGS{PLATFORM} ne 'win32') {
228 ++$skip{$_} foreach qw(
236 unless ($define{UNLINK_ALL_VERSIONS}) {
240 unless ($define{'DEBUGGING'}) {
241 ++$skip{$_} foreach qw(
256 if ($define{'PERL_IMPLICIT_SYS'}) {
257 ++$skip{$_} foreach qw(
261 ++$export{$_} foreach qw(perl_get_host_info perl_alloc_override);
262 ++$export{perl_clone_host} if $define{USE_ITHREADS};
265 ++$skip{$_} foreach qw(
280 unless ($define{'PERL_OLD_COPY_ON_WRITE'}) {
281 ++$skip{Perl_sv_setsv_cow};
284 unless ($define{'USE_REENTRANT_API'}) {
285 ++$skip{PL_reentrant_buffer};
288 if ($define{'MYMALLOC'}) {
297 unless ($define{USE_ITHREADS}) {
298 ++$skip{PL_malloc_mutex}
302 ++$skip{$_} foreach qw(
311 if ($define{'PERL_USE_SAFE_PUTENV'}) {
312 ++$skip{PL_use_safe_putenv};
315 unless ($define{'USE_ITHREADS'}) {
319 # USE_5005THREADS symbols. Kept as reference for easier removal
320 ++$skip{$_} foreach qw(
338 Perl_new_struct_thread
339 Perl_per_thread_magicals
347 unless ($define{'USE_ITHREADS'}) {
348 ++$skip{$_} foreach qw(
356 Perl_clone_params_del
357 Perl_clone_params_new
376 Perl_stashpv_hvname_match
377 Perl_regdupe_internal
382 unless ($define{'PERL_IMPLICIT_CONTEXT'}) {
383 ++$skip{$_} foreach qw(
392 Perl_load_module_nocontext
395 Perl_warner_nocontext
396 Perl_newSVpvf_nocontext
397 Perl_sv_catpvf_nocontext
398 Perl_sv_setpvf_nocontext
399 Perl_sv_catpvf_mg_nocontext
400 Perl_sv_setpvf_mg_nocontext
406 unless ($define{'PL_OP_SLAB_ALLOC'}) {
407 ++$skip{$_} foreach qw(
416 unless ($define{'PERL_DEBUG_READONLY_OPS'}) {
417 ++$skip{$_} foreach qw(
423 unless ($define{'THREADS_HAVE_PIDS'}) {
427 unless ($define{'PERL_NEED_APPCTX'}) {
431 unless ($define{'PERL_NEED_TIMESBASE'}) {
432 ++$skip{PL_timesbase};
435 unless ($define{'DEBUG_LEAKING_SCALARS'}) {
436 ++$skip{PL_sv_serial};
439 unless ($define{'DEBUG_LEAKING_SCALARS_FORK_DUMP'}) {
440 ++$skip{PL_dumper_fd};
443 unless ($define{'PERL_DONT_CREATE_GVSV'}) {
444 ++$skip{Perl_gv_SVadd};
447 if ($define{'SPRINTF_RETURNS_STRLEN'}) {
448 ++$skip{Perl_my_sprintf};
451 unless ($define{'PERL_USES_PL_PIDSTATUS'}) {
452 ++$skip{PL_pidstatus};
455 unless ($define{'PERL_TRACK_MEMPOOL'}) {
456 ++$skip{PL_memory_debug_header};
459 unless ($define{PERL_MAD}) {
460 ++$skip{$_} foreach qw(
466 unless ($define{'MULTIPLICITY'}) {
467 ++$skip{$_} foreach qw(
469 PL_interp_size_5_16_0
473 unless ($define{'PERL_GLOBAL_STRUCT'}) {
474 ++$skip{PL_global_struct_size};
477 unless ($define{'PERL_GLOBAL_STRUCT_PRIVATE'}) {
478 ++$skip{$_} foreach qw(
484 unless ($define{HAS_MMAP}) {
485 ++$skip{PL_mmap_page_size};
488 if ($define{HAS_SIGACTION}) {
489 ++$skip{PL_sig_trapped};
491 if ($ARGS{PLATFORM} eq 'vms') {
492 # FAKE_PERSISTENT_SIGNAL_HANDLERS defined as !defined(HAS_SIGACTION)
493 ++$skip{PL_sig_ignoring};
497 unless ($define{USE_LOCALE_COLLATE}) {
498 ++$skip{$_} foreach qw(
501 PL_collation_standard
505 Perl_sv_collxfrm_flags
509 unless ($define{USE_LOCALE_NUMERIC}) {
510 ++$skip{$_} foreach qw(
518 unless ($define{HAVE_INTERP_INTERN}) {
519 ++$skip{$_} foreach qw(
520 Perl_sys_intern_clear
527 if ($define{HAS_SIGNBIT}) {
528 ++$skip{Perl_signbit};
531 if ($define{'PERL_GLOBAL_STRUCT'}) {
532 readvar($perlvars_h, \%skip);
533 ++$export{Perl_GetVars};
534 try_symbols(qw(PL_Vars PL_VarsPtr)) unless $ARGS{CCTYPE} eq 'GCC';
536 ++$skip{$_} foreach qw(Perl_init_global_struct Perl_free_global_struct);
539 # functions from *.sym files
541 my @syms = ($global_sym, $globvar_sym);
543 # Symbols that are the public face of the PerlIO layers implementation
544 # These are in _addition to_ the public face of the abstraction
545 # and need to be exported to allow XS modules to implement layers
559 PerlIOBase_setlinebuf
598 Perl_PerlIO_context_layers
605 Perl_PerlIO_get_bufsiz
611 Perl_PerlIO_set_ptrcnt
612 Perl_PerlIO_setlinebuf
620 if ($ARGS{PLATFORM} eq 'netware') {
621 push(@layer_syms,'PL_def_layerlist','PL_known_layers','PL_perlio');
624 if ($define{'USE_PERLIO'}) {
625 # Export the symols that make up the PerlIO abstraction, regardless
626 # of its implementation - read from a file
627 push @syms, $perlio_sym;
629 # This part is then dependent on how the abstraction is implemented
630 if ($define{'USE_SFIO'}) {
631 # Old legacy non-stdio "PerlIO"
632 ++$skip{$_} foreach @layer_syms;
633 ++$skip{perlsio_binmode};
634 # SFIO defines most of the PerlIO routines as macros
635 # So undo most of what $perlio_sym has just done - d'oh !
636 # Perhaps it would be better to list the ones which do exist
638 ++$skip{$_} foreach qw(
689 Perl_PerlIO_get_bufsiz
695 Perl_PerlIO_set_ptrcnt
696 Perl_PerlIO_setlinebuf
709 # PerlIO with layers - export implementation
710 try_symbols(@layer_syms, 'perlsio_binmode');
714 # Skip the PerlIO layer symbols - although
715 # nothing should have exported them anyway.
716 ++$skip{$_} foreach @layer_syms;
717 ++$skip{$_} foreach qw(
724 PL_perlio_fd_refcnt_size
728 # Also do NOT add abstraction symbols from $perlio_sym
729 # abstraction is done as #define to stdio
730 # Remaining remnants that _may_ be functions are handled below.
733 ###############################################################################
735 # At this point all skip lists should be completed, as we are about to test
736 # many symbols against them.
738 for my $syms (@syms) {
739 open my $global, '<', $syms or die "failed to open $syms: $!\n";
740 # Functions already have a Perl_ prefix
741 # Variables need a PL_ prefix
742 my $prefix = $syms =~ /var\.sym$/i ? 'PL_' : '';
744 next unless /^([A-Za-z].*)/;
745 my $symbol = "$prefix$1";
746 ++$export{$symbol} unless exists $skip{$symbol};
752 if ($define{'MULTIPLICITY'} && $define{PERL_GLOBAL_STRUCT}) {
753 readvar($perlvars_h, \%export, sub { "Perl_" . $_[1] . $_[2] . "_ptr" });
754 # XXX AIX seems to want the perlvars.h symbols, for some reason
755 if ($ARGS{PLATFORM} eq 'aix' or $ARGS{PLATFORM} eq 'os2') { # OS/2 needs PL_thr_key
756 readvar($perlvars_h, \%export);
760 unless ($define{'PERL_GLOBAL_STRUCT'}) {
761 readvar($perlvars_h, \%export);
763 unless ($define{MULTIPLICITY}) {
764 readvar($intrpvar_h, \%export);
768 # Oddities from PerlIO
769 # All have alternate implementations in perlio.c, so always exist.
770 # Should they be considered to be part of the API?
781 if ($ARGS{PLATFORM} eq 'win32') {
793 if ($ARGS{PLATFORM} =~ /^win(?:32|ce)$/) {
854 win32_getprotobynumber
949 if ($ARGS{CCTYPE} eq "BORLAND") {
950 try_symbols('_matherr');
953 elsif ($ARGS{PLATFORM} eq 'vms') {
958 Perl_csighandler_init
961 Perl_fileify_dirspec_ts
962 Perl_fileify_dirspec_utf8
963 Perl_fileify_dirspec_utf8_ts
996 Perl_pathify_dirspec_ts
997 Perl_pathify_dirspec_utf8
998 Perl_pathify_dirspec_utf8_ts
1006 Perl_rmsexpand_utf8_ts
1008 Perl_sig_to_vmscondition
1012 Perl_tounixpath_utf8
1013 Perl_tounixpath_utf8_ts
1016 Perl_tounixspec_utf8
1017 Perl_tounixspec_utf8_ts
1021 Perl_tovmspath_utf8_ts
1025 Perl_tovmsspec_utf8_ts
1027 Perl_vms_case_tolerant
1038 elsif ($ARGS{PLATFORM} eq 'os2') {
1081 XS_Cwd_current_drive
1083 XS_Cwd_extLibpath_set
1087 XS_Cwd_sys_is_absolute
1088 XS_Cwd_sys_is_relative
1089 XS_Cwd_sys_is_rooted
1090 XS_DynaLoader_mod2fname
1091 XS_File__Copy_syscopy
1095 Perl_Process_Messages
1107 elsif ($ARGS{PLATFORM} eq 'netware') {
1234 fnInsertHashListAddrs
1246 # When added this code was only run for Win32 and WinCE
1247 # Currently only Win32 links static extensions into the shared library.
1248 # The WinCE makefile doesn't appear to support static extensions, so this code
1249 # can't have any effect there.
1250 # The NetWare Makefile doesn't support static extensions (and hardcodes the
1251 # list of dynamic extensions, and the rules to build them)
1252 # For *nix (and presumably OS/2) with a shared libperl, Makefile.SH compiles
1253 # static extensions with -fPIC, but links them to perl, not libperl.so
1254 # The VMS build scripts don't yet implement static extensions at all.
1256 if ($ARGS{PLATFORM} =~ /^win(?:32|ce)$/) {
1257 # records of type boot_module for statically linked modules (except Dynaloader)
1258 my $static_ext = $Config{static_ext} // "";
1259 $static_ext =~ s/\//__/g;
1260 $static_ext =~ s/\bDynaLoader\b//;
1261 try_symbols(map {"boot_$_"} grep {/\S/} split /\s+/, $static_ext);
1262 try_symbols("init_Win32CORE") if $static_ext =~ /\bWin32CORE\b/;
1265 if ($ARGS{PLATFORM} eq 'os2') {
1266 my (%mapped, @missing);
1267 open MAP, 'miniperl.map' or die 'Cannot read miniperl.map';
1268 /^\s*[\da-f:]+\s+(\w+)/i and $mapped{$1}++ foreach <MAP>;
1269 close MAP or die 'Cannot close miniperl.map';
1271 @missing = grep { !exists $mapped{$_} }
1273 @missing = grep { !exists $exportperlmalloc{$_} } @missing;
1274 delete $export{$_} foreach @missing;
1277 ###############################################################################
1279 # Now all symbols should be defined because next we are going to output them.
1281 # Start with platform specific headers:
1283 if ($ARGS{PLATFORM} =~ /^win(?:32|ce)$/) {
1284 (my $dll = ($define{PERL_DLL} || "perl515")) =~ s/\.dll$//i;
1285 print "LIBRARY $dll\n";
1286 # The DESCRIPTION module definition file statement is not supported
1288 if ($ARGS{CCTYPE} =~ /^(?:MSVC60|GCC|BORLAND)$/) {
1289 print "DESCRIPTION 'Perl interpreter'\n";
1293 elsif ($ARGS{PLATFORM} eq 'os2') {
1294 (my $v = $]) =~ s/(\d\.\d\d\d)(\d\d)$/$1_$2/;
1295 $v .= '-thread' if $Config{archname} =~ /-thread/;
1296 (my $dll = $define{PERL_DLL}) =~ s/\.dll$//i;
1297 $v .= "\@$Config{perl_patchlevel}" if $Config{perl_patchlevel};
1298 my $d = "DESCRIPTION '\@#perl5-porters\@perl.org:$v#\@ Perl interpreter, configured as $Config{config_args}'";
1299 $d = substr($d, 0, 249) . "...'" if length $d > 253;
1300 print <<"---EOP---";
1301 LIBRARY '$dll' INITINSTANCE TERMINSTANCE
1305 DATA LOADONCALL NONSHARED MULTIPLE
1309 elsif ($ARGS{PLATFORM} eq 'aix') {
1310 my $OSVER = `uname -v`;
1312 my $OSREL = `uname -r`;
1314 if ($OSVER > 4 || ($OSVER == 4 && $OSREL >= 3)) {
1320 elsif ($ARGS{PLATFORM} eq 'netware') {
1321 if ($ARGS{FILETYPE} eq 'def') {
1322 print "LIBRARY perl515\n";
1323 print "DESCRIPTION 'Perl interpreter for NetWare'\n";
1330 foreach my $symbol (sort keys %export) {
1331 if ($ARGS{PLATFORM} =~ /^win(?:32|ce)$/) {
1332 $symbol = "_$symbol" if $ARGS{CCTYPE} eq 'BORLAND';
1333 print "\t$symbol\n";
1335 elsif ($ARGS{PLATFORM} eq 'os2') {
1336 printf qq( %-31s \@%s\n),
1337 qq("$symbol"), $ordinal{$symbol} || ++$sym_ord;
1338 printf qq( %-31s \@%s\n),
1339 qq("$exportperlmalloc{$symbol}" = "$symbol"),
1340 $ordinal{$exportperlmalloc{$symbol}} || ++$sym_ord
1341 if $exportperlmalloc and exists $exportperlmalloc{$symbol};
1343 elsif ($ARGS{PLATFORM} eq 'netware') {
1344 print "\t$symbol,\n";
1350 # Then platform specific footers.
1352 if ($ARGS{PLATFORM} eq 'os2') {
1357 Perl_OS2_handler_install
1359 ; LAST_ORDINAL=$sym_ord