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);
43 my (%define, %ordinal);
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";
102 # All platforms export boot_DynaLoader unconditionally.
103 my %export = ( boot_DynaLoader => 1 );
105 s/^/$TARG_DIR/ foreach($intrpvar_h, $perlvars_h, $global_sym, $globvar_sym,
106 $perlio_sym, $config_sh);
108 unless ($PLATFORM eq 'win32' || $PLATFORM eq 'wince' || $PLATFORM eq 'netware') {
109 open(CFG,$config_sh) || die "Cannot open $config_sh: $!\n";
111 if (/^(?:ccflags|optimize)='(.+)'$/) {
113 $define{$1} = 1 while /-D(\w+)/g;
116 if /^(config_args|archname|perl_patchlevel)='(.+)'$/;
120 if ($PLATFORM eq 'win32' || $PLATFORM eq 'wince') {
121 open(CFG, '<', $config_sh) || die "Cannot open $config_sh: $!\n";
122 if ((join '', <CFG>) =~ /^static_ext='(.*)'$/m) {
128 open(CFG,$config_h) || die "Cannot open $config_h: $!\n";
130 $define{$1} = 1 if /^\s*\#\s*define\s+(MYMALLOC|MULTIPLICITY
131 |SPRINTF_RETURNS_STRLEN
132 |(?:PERL|USE|HAS)_\w+)\b/x;
136 # perl.h logic duplication begins
138 if ($define{PERL_IMPLICIT_SYS}) {
139 $define{PL_OP_SLAB_ALLOC} = 1;
142 if ($define{USE_ITHREADS}) {
143 if (!$define{MULTIPLICITY}) {
144 $define{MULTIPLICITY} = 1;
148 $define{PERL_IMPLICIT_CONTEXT} ||=
149 $define{USE_ITHREADS} ||
150 $define{MULTIPLICITY} ;
152 if ($define{USE_ITHREADS} && $PLATFORM ne 'win32' && $^O ne 'darwin') {
153 $define{USE_REENTRANT_API} = 1;
156 # perl.h logic duplication ends
160 print STDERR "Defines: (" . join(' ', sort keys %define) . ")\n";
162 if ($PLATFORM =~ /^win(?:32|ce)$/) {
163 (my $dll = ($define{PERL_DLL} || "perl515")) =~ s/\.dll$//i;
164 print "LIBRARY $dll\n";
165 # The DESCRIPTION module definition file statement is not supported
167 if ($CCTYPE =~ /^(?:MSVC60|GCC|BORLAND)$/) {
168 print "DESCRIPTION 'Perl interpreter'\n";
172 elsif ($PLATFORM eq 'os2') {
173 if (open my $fh, '<', 'perl5.def') {
175 last if /^\s*EXPORTS\b/;
178 $ordinal{$1} = $2 if /^\s*"(\w+)"\s*(?:=\s*"\w+"\s*)?\@(\d+)\s*$/;
179 # This allows skipping ordinals which were used in older versions
180 $sym_ord = $1 if /^\s*;\s*LAST_ORDINAL\s*=\s*(\d+)\s*$/;
182 $sym_ord < $_ and $sym_ord = $_ for values %ordinal; # Take the max
184 (my $v = $]) =~ s/(\d\.\d\d\d)(\d\d)$/$1_$2/;
185 $v .= '-thread' if $define{archname} =~ /-thread/;
186 (my $dll = $define{PERL_DLL}) =~ s/\.dll$//i;
187 $v .= "\@$define{perl_patchlevel}" if $define{perl_patchlevel};
188 my $d = "DESCRIPTION '\@#perl5-porters\@perl.org:$v#\@ Perl interpreter, configured as $define{config_args}'";
189 $d = substr($d, 0, 249) . "...'" if length $d > 253;
191 LIBRARY '$dll' INITINSTANCE TERMINSTANCE
195 DATA LOADONCALL NONSHARED MULTIPLE
199 elsif ($PLATFORM eq 'aix') {
200 my $OSVER = `uname -v`;
202 my $OSREL = `uname -r`;
204 if ($OSVER > 4 || ($OSVER == 4 && $OSREL >= 3)) {
210 elsif ($PLATFORM eq 'netware') {
211 if ($FILETYPE eq 'def') {
212 print "LIBRARY perl515\n";
213 print "DESCRIPTION 'Perl interpreter for NetWare'\n";
220 foreach my $symbol (@$list) {
221 my $skipsym = $symbol;
223 if ($define{MULTIPLICITY}) {
224 $skipsym =~ s/^Perl_[GIT](\w+)_ptr$/PL_$1/;
226 ++$export{$symbol} unless exists $skip{$skipsym};
230 if ($PLATFORM ne 'os2') {
231 ++$skip{$_} foreach qw(
245 if ($PLATFORM eq 'vms') {
246 ++$skip{PL_statusvalue_posix};
248 ++$skip{PL_statusvalue_vms};
249 if ($PLATFORM ne 'aix') {
250 ++$skip{$_} foreach qw(
262 if ($PLATFORM ne 'vms') {
263 # VMS does its own thing for these symbols.
264 ++$skip{$_} foreach qw(
265 PL_sig_handlers_initted
269 if ($PLATFORM ne 'win32') {
270 ++$skip{$_} foreach qw(
278 if ($PLATFORM eq 'os2') {
323 XS_Cwd_extLibpath_set
327 XS_Cwd_sys_is_absolute
328 XS_Cwd_sys_is_relative
330 XS_DynaLoader_mod2fname
331 XS_File__Copy_syscopy
335 Perl_Process_Messages
346 emit_symbols([qw(os2_cond_wait
351 if $define{'USE_5005THREADS'} or $define{'USE_ITHREADS'};
353 elsif ($PLATFORM eq 'vms') {
358 Perl_csighandler_init
361 Perl_fileify_dirspec_ts
362 Perl_fileify_dirspec_utf8
363 Perl_fileify_dirspec_utf8_ts
396 Perl_pathify_dirspec_ts
397 Perl_pathify_dirspec_utf8
398 Perl_pathify_dirspec_utf8_ts
406 Perl_rmsexpand_utf8_ts
408 Perl_sig_to_vmscondition
413 Perl_tounixpath_utf8_ts
417 Perl_tounixspec_utf8_ts
421 Perl_tovmspath_utf8_ts
425 Perl_tovmsspec_utf8_ts
427 Perl_vms_case_tolerant
439 unless ($define{UNLINK_ALL_VERSIONS}) {
443 unless ($define{'DEBUGGING'}) {
444 ++$skip{$_} foreach qw(
459 if ($define{'PERL_IMPLICIT_SYS'}) {
460 ++$skip{$_} foreach qw(
464 ++$export{$_} foreach qw(perl_get_host_info perl_alloc_override);
465 ++$export{perl_clone_host} if $define{USE_ITHREADS};
468 ++$skip{$_} foreach qw(
483 unless ($define{'PERL_OLD_COPY_ON_WRITE'}) {
484 ++$skip{Perl_sv_setsv_cow};
487 unless ($define{'USE_REENTRANT_API'}) {
488 ++$skip{PL_reentrant_buffer};
491 if ($define{'MYMALLOC'}) {
500 if ($define{'USE_ITHREADS'}) {
506 ++$skip{PL_malloc_mutex};
510 ++$skip{$_} foreach qw(
519 if ($define{'PERL_USE_SAFE_PUTENV'}) {
520 ++$skip{PL_use_safe_putenv};
523 unless ($define{'USE_ITHREADS'}) {
527 # USE_5005THREADS symbols. Kept as reference for easier removal
528 ++$skip{$_} foreach qw(
546 Perl_new_struct_thread
547 Perl_per_thread_magicals
555 unless ($define{'USE_ITHREADS'}) {
556 ++$skip{$_} foreach qw(
564 Perl_clone_params_del
565 Perl_clone_params_new
584 Perl_stashpv_hvname_match
585 Perl_regdupe_internal
590 unless ($define{'PERL_IMPLICIT_CONTEXT'}) {
591 ++$skip{$_} foreach qw(
600 Perl_load_module_nocontext
603 Perl_warner_nocontext
604 Perl_newSVpvf_nocontext
605 Perl_sv_catpvf_nocontext
606 Perl_sv_setpvf_nocontext
607 Perl_sv_catpvf_mg_nocontext
608 Perl_sv_setpvf_mg_nocontext
614 unless ($define{'PL_OP_SLAB_ALLOC'}) {
615 ++$skip{$_} foreach qw(
624 unless ($define{'PERL_DEBUG_READONLY_OPS'}) {
625 ++$skip{$_} foreach qw(
631 unless ($define{'THREADS_HAVE_PIDS'}) {
635 unless ($define{'PERL_NEED_APPCTX'}) {
639 unless ($define{'PERL_NEED_TIMESBASE'}) {
640 ++$skip{PL_timesbase};
643 unless ($define{'DEBUG_LEAKING_SCALARS'}) {
644 ++$skip{PL_sv_serial};
647 unless ($define{'DEBUG_LEAKING_SCALARS_FORK_DUMP'}) {
648 ++$skip{PL_dumper_fd};
651 unless ($define{'PERL_DONT_CREATE_GVSV'}) {
652 ++$skip{Perl_gv_SVadd};
655 if ($define{'SPRINTF_RETURNS_STRLEN'}) {
656 ++$skip{Perl_my_sprintf};
659 unless ($define{'PERL_USES_PL_PIDSTATUS'}) {
660 ++$skip{PL_pidstatus};
663 unless ($define{'PERL_TRACK_MEMPOOL'}) {
664 ++$skip{PL_memory_debug_header};
667 unless ($define{PERL_MAD}) {
668 ++$skip{$_} foreach qw(
674 unless ($define{'MULTIPLICITY'}) {
675 ++$skip{$_} foreach qw(
677 PL_interp_size_5_16_0
681 unless ($define{'PERL_GLOBAL_STRUCT'}) {
682 ++$skip{PL_global_struct_size};
685 unless ($define{'PERL_GLOBAL_STRUCT_PRIVATE'}) {
686 ++$skip{$_} foreach qw(
692 unless ($define{HAS_MMAP}) {
693 ++$skip{PL_mmap_page_size};
696 if ($define{HAS_SIGACTION}) {
697 ++$skip{PL_sig_trapped};
700 unless ($define{USE_LOCALE_COLLATE}) {
701 ++$skip{$_} foreach qw(
704 PL_collation_standard
708 Perl_sv_collxfrm_flags
712 unless ($define{USE_LOCALE_NUMERIC}) {
713 ++$skip{$_} foreach qw(
721 unless ($define{HAVE_INTERP_INTERN}) {
722 ++$skip{$_} foreach qw(
723 Perl_sys_intern_clear
730 if ($define{HAS_SIGNBIT}) {
731 ++$skip{Perl_signbit};
736 my $proc = shift || sub { "PL_$_[2]" };
737 open my $vars, '<', $file or die die "Cannot open $file: $!\n";
739 # All symbols have a Perl_ prefix because that's what embed.h sticks
740 # in front of them. The A?I?S?C? is strictly speaking wrong.
741 map {/\bPERLVAR(A?I?S?C?)\(([IGT])(\w+)/ ? &$proc($1,$2,$3) : ()} <$vars>;
744 if ($define{'PERL_GLOBAL_STRUCT'}) {
745 ++$skip{$_} foreach readvar($perlvars_h);
746 ++$export{Perl_GetVars};
747 emit_symbols [qw(PL_Vars PL_VarsPtr)] unless $CCTYPE eq 'GCC';
749 ++$skip{$_} foreach qw(Perl_init_global_struct Perl_free_global_struct);
752 # functions from *.sym files
754 my @syms = ($global_sym, $globvar_sym);
756 # Symbols that are the public face of the PerlIO layers implementation
757 # These are in _addition to_ the public face of the abstraction
758 # and need to be exported to allow XS modules to implement layers
772 PerlIOBase_setlinebuf
811 Perl_PerlIO_context_layers
818 Perl_PerlIO_get_bufsiz
824 Perl_PerlIO_set_ptrcnt
825 Perl_PerlIO_setlinebuf
833 if ($PLATFORM eq 'netware') {
834 push(@layer_syms,'PL_def_layerlist','PL_known_layers','PL_perlio');
837 if ($define{'USE_PERLIO'}) {
838 # Export the symols that make up the PerlIO abstraction, regardless
839 # of its implementation - read from a file
840 push @syms, $perlio_sym;
842 # This part is then dependent on how the abstraction is implemented
843 if ($define{'USE_SFIO'}) {
844 # Old legacy non-stdio "PerlIO"
845 ++$skip{$_} foreach @layer_syms;
846 ++$skip{perlsio_binmode};
847 # SFIO defines most of the PerlIO routines as macros
848 # So undo most of what $perlio_sym has just done - d'oh !
849 # Perhaps it would be better to list the ones which do exist
851 ++$skip{$_} foreach qw(
902 Perl_PerlIO_get_bufsiz
908 Perl_PerlIO_set_ptrcnt
909 Perl_PerlIO_setlinebuf
922 # PerlIO with layers - export implementation
923 emit_symbols \@layer_syms;
924 emit_symbols [qw(perlsio_binmode)];
926 if ($define{'USE_ITHREADS'}) {
932 ++$skip{PL_perlio_mutex};
936 # Skip the PerlIO layer symbols - although
937 # nothing should have exported them anyway.
938 ++$skip{$_} foreach @layer_syms;
939 ++$skip{$_} foreach qw(
946 PL_perlio_fd_refcnt_size
949 # Also do NOT add abstraction symbols from $perlio_sym
950 # abstraction is done as #define to stdio
951 # Remaining remnants that _may_ be functions are handled below.
954 for my $syms (@syms) {
955 open (GLOBAL, "<$syms") || die "failed to open $syms: $!\n";
957 next if (!/^[A-Za-z]/);
958 # Functions have a Perl_ prefix
959 # Variables have a PL_ prefix
961 my $symbol = ($syms =~ /var\.sym$/i ? "PL_" : "");
963 ++$export{$symbol} unless exists $skip{$symbol};
970 if ($define{'MULTIPLICITY'} && $define{PERL_GLOBAL_STRUCT}) {
971 for my $f ($perlvars_h) {
972 emit_symbols [readvar($f, sub { "Perl_" . $_[1] . $_[2] . "_ptr" })];
974 # XXX AIX seems to want the perlvars.h symbols, for some reason
975 if ($PLATFORM eq 'aix' or $PLATFORM eq 'os2') { # OS/2 needs PL_thr_key
976 emit_symbols [readvar($perlvars_h)];
980 unless ($define{'PERL_GLOBAL_STRUCT'}) {
981 emit_symbols [readvar($perlvars_h)];
983 unless ($define{MULTIPLICITY}) {
984 emit_symbols [readvar($intrpvar_h)];
990 ++$export{$symbol} unless $skip{$symbol};
993 # Oddities from PerlIO
1005 if ($PLATFORM eq 'win32') {
1006 try_symbol($_) foreach qw(
1017 if ($PLATFORM =~ /^win(?:32|ce)$/) {
1018 foreach my $symbol (qw(
1077 win32_getprotobyname
1078 win32_getprotobynumber
1107 win32_open_osfhandle
1174 try_symbol($symbol);
1176 if ($CCTYPE eq "BORLAND") {
1177 try_symbol('_matherr');
1180 elsif ($PLATFORM eq 'os2') {
1181 my (%mapped, @missing);
1182 open MAP, 'miniperl.map' or die 'Cannot read miniperl.map';
1183 /^\s*[\da-f:]+\s+(\w+)/i and $mapped{$1}++ foreach <MAP>;
1184 close MAP or die 'Cannot close miniperl.map';
1186 @missing = grep { !exists $mapped{$_} }
1188 @missing = grep { !exists $exportperlmalloc{$_} } @missing;
1189 delete $export{$_} foreach @missing;
1191 elsif ($PLATFORM eq 'netware') {
1192 foreach my $symbol (qw(
1318 fnInsertHashListAddrs
1329 try_symbol($symbol);
1333 # records of type boot_module for statically linked modules (except Dynaloader)
1334 $static_ext =~ s/\//__/g;
1335 $static_ext =~ s/\bDynaLoader\b//;
1336 my @stat_mods = map {"boot_$_"} grep {/\S/} split /\s+/, $static_ext;
1337 foreach my $symbol (@stat_mods)
1339 try_symbol($symbol);
1342 try_symbol("init_Win32CORE") if $static_ext =~ /\bWin32CORE\b/;
1344 # Now all symbols should be defined because
1345 # next we are going to output them.
1347 foreach my $symbol (sort keys %export) {
1348 output_symbol($symbol);
1351 if ($PLATFORM eq 'os2') {
1356 Perl_OS2_handler_install
1358 ; LAST_ORDINAL=$sym_ord
1364 if ($PLATFORM =~ /^win(?:32|ce)$/) {
1365 $symbol = "_$symbol" if $CCTYPE eq 'BORLAND';
1366 print "\t$symbol\n";
1367 # XXX: binary compatibility between compilers is an exercise
1368 # in frustration :-(
1369 # if ($CCTYPE eq "BORLAND") {
1370 # # workaround Borland quirk by exporting both the straight
1371 # # name and a name with leading underscore. Note the
1372 # # alias *must* come after the symbol itself, if both
1373 # # are to be exported. (Linker bug?)
1374 # print "\t_$symbol\n";
1375 # print "\t$symbol = _$symbol\n";
1377 # elsif ($CCTYPE eq 'GCC') {
1378 # # Symbols have leading _ whole process is $%@"% slow
1379 # # so skip aliases for now
1380 # nprint "\t$symbol\n";
1383 # # for binary coexistence, export both the symbol and
1384 # # alias with leading underscore
1385 # print "\t$symbol\n";
1386 # print "\t_$symbol = $symbol\n";
1389 elsif ($PLATFORM eq 'os2') {
1390 printf qq( %-31s \@%s\n),
1391 qq("$symbol"), $ordinal{$symbol} || ++$sym_ord;
1392 printf qq( %-31s \@%s\n),
1393 qq("$exportperlmalloc{$symbol}" = "$symbol"),
1394 $ordinal{$exportperlmalloc{$symbol}} || ++$sym_ord
1395 if $exportperlmalloc and exists $exportperlmalloc{$symbol};
1397 elsif ($PLATFORM eq 'aix' || $PLATFORM eq 'vms') {
1400 elsif ($PLATFORM eq 'netware') {
1401 print "\t$symbol,\n";