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";
83 or die "Couldn't run [$cmd]: $!";
84 my($options) = $config =~ /^ Compile-time options: (.*?)\n^ \S/ms;
85 $options =~ s/\s+/ /g;
86 print STDERR "Options: ($options)\n";
87 foreach (split /\s+/, $options) {
92 my %exportperlmalloc =
94 Perl_malloc => "malloc",
96 Perl_realloc => "realloc",
97 Perl_calloc => "calloc",
100 my $exportperlmalloc = $PLATFORM eq 'os2';
102 my $config_sh = "config.sh";
103 my $config_h = "config.h";
104 my $intrpvar_h = "intrpvar.h";
105 my $perlvars_h = "perlvars.h";
106 my $global_sym = "global.sym";
107 my $pp_sym = "pp.sym";
108 my $globvar_sym = "globvar.sym";
109 my $perlio_sym = "perlio.sym";
112 if ($PLATFORM eq 'aix') {
115 elsif ($PLATFORM =~ /^win(?:32|ce)$/ || $PLATFORM eq 'netware') {
116 $CCTYPE = "MSVC" unless defined $CCTYPE;
117 foreach ($intrpvar_h, $perlvars_h, $global_sym,
118 $pp_sym, $globvar_sym, $perlio_sym) {
122 elsif ($PLATFORM eq 'MacOS') {
123 foreach ($intrpvar_h, $perlvars_h, $global_sym,
124 $pp_sym, $globvar_sym, $perlio_sym) {
129 unless ($PLATFORM eq 'win32' || $PLATFORM eq 'wince' || $PLATFORM eq 'MacOS' || $PLATFORM eq 'netware') {
130 open(CFG,$config_sh) || die "Cannot open $config_sh: $!\n";
132 if (/^(?:ccflags|optimize)='(.+)'$/) {
134 $define{$1} = 1 while /-D(\w+)/g;
136 if (/^(d_(?:mmap|sigaction))='(.+)'$/) {
139 if ($PLATFORM eq 'os2') {
140 $CONFIG_ARGS = $1 if /^config_args='(.+)'$/;
141 $ARCHNAME = $1 if /^archname='(.+)'$/;
142 $PATCHLEVEL = $1 if /^perl_patchlevel='(.+)'$/;
147 if ($PLATFORM eq 'win32' || $PLATFORM eq 'wince') {
148 open(CFG,"<..\\$config_sh") || die "Cannot open ..\\$config_sh: $!\n";
149 if ((join '', <CFG>) =~ /^static_ext='(.*)'$/m) {
155 open(CFG,$config_h) || die "Cannot open $config_h: $!\n";
157 $define{$1} = 1 if /^\s*#\s*define\s+(MYMALLOC)\b/;
158 $define{$1} = 1 if /^\s*#\s*define\s+(MULTIPLICITY)\b/;
159 $define{$1} = 1 if /^\s*#\s*define\s+(PERL_\w+)\b/;
160 $define{$1} = 1 if /^\s*#\s*define\s+(USE_\w+)\b/;
161 $define{$1} = 1 if /^\s*#\s*define\s+(HAS_\w+)\b/;
165 # perl.h logic duplication begins
167 if ($define{PERL_IMPLICIT_SYS}) {
168 $define{PL_OP_SLAB_ALLOC} = 1;
171 if ($define{USE_ITHREADS}) {
172 if (!$define{MULTIPLICITY}) {
173 $define{MULTIPLICITY} = 1;
177 $define{PERL_IMPLICIT_CONTEXT} ||=
178 $define{USE_ITHREADS} ||
179 $define{MULTIPLICITY} ;
181 if ($define{USE_ITHREADS} && $PLATFORM ne 'win32' && $^O ne 'darwin') {
182 $define{USE_REENTRANT_API} = 1;
185 # perl.h logic duplication ends
189 print STDERR "Defines: (" . join(' ', sort keys %define) . ")\n";
191 if ($PLATFORM =~ /^win(?:32|ce)$/) {
192 (my $dll = ($define{PERL_DLL} || "perl511")) =~ s/\.dll$//i;
193 print "LIBRARY $dll\n";
194 # The DESCRIPTION module definition file statement is not supported
196 if ($CCTYPE !~ /^MSVC7/ && $CCTYPE !~ /^MSVC8/ && $CCTYPE !~ /^MSVC9/) {
197 print "DESCRIPTION 'Perl interpreter'\n";
200 if ($define{PERL_IMPLICIT_SYS}) {
201 output_symbol("perl_get_host_info");
202 output_symbol("perl_alloc_override");
204 if ($define{USE_ITHREADS} and $define{PERL_IMPLICIT_SYS}) {
205 output_symbol("perl_clone_host");
208 elsif ($PLATFORM eq 'os2') {
209 if (open my $fh, '<', 'perl5.def') {
211 last if /^\s*EXPORTS\b/;
214 $ordinal{$1} = $2 if /^\s*"(\w+)"\s*(?:=\s*"\w+"\s*)?\@(\d+)\s*$/;
215 # This allows skipping ordinals which were used in older versions
216 $sym_ord = $1 if /^\s*;\s*LAST_ORDINAL\s*=\s*(\d+)\s*$/;
218 $sym_ord < $_ and $sym_ord = $_ for values %ordinal; # Take the max
220 (my $v = $]) =~ s/(\d\.\d\d\d)(\d\d)$/$1_$2/;
221 $v .= '-thread' if $ARCHNAME =~ /-thread/;
222 (my $dll = $define{PERL_DLL}) =~ s/\.dll$//i;
223 $v .= "\@$PATCHLEVEL" if $PATCHLEVEL;
224 my $d = "DESCRIPTION '\@#perl5-porters\@perl.org:$v#\@ Perl interpreter, configured as $CONFIG_ARGS'";
225 $d = substr($d, 0, 249) . "...'" if length $d > 253;
227 LIBRARY '$dll' INITINSTANCE TERMINSTANCE
231 DATA LOADONCALL NONSHARED MULTIPLE
235 elsif ($PLATFORM eq 'aix') {
236 my $OSVER = `uname -v`;
238 my $OSREL = `uname -r`;
240 if ($OSVER > 4 || ($OSVER == 4 && $OSREL >= 3)) {
246 elsif ($PLATFORM eq 'netware') {
247 if ($FILETYPE eq 'def') {
248 print "LIBRARY perl511\n";
249 print "DESCRIPTION 'Perl interpreter for NetWare'\n";
252 if ($define{PERL_IMPLICIT_SYS}) {
253 output_symbol("perl_get_host_info");
254 output_symbol("perl_alloc_override");
255 output_symbol("perl_clone_host");
264 foreach my $symbol (@$list) {
271 foreach my $symbol (@$list) {
272 my $skipsym = $symbol;
274 if ($define{MULTIPLICITY}) {
275 $skipsym =~ s/^Perl_[GIT](\w+)_ptr$/PL_$1/;
277 emit_symbol($symbol) unless exists $skip{$skipsym};
281 if ($PLATFORM eq 'win32') {
305 Perl_init_thread_intern
339 if ($PLATFORM eq 'wince') {
354 PL_collation_standard
382 Perl_init_thread_intern
409 elsif ($PLATFORM eq 'aix') {
428 Perl_sys_intern_clear
440 if $define{'HAS_SIGNBIT'};
445 elsif ($PLATFORM eq 'os2') {
490 XS_Cwd_extLibpath_set
494 XS_Cwd_sys_is_absolute
495 XS_Cwd_sys_is_relative
497 XS_DynaLoader_mod2fname
498 XS_File__Copy_syscopy
502 Perl_Process_Messages
513 emit_symbols([qw(os2_cond_wait
518 if $define{'USE_5005THREADS'} or $define{'USE_ITHREADS'};
520 elsif ($PLATFORM eq 'MacOS') {
544 Perl_sys_intern_clear
548 elsif ($PLATFORM eq 'netware') {
572 Perl_init_thread_intern
597 Perl_sys_intern_clear
605 Perl_PerlIO_setlinebuf
606 Perl_PerlIO_set_ptrcnt
612 Perl_PerlIO_get_bufsiz
625 unless ($define{'DEBUGGING'}) {
641 if ($define{'PERL_IMPLICIT_CONTEXT'}) {
647 if ($define{'PERL_IMPLICIT_SYS'}) {
668 unless ($define{'PERL_OLD_COPY_ON_WRITE'}) {
674 unless ($define{'USE_REENTRANT_API'}) {
680 if ($define{'MYMALLOC'}) {
689 if ($define{'USE_ITHREADS'}) {
706 Perl_malloc_good_size
712 if ($define{'PERL_USE_SAFE_PUTENV'}) {
718 unless ($define{'USE_ITHREADS'}) {
724 # USE_5005THREADS symbols. Kept as reference for easier removal
743 Perl_new_struct_thread
744 Perl_per_thread_magicals
752 unless ($define{'USE_ITHREADS'}) {
758 PL_sharedsv_space_mutex
785 Perl_sharedsv_thrcnt_dec
786 Perl_sharedsv_thrcnt_inc
788 Perl_stashpv_hvname_match
789 Perl_regdupe_internal
794 unless ($define{'PERL_IMPLICIT_CONTEXT'}) {
805 Perl_load_module_nocontext
808 Perl_warner_nocontext
809 Perl_newSVpvf_nocontext
810 Perl_sv_catpvf_nocontext
811 Perl_sv_setpvf_nocontext
812 Perl_sv_catpvf_mg_nocontext
813 Perl_sv_setpvf_mg_nocontext
819 unless ($define{'PERL_IMPLICIT_SYS'}) {
826 unless ($define{'FAKE_THREADS'}) {
827 skip_symbols [qw(PL_curthr)];
830 unless ($define{'PL_OP_SLAB_ALLOC'}) {
840 unless ($define{'PERL_DEBUG_READONLY_OPS'}) {
847 unless ($define{'THREADS_HAVE_PIDS'}) {
848 skip_symbols [qw(PL_ppid)];
851 unless ($define{'PERL_NEED_APPCTX'}) {
857 unless ($define{'PERL_NEED_TIMESBASE'}) {
863 unless ($define{'DEBUG_LEAKING_SCALARS'}) {
869 unless ($define{'DEBUG_LEAKING_SCALARS_FORK_DUMP'}) {
874 unless ($define{'PERL_DONT_CREATE_GVSV'}) {
879 if ($define{'SPRINTF_RETURNS_STRLEN'}) {
884 unless ($define{'PERL_USES_PL_PIDSTATUS'}) {
891 unless ($define{'PERL_TRACK_MEMPOOL'}) {
893 PL_memory_debug_header
897 if ($define{'PERL_MAD'}) {
923 Perl_xmldump_packsubs
937 unless ($define{'MULTIPLICITY'}) {
940 PL_interp_size_5_10_0
944 unless ($define{'PERL_GLOBAL_STRUCT'}) {
946 PL_global_struct_size
950 unless ($define{'PERL_GLOBAL_STRUCT_PRIVATE'}) {
957 unless ($define{'d_mmap'}) {
963 if ($define{'d_sigaction'}) {
970 # VMS does its own thing for these symbols.
971 skip_symbols [qw(PL_sig_handlers_initted
978 my $proc = shift || sub { "PL_$_[2]" };
979 open(VARS,$file) || die "Cannot open $file: $!\n";
982 # All symbols have a Perl_ prefix because that's what embed.h
983 # sticks in front of them. The A?I?S?C? is strictly speaking
985 push(@syms, &$proc($1,$2,$3)) if (/\bPERLVAR(A?I?S?C?)\(([IGT])(\w+)/);
991 if ($define{'PERL_GLOBAL_STRUCT'}) {
992 my $global = readvar($perlvars_h);
993 skip_symbols $global;
994 emit_symbol('Perl_GetVars');
995 emit_symbols [qw(PL_Vars PL_VarsPtr)] unless $CCTYPE eq 'GCC';
997 skip_symbols [qw(Perl_init_global_struct Perl_free_global_struct)];
1000 # functions from *.sym files
1002 my @syms = ($global_sym, $globvar_sym); # $pp_sym is not part of the API
1004 # Symbols that are the public face of the PerlIO layers implementation
1005 # These are in _addition to_ the public face of the abstraction
1006 # and need to be exported to allow XS modules to implement layers
1007 my @layer_syms = qw(
1015 PerlIOBase_noop_fail
1020 PerlIOBase_setlinebuf
1035 PerlIOBuf_set_ptrcnt
1057 Perl_PerlIO_clearerr
1059 Perl_PerlIO_context_layers
1065 Perl_PerlIO_get_base
1066 Perl_PerlIO_get_bufsiz
1072 Perl_PerlIO_set_ptrcnt
1073 Perl_PerlIO_setlinebuf
1081 if ($PLATFORM eq 'netware') {
1082 push(@layer_syms,'PL_def_layerlist','PL_known_layers','PL_perlio');
1085 if ($define{'USE_PERLIO'}) {
1086 # Export the symols that make up the PerlIO abstraction, regardless
1087 # of its implementation - read from a file
1088 push @syms, $perlio_sym;
1090 # This part is then dependent on how the abstraction is implemented
1091 if ($define{'USE_SFIO'}) {
1092 # Old legacy non-stdio "PerlIO"
1093 skip_symbols \@layer_syms;
1094 skip_symbols [qw(perlsio_binmode)];
1095 # SFIO defines most of the PerlIO routines as macros
1096 # So undo most of what $perlio_sym has just done - d'oh !
1097 # Perhaps it would be better to list the ones which do exist
1142 Perl_PerlIO_clearerr
1149 Perl_PerlIO_get_base
1150 Perl_PerlIO_get_bufsiz
1156 Perl_PerlIO_set_ptrcnt
1157 Perl_PerlIO_setlinebuf
1170 # PerlIO with layers - export implementation
1171 emit_symbols \@layer_syms;
1172 emit_symbols [qw(perlsio_binmode)];
1174 if ($define{'USE_ITHREADS'}) {
1186 # Skip the PerlIO layer symbols - although
1187 # nothing should have exported them anyway.
1188 skip_symbols \@layer_syms;
1196 PL_perlio_fd_refcnt_size
1199 # Also do NOT add abstraction symbols from $perlio_sym
1200 # abstraction is done as #define to stdio
1201 # Remaining remnants that _may_ be functions
1202 # are handled in <DATA>
1205 for my $syms (@syms) {
1206 open (GLOBAL, "<$syms") || die "failed to open $syms: $!\n";
1208 next if (!/^[A-Za-z]/);
1209 # Functions have a Perl_ prefix
1210 # Variables have a PL_ prefix
1212 my $symbol = ($syms =~ /var\.sym$/i ? "PL_" : "");
1214 emit_symbol($symbol) unless exists $skip{$symbol};
1221 if ($define{'MULTIPLICITY'}) {
1222 for my $f ($perlvars_h, $intrpvar_h) {
1223 my $glob = readvar($f, sub { "Perl_" . $_[1] . $_[2] . "_ptr" });
1226 # XXX AIX seems to want the perlvars.h symbols, for some reason
1227 if ($PLATFORM eq 'aix' or $PLATFORM eq 'os2') { # OS/2 needs PL_thr_key
1228 my $glob = readvar($perlvars_h);
1233 unless ($define{'PERL_GLOBAL_STRUCT'}) {
1234 my $glob = readvar($perlvars_h);
1237 unless ($define{'MULTIPLICITY'}) {
1238 my $glob = readvar($intrpvar_h);
1246 return if $symbol !~ /^[A-Za-z_]/;
1247 return if $symbol =~ /^\#/;
1250 return if exists $skip{$symbol};
1251 emit_symbol($symbol);
1258 if ($PLATFORM =~ /^win(?:32|ce)$/) {
1259 foreach my $symbol (qw(
1321 win32_getprotobyname
1322 win32_getprotobynumber
1351 win32_open_osfhandle
1422 try_symbol($symbol);
1424 if ($CCTYPE eq "BORLAND") {
1425 try_symbol('_matherr');
1428 elsif ($PLATFORM eq 'os2') {
1429 my (%mapped, @missing);
1430 open MAP, 'miniperl.map' or die 'Cannot read miniperl.map';
1431 /^\s*[\da-f:]+\s+(\w+)/i and $mapped{$1}++ foreach <MAP>;
1432 close MAP or die 'Cannot close miniperl.map';
1434 @missing = grep { !exists $mapped{$_} }
1436 @missing = grep { !exists $exportperlmalloc{$_} } @missing;
1437 delete $export{$_} foreach @missing;
1439 elsif ($PLATFORM eq 'MacOS') {
1440 open MACSYMS, 'macperl.sym' or die 'Cannot read macperl.sym';
1448 elsif ($PLATFORM eq 'netware') {
1449 foreach my $symbol (qw(
1576 fnInsertHashListAddrs
1587 try_symbol($symbol);
1591 # records of type boot_module for statically linked modules (except Dynaloader)
1592 $static_ext =~ s/\//__/g;
1593 $static_ext =~ s/\bDynaLoader\b//;
1594 my @stat_mods = map {"boot_$_"} grep {/\S/} split /\s+/, $static_ext;
1595 foreach my $symbol (@stat_mods)
1597 try_symbol($symbol);
1600 try_symbol("init_Win32CORE") if $static_ext =~ /\bWin32CORE\b/;
1602 # Now all symbols should be defined because
1603 # next we are going to output them.
1605 foreach my $symbol (sort keys %export) {
1606 output_symbol($symbol);
1609 if ($PLATFORM eq 'os2') {
1614 Perl_OS2_handler_install
1616 ; LAST_ORDINAL=$sym_ord
1623 $export{$symbol} = 1;
1628 if ($PLATFORM =~ /^win(?:32|ce)$/) {
1629 $symbol = "_$symbol" if $CCTYPE eq 'BORLAND';
1630 print "\t$symbol\n";
1631 # XXX: binary compatibility between compilers is an exercise
1632 # in frustration :-(
1633 # if ($CCTYPE eq "BORLAND") {
1634 # # workaround Borland quirk by exporting both the straight
1635 # # name and a name with leading underscore. Note the
1636 # # alias *must* come after the symbol itself, if both
1637 # # are to be exported. (Linker bug?)
1638 # print "\t_$symbol\n";
1639 # print "\t$symbol = _$symbol\n";
1641 # elsif ($CCTYPE eq 'GCC') {
1642 # # Symbols have leading _ whole process is $%@"% slow
1643 # # so skip aliases for now
1644 # nprint "\t$symbol\n";
1647 # # for binary coexistence, export both the symbol and
1648 # # alias with leading underscore
1649 # print "\t$symbol\n";
1650 # print "\t_$symbol = $symbol\n";
1653 elsif ($PLATFORM eq 'os2') {
1654 printf qq( %-31s \@%s\n),
1655 qq("$symbol"), $ordinal{$symbol} || ++$sym_ord;
1656 printf qq( %-31s \@%s\n),
1657 qq("$exportperlmalloc{$symbol}" = "$symbol"),
1658 $ordinal{$exportperlmalloc{$symbol}} || ++$sym_ord
1659 if $exportperlmalloc and exists $exportperlmalloc{$symbol};
1661 elsif ($PLATFORM eq 'aix' || $PLATFORM eq 'MacOS') {
1664 elsif ($PLATFORM eq 'netware') {
1665 print "\t$symbol,\n";
1671 # Oddities from PerlIO