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)
22 # plus long lists of function names hard-coded directly in this script.
24 # Writes the result to STDOUT.
26 # Normally this script is invoked from a makefile (e.g. win32/Makefile),
27 # which redirects STDOUT to a suitable file, such as:
35 BEGIN { unshift @INC, "lib" }
39 my %ARGS = (CCTYPE => 'MSVC', TARG_DIR => '');
43 sub process_cc_flags {
44 foreach (map {split /\s+/, $_} @_) {
45 $define{$1} = $2 // 1 if /^-D(\w+)(?:=(.+))?/;
51 if ($flag =~ /^(?:CC_FLAGS=)?(-D\w.*)/) {
53 } elsif ($flag =~ /^(CCTYPE|FILETYPE|PLATFORM|TARG_DIR)=(.+)$/) {
58 require "$ARGS{TARG_DIR}regen/embed_lib.pl";
61 my @PLATFORM = qw(aix win32 wince os2 netware vms test);
63 @PLATFORM{@PLATFORM} = ();
65 die "PLATFORM undefined, must be one of: @PLATFORM\n"
66 unless defined $ARGS{PLATFORM};
67 die "PLATFORM must be one of: @PLATFORM\n"
68 unless exists $PLATFORM{$ARGS{PLATFORM}};
71 # Is the following guard strictly necessary? Added during refactoring
72 # to keep the same behaviour when merging other code into here.
73 process_cc_flags(@Config{qw(ccflags optimize)})
74 if $ARGS{PLATFORM} ne 'win32' && $ARGS{PLATFORM} ne 'wince'
75 && $ARGS{PLATFORM} ne 'netware';
77 # Add the compile-time options that miniperl was built with to %define.
78 # On Win32 these are not the same options as perl itself will be built
79 # with since miniperl is built with a canned config (one of the win32/
80 # config_H.*) and none of the BUILDOPT's that are set in the makefiles,
81 # but they do include some #define's that are hard-coded in various
82 # source files and header files and don't include any BUILDOPT's that
83 # the user might have chosen to disable because the canned configs are
84 # minimal configs that don't include any of those options.
86 my @options = sort(Config::bincompat_options(), Config::non_bincompat_options());
87 print STDERR "Options: (@options)\n" unless $ARGS{PLATFORM} eq 'test';
88 $define{$_} = 1 foreach @options;
90 my %exportperlmalloc =
92 Perl_malloc => "malloc",
94 Perl_realloc => "realloc",
95 Perl_calloc => "calloc",
98 my $exportperlmalloc = $ARGS{PLATFORM} eq 'os2';
100 open(CFG, '<', 'config.h') || die "Cannot open config.h: $!\n";
102 $define{$1} = 1 if /^\s*\#\s*define\s+(MYMALLOC|MULTIPLICITY
103 |SPRINTF_RETURNS_STRLEN
104 |(?:PERL|USE|HAS)_\w+)\b/x;
108 # perl.h logic duplication begins
110 if ($define{PERL_IMPLICIT_SYS}) {
111 $define{PL_OP_SLAB_ALLOC} = 1;
114 if ($define{USE_ITHREADS}) {
115 if (!$define{MULTIPLICITY}) {
116 $define{MULTIPLICITY} = 1;
120 $define{PERL_IMPLICIT_CONTEXT} ||=
121 $define{USE_ITHREADS} ||
122 $define{MULTIPLICITY} ;
124 if ($define{USE_ITHREADS} && $ARGS{PLATFORM} ne 'win32' && $^O ne 'darwin') {
125 $define{USE_REENTRANT_API} = 1;
128 # perl.h logic duplication ends
130 print STDERR "Defines: (" . join(' ', sort keys %define) . ")\n"
131 unless $ARGS{PLATFORM} eq 'test';
136 if ($ARGS{PLATFORM} eq 'os2') {
137 if (open my $fh, '<', 'perl5.def') {
139 last if /^\s*EXPORTS\b/;
142 $ordinal{$1} = $2 if /^\s*"(\w+)"\s*(?:=\s*"\w+"\s*)?\@(\d+)\s*$/;
143 # This allows skipping ordinals which were used in older versions
144 $sym_ord = $1 if /^\s*;\s*LAST_ORDINAL\s*=\s*(\d+)\s*$/;
146 $sym_ord < $_ and $sym_ord = $_ for values %ordinal; # Take the max
151 # All platforms export boot_DynaLoader unconditionally.
152 my %export = ( boot_DynaLoader => 1 );
155 foreach my $symbol (@_) {
156 ++$export{$symbol} unless exists $skip{$symbol};
161 # $hash is the hash that we're adding to. For one of our callers, it will
162 # actually be the skip hash but that doesn't affect the intent of what
163 # we're doing, as in that case we skip adding something to the skip hash
164 # for the second time.
166 my $file = $ARGS{TARG_DIR} . shift;
169 open my $vars, '<', $file or die die "Cannot open $file: $!\n";
172 # All symbols have a Perl_ prefix because that's what embed.h sticks
173 # in front of them. The A?I?S?C? is strictly speaking wrong.
174 next unless /\bPERLVAR(A?I?S?C?)\(([IGT]),\s*(\w+)/;
177 my $symbol = $proc ? &$proc($1,$2,$3) : $var;
178 ++$hash->{$symbol} unless exists $skip{$var};
182 if ($ARGS{PLATFORM} ne 'os2') {
183 ++$skip{$_} foreach qw(
197 if ($ARGS{PLATFORM} eq 'vms') {
198 ++$skip{PL_statusvalue_posix};
200 ++$skip{PL_statusvalue_vms};
201 if ($ARGS{PLATFORM} ne 'aix') {
202 ++$skip{$_} foreach qw(
214 if ($ARGS{PLATFORM} ne 'vms') {
215 # VMS does its own thing for these symbols.
216 ++$skip{$_} foreach qw(
217 PL_sig_handlers_initted
221 if ($ARGS{PLATFORM} ne 'win32') {
222 ++$skip{$_} foreach qw(
230 unless ($define{UNLINK_ALL_VERSIONS}) {
234 unless ($define{'DEBUGGING'}) {
235 ++$skip{$_} foreach qw(
250 if ($define{'PERL_IMPLICIT_SYS'}) {
251 ++$skip{$_} foreach qw(
255 ++$export{$_} foreach qw(perl_get_host_info perl_alloc_override);
256 ++$export{perl_clone_host} if $define{USE_ITHREADS};
259 ++$skip{$_} foreach qw(
274 unless ($define{'PERL_OLD_COPY_ON_WRITE'}) {
275 ++$skip{Perl_sv_setsv_cow};
278 unless ($define{'USE_REENTRANT_API'}) {
279 ++$skip{PL_reentrant_buffer};
282 if ($define{'MYMALLOC'}) {
291 unless ($define{USE_ITHREADS}) {
292 ++$skip{PL_malloc_mutex}
296 ++$skip{$_} foreach qw(
305 if ($define{'PERL_USE_SAFE_PUTENV'}) {
306 ++$skip{PL_use_safe_putenv};
309 unless ($define{'USE_ITHREADS'}) {
313 # USE_5005THREADS symbols. Kept as reference for easier removal
314 ++$skip{$_} foreach qw(
332 Perl_new_struct_thread
333 Perl_per_thread_magicals
341 unless ($define{'USE_ITHREADS'}) {
342 ++$skip{$_} foreach qw(
350 Perl_clone_params_del
351 Perl_clone_params_new
370 Perl_stashpv_hvname_match
371 Perl_regdupe_internal
376 unless ($define{'PERL_IMPLICIT_CONTEXT'}) {
377 ++$skip{$_} foreach qw(
386 Perl_load_module_nocontext
389 Perl_warner_nocontext
390 Perl_newSVpvf_nocontext
391 Perl_sv_catpvf_nocontext
392 Perl_sv_setpvf_nocontext
393 Perl_sv_catpvf_mg_nocontext
394 Perl_sv_setpvf_mg_nocontext
400 unless ($define{'PL_OP_SLAB_ALLOC'}) {
401 ++$skip{$_} foreach qw(
410 unless ($define{'PERL_DEBUG_READONLY_OPS'}) {
411 ++$skip{$_} foreach qw(
417 unless ($define{'THREADS_HAVE_PIDS'}) {
421 unless ($define{'PERL_NEED_APPCTX'}) {
425 unless ($define{'PERL_NEED_TIMESBASE'}) {
426 ++$skip{PL_timesbase};
429 unless ($define{'DEBUG_LEAKING_SCALARS'}) {
430 ++$skip{PL_sv_serial};
433 unless ($define{'DEBUG_LEAKING_SCALARS_FORK_DUMP'}) {
434 ++$skip{PL_dumper_fd};
437 unless ($define{'PERL_DONT_CREATE_GVSV'}) {
438 ++$skip{Perl_gv_SVadd};
441 if ($define{'SPRINTF_RETURNS_STRLEN'}) {
442 ++$skip{Perl_my_sprintf};
445 unless ($define{'PERL_USES_PL_PIDSTATUS'}) {
446 ++$skip{PL_pidstatus};
449 unless ($define{'PERL_TRACK_MEMPOOL'}) {
450 ++$skip{PL_memory_debug_header};
453 unless ($define{PERL_MAD}) {
454 ++$skip{$_} foreach qw(
460 unless ($define{'MULTIPLICITY'}) {
461 ++$skip{$_} foreach qw(
463 PL_interp_size_5_16_0
467 unless ($define{'PERL_GLOBAL_STRUCT'}) {
468 ++$skip{PL_global_struct_size};
471 unless ($define{'PERL_GLOBAL_STRUCT_PRIVATE'}) {
472 ++$skip{$_} foreach qw(
478 unless ($define{HAS_MMAP}) {
479 ++$skip{PL_mmap_page_size};
482 if ($define{HAS_SIGACTION}) {
483 ++$skip{PL_sig_trapped};
485 if ($ARGS{PLATFORM} eq 'vms') {
486 # FAKE_PERSISTENT_SIGNAL_HANDLERS defined as !defined(HAS_SIGACTION)
487 ++$skip{PL_sig_ignoring};
491 unless ($define{USE_LOCALE_COLLATE}) {
492 ++$skip{$_} foreach qw(
495 PL_collation_standard
499 Perl_sv_collxfrm_flags
503 unless ($define{USE_LOCALE_NUMERIC}) {
504 ++$skip{$_} foreach qw(
512 unless ($define{HAVE_INTERP_INTERN}) {
513 ++$skip{$_} foreach qw(
514 Perl_sys_intern_clear
521 if ($define{HAS_SIGNBIT}) {
522 ++$skip{Perl_signbit};
525 if ($define{'PERL_GLOBAL_STRUCT'}) {
526 readvar('perlvars.h', \%skip);
527 # This seems like the least ugly way to cope with the fact that PL_sh_path
528 # is mentioned in perlvar.h and globvar.sym, and always exported.
529 delete $skip{PL_sh_path};
530 ++$export{Perl_GetVars};
531 try_symbols(qw(PL_Vars PL_VarsPtr)) unless $ARGS{CCTYPE} eq 'GCC';
533 ++$skip{$_} foreach qw(Perl_init_global_struct Perl_free_global_struct);
536 # functions from *.sym files
538 my @syms = qw(globvar.sym);
540 # Symbols that are the public face of the PerlIO layers implementation
541 # These are in _addition to_ the public face of the abstraction
542 # and need to be exported to allow XS modules to implement layers
556 PerlIOBase_setlinebuf
595 Perl_PerlIO_context_layers
602 Perl_PerlIO_get_bufsiz
608 Perl_PerlIO_set_ptrcnt
609 Perl_PerlIO_setlinebuf
617 if ($ARGS{PLATFORM} eq 'netware') {
618 push(@layer_syms,'PL_def_layerlist','PL_known_layers','PL_perlio');
621 if ($define{'USE_PERLIO'}) {
622 # Export the symols that make up the PerlIO abstraction, regardless
623 # of its implementation - read from a file
624 push @syms, 'perlio.sym';
626 # This part is then dependent on how the abstraction is implemented
627 if ($define{'USE_SFIO'}) {
628 # Old legacy non-stdio "PerlIO"
629 ++$skip{$_} foreach @layer_syms;
630 ++$skip{perlsio_binmode};
631 # SFIO defines most of the PerlIO routines as macros
632 # So undo most of what $perlio_sym has just done - d'oh !
633 # Perhaps it would be better to list the ones which do exist
635 ++$skip{$_} foreach qw(
686 Perl_PerlIO_get_bufsiz
692 Perl_PerlIO_set_ptrcnt
693 Perl_PerlIO_setlinebuf
706 # PerlIO with layers - export implementation
707 try_symbols(@layer_syms, 'perlsio_binmode');
711 # Skip the PerlIO layer symbols - although
712 # nothing should have exported them anyway.
713 ++$skip{$_} foreach @layer_syms;
714 ++$skip{$_} foreach qw(
721 PL_perlio_fd_refcnt_size
725 # Also do NOT add abstraction symbols from $perlio_sym
726 # abstraction is done as #define to stdio
727 # Remaining remnants that _may_ be functions are handled below.
730 ###############################################################################
732 # At this point all skip lists should be completed, as we are about to test
733 # many symbols against them.
737 my ($embed) = setup_embed($ARGS{TARG_DIR});
740 my ($flags, $retval, $func, @args) = @$_;
742 if ($flags =~ /[AX]/ && $flags !~ /[xm]/ || $flags =~ /b/) {
743 # public API, so export
745 # If a function is defined twice, for example before and after
746 # an #else, only export its name once. Important to do this test
747 # within the block, as the *first* definition may have flags which
748 # mean "don't export"
749 next if $seen{$func}++;
750 $func = "Perl_$func" if $flags =~ /[pbX]/;
751 ++$export{$func} unless exists $skip{$func};
757 my $syms = $ARGS{TARG_DIR} . $_;
758 open my $global, '<', $syms or die "failed to open $syms: $!\n";
759 # Functions already have a Perl_ prefix
760 # Variables need a PL_ prefix
761 my $prefix = $syms =~ /var\.sym$/i ? 'PL_' : '';
763 next unless /^([A-Za-z].*)/;
764 my $symbol = "$prefix$1";
765 ++$export{$symbol} unless exists $skip{$symbol};
771 if ($define{'MULTIPLICITY'} && $define{PERL_GLOBAL_STRUCT}) {
772 readvar('perlvars.h', \%export, sub { "Perl_" . $_[1] . $_[2] . "_ptr" });
773 # XXX AIX seems to want the perlvars.h symbols, for some reason
774 if ($ARGS{PLATFORM} eq 'aix' or $ARGS{PLATFORM} eq 'os2') { # OS/2 needs PL_thr_key
775 readvar('perlvars.h', \%export);
779 unless ($define{'PERL_GLOBAL_STRUCT'}) {
780 readvar('perlvars.h', \%export);
782 unless ($define{MULTIPLICITY}) {
783 readvar('intrpvar.h', \%export);
787 # Oddities from PerlIO
788 # All have alternate implementations in perlio.c, so always exist.
789 # Should they be considered to be part of the API?
800 if ($ARGS{PLATFORM} eq 'win32') {
812 if ($ARGS{PLATFORM} =~ /^win(?:32|ce)$/) {
873 win32_getprotobynumber
969 elsif ($ARGS{PLATFORM} eq 'vms') {
974 Perl_csighandler_init
977 Perl_fileify_dirspec_ts
978 Perl_fileify_dirspec_utf8
979 Perl_fileify_dirspec_utf8_ts
1011 Perl_pathify_dirspec
1012 Perl_pathify_dirspec_ts
1013 Perl_pathify_dirspec_utf8
1014 Perl_pathify_dirspec_utf8_ts
1022 Perl_rmsexpand_utf8_ts
1024 Perl_sig_to_vmscondition
1028 Perl_tounixpath_utf8
1029 Perl_tounixpath_utf8_ts
1032 Perl_tounixspec_utf8
1033 Perl_tounixspec_utf8_ts
1037 Perl_tovmspath_utf8_ts
1041 Perl_tovmsspec_utf8_ts
1043 Perl_vms_case_tolerant
1054 elsif ($ARGS{PLATFORM} eq 'os2') {
1097 XS_Cwd_current_drive
1099 XS_Cwd_extLibpath_set
1103 XS_Cwd_sys_is_absolute
1104 XS_Cwd_sys_is_relative
1105 XS_Cwd_sys_is_rooted
1106 XS_DynaLoader_mod2fname
1107 XS_File__Copy_syscopy
1111 Perl_Process_Messages
1123 elsif ($ARGS{PLATFORM} eq 'netware') {
1250 fnInsertHashListAddrs
1262 # When added this code was only run for Win32 and WinCE
1263 # Currently only Win32 links static extensions into the shared library.
1264 # The WinCE makefile doesn't appear to support static extensions, so this code
1265 # can't have any effect there.
1266 # The NetWare Makefile doesn't support static extensions (and hardcodes the
1267 # list of dynamic extensions, and the rules to build them)
1268 # For *nix (and presumably OS/2) with a shared libperl, Makefile.SH compiles
1269 # static extensions with -fPIC, but links them to perl, not libperl.so
1270 # The VMS build scripts don't yet implement static extensions at all.
1272 if ($ARGS{PLATFORM} =~ /^win(?:32|ce)$/) {
1273 # records of type boot_module for statically linked modules (except Dynaloader)
1274 my $static_ext = $Config{static_ext} // "";
1275 $static_ext =~ s/\//__/g;
1276 $static_ext =~ s/\bDynaLoader\b//;
1277 try_symbols(map {"boot_$_"} grep {/\S/} split /\s+/, $static_ext);
1278 try_symbols("init_Win32CORE") if $static_ext =~ /\bWin32CORE\b/;
1281 if ($ARGS{PLATFORM} eq 'os2') {
1282 my (%mapped, @missing);
1283 open MAP, 'miniperl.map' or die 'Cannot read miniperl.map';
1284 /^\s*[\da-f:]+\s+(\w+)/i and $mapped{$1}++ foreach <MAP>;
1285 close MAP or die 'Cannot close miniperl.map';
1287 @missing = grep { !exists $mapped{$_} }
1289 @missing = grep { !exists $exportperlmalloc{$_} } @missing;
1290 delete $export{$_} foreach @missing;
1293 ###############################################################################
1295 # Now all symbols should be defined because next we are going to output them.
1297 # Start with platform specific headers:
1299 if ($ARGS{PLATFORM} =~ /^win(?:32|ce)$/) {
1300 my $dll = $define{PERL_DLL} ? $define{PERL_DLL} =~ s/\.dll$//ir
1301 : "perl$Config{api_revision}$Config{api_version}";
1302 print "LIBRARY $dll\n";
1303 # The DESCRIPTION module definition file statement is not supported
1305 if ($ARGS{CCTYPE} =~ /^(?:MSVC60|GCC)$/) {
1306 print "DESCRIPTION 'Perl interpreter'\n";
1310 elsif ($ARGS{PLATFORM} eq 'os2') {
1311 (my $v = $]) =~ s/(\d\.\d\d\d)(\d\d)$/$1_$2/;
1312 $v .= '-thread' if $Config{archname} =~ /-thread/;
1313 (my $dll = $define{PERL_DLL}) =~ s/\.dll$//i;
1314 $v .= "\@$Config{perl_patchlevel}" if $Config{perl_patchlevel};
1315 my $d = "DESCRIPTION '\@#perl5-porters\@perl.org:$v#\@ Perl interpreter, configured as $Config{config_args}'";
1316 $d = substr($d, 0, 249) . "...'" if length $d > 253;
1317 print <<"---EOP---";
1318 LIBRARY '$dll' INITINSTANCE TERMINSTANCE
1322 DATA LOADONCALL NONSHARED MULTIPLE
1326 elsif ($ARGS{PLATFORM} eq 'aix') {
1327 my $OSVER = `uname -v`;
1329 my $OSREL = `uname -r`;
1331 if ($OSVER > 4 || ($OSVER == 4 && $OSREL >= 3)) {
1337 elsif ($ARGS{PLATFORM} eq 'netware') {
1338 if ($ARGS{FILETYPE} eq 'def') {
1339 print "LIBRARY perl$Config{api_revision}$Config{api_version}\n";
1340 print "DESCRIPTION 'Perl interpreter for NetWare'\n";
1347 foreach my $symbol (sort keys %export) {
1348 if ($ARGS{PLATFORM} =~ /^win(?:32|ce)$/) {
1349 print "\t$symbol\n";
1351 elsif ($ARGS{PLATFORM} eq 'os2') {
1352 printf qq( %-31s \@%s\n),
1353 qq("$symbol"), $ordinal{$symbol} || ++$sym_ord;
1354 printf qq( %-31s \@%s\n),
1355 qq("$exportperlmalloc{$symbol}" = "$symbol"),
1356 $ordinal{$exportperlmalloc{$symbol}} || ++$sym_ord
1357 if $exportperlmalloc and exists $exportperlmalloc{$symbol};
1359 elsif ($ARGS{PLATFORM} eq 'netware') {
1360 print "\t$symbol,\n";
1366 # Then platform specific footers.
1368 if ($ARGS{PLATFORM} eq 'os2') {
1373 Perl_OS2_handler_install
1375 ; LAST_ORDINAL=$sym_ord