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'}) {
642 if ($define{'PERL_IMPLICIT_CONTEXT'}) {
648 if ($define{'PERL_IMPLICIT_SYS'}) {
669 unless ($define{'PERL_OLD_COPY_ON_WRITE'}) {
675 unless ($define{'USE_REENTRANT_API'}) {
681 if ($define{'MYMALLOC'}) {
690 if ($define{'USE_ITHREADS'}) {
707 Perl_malloc_good_size
713 if ($define{'PERL_USE_SAFE_PUTENV'}) {
719 unless ($define{'USE_ITHREADS'}) {
725 # USE_5005THREADS symbols. Kept as reference for easier removal
744 Perl_new_struct_thread
745 Perl_per_thread_magicals
753 unless ($define{'USE_ITHREADS'}) {
759 PL_sharedsv_space_mutex
786 Perl_sharedsv_thrcnt_dec
787 Perl_sharedsv_thrcnt_inc
789 Perl_stashpv_hvname_match
790 Perl_regdupe_internal
795 unless ($define{'PERL_IMPLICIT_CONTEXT'}) {
806 Perl_load_module_nocontext
809 Perl_warner_nocontext
810 Perl_newSVpvf_nocontext
811 Perl_sv_catpvf_nocontext
812 Perl_sv_setpvf_nocontext
813 Perl_sv_catpvf_mg_nocontext
814 Perl_sv_setpvf_mg_nocontext
820 unless ($define{'PERL_IMPLICIT_SYS'}) {
827 unless ($define{'FAKE_THREADS'}) {
828 skip_symbols [qw(PL_curthr)];
831 unless ($define{'PL_OP_SLAB_ALLOC'}) {
841 unless ($define{'PERL_DEBUG_READONLY_OPS'}) {
848 unless ($define{'THREADS_HAVE_PIDS'}) {
849 skip_symbols [qw(PL_ppid)];
852 unless ($define{'PERL_NEED_APPCTX'}) {
858 unless ($define{'PERL_NEED_TIMESBASE'}) {
864 unless ($define{'DEBUG_LEAKING_SCALARS'}) {
870 unless ($define{'DEBUG_LEAKING_SCALARS_FORK_DUMP'}) {
875 unless ($define{'PERL_DONT_CREATE_GVSV'}) {
880 if ($define{'SPRINTF_RETURNS_STRLEN'}) {
885 unless ($define{'PERL_USES_PL_PIDSTATUS'}) {
892 unless ($define{'PERL_TRACK_MEMPOOL'}) {
894 PL_memory_debug_header
898 if ($define{'PERL_MAD'}) {
924 Perl_xmldump_packsubs
938 unless ($define{'MULTIPLICITY'}) {
941 PL_interp_size_5_10_0
945 unless ($define{'PERL_GLOBAL_STRUCT'}) {
947 PL_global_struct_size
951 unless ($define{'PERL_GLOBAL_STRUCT_PRIVATE'}) {
958 unless ($define{'d_mmap'}) {
964 if ($define{'d_sigaction'}) {
971 # VMS does its own thing for these symbols.
972 skip_symbols [qw(PL_sig_handlers_initted
979 my $proc = shift || sub { "PL_$_[2]" };
980 open(VARS,$file) || die "Cannot open $file: $!\n";
983 # All symbols have a Perl_ prefix because that's what embed.h
984 # sticks in front of them. The A?I?S?C? is strictly speaking
986 push(@syms, &$proc($1,$2,$3)) if (/\bPERLVAR(A?I?S?C?)\(([IGT])(\w+)/);
992 if ($define{'PERL_GLOBAL_STRUCT'}) {
993 my $global = readvar($perlvars_h);
994 skip_symbols $global;
995 emit_symbol('Perl_GetVars');
996 emit_symbols [qw(PL_Vars PL_VarsPtr)] unless $CCTYPE eq 'GCC';
998 skip_symbols [qw(Perl_init_global_struct Perl_free_global_struct)];
1001 # functions from *.sym files
1003 my @syms = ($global_sym, $globvar_sym); # $pp_sym is not part of the API
1005 # Symbols that are the public face of the PerlIO layers implementation
1006 # These are in _addition to_ the public face of the abstraction
1007 # and need to be exported to allow XS modules to implement layers
1008 my @layer_syms = qw(
1016 PerlIOBase_noop_fail
1021 PerlIOBase_setlinebuf
1036 PerlIOBuf_set_ptrcnt
1058 Perl_PerlIO_clearerr
1060 Perl_PerlIO_context_layers
1066 Perl_PerlIO_get_base
1067 Perl_PerlIO_get_bufsiz
1073 Perl_PerlIO_set_ptrcnt
1074 Perl_PerlIO_setlinebuf
1082 if ($PLATFORM eq 'netware') {
1083 push(@layer_syms,'PL_def_layerlist','PL_known_layers','PL_perlio');
1086 if ($define{'USE_PERLIO'}) {
1087 # Export the symols that make up the PerlIO abstraction, regardless
1088 # of its implementation - read from a file
1089 push @syms, $perlio_sym;
1091 # This part is then dependent on how the abstraction is implemented
1092 if ($define{'USE_SFIO'}) {
1093 # Old legacy non-stdio "PerlIO"
1094 skip_symbols \@layer_syms;
1095 skip_symbols [qw(perlsio_binmode)];
1096 # SFIO defines most of the PerlIO routines as macros
1097 # So undo most of what $perlio_sym has just done - d'oh !
1098 # Perhaps it would be better to list the ones which do exist
1143 Perl_PerlIO_clearerr
1150 Perl_PerlIO_get_base
1151 Perl_PerlIO_get_bufsiz
1157 Perl_PerlIO_set_ptrcnt
1158 Perl_PerlIO_setlinebuf
1171 # PerlIO with layers - export implementation
1172 emit_symbols \@layer_syms;
1173 emit_symbols [qw(perlsio_binmode)];
1175 if ($define{'USE_ITHREADS'}) {
1187 # Skip the PerlIO layer symbols - although
1188 # nothing should have exported them anyway.
1189 skip_symbols \@layer_syms;
1197 PL_perlio_fd_refcnt_size
1200 # Also do NOT add abstraction symbols from $perlio_sym
1201 # abstraction is done as #define to stdio
1202 # Remaining remnants that _may_ be functions
1203 # are handled in <DATA>
1206 for my $syms (@syms) {
1207 open (GLOBAL, "<$syms") || die "failed to open $syms: $!\n";
1209 next if (!/^[A-Za-z]/);
1210 # Functions have a Perl_ prefix
1211 # Variables have a PL_ prefix
1213 my $symbol = ($syms =~ /var\.sym$/i ? "PL_" : "");
1215 emit_symbol($symbol) unless exists $skip{$symbol};
1222 if ($define{'MULTIPLICITY'}) {
1223 for my $f ($perlvars_h, $intrpvar_h) {
1224 my $glob = readvar($f, sub { "Perl_" . $_[1] . $_[2] . "_ptr" });
1227 # XXX AIX seems to want the perlvars.h symbols, for some reason
1228 if ($PLATFORM eq 'aix' or $PLATFORM eq 'os2') { # OS/2 needs PL_thr_key
1229 my $glob = readvar($perlvars_h);
1234 unless ($define{'PERL_GLOBAL_STRUCT'}) {
1235 my $glob = readvar($perlvars_h);
1238 unless ($define{'MULTIPLICITY'}) {
1239 my $glob = readvar($intrpvar_h);
1247 return if $symbol !~ /^[A-Za-z_]/;
1248 return if $symbol =~ /^\#/;
1251 return if exists $skip{$symbol};
1252 emit_symbol($symbol);
1259 if ($PLATFORM =~ /^win(?:32|ce)$/) {
1260 foreach my $symbol (qw(
1322 win32_getprotobyname
1323 win32_getprotobynumber
1352 win32_open_osfhandle
1423 try_symbol($symbol);
1425 if ($CCTYPE eq "BORLAND") {
1426 try_symbol('_matherr');
1429 elsif ($PLATFORM eq 'os2') {
1430 my (%mapped, @missing);
1431 open MAP, 'miniperl.map' or die 'Cannot read miniperl.map';
1432 /^\s*[\da-f:]+\s+(\w+)/i and $mapped{$1}++ foreach <MAP>;
1433 close MAP or die 'Cannot close miniperl.map';
1435 @missing = grep { !exists $mapped{$_} }
1437 @missing = grep { !exists $exportperlmalloc{$_} } @missing;
1438 delete $export{$_} foreach @missing;
1440 elsif ($PLATFORM eq 'MacOS') {
1441 open MACSYMS, 'macperl.sym' or die 'Cannot read macperl.sym';
1449 elsif ($PLATFORM eq 'netware') {
1450 foreach my $symbol (qw(
1577 fnInsertHashListAddrs
1588 try_symbol($symbol);
1592 # records of type boot_module for statically linked modules (except Dynaloader)
1593 $static_ext =~ s/\//__/g;
1594 $static_ext =~ s/\bDynaLoader\b//;
1595 my @stat_mods = map {"boot_$_"} grep {/\S/} split /\s+/, $static_ext;
1596 foreach my $symbol (@stat_mods)
1598 try_symbol($symbol);
1601 try_symbol("init_Win32CORE") if $static_ext =~ /\bWin32CORE\b/;
1603 # Now all symbols should be defined because
1604 # next we are going to output them.
1606 foreach my $symbol (sort keys %export) {
1607 output_symbol($symbol);
1610 if ($PLATFORM eq 'os2') {
1615 Perl_OS2_handler_install
1617 ; LAST_ORDINAL=$sym_ord
1624 $export{$symbol} = 1;
1629 if ($PLATFORM =~ /^win(?:32|ce)$/) {
1630 $symbol = "_$symbol" if $CCTYPE eq 'BORLAND';
1631 print "\t$symbol\n";
1632 # XXX: binary compatibility between compilers is an exercise
1633 # in frustration :-(
1634 # if ($CCTYPE eq "BORLAND") {
1635 # # workaround Borland quirk by exporting both the straight
1636 # # name and a name with leading underscore. Note the
1637 # # alias *must* come after the symbol itself, if both
1638 # # are to be exported. (Linker bug?)
1639 # print "\t_$symbol\n";
1640 # print "\t$symbol = _$symbol\n";
1642 # elsif ($CCTYPE eq 'GCC') {
1643 # # Symbols have leading _ whole process is $%@"% slow
1644 # # so skip aliases for now
1645 # nprint "\t$symbol\n";
1648 # # for binary coexistence, export both the symbol and
1649 # # alias with leading underscore
1650 # print "\t$symbol\n";
1651 # print "\t_$symbol = $symbol\n";
1654 elsif ($PLATFORM eq 'os2') {
1655 printf qq( %-31s \@%s\n),
1656 qq("$symbol"), $ordinal{$symbol} || ++$sym_ord;
1657 printf qq( %-31s \@%s\n),
1658 qq("$exportperlmalloc{$symbol}" = "$symbol"),
1659 $ordinal{$exportperlmalloc{$symbol}} || ++$sym_ord
1660 if $exportperlmalloc and exists $exportperlmalloc{$symbol};
1662 elsif ($PLATFORM eq 'aix' || $PLATFORM eq 'MacOS') {
1665 elsif ($PLATFORM eq 'netware') {
1666 print "\t$symbol,\n";
1672 # Oddities from PerlIO