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 global.sym, pp.sym, perlvars.h, intrpvar.h, config.h
10 # On OS/2 reads miniperl.map and the previous version of perl5.def as well
12 BEGIN { unshift @INC, "lib" }
15 use vars qw($PLATFORM $CCTYPE $FILETYPE $CONFIG_ARGS $ARCHNAME $PATCHLEVEL);
17 my (%define, %ordinal);
21 if ($flag =~ s/^CC_FLAGS=/ /) {
22 for my $fflag ($flag =~ /(?:^|\s)-D(\S+)/g) {
23 $fflag .= '=1' unless $fflag =~ /^(\w+)=/;
24 $define{$1} = $2 if $fflag =~ /^(\w+)=(.+)$/;
28 $define{$1} = 1 if ($flag =~ /^-D(\w+)$/);
29 $define{$1} = $2 if ($flag =~ /^-D(\w+)=(.+)$/);
30 $CCTYPE = $1 if ($flag =~ /^CCTYPE=(\w+)$/);
31 $PLATFORM = $1 if ($flag =~ /^PLATFORM=(\w+)$/);
32 if ($PLATFORM eq 'netware') {
33 $FILETYPE = $1 if ($flag =~ /^FILETYPE=(\w+)$/);
37 my @PLATFORM = qw(aix win32 wince os2 MacOS netware);
39 @PLATFORM{@PLATFORM} = ();
41 defined $PLATFORM || die "PLATFORM undefined, must be one of: @PLATFORM\n";
42 exists $PLATFORM{$PLATFORM} || die "PLATFORM must be one of: @PLATFORM\n";
44 if ($PLATFORM eq 'win32' or $PLATFORM eq 'wince' or $PLATFORM eq "aix") {
45 # Add the compile-time options that miniperl was built with to %define.
46 # On Win32 these are not the same options as perl itself will be built
47 # with since miniperl is built with a canned config (one of the win32/
48 # config_H.*) and none of the BUILDOPT's that are set in the makefiles,
49 # but they do include some #define's that are hard-coded in various
50 # source files and header files and don't include any BUILDOPT's that
51 # the user might have chosen to disable because the canned configs are
52 # minimal configs that don't include any of those options.
53 my $opts = ($PLATFORM eq 'wince' ? '-MCross' : ''); # for wince need Cross.pm to get Config.pm
54 my $config = `$^X $opts -Ilib -V`;
55 my($options) = $config =~ /^ Compile-time options: (.*?)\n^ \S/ms;
56 $options =~ s/\s+/ /g;
57 print STDERR "Options: ($options)\n";
58 foreach (split /\s+/, $options) {
63 my %exportperlmalloc =
65 Perl_malloc => "malloc",
67 Perl_realloc => "realloc",
68 Perl_calloc => "calloc",
71 my $exportperlmalloc = $PLATFORM eq 'os2';
73 my $config_sh = "config.sh";
74 my $config_h = "config.h";
75 my $intrpvar_h = "intrpvar.h";
76 my $perlvars_h = "perlvars.h";
77 my $global_sym = "global.sym";
78 my $pp_sym = "pp.sym";
79 my $globvar_sym = "globvar.sym";
80 my $perlio_sym = "perlio.sym";
83 if ($PLATFORM eq 'aix') {
86 elsif ($PLATFORM =~ /^win(?:32|ce)$/ || $PLATFORM eq 'netware') {
87 $CCTYPE = "MSVC" unless defined $CCTYPE;
88 foreach ($intrpvar_h, $perlvars_h, $global_sym,
89 $pp_sym, $globvar_sym, $perlio_sym) {
93 elsif ($PLATFORM eq 'MacOS') {
94 foreach ($intrpvar_h, $perlvars_h, $global_sym,
95 $pp_sym, $globvar_sym, $perlio_sym) {
100 unless ($PLATFORM eq 'win32' || $PLATFORM eq 'wince' || $PLATFORM eq 'MacOS' || $PLATFORM eq 'netware') {
101 open(CFG,$config_sh) || die "Cannot open $config_sh: $!\n";
103 if (/^(?:ccflags|optimize)='(.+)'$/) {
105 $define{$1} = 1 while /-D(\w+)/g;
107 if (/^(d_(?:mmap|sigaction))='(.+)'$/) {
110 if ($PLATFORM eq 'os2') {
111 $CONFIG_ARGS = $1 if /^config_args='(.+)'$/;
112 $ARCHNAME = $1 if /^archname='(.+)'$/;
113 $PATCHLEVEL = $1 if /^perl_patchlevel='(.+)'$/;
118 if ($PLATFORM eq 'win32' || $PLATFORM eq 'wince') {
119 open(CFG,"<..\\$config_sh") || die "Cannot open ..\\$config_sh: $!\n";
120 if ((join '', <CFG>) =~ /^static_ext='(.*)'$/m) {
126 open(CFG,$config_h) || die "Cannot open $config_h: $!\n";
128 $define{$1} = 1 if /^\s*#\s*define\s+(MYMALLOC)\b/;
129 $define{$1} = 1 if /^\s*#\s*define\s+(MULTIPLICITY)\b/;
130 $define{$1} = 1 if /^\s*#\s*define\s+(PERL_\w+)\b/;
131 $define{$1} = 1 if /^\s*#\s*define\s+(USE_\w+)\b/;
135 # perl.h logic duplication begins
137 if ($define{PERL_IMPLICIT_SYS}) {
138 $define{PL_OP_SLAB_ALLOC} = 1;
141 if ($define{USE_ITHREADS}) {
142 if (!$define{MULTIPLICITY}) {
143 $define{MULTIPLICITY} = 1;
147 $define{PERL_IMPLICIT_CONTEXT} ||=
148 $define{USE_ITHREADS} ||
149 $define{MULTIPLICITY} ;
151 if ($define{USE_ITHREADS} && $PLATFORM ne 'win32' && $^O ne 'darwin') {
152 $define{USE_REENTRANT_API} = 1;
155 # perl.h logic duplication ends
159 print STDERR "Defines: (" . join(' ', sort keys %define) . ")\n";
161 if ($PLATFORM =~ /^win(?:32|ce)$/) {
162 (my $dll = ($define{PERL_DLL} || "perl511")) =~ s/\.dll$//i;
163 print "LIBRARY $dll\n";
164 # The DESCRIPTION module definition file statement is not supported
166 if ($CCTYPE !~ /^MSVC7/ && $CCTYPE !~ /^MSVC8/ && $CCTYPE !~ /^MSVC9/) {
167 print "DESCRIPTION 'Perl interpreter'\n";
170 if ($define{PERL_IMPLICIT_SYS}) {
171 output_symbol("perl_get_host_info");
172 output_symbol("perl_alloc_override");
174 if ($define{USE_ITHREADS} and $define{PERL_IMPLICIT_SYS}) {
175 output_symbol("perl_clone_host");
178 elsif ($PLATFORM eq 'os2') {
179 if (open my $fh, '<', 'perl5.def') {
181 last if /^\s*EXPORTS\b/;
184 $ordinal{$1} = $2 if /^\s*"(\w+)"\s*(?:=\s*"\w+"\s*)?\@(\d+)\s*$/;
185 # This allows skipping ordinals which were used in older versions
186 $sym_ord = $1 if /^\s*;\s*LAST_ORDINAL\s*=\s*(\d+)\s*$/;
188 $sym_ord < $_ and $sym_ord = $_ for values %ordinal; # Take the max
190 (my $v = $]) =~ s/(\d\.\d\d\d)(\d\d)$/$1_$2/;
191 $v .= '-thread' if $ARCHNAME =~ /-thread/;
192 (my $dll = $define{PERL_DLL}) =~ s/\.dll$//i;
193 $v .= "\@$PATCHLEVEL" if $PATCHLEVEL;
194 my $d = "DESCRIPTION '\@#perl5-porters\@perl.org:$v#\@ Perl interpreter, configured as $CONFIG_ARGS'";
195 $d = substr($d, 0, 249) . "...'" if length $d > 253;
197 LIBRARY '$dll' INITINSTANCE TERMINSTANCE
201 DATA LOADONCALL NONSHARED MULTIPLE
205 elsif ($PLATFORM eq 'aix') {
206 my $OSVER = `uname -v`;
208 my $OSREL = `uname -r`;
210 if ($OSVER > 4 || ($OSVER == 4 && $OSREL >= 3)) {
216 elsif ($PLATFORM eq 'netware') {
217 if ($FILETYPE eq 'def') {
218 print "LIBRARY perl511\n";
219 print "DESCRIPTION 'Perl interpreter for NetWare'\n";
222 if ($define{PERL_IMPLICIT_SYS}) {
223 output_symbol("perl_get_host_info");
224 output_symbol("perl_alloc_override");
225 output_symbol("perl_clone_host");
234 foreach my $symbol (@$list) {
241 foreach my $symbol (@$list) {
242 my $skipsym = $symbol;
244 if ($define{MULTIPLICITY}) {
245 $skipsym =~ s/^Perl_[GIT](\w+)_ptr$/PL_$1/;
247 emit_symbol($symbol) unless exists $skip{$skipsym};
251 if ($PLATFORM eq 'win32') {
275 Perl_init_thread_intern
309 if ($PLATFORM eq 'wince') {
324 PL_collation_standard
352 Perl_init_thread_intern
379 elsif ($PLATFORM eq 'aix') {
398 Perl_sys_intern_clear
408 elsif ($PLATFORM eq 'os2') {
453 XS_Cwd_extLibpath_set
457 XS_Cwd_sys_is_absolute
458 XS_Cwd_sys_is_relative
460 XS_DynaLoader_mod2fname
461 XS_File__Copy_syscopy
465 Perl_Process_Messages
476 emit_symbols([qw(os2_cond_wait
481 if $define{'USE_5005THREADS'} or $define{'USE_ITHREADS'};
483 elsif ($PLATFORM eq 'MacOS') {
507 Perl_sys_intern_clear
511 elsif ($PLATFORM eq 'netware') {
535 Perl_init_thread_intern
560 Perl_sys_intern_clear
568 Perl_PerlIO_setlinebuf
569 Perl_PerlIO_set_ptrcnt
575 Perl_PerlIO_get_bufsiz
588 unless ($define{'DEBUGGING'}) {
605 if ($define{'PERL_IMPLICIT_CONTEXT'}) {
611 if ($define{'PERL_IMPLICIT_SYS'}) {
632 unless ($define{'PERL_OLD_COPY_ON_WRITE'}) {
638 unless ($define{'USE_REENTRANT_API'}) {
644 if ($define{'MYMALLOC'}) {
653 if ($define{'USE_ITHREADS'}) {
670 Perl_malloc_good_size
676 if ($define{'PERL_USE_SAFE_PUTENV'}) {
682 unless ($define{'USE_ITHREADS'}) {
688 # USE_5005THREADS symbols. Kept as reference for easier removal
707 Perl_new_struct_thread
708 Perl_per_thread_magicals
716 unless ($define{'USE_ITHREADS'}) {
722 PL_sharedsv_space_mutex
749 Perl_sharedsv_thrcnt_dec
750 Perl_sharedsv_thrcnt_inc
752 Perl_stashpv_hvname_match
753 Perl_regdupe_internal
758 unless ($define{'PERL_IMPLICIT_CONTEXT'}) {
769 Perl_load_module_nocontext
772 Perl_warner_nocontext
773 Perl_newSVpvf_nocontext
774 Perl_sv_catpvf_nocontext
775 Perl_sv_setpvf_nocontext
776 Perl_sv_catpvf_mg_nocontext
777 Perl_sv_setpvf_mg_nocontext
783 unless ($define{'PERL_IMPLICIT_SYS'}) {
790 unless ($define{'FAKE_THREADS'}) {
791 skip_symbols [qw(PL_curthr)];
794 unless ($define{'PL_OP_SLAB_ALLOC'}) {
804 unless ($define{'PERL_DEBUG_READONLY_OPS'}) {
811 unless ($define{'THREADS_HAVE_PIDS'}) {
812 skip_symbols [qw(PL_ppid)];
815 unless ($define{'PERL_NEED_APPCTX'}) {
821 unless ($define{'PERL_NEED_TIMESBASE'}) {
827 unless ($define{'DEBUG_LEAKING_SCALARS_FORK_DUMP'}) {
832 unless ($define{'PERL_DONT_CREATE_GVSV'}) {
837 if ($define{'SPRINTF_RETURNS_STRLEN'}) {
842 unless ($define{'PERL_USES_PL_PIDSTATUS'}) {
849 unless ($define{'PERL_TRACK_MEMPOOL'}) {
851 PL_memory_debug_header
855 if ($define{'PERL_MAD'}) {
881 Perl_xmldump_packsubs
895 unless ($define{'MULTIPLICITY'}) {
898 PL_interp_size_5_10_0
902 unless ($define{'PERL_GLOBAL_STRUCT'}) {
904 PL_global_struct_size
908 unless ($define{'PERL_GLOBAL_STRUCT_PRIVATE'}) {
915 unless ($define{'d_mmap'}) {
921 if ($define{'d_sigaction'}) {
928 # VMS does its own thing for these symbols.
929 skip_symbols [qw(PL_sig_handlers_initted
936 my $proc = shift || sub { "PL_$_[2]" };
937 open(VARS,$file) || die "Cannot open $file: $!\n";
940 # All symbols have a Perl_ prefix because that's what embed.h
941 # sticks in front of them. The A?I?S?C? is strictly speaking
943 push(@syms, &$proc($1,$2,$3)) if (/\bPERLVAR(A?I?S?C?)\(([IGT])(\w+)/);
949 if ($define{'PERL_GLOBAL_STRUCT'}) {
950 my $global = readvar($perlvars_h);
951 skip_symbols $global;
952 emit_symbol('Perl_GetVars');
953 emit_symbols [qw(PL_Vars PL_VarsPtr)] unless $CCTYPE eq 'GCC';
955 skip_symbols [qw(Perl_init_global_struct Perl_free_global_struct)];
958 # functions from *.sym files
960 my @syms = ($global_sym, $globvar_sym); # $pp_sym is not part of the API
962 # Symbols that are the public face of the PerlIO layers implementation
963 # These are in _addition to_ the public face of the abstraction
964 # and need to be exported to allow XS modules to implement layers
978 PerlIOBase_setlinebuf
1013 Perl_PerlIO_clearerr
1015 Perl_PerlIO_context_layers
1021 Perl_PerlIO_get_base
1022 Perl_PerlIO_get_bufsiz
1028 Perl_PerlIO_set_ptrcnt
1029 Perl_PerlIO_setlinebuf
1037 if ($PLATFORM eq 'netware') {
1038 push(@layer_syms,'PL_def_layerlist','PL_known_layers','PL_perlio');
1041 if ($define{'USE_PERLIO'}) {
1042 # Export the symols that make up the PerlIO abstraction, regardless
1043 # of its implementation - read from a file
1044 push @syms, $perlio_sym;
1046 # This part is then dependent on how the abstraction is implemented
1047 if ($define{'USE_SFIO'}) {
1048 # Old legacy non-stdio "PerlIO"
1049 skip_symbols \@layer_syms;
1050 skip_symbols [qw(perlsio_binmode)];
1051 # SFIO defines most of the PerlIO routines as macros
1052 # So undo most of what $perlio_sym has just done - d'oh !
1053 # Perhaps it would be better to list the ones which do exist
1098 Perl_PerlIO_clearerr
1105 Perl_PerlIO_get_base
1106 Perl_PerlIO_get_bufsiz
1112 Perl_PerlIO_set_ptrcnt
1113 Perl_PerlIO_setlinebuf
1126 # PerlIO with layers - export implementation
1127 emit_symbols \@layer_syms;
1128 emit_symbols [qw(perlsio_binmode)];
1130 if ($define{'USE_ITHREADS'}) {
1142 # Skip the PerlIO layer symbols - although
1143 # nothing should have exported them anyway.
1144 skip_symbols \@layer_syms;
1152 PL_perlio_fd_refcnt_size
1155 # Also do NOT add abstraction symbols from $perlio_sym
1156 # abstraction is done as #define to stdio
1157 # Remaining remnants that _may_ be functions
1158 # are handled in <DATA>
1161 for my $syms (@syms) {
1162 open (GLOBAL, "<$syms") || die "failed to open $syms: $!\n";
1164 next if (!/^[A-Za-z]/);
1165 # Functions have a Perl_ prefix
1166 # Variables have a PL_ prefix
1168 my $symbol = ($syms =~ /var\.sym$/i ? "PL_" : "");
1170 emit_symbol($symbol) unless exists $skip{$symbol};
1177 if ($define{'MULTIPLICITY'}) {
1178 for my $f ($perlvars_h, $intrpvar_h) {
1179 my $glob = readvar($f, sub { "Perl_" . $_[1] . $_[2] . "_ptr" });
1182 # XXX AIX seems to want the perlvars.h symbols, for some reason
1183 if ($PLATFORM eq 'aix' or $PLATFORM eq 'os2') { # OS/2 needs PL_thr_key
1184 my $glob = readvar($perlvars_h);
1189 unless ($define{'PERL_GLOBAL_STRUCT'}) {
1190 my $glob = readvar($perlvars_h);
1193 unless ($define{'MULTIPLICITY'}) {
1194 my $glob = readvar($intrpvar_h);
1202 return if $symbol !~ /^[A-Za-z_]/;
1203 return if $symbol =~ /^\#/;
1206 return if exists $skip{$symbol};
1207 emit_symbol($symbol);
1214 if ($PLATFORM =~ /^win(?:32|ce)$/) {
1215 foreach my $symbol (qw(
1277 win32_getprotobyname
1278 win32_getprotobynumber
1307 win32_open_osfhandle
1378 try_symbol($symbol);
1380 if ($CCTYPE eq "BORLAND") {
1381 try_symbol('_matherr');
1384 elsif ($PLATFORM eq 'os2') {
1385 my (%mapped, @missing);
1386 open MAP, 'miniperl.map' or die 'Cannot read miniperl.map';
1387 /^\s*[\da-f:]+\s+(\w+)/i and $mapped{$1}++ foreach <MAP>;
1388 close MAP or die 'Cannot close miniperl.map';
1390 @missing = grep { !exists $mapped{$_} }
1392 @missing = grep { !exists $exportperlmalloc{$_} } @missing;
1393 delete $export{$_} foreach @missing;
1395 elsif ($PLATFORM eq 'MacOS') {
1396 open MACSYMS, 'macperl.sym' or die 'Cannot read macperl.sym';
1404 elsif ($PLATFORM eq 'netware') {
1405 foreach my $symbol (qw(
1532 fnInsertHashListAddrs
1543 try_symbol($symbol);
1547 # records of type boot_module for statically linked modules (except Dynaloader)
1548 $static_ext =~ s/\//__/g;
1549 $static_ext =~ s/\bDynaLoader\b//;
1550 my @stat_mods = map {"boot_$_"} grep {/\S/} split /\s+/, $static_ext;
1551 foreach my $symbol (@stat_mods)
1553 try_symbol($symbol);
1556 try_symbol("init_Win32CORE") if $static_ext =~ /\bWin32CORE\b/;
1558 # Now all symbols should be defined because
1559 # next we are going to output them.
1561 foreach my $symbol (sort keys %export) {
1562 output_symbol($symbol);
1565 if ($PLATFORM eq 'os2') {
1570 Perl_OS2_handler_install
1572 ; LAST_ORDINAL=$sym_ord
1579 $export{$symbol} = 1;
1584 if ($PLATFORM =~ /^win(?:32|ce)$/) {
1585 $symbol = "_$symbol" if $CCTYPE eq 'BORLAND';
1586 print "\t$symbol\n";
1587 # XXX: binary compatibility between compilers is an exercise
1588 # in frustration :-(
1589 # if ($CCTYPE eq "BORLAND") {
1590 # # workaround Borland quirk by exporting both the straight
1591 # # name and a name with leading underscore. Note the
1592 # # alias *must* come after the symbol itself, if both
1593 # # are to be exported. (Linker bug?)
1594 # print "\t_$symbol\n";
1595 # print "\t$symbol = _$symbol\n";
1597 # elsif ($CCTYPE eq 'GCC') {
1598 # # Symbols have leading _ whole process is $%@"% slow
1599 # # so skip aliases for now
1600 # nprint "\t$symbol\n";
1603 # # for binary coexistence, export both the symbol and
1604 # # alias with leading underscore
1605 # print "\t$symbol\n";
1606 # print "\t_$symbol = $symbol\n";
1609 elsif ($PLATFORM eq 'os2') {
1610 printf qq( %-31s \@%s\n),
1611 qq("$symbol"), $ordinal{$symbol} || ++$sym_ord;
1612 printf qq( %-31s \@%s\n),
1613 qq("$exportperlmalloc{$symbol}" = "$symbol"),
1614 $ordinal{$exportperlmalloc{$symbol}} || ++$sym_ord
1615 if $exportperlmalloc and exists $exportperlmalloc{$symbol};
1617 elsif ($PLATFORM eq 'aix' || $PLATFORM eq 'MacOS') {
1620 elsif ($PLATFORM eq 'netware') {
1621 print "\t$symbol,\n";
1627 # Oddities from PerlIO