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 MacOS Classic.
9 # Reads from information stored in
16 # macperl.sym (on MacOS)
17 # miniperl.map (on OS/2)
18 # 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 and
23 # in the DATA section.
25 # Writes the result to STDOUT.
27 # Normally this script is invoked from a makefile (e.g. win32/Makefile),
28 # which redirects STDOUT to a suitable file, such as:
36 BEGIN { unshift @INC, "lib" }
40 use vars qw($PLATFORM $CCTYPE $FILETYPE $CONFIG_ARGS $ARCHNAME $PATCHLEVEL);
42 my (%define, %ordinal);
46 if ($flag =~ s/^CC_FLAGS=/ /) {
47 for my $fflag ($flag =~ /(?:^|\s)-D(\S+)/g) {
48 $fflag .= '=1' unless $fflag =~ /^(\w+)=/;
49 $define{$1} = $2 if $fflag =~ /^(\w+)=(.+)$/;
53 $define{$1} = 1 if ($flag =~ /^-D(\w+)$/);
54 $define{$1} = $2 if ($flag =~ /^-D(\w+)=(.+)$/);
55 $CCTYPE = $1 if ($flag =~ /^CCTYPE=(\w+)$/);
56 $PLATFORM = $1 if ($flag =~ /^PLATFORM=(\w+)$/);
57 if ($PLATFORM eq 'netware') {
58 $FILETYPE = $1 if ($flag =~ /^FILETYPE=(\w+)$/);
62 my @PLATFORM = qw(aix win32 wince os2 MacOS netware);
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 if ($PLATFORM eq 'win32' or $PLATFORM eq 'wince' or $PLATFORM eq "aix") {
70 # Add the compile-time options that miniperl was built with to %define.
71 # On Win32 these are not the same options as perl itself will be built
72 # with since miniperl is built with a canned config (one of the win32/
73 # config_H.*) and none of the BUILDOPT's that are set in the makefiles,
74 # but they do include some #define's that are hard-coded in various
75 # source files and header files and don't include any BUILDOPT's that
76 # the user might have chosen to disable because the canned configs are
77 # minimal configs that don't include any of those options.
78 my $opts = ($PLATFORM eq 'wince' ? '-MCross' : ''); # for wince need Cross.pm to get Config.pm
80 $ENV{PERL5LIB} = join $Config{path_sep}, @INC;
81 my $cmd = "$^X $opts -V";
84 die "Couldn't run [$cmd]: $!";
86 my($options) = $config =~ /^ Compile-time options: (.*?)\n^ \S/ms;
87 $options =~ s/\s+/ /g;
88 print STDERR "Options: ($options)\n";
89 foreach (split /\s+/, $options) {
94 my %exportperlmalloc =
96 Perl_malloc => "malloc",
98 Perl_realloc => "realloc",
99 Perl_calloc => "calloc",
102 my $exportperlmalloc = $PLATFORM eq 'os2';
104 my $config_sh = "config.sh";
105 my $config_h = "config.h";
106 my $intrpvar_h = "intrpvar.h";
107 my $perlvars_h = "perlvars.h";
108 my $global_sym = "global.sym";
109 my $pp_sym = "pp.sym";
110 my $globvar_sym = "globvar.sym";
111 my $perlio_sym = "perlio.sym";
114 if ($PLATFORM eq 'aix') {
117 elsif ($PLATFORM =~ /^win(?:32|ce)$/ || $PLATFORM eq 'netware') {
118 $CCTYPE = "MSVC" unless defined $CCTYPE;
119 foreach ($intrpvar_h, $perlvars_h, $global_sym,
120 $pp_sym, $globvar_sym, $perlio_sym) {
124 elsif ($PLATFORM eq 'MacOS') {
125 foreach ($intrpvar_h, $perlvars_h, $global_sym,
126 $pp_sym, $globvar_sym, $perlio_sym) {
131 unless ($PLATFORM eq 'win32' || $PLATFORM eq 'wince' || $PLATFORM eq 'MacOS' || $PLATFORM eq 'netware') {
132 open(CFG,$config_sh) || die "Cannot open $config_sh: $!\n";
134 if (/^(?:ccflags|optimize)='(.+)'$/) {
136 $define{$1} = 1 while /-D(\w+)/g;
138 if (/^(d_(?:mmap|sigaction))='(.+)'$/) {
141 if ($PLATFORM eq 'os2') {
142 $CONFIG_ARGS = $1 if /^config_args='(.+)'$/;
143 $ARCHNAME = $1 if /^archname='(.+)'$/;
144 $PATCHLEVEL = $1 if /^perl_patchlevel='(.+)'$/;
149 if ($PLATFORM eq 'win32' || $PLATFORM eq 'wince') {
150 open(CFG,"<..\\$config_sh") || die "Cannot open ..\\$config_sh: $!\n";
151 if ((join '', <CFG>) =~ /^static_ext='(.*)'$/m) {
157 open(CFG,$config_h) || die "Cannot open $config_h: $!\n";
159 $define{$1} = 1 if /^\s*#\s*define\s+(MYMALLOC)\b/;
160 $define{$1} = 1 if /^\s*#\s*define\s+(MULTIPLICITY)\b/;
161 $define{$1} = 1 if /^\s*#\s*define\s+(PERL_\w+)\b/;
162 $define{$1} = 1 if /^\s*#\s*define\s+(USE_\w+)\b/;
163 $define{$1} = 1 if /^\s*#\s*define\s+(HAS_\w+)\b/;
167 # perl.h logic duplication begins
169 if ($define{PERL_IMPLICIT_SYS}) {
170 $define{PL_OP_SLAB_ALLOC} = 1;
173 if ($define{USE_ITHREADS}) {
174 if (!$define{MULTIPLICITY}) {
175 $define{MULTIPLICITY} = 1;
179 $define{PERL_IMPLICIT_CONTEXT} ||=
180 $define{USE_ITHREADS} ||
181 $define{MULTIPLICITY} ;
183 if ($define{USE_ITHREADS} && $PLATFORM ne 'win32' && $^O ne 'darwin') {
184 $define{USE_REENTRANT_API} = 1;
187 # perl.h logic duplication ends
191 print STDERR "Defines: (" . join(' ', sort keys %define) . ")\n";
193 if ($PLATFORM =~ /^win(?:32|ce)$/) {
194 (my $dll = ($define{PERL_DLL} || "perl511")) =~ s/\.dll$//i;
195 print "LIBRARY $dll\n";
196 # The DESCRIPTION module definition file statement is not supported
198 if ($CCTYPE !~ /^MSVC7/ && $CCTYPE !~ /^MSVC8/ && $CCTYPE !~ /^MSVC9/) {
199 print "DESCRIPTION 'Perl interpreter'\n";
202 if ($define{PERL_IMPLICIT_SYS}) {
203 output_symbol("perl_get_host_info");
204 output_symbol("perl_alloc_override");
206 if ($define{USE_ITHREADS} and $define{PERL_IMPLICIT_SYS}) {
207 output_symbol("perl_clone_host");
210 elsif ($PLATFORM eq 'os2') {
211 if (open my $fh, '<', 'perl5.def') {
213 last if /^\s*EXPORTS\b/;
216 $ordinal{$1} = $2 if /^\s*"(\w+)"\s*(?:=\s*"\w+"\s*)?\@(\d+)\s*$/;
217 # This allows skipping ordinals which were used in older versions
218 $sym_ord = $1 if /^\s*;\s*LAST_ORDINAL\s*=\s*(\d+)\s*$/;
220 $sym_ord < $_ and $sym_ord = $_ for values %ordinal; # Take the max
222 (my $v = $]) =~ s/(\d\.\d\d\d)(\d\d)$/$1_$2/;
223 $v .= '-thread' if $ARCHNAME =~ /-thread/;
224 (my $dll = $define{PERL_DLL}) =~ s/\.dll$//i;
225 $v .= "\@$PATCHLEVEL" if $PATCHLEVEL;
226 my $d = "DESCRIPTION '\@#perl5-porters\@perl.org:$v#\@ Perl interpreter, configured as $CONFIG_ARGS'";
227 $d = substr($d, 0, 249) . "...'" if length $d > 253;
229 LIBRARY '$dll' INITINSTANCE TERMINSTANCE
233 DATA LOADONCALL NONSHARED MULTIPLE
237 elsif ($PLATFORM eq 'aix') {
238 my $OSVER = `uname -v`;
240 my $OSREL = `uname -r`;
242 if ($OSVER > 4 || ($OSVER == 4 && $OSREL >= 3)) {
248 elsif ($PLATFORM eq 'netware') {
249 if ($FILETYPE eq 'def') {
250 print "LIBRARY perl511\n";
251 print "DESCRIPTION 'Perl interpreter for NetWare'\n";
254 if ($define{PERL_IMPLICIT_SYS}) {
255 output_symbol("perl_get_host_info");
256 output_symbol("perl_alloc_override");
257 output_symbol("perl_clone_host");
266 foreach my $symbol (@$list) {
273 foreach my $symbol (@$list) {
274 my $skipsym = $symbol;
276 if ($define{MULTIPLICITY}) {
277 $skipsym =~ s/^Perl_[GIT](\w+)_ptr$/PL_$1/;
279 emit_symbol($symbol) unless exists $skip{$skipsym};
283 if ($PLATFORM eq 'win32') {
307 Perl_init_thread_intern
341 if ($PLATFORM eq 'wince') {
356 PL_collation_standard
384 Perl_init_thread_intern
411 elsif ($PLATFORM eq 'aix') {
430 Perl_sys_intern_clear
442 if $define{'HAS_SIGNBIT'};
447 elsif ($PLATFORM eq 'os2') {
492 XS_Cwd_extLibpath_set
496 XS_Cwd_sys_is_absolute
497 XS_Cwd_sys_is_relative
499 XS_DynaLoader_mod2fname
500 XS_File__Copy_syscopy
504 Perl_Process_Messages
515 emit_symbols([qw(os2_cond_wait
520 if $define{'USE_5005THREADS'} or $define{'USE_ITHREADS'};
522 elsif ($PLATFORM eq 'MacOS') {
546 Perl_sys_intern_clear
550 elsif ($PLATFORM eq 'netware') {
574 Perl_init_thread_intern
599 Perl_sys_intern_clear
607 Perl_PerlIO_setlinebuf
608 Perl_PerlIO_set_ptrcnt
614 Perl_PerlIO_get_bufsiz
627 unless ($define{'DEBUGGING'}) {
643 if ($define{'PERL_IMPLICIT_CONTEXT'}) {
649 if ($define{'PERL_IMPLICIT_SYS'}) {
670 unless ($define{'PERL_OLD_COPY_ON_WRITE'}) {
676 unless ($define{'USE_REENTRANT_API'}) {
682 if ($define{'MYMALLOC'}) {
691 if ($define{'USE_ITHREADS'}) {
708 Perl_malloc_good_size
714 if ($define{'PERL_USE_SAFE_PUTENV'}) {
720 unless ($define{'USE_ITHREADS'}) {
726 # USE_5005THREADS symbols. Kept as reference for easier removal
745 Perl_new_struct_thread
746 Perl_per_thread_magicals
754 unless ($define{'USE_ITHREADS'}) {
760 PL_sharedsv_space_mutex
787 Perl_sharedsv_thrcnt_dec
788 Perl_sharedsv_thrcnt_inc
790 Perl_stashpv_hvname_match
791 Perl_regdupe_internal
796 unless ($define{'PERL_IMPLICIT_CONTEXT'}) {
807 Perl_load_module_nocontext
810 Perl_warner_nocontext
811 Perl_newSVpvf_nocontext
812 Perl_sv_catpvf_nocontext
813 Perl_sv_setpvf_nocontext
814 Perl_sv_catpvf_mg_nocontext
815 Perl_sv_setpvf_mg_nocontext
821 unless ($define{'PERL_IMPLICIT_SYS'}) {
828 unless ($define{'FAKE_THREADS'}) {
829 skip_symbols [qw(PL_curthr)];
832 unless ($define{'PL_OP_SLAB_ALLOC'}) {
842 unless ($define{'PERL_DEBUG_READONLY_OPS'}) {
849 unless ($define{'THREADS_HAVE_PIDS'}) {
850 skip_symbols [qw(PL_ppid)];
853 unless ($define{'PERL_NEED_APPCTX'}) {
859 unless ($define{'PERL_NEED_TIMESBASE'}) {
865 unless ($define{'DEBUG_LEAKING_SCALARS'}) {
871 unless ($define{'DEBUG_LEAKING_SCALARS_FORK_DUMP'}) {
876 unless ($define{'PERL_DONT_CREATE_GVSV'}) {
881 if ($define{'SPRINTF_RETURNS_STRLEN'}) {
886 unless ($define{'PERL_USES_PL_PIDSTATUS'}) {
893 unless ($define{'PERL_TRACK_MEMPOOL'}) {
895 PL_memory_debug_header
899 if ($define{'PERL_MAD'}) {
925 Perl_xmldump_packsubs
939 unless ($define{'MULTIPLICITY'}) {
942 PL_interp_size_5_10_0
946 unless ($define{'PERL_GLOBAL_STRUCT'}) {
948 PL_global_struct_size
952 unless ($define{'PERL_GLOBAL_STRUCT_PRIVATE'}) {
959 unless ($define{'d_mmap'}) {
965 if ($define{'d_sigaction'}) {
972 # VMS does its own thing for these symbols.
973 skip_symbols [qw(PL_sig_handlers_initted
980 my $proc = shift || sub { "PL_$_[2]" };
981 open(VARS,$file) || die "Cannot open $file: $!\n";
984 # All symbols have a Perl_ prefix because that's what embed.h
985 # sticks in front of them. The A?I?S?C? is strictly speaking
987 push(@syms, &$proc($1,$2,$3)) if (/\bPERLVAR(A?I?S?C?)\(([IGT])(\w+)/);
993 if ($define{'PERL_GLOBAL_STRUCT'}) {
994 my $global = readvar($perlvars_h);
995 skip_symbols $global;
996 emit_symbol('Perl_GetVars');
997 emit_symbols [qw(PL_Vars PL_VarsPtr)] unless $CCTYPE eq 'GCC';
999 skip_symbols [qw(Perl_init_global_struct Perl_free_global_struct)];
1002 # functions from *.sym files
1004 my @syms = ($global_sym, $globvar_sym); # $pp_sym is not part of the API
1006 # Symbols that are the public face of the PerlIO layers implementation
1007 # These are in _addition to_ the public face of the abstraction
1008 # and need to be exported to allow XS modules to implement layers
1009 my @layer_syms = qw(
1017 PerlIOBase_noop_fail
1022 PerlIOBase_setlinebuf
1037 PerlIOBuf_set_ptrcnt
1059 Perl_PerlIO_clearerr
1061 Perl_PerlIO_context_layers
1067 Perl_PerlIO_get_base
1068 Perl_PerlIO_get_bufsiz
1074 Perl_PerlIO_set_ptrcnt
1075 Perl_PerlIO_setlinebuf
1083 if ($PLATFORM eq 'netware') {
1084 push(@layer_syms,'PL_def_layerlist','PL_known_layers','PL_perlio');
1087 if ($define{'USE_PERLIO'}) {
1088 # Export the symols that make up the PerlIO abstraction, regardless
1089 # of its implementation - read from a file
1090 push @syms, $perlio_sym;
1092 # This part is then dependent on how the abstraction is implemented
1093 if ($define{'USE_SFIO'}) {
1094 # Old legacy non-stdio "PerlIO"
1095 skip_symbols \@layer_syms;
1096 skip_symbols [qw(perlsio_binmode)];
1097 # SFIO defines most of the PerlIO routines as macros
1098 # So undo most of what $perlio_sym has just done - d'oh !
1099 # Perhaps it would be better to list the ones which do exist
1144 Perl_PerlIO_clearerr
1151 Perl_PerlIO_get_base
1152 Perl_PerlIO_get_bufsiz
1158 Perl_PerlIO_set_ptrcnt
1159 Perl_PerlIO_setlinebuf
1172 # PerlIO with layers - export implementation
1173 emit_symbols \@layer_syms;
1174 emit_symbols [qw(perlsio_binmode)];
1176 if ($define{'USE_ITHREADS'}) {
1188 # Skip the PerlIO layer symbols - although
1189 # nothing should have exported them anyway.
1190 skip_symbols \@layer_syms;
1198 PL_perlio_fd_refcnt_size
1201 # Also do NOT add abstraction symbols from $perlio_sym
1202 # abstraction is done as #define to stdio
1203 # Remaining remnants that _may_ be functions
1204 # are handled in <DATA>
1207 for my $syms (@syms) {
1208 open (GLOBAL, "<$syms") || die "failed to open $syms: $!\n";
1210 next if (!/^[A-Za-z]/);
1211 # Functions have a Perl_ prefix
1212 # Variables have a PL_ prefix
1214 my $symbol = ($syms =~ /var\.sym$/i ? "PL_" : "");
1216 emit_symbol($symbol) unless exists $skip{$symbol};
1223 if ($define{'MULTIPLICITY'}) {
1224 for my $f ($perlvars_h, $intrpvar_h) {
1225 my $glob = readvar($f, sub { "Perl_" . $_[1] . $_[2] . "_ptr" });
1228 # XXX AIX seems to want the perlvars.h symbols, for some reason
1229 if ($PLATFORM eq 'aix' or $PLATFORM eq 'os2') { # OS/2 needs PL_thr_key
1230 my $glob = readvar($perlvars_h);
1235 unless ($define{'PERL_GLOBAL_STRUCT'}) {
1236 my $glob = readvar($perlvars_h);
1239 unless ($define{'MULTIPLICITY'}) {
1240 my $glob = readvar($intrpvar_h);
1248 return if $symbol !~ /^[A-Za-z_]/;
1249 return if $symbol =~ /^\#/;
1252 return if exists $skip{$symbol};
1253 emit_symbol($symbol);
1260 if ($PLATFORM =~ /^win(?:32|ce)$/) {
1261 foreach my $symbol (qw(
1323 win32_getprotobyname
1324 win32_getprotobynumber
1353 win32_open_osfhandle
1424 try_symbol($symbol);
1426 if ($CCTYPE eq "BORLAND") {
1427 try_symbol('_matherr');
1430 elsif ($PLATFORM eq 'os2') {
1431 my (%mapped, @missing);
1432 open MAP, 'miniperl.map' or die 'Cannot read miniperl.map';
1433 /^\s*[\da-f:]+\s+(\w+)/i and $mapped{$1}++ foreach <MAP>;
1434 close MAP or die 'Cannot close miniperl.map';
1436 @missing = grep { !exists $mapped{$_} }
1438 @missing = grep { !exists $exportperlmalloc{$_} } @missing;
1439 delete $export{$_} foreach @missing;
1441 elsif ($PLATFORM eq 'MacOS') {
1442 open MACSYMS, 'macperl.sym' or die 'Cannot read macperl.sym';
1450 elsif ($PLATFORM eq 'netware') {
1451 foreach my $symbol (qw(
1578 fnInsertHashListAddrs
1589 try_symbol($symbol);
1593 # records of type boot_module for statically linked modules (except Dynaloader)
1594 $static_ext =~ s/\//__/g;
1595 $static_ext =~ s/\bDynaLoader\b//;
1596 my @stat_mods = map {"boot_$_"} grep {/\S/} split /\s+/, $static_ext;
1597 foreach my $symbol (@stat_mods)
1599 try_symbol($symbol);
1602 try_symbol("init_Win32CORE") if $static_ext =~ /\bWin32CORE\b/;
1604 # Now all symbols should be defined because
1605 # next we are going to output them.
1607 foreach my $symbol (sort keys %export) {
1608 output_symbol($symbol);
1611 if ($PLATFORM eq 'os2') {
1616 Perl_OS2_handler_install
1618 ; LAST_ORDINAL=$sym_ord
1625 $export{$symbol} = 1;
1630 if ($PLATFORM =~ /^win(?:32|ce)$/) {
1631 $symbol = "_$symbol" if $CCTYPE eq 'BORLAND';
1632 print "\t$symbol\n";
1633 # XXX: binary compatibility between compilers is an exercise
1634 # in frustration :-(
1635 # if ($CCTYPE eq "BORLAND") {
1636 # # workaround Borland quirk by exporting both the straight
1637 # # name and a name with leading underscore. Note the
1638 # # alias *must* come after the symbol itself, if both
1639 # # are to be exported. (Linker bug?)
1640 # print "\t_$symbol\n";
1641 # print "\t$symbol = _$symbol\n";
1643 # elsif ($CCTYPE eq 'GCC') {
1644 # # Symbols have leading _ whole process is $%@"% slow
1645 # # so skip aliases for now
1646 # nprint "\t$symbol\n";
1649 # # for binary coexistence, export both the symbol and
1650 # # alias with leading underscore
1651 # print "\t$symbol\n";
1652 # print "\t_$symbol = $symbol\n";
1655 elsif ($PLATFORM eq 'os2') {
1656 printf qq( %-31s \@%s\n),
1657 qq("$symbol"), $ordinal{$symbol} || ++$sym_ord;
1658 printf qq( %-31s \@%s\n),
1659 qq("$exportperlmalloc{$symbol}" = "$symbol"),
1660 $ordinal{$exportperlmalloc{$symbol}} || ++$sym_ord
1661 if $exportperlmalloc and exists $exportperlmalloc{$symbol};
1663 elsif ($PLATFORM eq 'aix' || $PLATFORM eq 'MacOS') {
1666 elsif ($PLATFORM eq 'netware') {
1667 print "\t$symbol,\n";
1673 # Oddities from PerlIO