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 VMS for creating perlshr.exe.
9 # Reads from information stored in
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 use vars qw($PLATFORM $CCTYPE $FILETYPE $TARG_DIR);
47 if ($flag =~ s/^CC_FLAGS=/ /) {
48 for my $fflag ($flag =~ /(?:^|\s)-D(\S+)/g) {
49 $fflag .= '=1' unless $fflag =~ /^(\w+)=/;
50 $define{$1} = $2 if $fflag =~ /^(\w+)=(.+)$/;
54 $define{$1} = 1 if ($flag =~ /^-D(\w+)$/);
55 $define{$1} = $2 if ($flag =~ /^-D(\w+)=(.+)$/);
56 $CCTYPE = $1 if ($flag =~ /^CCTYPE=(\w+)$/);
57 $PLATFORM = $1 if ($flag =~ /^PLATFORM=(\w+)$/);
58 $FILETYPE = $1 if ($flag =~ /^FILETYPE=(\w+)$/);
59 $TARG_DIR = $1 if $flag =~ /^TARG_DIR=(.+)$/;
62 my @PLATFORM = qw(aix win32 wince os2 netware vms);
64 @PLATFORM{@PLATFORM} = ();
66 defined $PLATFORM || die "PLATFORM undefined, must be one of: @PLATFORM\n";
67 exists $PLATFORM{$PLATFORM} || die "PLATFORM must be one of: @PLATFORM\n";
69 # Add the compile-time options that miniperl was built with to %define.
70 # On Win32 these are not the same options as perl itself will be built
71 # with since miniperl is built with a canned config (one of the win32/
72 # config_H.*) and none of the BUILDOPT's that are set in the makefiles,
73 # but they do include some #define's that are hard-coded in various
74 # source files and header files and don't include any BUILDOPT's that
75 # the user might have chosen to disable because the canned configs are
76 # minimal configs that don't include any of those options.
78 my @options = sort(Config::bincompat_options(), Config::non_bincompat_options());
79 print STDERR "Options: (@options)\n";
80 $define{$_} = 1 foreach @options;
82 my %exportperlmalloc =
84 Perl_malloc => "malloc",
86 Perl_realloc => "realloc",
87 Perl_calloc => "calloc",
90 my $exportperlmalloc = $PLATFORM eq 'os2';
92 my $config_sh = "config.sh";
93 my $config_h = "config.h";
94 my $intrpvar_h = "intrpvar.h";
95 my $perlvars_h = "perlvars.h";
96 my $global_sym = "global.sym";
97 my $globvar_sym = "globvar.sym";
98 my $perlio_sym = "perlio.sym";
101 s/^/$TARG_DIR/ foreach($intrpvar_h, $perlvars_h, $global_sym, $globvar_sym,
102 $perlio_sym, $config_sh);
104 unless ($PLATFORM eq 'win32' || $PLATFORM eq 'wince' || $PLATFORM eq 'netware') {
105 open(CFG,$config_sh) || die "Cannot open $config_sh: $!\n";
107 if (/^(?:ccflags|optimize)='(.+)'$/) {
109 $define{$1} = 1 while /-D(\w+)/g;
112 if /^(config_args|archname|perl_patchlevel)='(.+)'$/;
116 if ($PLATFORM eq 'win32' || $PLATFORM eq 'wince') {
117 open(CFG, '<', $config_sh) || die "Cannot open $config_sh: $!\n";
118 if ((join '', <CFG>) =~ /^static_ext='(.*)'$/m) {
124 open(CFG,$config_h) || die "Cannot open $config_h: $!\n";
126 $define{$1} = 1 if /^\s*\#\s*define\s+(MYMALLOC|MULTIPLICITY
127 |SPRINTF_RETURNS_STRLEN
128 |(?:PERL|USE|HAS)_\w+)\b/x;
132 # perl.h logic duplication begins
134 if ($define{PERL_IMPLICIT_SYS}) {
135 $define{PL_OP_SLAB_ALLOC} = 1;
138 if ($define{USE_ITHREADS}) {
139 if (!$define{MULTIPLICITY}) {
140 $define{MULTIPLICITY} = 1;
144 $define{PERL_IMPLICIT_CONTEXT} ||=
145 $define{USE_ITHREADS} ||
146 $define{MULTIPLICITY} ;
148 if ($define{USE_ITHREADS} && $PLATFORM ne 'win32' && $^O ne 'darwin') {
149 $define{USE_REENTRANT_API} = 1;
152 # perl.h logic duplication ends
154 print STDERR "Defines: (" . join(' ', sort keys %define) . ")\n";
159 if ($PLATFORM eq 'os2') {
160 if (open my $fh, '<', 'perl5.def') {
162 last if /^\s*EXPORTS\b/;
165 $ordinal{$1} = $2 if /^\s*"(\w+)"\s*(?:=\s*"\w+"\s*)?\@(\d+)\s*$/;
166 # This allows skipping ordinals which were used in older versions
167 $sym_ord = $1 if /^\s*;\s*LAST_ORDINAL\s*=\s*(\d+)\s*$/;
169 $sym_ord < $_ and $sym_ord = $_ for values %ordinal; # Take the max
174 # All platforms export boot_DynaLoader unconditionally.
175 my %export = ( boot_DynaLoader => 1 );
178 foreach my $symbol (@_) {
179 ++$export{$symbol} unless exists $skip{$symbol};
184 # $hash is the hash that we're adding to. For one of our callers, it will
185 # actually be the skip hash but that doesn't affect the intent of what
186 # we're doing, as in that case we skip adding something to the skip hash
187 # for the second time.
189 my ($file, $hash, $proc) = @_;
190 open my $vars, '<', $file or die die "Cannot open $file: $!\n";
193 # All symbols have a Perl_ prefix because that's what embed.h sticks
194 # in front of them. The A?I?S?C? is strictly speaking wrong.
195 next unless /\bPERLVAR(A?I?S?C?)\(([IGT])(\w+)/;
198 my $symbol = $proc ? &$proc($1,$2,$3) : $var;
199 ++$hash->{$symbol} unless exists $skip{$var};
203 if ($PLATFORM ne 'os2') {
204 ++$skip{$_} foreach qw(
218 if ($PLATFORM eq 'vms') {
219 ++$skip{PL_statusvalue_posix};
221 ++$skip{PL_statusvalue_vms};
222 if ($PLATFORM ne 'aix') {
223 ++$skip{$_} foreach qw(
235 if ($PLATFORM ne 'vms') {
236 # VMS does its own thing for these symbols.
237 ++$skip{$_} foreach qw(
238 PL_sig_handlers_initted
242 if ($PLATFORM ne 'win32') {
243 ++$skip{$_} foreach qw(
251 if ($PLATFORM eq 'os2') {
296 XS_Cwd_extLibpath_set
300 XS_Cwd_sys_is_absolute
301 XS_Cwd_sys_is_relative
303 XS_DynaLoader_mod2fname
304 XS_File__Copy_syscopy
308 Perl_Process_Messages
325 if $define{'USE_5005THREADS'} or $define{'USE_ITHREADS'};
327 elsif ($PLATFORM eq 'vms') {
332 Perl_csighandler_init
335 Perl_fileify_dirspec_ts
336 Perl_fileify_dirspec_utf8
337 Perl_fileify_dirspec_utf8_ts
370 Perl_pathify_dirspec_ts
371 Perl_pathify_dirspec_utf8
372 Perl_pathify_dirspec_utf8_ts
380 Perl_rmsexpand_utf8_ts
382 Perl_sig_to_vmscondition
387 Perl_tounixpath_utf8_ts
391 Perl_tounixspec_utf8_ts
395 Perl_tovmspath_utf8_ts
399 Perl_tovmsspec_utf8_ts
401 Perl_vms_case_tolerant
413 unless ($define{UNLINK_ALL_VERSIONS}) {
417 unless ($define{'DEBUGGING'}) {
418 ++$skip{$_} foreach qw(
433 if ($define{'PERL_IMPLICIT_SYS'}) {
434 ++$skip{$_} foreach qw(
438 ++$export{$_} foreach qw(perl_get_host_info perl_alloc_override);
439 ++$export{perl_clone_host} if $define{USE_ITHREADS};
442 ++$skip{$_} foreach qw(
457 unless ($define{'PERL_OLD_COPY_ON_WRITE'}) {
458 ++$skip{Perl_sv_setsv_cow};
461 unless ($define{'USE_REENTRANT_API'}) {
462 ++$skip{PL_reentrant_buffer};
465 if ($define{'MYMALLOC'}) {
474 if ($define{'USE_ITHREADS'}) {
480 ++$skip{PL_malloc_mutex};
484 ++$skip{$_} foreach qw(
493 if ($define{'PERL_USE_SAFE_PUTENV'}) {
494 ++$skip{PL_use_safe_putenv};
497 unless ($define{'USE_ITHREADS'}) {
501 # USE_5005THREADS symbols. Kept as reference for easier removal
502 ++$skip{$_} foreach qw(
520 Perl_new_struct_thread
521 Perl_per_thread_magicals
529 unless ($define{'USE_ITHREADS'}) {
530 ++$skip{$_} foreach qw(
538 Perl_clone_params_del
539 Perl_clone_params_new
558 Perl_stashpv_hvname_match
559 Perl_regdupe_internal
564 unless ($define{'PERL_IMPLICIT_CONTEXT'}) {
565 ++$skip{$_} foreach qw(
574 Perl_load_module_nocontext
577 Perl_warner_nocontext
578 Perl_newSVpvf_nocontext
579 Perl_sv_catpvf_nocontext
580 Perl_sv_setpvf_nocontext
581 Perl_sv_catpvf_mg_nocontext
582 Perl_sv_setpvf_mg_nocontext
588 unless ($define{'PL_OP_SLAB_ALLOC'}) {
589 ++$skip{$_} foreach qw(
598 unless ($define{'PERL_DEBUG_READONLY_OPS'}) {
599 ++$skip{$_} foreach qw(
605 unless ($define{'THREADS_HAVE_PIDS'}) {
609 unless ($define{'PERL_NEED_APPCTX'}) {
613 unless ($define{'PERL_NEED_TIMESBASE'}) {
614 ++$skip{PL_timesbase};
617 unless ($define{'DEBUG_LEAKING_SCALARS'}) {
618 ++$skip{PL_sv_serial};
621 unless ($define{'DEBUG_LEAKING_SCALARS_FORK_DUMP'}) {
622 ++$skip{PL_dumper_fd};
625 unless ($define{'PERL_DONT_CREATE_GVSV'}) {
626 ++$skip{Perl_gv_SVadd};
629 if ($define{'SPRINTF_RETURNS_STRLEN'}) {
630 ++$skip{Perl_my_sprintf};
633 unless ($define{'PERL_USES_PL_PIDSTATUS'}) {
634 ++$skip{PL_pidstatus};
637 unless ($define{'PERL_TRACK_MEMPOOL'}) {
638 ++$skip{PL_memory_debug_header};
641 unless ($define{PERL_MAD}) {
642 ++$skip{$_} foreach qw(
648 unless ($define{'MULTIPLICITY'}) {
649 ++$skip{$_} foreach qw(
651 PL_interp_size_5_16_0
655 unless ($define{'PERL_GLOBAL_STRUCT'}) {
656 ++$skip{PL_global_struct_size};
659 unless ($define{'PERL_GLOBAL_STRUCT_PRIVATE'}) {
660 ++$skip{$_} foreach qw(
666 unless ($define{HAS_MMAP}) {
667 ++$skip{PL_mmap_page_size};
670 if ($define{HAS_SIGACTION}) {
671 ++$skip{PL_sig_trapped};
674 unless ($define{USE_LOCALE_COLLATE}) {
675 ++$skip{$_} foreach qw(
678 PL_collation_standard
682 Perl_sv_collxfrm_flags
686 unless ($define{USE_LOCALE_NUMERIC}) {
687 ++$skip{$_} foreach qw(
695 unless ($define{HAVE_INTERP_INTERN}) {
696 ++$skip{$_} foreach qw(
697 Perl_sys_intern_clear
704 if ($define{HAS_SIGNBIT}) {
705 ++$skip{Perl_signbit};
708 if ($define{'PERL_GLOBAL_STRUCT'}) {
709 readvar($perlvars_h, \%skip);
710 ++$export{Perl_GetVars};
711 try_symbols(qw(PL_Vars PL_VarsPtr)) unless $CCTYPE eq 'GCC';
713 ++$skip{$_} foreach qw(Perl_init_global_struct Perl_free_global_struct);
716 # functions from *.sym files
718 my @syms = ($global_sym, $globvar_sym);
720 # Symbols that are the public face of the PerlIO layers implementation
721 # These are in _addition to_ the public face of the abstraction
722 # and need to be exported to allow XS modules to implement layers
736 PerlIOBase_setlinebuf
775 Perl_PerlIO_context_layers
782 Perl_PerlIO_get_bufsiz
788 Perl_PerlIO_set_ptrcnt
789 Perl_PerlIO_setlinebuf
797 if ($PLATFORM eq 'netware') {
798 push(@layer_syms,'PL_def_layerlist','PL_known_layers','PL_perlio');
801 if ($define{'USE_PERLIO'}) {
802 # Export the symols that make up the PerlIO abstraction, regardless
803 # of its implementation - read from a file
804 push @syms, $perlio_sym;
806 # This part is then dependent on how the abstraction is implemented
807 if ($define{'USE_SFIO'}) {
808 # Old legacy non-stdio "PerlIO"
809 ++$skip{$_} foreach @layer_syms;
810 ++$skip{perlsio_binmode};
811 # SFIO defines most of the PerlIO routines as macros
812 # So undo most of what $perlio_sym has just done - d'oh !
813 # Perhaps it would be better to list the ones which do exist
815 ++$skip{$_} foreach qw(
866 Perl_PerlIO_get_bufsiz
872 Perl_PerlIO_set_ptrcnt
873 Perl_PerlIO_setlinebuf
886 # PerlIO with layers - export implementation
887 try_symbols(@layer_syms, 'perlsio_binmode');
889 if ($define{'USE_ITHREADS'}) {
895 ++$skip{PL_perlio_mutex};
899 # Skip the PerlIO layer symbols - although
900 # nothing should have exported them anyway.
901 ++$skip{$_} foreach @layer_syms;
902 ++$skip{$_} foreach qw(
909 PL_perlio_fd_refcnt_size
912 # Also do NOT add abstraction symbols from $perlio_sym
913 # abstraction is done as #define to stdio
914 # Remaining remnants that _may_ be functions are handled below.
917 for my $syms (@syms) {
918 open (GLOBAL, "<$syms") || die "failed to open $syms: $!\n";
920 next if (!/^[A-Za-z]/);
921 # Functions have a Perl_ prefix
922 # Variables have a PL_ prefix
924 my $symbol = ($syms =~ /var\.sym$/i ? "PL_" : "");
926 ++$export{$symbol} unless exists $skip{$symbol};
933 if ($define{'MULTIPLICITY'} && $define{PERL_GLOBAL_STRUCT}) {
934 readvar($perlvars_h, \%export, sub { "Perl_" . $_[1] . $_[2] . "_ptr" });
935 # XXX AIX seems to want the perlvars.h symbols, for some reason
936 if ($PLATFORM eq 'aix' or $PLATFORM eq 'os2') { # OS/2 needs PL_thr_key
937 readvar($perlvars_h, \%export);
941 unless ($define{'PERL_GLOBAL_STRUCT'}) {
942 readvar($perlvars_h, \%export);
944 unless ($define{MULTIPLICITY}) {
945 readvar($intrpvar_h, \%export);
951 ++$export{$symbol} unless $skip{$symbol};
954 # Oddities from PerlIO
966 if ($PLATFORM eq 'win32') {
967 try_symbol($_) foreach qw(
978 if ($PLATFORM =~ /^win(?:32|ce)$/) {
979 foreach my $symbol (qw(
1038 win32_getprotobyname
1039 win32_getprotobynumber
1068 win32_open_osfhandle
1135 try_symbol($symbol);
1137 if ($CCTYPE eq "BORLAND") {
1138 try_symbol('_matherr');
1141 elsif ($PLATFORM eq 'os2') {
1142 my (%mapped, @missing);
1143 open MAP, 'miniperl.map' or die 'Cannot read miniperl.map';
1144 /^\s*[\da-f:]+\s+(\w+)/i and $mapped{$1}++ foreach <MAP>;
1145 close MAP or die 'Cannot close miniperl.map';
1147 @missing = grep { !exists $mapped{$_} }
1149 @missing = grep { !exists $exportperlmalloc{$_} } @missing;
1150 delete $export{$_} foreach @missing;
1152 elsif ($PLATFORM eq 'netware') {
1153 foreach my $symbol (qw(
1279 fnInsertHashListAddrs
1290 try_symbol($symbol);
1294 # records of type boot_module for statically linked modules (except Dynaloader)
1295 $static_ext =~ s/\//__/g;
1296 $static_ext =~ s/\bDynaLoader\b//;
1297 my @stat_mods = map {"boot_$_"} grep {/\S/} split /\s+/, $static_ext;
1298 foreach my $symbol (@stat_mods)
1300 try_symbol($symbol);
1303 try_symbol("init_Win32CORE") if $static_ext =~ /\bWin32CORE\b/;
1305 ###############################################################################
1307 # Now all symbols should be defined because next we are going to output them.
1309 # Start with platform specific headers:
1311 if ($PLATFORM =~ /^win(?:32|ce)$/) {
1312 (my $dll = ($define{PERL_DLL} || "perl515")) =~ s/\.dll$//i;
1313 print "LIBRARY $dll\n";
1314 # The DESCRIPTION module definition file statement is not supported
1316 if ($CCTYPE =~ /^(?:MSVC60|GCC|BORLAND)$/) {
1317 print "DESCRIPTION 'Perl interpreter'\n";
1321 elsif ($PLATFORM eq 'os2') {
1322 (my $v = $]) =~ s/(\d\.\d\d\d)(\d\d)$/$1_$2/;
1323 $v .= '-thread' if $define{archname} =~ /-thread/;
1324 (my $dll = $define{PERL_DLL}) =~ s/\.dll$//i;
1325 $v .= "\@$define{perl_patchlevel}" if $define{perl_patchlevel};
1326 my $d = "DESCRIPTION '\@#perl5-porters\@perl.org:$v#\@ Perl interpreter, configured as $define{config_args}'";
1327 $d = substr($d, 0, 249) . "...'" if length $d > 253;
1328 print <<"---EOP---";
1329 LIBRARY '$dll' INITINSTANCE TERMINSTANCE
1333 DATA LOADONCALL NONSHARED MULTIPLE
1337 elsif ($PLATFORM eq 'aix') {
1338 my $OSVER = `uname -v`;
1340 my $OSREL = `uname -r`;
1342 if ($OSVER > 4 || ($OSVER == 4 && $OSREL >= 3)) {
1348 elsif ($PLATFORM eq 'netware') {
1349 if ($FILETYPE eq 'def') {
1350 print "LIBRARY perl515\n";
1351 print "DESCRIPTION 'Perl interpreter for NetWare'\n";
1358 foreach my $symbol (sort keys %export) {
1359 if ($PLATFORM =~ /^win(?:32|ce)$/) {
1360 $symbol = "_$symbol" if $CCTYPE eq 'BORLAND';
1361 print "\t$symbol\n";
1363 elsif ($PLATFORM eq 'os2') {
1364 printf qq( %-31s \@%s\n),
1365 qq("$symbol"), $ordinal{$symbol} || ++$sym_ord;
1366 printf qq( %-31s \@%s\n),
1367 qq("$exportperlmalloc{$symbol}" = "$symbol"),
1368 $ordinal{$exportperlmalloc{$symbol}} || ++$sym_ord
1369 if $exportperlmalloc and exists $exportperlmalloc{$symbol};
1371 elsif ($PLATFORM eq 'netware') {
1372 print "\t$symbol,\n";
1378 # Then platform specific footers.
1380 if ($PLATFORM eq 'os2') {
1385 Perl_OS2_handler_install
1387 ; LAST_ORDINAL=$sym_ord