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" }
39 use vars qw($PLATFORM $CCTYPE $FILETYPE $CONFIG_ARGS $ARCHNAME $PATCHLEVEL);
41 my (%define, %ordinal);
45 if ($flag =~ s/^CC_FLAGS=/ /) {
46 for my $fflag ($flag =~ /(?:^|\s)-D(\S+)/g) {
47 $fflag .= '=1' unless $fflag =~ /^(\w+)=/;
48 $define{$1} = $2 if $fflag =~ /^(\w+)=(.+)$/;
52 $define{$1} = 1 if ($flag =~ /^-D(\w+)$/);
53 $define{$1} = $2 if ($flag =~ /^-D(\w+)=(.+)$/);
54 $CCTYPE = $1 if ($flag =~ /^CCTYPE=(\w+)$/);
55 $PLATFORM = $1 if ($flag =~ /^PLATFORM=(\w+)$/);
56 if ($PLATFORM eq 'netware') {
57 $FILETYPE = $1 if ($flag =~ /^FILETYPE=(\w+)$/);
61 my @PLATFORM = qw(aix win32 wince os2 MacOS netware);
63 @PLATFORM{@PLATFORM} = ();
65 defined $PLATFORM || die "PLATFORM undefined, must be one of: @PLATFORM\n";
66 exists $PLATFORM{$PLATFORM} || die "PLATFORM must be one of: @PLATFORM\n";
68 if ($PLATFORM eq 'win32' or $PLATFORM eq 'wince' or $PLATFORM eq "aix") {
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.
77 my $opts = ($PLATFORM eq 'wince' ? '-MCross' : ''); # for wince need Cross.pm to get Config.pm
78 my $config = `$^X $opts -Ilib -V`;
79 my($options) = $config =~ /^ Compile-time options: (.*?)\n^ \S/ms;
80 $options =~ s/\s+/ /g;
81 print STDERR "Options: ($options)\n";
82 foreach (split /\s+/, $options) {
87 my %exportperlmalloc =
89 Perl_malloc => "malloc",
91 Perl_realloc => "realloc",
92 Perl_calloc => "calloc",
95 my $exportperlmalloc = $PLATFORM eq 'os2';
97 my $config_sh = "config.sh";
98 my $config_h = "config.h";
99 my $intrpvar_h = "intrpvar.h";
100 my $perlvars_h = "perlvars.h";
101 my $global_sym = "global.sym";
102 my $pp_sym = "pp.sym";
103 my $globvar_sym = "globvar.sym";
104 my $perlio_sym = "perlio.sym";
107 if ($PLATFORM eq 'aix') {
110 elsif ($PLATFORM =~ /^win(?:32|ce)$/ || $PLATFORM eq 'netware') {
111 $CCTYPE = "MSVC" unless defined $CCTYPE;
112 foreach ($intrpvar_h, $perlvars_h, $global_sym,
113 $pp_sym, $globvar_sym, $perlio_sym) {
117 elsif ($PLATFORM eq 'MacOS') {
118 foreach ($intrpvar_h, $perlvars_h, $global_sym,
119 $pp_sym, $globvar_sym, $perlio_sym) {
124 unless ($PLATFORM eq 'win32' || $PLATFORM eq 'wince' || $PLATFORM eq 'MacOS' || $PLATFORM eq 'netware') {
125 open(CFG,$config_sh) || die "Cannot open $config_sh: $!\n";
127 if (/^(?:ccflags|optimize)='(.+)'$/) {
129 $define{$1} = 1 while /-D(\w+)/g;
131 if (/^(d_(?:mmap|sigaction))='(.+)'$/) {
134 if ($PLATFORM eq 'os2') {
135 $CONFIG_ARGS = $1 if /^config_args='(.+)'$/;
136 $ARCHNAME = $1 if /^archname='(.+)'$/;
137 $PATCHLEVEL = $1 if /^perl_patchlevel='(.+)'$/;
142 if ($PLATFORM eq 'win32' || $PLATFORM eq 'wince') {
143 open(CFG,"<..\\$config_sh") || die "Cannot open ..\\$config_sh: $!\n";
144 if ((join '', <CFG>) =~ /^static_ext='(.*)'$/m) {
150 open(CFG,$config_h) || die "Cannot open $config_h: $!\n";
152 $define{$1} = 1 if /^\s*#\s*define\s+(MYMALLOC)\b/;
153 $define{$1} = 1 if /^\s*#\s*define\s+(MULTIPLICITY)\b/;
154 $define{$1} = 1 if /^\s*#\s*define\s+(PERL_\w+)\b/;
155 $define{$1} = 1 if /^\s*#\s*define\s+(USE_\w+)\b/;
156 $define{$1} = 1 if /^\s*#\s*define\s+(HAS_\w+)\b/;
160 # perl.h logic duplication begins
162 if ($define{PERL_IMPLICIT_SYS}) {
163 $define{PL_OP_SLAB_ALLOC} = 1;
166 if ($define{USE_ITHREADS}) {
167 if (!$define{MULTIPLICITY}) {
168 $define{MULTIPLICITY} = 1;
172 $define{PERL_IMPLICIT_CONTEXT} ||=
173 $define{USE_ITHREADS} ||
174 $define{MULTIPLICITY} ;
176 if ($define{USE_ITHREADS} && $PLATFORM ne 'win32' && $^O ne 'darwin') {
177 $define{USE_REENTRANT_API} = 1;
180 # perl.h logic duplication ends
184 print STDERR "Defines: (" . join(' ', sort keys %define) . ")\n";
186 if ($PLATFORM =~ /^win(?:32|ce)$/) {
187 (my $dll = ($define{PERL_DLL} || "perl511")) =~ s/\.dll$//i;
188 print "LIBRARY $dll\n";
189 # The DESCRIPTION module definition file statement is not supported
191 if ($CCTYPE !~ /^MSVC7/ && $CCTYPE !~ /^MSVC8/ && $CCTYPE !~ /^MSVC9/) {
192 print "DESCRIPTION 'Perl interpreter'\n";
195 if ($define{PERL_IMPLICIT_SYS}) {
196 output_symbol("perl_get_host_info");
197 output_symbol("perl_alloc_override");
199 if ($define{USE_ITHREADS} and $define{PERL_IMPLICIT_SYS}) {
200 output_symbol("perl_clone_host");
203 elsif ($PLATFORM eq 'os2') {
204 if (open my $fh, '<', 'perl5.def') {
206 last if /^\s*EXPORTS\b/;
209 $ordinal{$1} = $2 if /^\s*"(\w+)"\s*(?:=\s*"\w+"\s*)?\@(\d+)\s*$/;
210 # This allows skipping ordinals which were used in older versions
211 $sym_ord = $1 if /^\s*;\s*LAST_ORDINAL\s*=\s*(\d+)\s*$/;
213 $sym_ord < $_ and $sym_ord = $_ for values %ordinal; # Take the max
215 (my $v = $]) =~ s/(\d\.\d\d\d)(\d\d)$/$1_$2/;
216 $v .= '-thread' if $ARCHNAME =~ /-thread/;
217 (my $dll = $define{PERL_DLL}) =~ s/\.dll$//i;
218 $v .= "\@$PATCHLEVEL" if $PATCHLEVEL;
219 my $d = "DESCRIPTION '\@#perl5-porters\@perl.org:$v#\@ Perl interpreter, configured as $CONFIG_ARGS'";
220 $d = substr($d, 0, 249) . "...'" if length $d > 253;
222 LIBRARY '$dll' INITINSTANCE TERMINSTANCE
226 DATA LOADONCALL NONSHARED MULTIPLE
230 elsif ($PLATFORM eq 'aix') {
231 my $OSVER = `uname -v`;
233 my $OSREL = `uname -r`;
235 if ($OSVER > 4 || ($OSVER == 4 && $OSREL >= 3)) {
241 elsif ($PLATFORM eq 'netware') {
242 if ($FILETYPE eq 'def') {
243 print "LIBRARY perl511\n";
244 print "DESCRIPTION 'Perl interpreter for NetWare'\n";
247 if ($define{PERL_IMPLICIT_SYS}) {
248 output_symbol("perl_get_host_info");
249 output_symbol("perl_alloc_override");
250 output_symbol("perl_clone_host");
259 foreach my $symbol (@$list) {
266 foreach my $symbol (@$list) {
267 my $skipsym = $symbol;
269 if ($define{MULTIPLICITY}) {
270 $skipsym =~ s/^Perl_[GIT](\w+)_ptr$/PL_$1/;
272 emit_symbol($symbol) unless exists $skip{$skipsym};
276 if ($PLATFORM eq 'win32') {
300 Perl_init_thread_intern
334 if ($PLATFORM eq 'wince') {
349 PL_collation_standard
377 Perl_init_thread_intern
404 elsif ($PLATFORM eq 'aix') {
423 Perl_sys_intern_clear
435 if $define{'HAS_SIGNBIT'};
440 elsif ($PLATFORM eq 'os2') {
485 XS_Cwd_extLibpath_set
489 XS_Cwd_sys_is_absolute
490 XS_Cwd_sys_is_relative
492 XS_DynaLoader_mod2fname
493 XS_File__Copy_syscopy
497 Perl_Process_Messages
508 emit_symbols([qw(os2_cond_wait
513 if $define{'USE_5005THREADS'} or $define{'USE_ITHREADS'};
515 elsif ($PLATFORM eq 'MacOS') {
539 Perl_sys_intern_clear
543 elsif ($PLATFORM eq 'netware') {
567 Perl_init_thread_intern
592 Perl_sys_intern_clear
600 Perl_PerlIO_setlinebuf
601 Perl_PerlIO_set_ptrcnt
607 Perl_PerlIO_get_bufsiz
620 unless ($define{'DEBUGGING'}) {
636 if ($define{'PERL_IMPLICIT_CONTEXT'}) {
642 if ($define{'PERL_IMPLICIT_SYS'}) {
663 unless ($define{'PERL_OLD_COPY_ON_WRITE'}) {
669 unless ($define{'USE_REENTRANT_API'}) {
675 if ($define{'MYMALLOC'}) {
684 if ($define{'USE_ITHREADS'}) {
701 Perl_malloc_good_size
707 if ($define{'PERL_USE_SAFE_PUTENV'}) {
713 unless ($define{'USE_ITHREADS'}) {
719 # USE_5005THREADS symbols. Kept as reference for easier removal
738 Perl_new_struct_thread
739 Perl_per_thread_magicals
747 unless ($define{'USE_ITHREADS'}) {
753 PL_sharedsv_space_mutex
780 Perl_sharedsv_thrcnt_dec
781 Perl_sharedsv_thrcnt_inc
783 Perl_stashpv_hvname_match
784 Perl_regdupe_internal
789 unless ($define{'PERL_IMPLICIT_CONTEXT'}) {
800 Perl_load_module_nocontext
803 Perl_warner_nocontext
804 Perl_newSVpvf_nocontext
805 Perl_sv_catpvf_nocontext
806 Perl_sv_setpvf_nocontext
807 Perl_sv_catpvf_mg_nocontext
808 Perl_sv_setpvf_mg_nocontext
814 unless ($define{'PERL_IMPLICIT_SYS'}) {
821 unless ($define{'FAKE_THREADS'}) {
822 skip_symbols [qw(PL_curthr)];
825 unless ($define{'PL_OP_SLAB_ALLOC'}) {
835 unless ($define{'PERL_DEBUG_READONLY_OPS'}) {
842 unless ($define{'THREADS_HAVE_PIDS'}) {
843 skip_symbols [qw(PL_ppid)];
846 unless ($define{'PERL_NEED_APPCTX'}) {
852 unless ($define{'PERL_NEED_TIMESBASE'}) {
858 unless ($define{'DEBUG_LEAKING_SCALARS'}) {
864 unless ($define{'DEBUG_LEAKING_SCALARS_FORK_DUMP'}) {
869 unless ($define{'PERL_DONT_CREATE_GVSV'}) {
874 if ($define{'SPRINTF_RETURNS_STRLEN'}) {
879 unless ($define{'PERL_USES_PL_PIDSTATUS'}) {
886 unless ($define{'PERL_TRACK_MEMPOOL'}) {
888 PL_memory_debug_header
892 if ($define{'PERL_MAD'}) {
918 Perl_xmldump_packsubs
932 unless ($define{'MULTIPLICITY'}) {
935 PL_interp_size_5_10_0
939 unless ($define{'PERL_GLOBAL_STRUCT'}) {
941 PL_global_struct_size
945 unless ($define{'PERL_GLOBAL_STRUCT_PRIVATE'}) {
952 unless ($define{'d_mmap'}) {
958 if ($define{'d_sigaction'}) {
965 # VMS does its own thing for these symbols.
966 skip_symbols [qw(PL_sig_handlers_initted
973 my $proc = shift || sub { "PL_$_[2]" };
974 open(VARS,$file) || die "Cannot open $file: $!\n";
977 # All symbols have a Perl_ prefix because that's what embed.h
978 # sticks in front of them. The A?I?S?C? is strictly speaking
980 push(@syms, &$proc($1,$2,$3)) if (/\bPERLVAR(A?I?S?C?)\(([IGT])(\w+)/);
986 if ($define{'PERL_GLOBAL_STRUCT'}) {
987 my $global = readvar($perlvars_h);
988 skip_symbols $global;
989 emit_symbol('Perl_GetVars');
990 emit_symbols [qw(PL_Vars PL_VarsPtr)] unless $CCTYPE eq 'GCC';
992 skip_symbols [qw(Perl_init_global_struct Perl_free_global_struct)];
995 # functions from *.sym files
997 my @syms = ($global_sym, $globvar_sym); # $pp_sym is not part of the API
999 # Symbols that are the public face of the PerlIO layers implementation
1000 # These are in _addition to_ the public face of the abstraction
1001 # and need to be exported to allow XS modules to implement layers
1002 my @layer_syms = qw(
1010 PerlIOBase_noop_fail
1015 PerlIOBase_setlinebuf
1030 PerlIOBuf_set_ptrcnt
1052 Perl_PerlIO_clearerr
1054 Perl_PerlIO_context_layers
1060 Perl_PerlIO_get_base
1061 Perl_PerlIO_get_bufsiz
1067 Perl_PerlIO_set_ptrcnt
1068 Perl_PerlIO_setlinebuf
1076 if ($PLATFORM eq 'netware') {
1077 push(@layer_syms,'PL_def_layerlist','PL_known_layers','PL_perlio');
1080 if ($define{'USE_PERLIO'}) {
1081 # Export the symols that make up the PerlIO abstraction, regardless
1082 # of its implementation - read from a file
1083 push @syms, $perlio_sym;
1085 # This part is then dependent on how the abstraction is implemented
1086 if ($define{'USE_SFIO'}) {
1087 # Old legacy non-stdio "PerlIO"
1088 skip_symbols \@layer_syms;
1089 skip_symbols [qw(perlsio_binmode)];
1090 # SFIO defines most of the PerlIO routines as macros
1091 # So undo most of what $perlio_sym has just done - d'oh !
1092 # Perhaps it would be better to list the ones which do exist
1137 Perl_PerlIO_clearerr
1144 Perl_PerlIO_get_base
1145 Perl_PerlIO_get_bufsiz
1151 Perl_PerlIO_set_ptrcnt
1152 Perl_PerlIO_setlinebuf
1165 # PerlIO with layers - export implementation
1166 emit_symbols \@layer_syms;
1167 emit_symbols [qw(perlsio_binmode)];
1169 if ($define{'USE_ITHREADS'}) {
1181 # Skip the PerlIO layer symbols - although
1182 # nothing should have exported them anyway.
1183 skip_symbols \@layer_syms;
1191 PL_perlio_fd_refcnt_size
1194 # Also do NOT add abstraction symbols from $perlio_sym
1195 # abstraction is done as #define to stdio
1196 # Remaining remnants that _may_ be functions
1197 # are handled in <DATA>
1200 for my $syms (@syms) {
1201 open (GLOBAL, "<$syms") || die "failed to open $syms: $!\n";
1203 next if (!/^[A-Za-z]/);
1204 # Functions have a Perl_ prefix
1205 # Variables have a PL_ prefix
1207 my $symbol = ($syms =~ /var\.sym$/i ? "PL_" : "");
1209 emit_symbol($symbol) unless exists $skip{$symbol};
1216 if ($define{'MULTIPLICITY'}) {
1217 for my $f ($perlvars_h, $intrpvar_h) {
1218 my $glob = readvar($f, sub { "Perl_" . $_[1] . $_[2] . "_ptr" });
1221 # XXX AIX seems to want the perlvars.h symbols, for some reason
1222 if ($PLATFORM eq 'aix' or $PLATFORM eq 'os2') { # OS/2 needs PL_thr_key
1223 my $glob = readvar($perlvars_h);
1228 unless ($define{'PERL_GLOBAL_STRUCT'}) {
1229 my $glob = readvar($perlvars_h);
1232 unless ($define{'MULTIPLICITY'}) {
1233 my $glob = readvar($intrpvar_h);
1241 return if $symbol !~ /^[A-Za-z_]/;
1242 return if $symbol =~ /^\#/;
1245 return if exists $skip{$symbol};
1246 emit_symbol($symbol);
1253 if ($PLATFORM =~ /^win(?:32|ce)$/) {
1254 foreach my $symbol (qw(
1316 win32_getprotobyname
1317 win32_getprotobynumber
1346 win32_open_osfhandle
1417 try_symbol($symbol);
1419 if ($CCTYPE eq "BORLAND") {
1420 try_symbol('_matherr');
1423 elsif ($PLATFORM eq 'os2') {
1424 my (%mapped, @missing);
1425 open MAP, 'miniperl.map' or die 'Cannot read miniperl.map';
1426 /^\s*[\da-f:]+\s+(\w+)/i and $mapped{$1}++ foreach <MAP>;
1427 close MAP or die 'Cannot close miniperl.map';
1429 @missing = grep { !exists $mapped{$_} }
1431 @missing = grep { !exists $exportperlmalloc{$_} } @missing;
1432 delete $export{$_} foreach @missing;
1434 elsif ($PLATFORM eq 'MacOS') {
1435 open MACSYMS, 'macperl.sym' or die 'Cannot read macperl.sym';
1443 elsif ($PLATFORM eq 'netware') {
1444 foreach my $symbol (qw(
1571 fnInsertHashListAddrs
1582 try_symbol($symbol);
1586 # records of type boot_module for statically linked modules (except Dynaloader)
1587 $static_ext =~ s/\//__/g;
1588 $static_ext =~ s/\bDynaLoader\b//;
1589 my @stat_mods = map {"boot_$_"} grep {/\S/} split /\s+/, $static_ext;
1590 foreach my $symbol (@stat_mods)
1592 try_symbol($symbol);
1595 try_symbol("init_Win32CORE") if $static_ext =~ /\bWin32CORE\b/;
1597 # Now all symbols should be defined because
1598 # next we are going to output them.
1600 foreach my $symbol (sort keys %export) {
1601 output_symbol($symbol);
1604 if ($PLATFORM eq 'os2') {
1609 Perl_OS2_handler_install
1611 ; LAST_ORDINAL=$sym_ord
1618 $export{$symbol} = 1;
1623 if ($PLATFORM =~ /^win(?:32|ce)$/) {
1624 $symbol = "_$symbol" if $CCTYPE eq 'BORLAND';
1625 print "\t$symbol\n";
1626 # XXX: binary compatibility between compilers is an exercise
1627 # in frustration :-(
1628 # if ($CCTYPE eq "BORLAND") {
1629 # # workaround Borland quirk by exporting both the straight
1630 # # name and a name with leading underscore. Note the
1631 # # alias *must* come after the symbol itself, if both
1632 # # are to be exported. (Linker bug?)
1633 # print "\t_$symbol\n";
1634 # print "\t$symbol = _$symbol\n";
1636 # elsif ($CCTYPE eq 'GCC') {
1637 # # Symbols have leading _ whole process is $%@"% slow
1638 # # so skip aliases for now
1639 # nprint "\t$symbol\n";
1642 # # for binary coexistence, export both the symbol and
1643 # # alias with leading underscore
1644 # print "\t$symbol\n";
1645 # print "\t_$symbol = $symbol\n";
1648 elsif ($PLATFORM eq 'os2') {
1649 printf qq( %-31s \@%s\n),
1650 qq("$symbol"), $ordinal{$symbol} || ++$sym_ord;
1651 printf qq( %-31s \@%s\n),
1652 qq("$exportperlmalloc{$symbol}" = "$symbol"),
1653 $ordinal{$exportperlmalloc{$symbol}} || ++$sym_ord
1654 if $exportperlmalloc and exists $exportperlmalloc{$symbol};
1656 elsif ($PLATFORM eq 'aix' || $PLATFORM eq 'MacOS') {
1659 elsif ($PLATFORM eq 'netware') {
1660 print "\t$symbol,\n";
1666 # Oddities from PerlIO