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/;
132 $define{$1} = 1 if /^\s*#\s*define\s+(HAS_\w+)\b/;
136 # perl.h logic duplication begins
138 if ($define{PERL_IMPLICIT_SYS}) {
139 $define{PL_OP_SLAB_ALLOC} = 1;
142 if ($define{USE_ITHREADS}) {
143 if (!$define{MULTIPLICITY}) {
144 $define{MULTIPLICITY} = 1;
148 $define{PERL_IMPLICIT_CONTEXT} ||=
149 $define{USE_ITHREADS} ||
150 $define{MULTIPLICITY} ;
152 if ($define{USE_ITHREADS} && $PLATFORM ne 'win32' && $^O ne 'darwin') {
153 $define{USE_REENTRANT_API} = 1;
156 # perl.h logic duplication ends
160 print STDERR "Defines: (" . join(' ', sort keys %define) . ")\n";
162 if ($PLATFORM =~ /^win(?:32|ce)$/) {
163 (my $dll = ($define{PERL_DLL} || "perl511")) =~ s/\.dll$//i;
164 print "LIBRARY $dll\n";
165 # The DESCRIPTION module definition file statement is not supported
167 if ($CCTYPE !~ /^MSVC7/ && $CCTYPE !~ /^MSVC8/ && $CCTYPE !~ /^MSVC9/) {
168 print "DESCRIPTION 'Perl interpreter'\n";
171 if ($define{PERL_IMPLICIT_SYS}) {
172 output_symbol("perl_get_host_info");
173 output_symbol("perl_alloc_override");
175 if ($define{USE_ITHREADS} and $define{PERL_IMPLICIT_SYS}) {
176 output_symbol("perl_clone_host");
179 elsif ($PLATFORM eq 'os2') {
180 if (open my $fh, '<', 'perl5.def') {
182 last if /^\s*EXPORTS\b/;
185 $ordinal{$1} = $2 if /^\s*"(\w+)"\s*(?:=\s*"\w+"\s*)?\@(\d+)\s*$/;
186 # This allows skipping ordinals which were used in older versions
187 $sym_ord = $1 if /^\s*;\s*LAST_ORDINAL\s*=\s*(\d+)\s*$/;
189 $sym_ord < $_ and $sym_ord = $_ for values %ordinal; # Take the max
191 (my $v = $]) =~ s/(\d\.\d\d\d)(\d\d)$/$1_$2/;
192 $v .= '-thread' if $ARCHNAME =~ /-thread/;
193 (my $dll = $define{PERL_DLL}) =~ s/\.dll$//i;
194 $v .= "\@$PATCHLEVEL" if $PATCHLEVEL;
195 my $d = "DESCRIPTION '\@#perl5-porters\@perl.org:$v#\@ Perl interpreter, configured as $CONFIG_ARGS'";
196 $d = substr($d, 0, 249) . "...'" if length $d > 253;
198 LIBRARY '$dll' INITINSTANCE TERMINSTANCE
202 DATA LOADONCALL NONSHARED MULTIPLE
206 elsif ($PLATFORM eq 'aix') {
207 my $OSVER = `uname -v`;
209 my $OSREL = `uname -r`;
211 if ($OSVER > 4 || ($OSVER == 4 && $OSREL >= 3)) {
217 elsif ($PLATFORM eq 'netware') {
218 if ($FILETYPE eq 'def') {
219 print "LIBRARY perl511\n";
220 print "DESCRIPTION 'Perl interpreter for NetWare'\n";
223 if ($define{PERL_IMPLICIT_SYS}) {
224 output_symbol("perl_get_host_info");
225 output_symbol("perl_alloc_override");
226 output_symbol("perl_clone_host");
235 foreach my $symbol (@$list) {
242 foreach my $symbol (@$list) {
243 my $skipsym = $symbol;
245 if ($define{MULTIPLICITY}) {
246 $skipsym =~ s/^Perl_[GIT](\w+)_ptr$/PL_$1/;
248 emit_symbol($symbol) unless exists $skip{$skipsym};
252 if ($PLATFORM eq 'win32') {
276 Perl_init_thread_intern
310 if ($PLATFORM eq 'wince') {
325 PL_collation_standard
353 Perl_init_thread_intern
380 elsif ($PLATFORM eq 'aix') {
399 Perl_sys_intern_clear
411 if $define{'HAS_SIGNBIT'};
416 elsif ($PLATFORM eq 'os2') {
461 XS_Cwd_extLibpath_set
465 XS_Cwd_sys_is_absolute
466 XS_Cwd_sys_is_relative
468 XS_DynaLoader_mod2fname
469 XS_File__Copy_syscopy
473 Perl_Process_Messages
484 emit_symbols([qw(os2_cond_wait
489 if $define{'USE_5005THREADS'} or $define{'USE_ITHREADS'};
491 elsif ($PLATFORM eq 'MacOS') {
515 Perl_sys_intern_clear
519 elsif ($PLATFORM eq 'netware') {
543 Perl_init_thread_intern
568 Perl_sys_intern_clear
576 Perl_PerlIO_setlinebuf
577 Perl_PerlIO_set_ptrcnt
583 Perl_PerlIO_get_bufsiz
596 unless ($define{'DEBUGGING'}) {
612 if ($define{'PERL_IMPLICIT_CONTEXT'}) {
618 if ($define{'PERL_IMPLICIT_SYS'}) {
639 unless ($define{'PERL_OLD_COPY_ON_WRITE'}) {
645 unless ($define{'USE_REENTRANT_API'}) {
651 if ($define{'MYMALLOC'}) {
660 if ($define{'USE_ITHREADS'}) {
677 Perl_malloc_good_size
683 if ($define{'PERL_USE_SAFE_PUTENV'}) {
689 unless ($define{'USE_ITHREADS'}) {
695 # USE_5005THREADS symbols. Kept as reference for easier removal
714 Perl_new_struct_thread
715 Perl_per_thread_magicals
723 unless ($define{'USE_ITHREADS'}) {
729 PL_sharedsv_space_mutex
756 Perl_sharedsv_thrcnt_dec
757 Perl_sharedsv_thrcnt_inc
759 Perl_stashpv_hvname_match
760 Perl_regdupe_internal
765 unless ($define{'PERL_IMPLICIT_CONTEXT'}) {
776 Perl_load_module_nocontext
779 Perl_warner_nocontext
780 Perl_newSVpvf_nocontext
781 Perl_sv_catpvf_nocontext
782 Perl_sv_setpvf_nocontext
783 Perl_sv_catpvf_mg_nocontext
784 Perl_sv_setpvf_mg_nocontext
790 unless ($define{'PERL_IMPLICIT_SYS'}) {
797 unless ($define{'FAKE_THREADS'}) {
798 skip_symbols [qw(PL_curthr)];
801 unless ($define{'PL_OP_SLAB_ALLOC'}) {
811 unless ($define{'PERL_DEBUG_READONLY_OPS'}) {
818 unless ($define{'THREADS_HAVE_PIDS'}) {
819 skip_symbols [qw(PL_ppid)];
822 unless ($define{'PERL_NEED_APPCTX'}) {
828 unless ($define{'PERL_NEED_TIMESBASE'}) {
834 unless ($define{'DEBUG_LEAKING_SCALARS'}) {
840 unless ($define{'DEBUG_LEAKING_SCALARS_FORK_DUMP'}) {
845 unless ($define{'PERL_DONT_CREATE_GVSV'}) {
850 if ($define{'SPRINTF_RETURNS_STRLEN'}) {
855 unless ($define{'PERL_USES_PL_PIDSTATUS'}) {
862 unless ($define{'PERL_TRACK_MEMPOOL'}) {
864 PL_memory_debug_header
868 if ($define{'PERL_MAD'}) {
894 Perl_xmldump_packsubs
908 unless ($define{'MULTIPLICITY'}) {
911 PL_interp_size_5_10_0
915 unless ($define{'PERL_GLOBAL_STRUCT'}) {
917 PL_global_struct_size
921 unless ($define{'PERL_GLOBAL_STRUCT_PRIVATE'}) {
928 unless ($define{'d_mmap'}) {
934 if ($define{'d_sigaction'}) {
941 # VMS does its own thing for these symbols.
942 skip_symbols [qw(PL_sig_handlers_initted
949 my $proc = shift || sub { "PL_$_[2]" };
950 open(VARS,$file) || die "Cannot open $file: $!\n";
953 # All symbols have a Perl_ prefix because that's what embed.h
954 # sticks in front of them. The A?I?S?C? is strictly speaking
956 push(@syms, &$proc($1,$2,$3)) if (/\bPERLVAR(A?I?S?C?)\(([IGT])(\w+)/);
962 if ($define{'PERL_GLOBAL_STRUCT'}) {
963 my $global = readvar($perlvars_h);
964 skip_symbols $global;
965 emit_symbol('Perl_GetVars');
966 emit_symbols [qw(PL_Vars PL_VarsPtr)] unless $CCTYPE eq 'GCC';
968 skip_symbols [qw(Perl_init_global_struct Perl_free_global_struct)];
971 # functions from *.sym files
973 my @syms = ($global_sym, $globvar_sym); # $pp_sym is not part of the API
975 # Symbols that are the public face of the PerlIO layers implementation
976 # These are in _addition to_ the public face of the abstraction
977 # and need to be exported to allow XS modules to implement layers
991 PerlIOBase_setlinebuf
1006 PerlIOBuf_set_ptrcnt
1026 Perl_PerlIO_clearerr
1028 Perl_PerlIO_context_layers
1034 Perl_PerlIO_get_base
1035 Perl_PerlIO_get_bufsiz
1041 Perl_PerlIO_set_ptrcnt
1042 Perl_PerlIO_setlinebuf
1050 if ($PLATFORM eq 'netware') {
1051 push(@layer_syms,'PL_def_layerlist','PL_known_layers','PL_perlio');
1054 if ($define{'USE_PERLIO'}) {
1055 # Export the symols that make up the PerlIO abstraction, regardless
1056 # of its implementation - read from a file
1057 push @syms, $perlio_sym;
1059 # This part is then dependent on how the abstraction is implemented
1060 if ($define{'USE_SFIO'}) {
1061 # Old legacy non-stdio "PerlIO"
1062 skip_symbols \@layer_syms;
1063 skip_symbols [qw(perlsio_binmode)];
1064 # SFIO defines most of the PerlIO routines as macros
1065 # So undo most of what $perlio_sym has just done - d'oh !
1066 # Perhaps it would be better to list the ones which do exist
1111 Perl_PerlIO_clearerr
1118 Perl_PerlIO_get_base
1119 Perl_PerlIO_get_bufsiz
1125 Perl_PerlIO_set_ptrcnt
1126 Perl_PerlIO_setlinebuf
1139 # PerlIO with layers - export implementation
1140 emit_symbols \@layer_syms;
1141 emit_symbols [qw(perlsio_binmode)];
1143 if ($define{'USE_ITHREADS'}) {
1155 # Skip the PerlIO layer symbols - although
1156 # nothing should have exported them anyway.
1157 skip_symbols \@layer_syms;
1165 PL_perlio_fd_refcnt_size
1168 # Also do NOT add abstraction symbols from $perlio_sym
1169 # abstraction is done as #define to stdio
1170 # Remaining remnants that _may_ be functions
1171 # are handled in <DATA>
1174 for my $syms (@syms) {
1175 open (GLOBAL, "<$syms") || die "failed to open $syms: $!\n";
1177 next if (!/^[A-Za-z]/);
1178 # Functions have a Perl_ prefix
1179 # Variables have a PL_ prefix
1181 my $symbol = ($syms =~ /var\.sym$/i ? "PL_" : "");
1183 emit_symbol($symbol) unless exists $skip{$symbol};
1190 if ($define{'MULTIPLICITY'}) {
1191 for my $f ($perlvars_h, $intrpvar_h) {
1192 my $glob = readvar($f, sub { "Perl_" . $_[1] . $_[2] . "_ptr" });
1195 # XXX AIX seems to want the perlvars.h symbols, for some reason
1196 if ($PLATFORM eq 'aix' or $PLATFORM eq 'os2') { # OS/2 needs PL_thr_key
1197 my $glob = readvar($perlvars_h);
1202 unless ($define{'PERL_GLOBAL_STRUCT'}) {
1203 my $glob = readvar($perlvars_h);
1206 unless ($define{'MULTIPLICITY'}) {
1207 my $glob = readvar($intrpvar_h);
1215 return if $symbol !~ /^[A-Za-z_]/;
1216 return if $symbol =~ /^\#/;
1219 return if exists $skip{$symbol};
1220 emit_symbol($symbol);
1227 if ($PLATFORM =~ /^win(?:32|ce)$/) {
1228 foreach my $symbol (qw(
1290 win32_getprotobyname
1291 win32_getprotobynumber
1320 win32_open_osfhandle
1391 try_symbol($symbol);
1393 if ($CCTYPE eq "BORLAND") {
1394 try_symbol('_matherr');
1397 elsif ($PLATFORM eq 'os2') {
1398 my (%mapped, @missing);
1399 open MAP, 'miniperl.map' or die 'Cannot read miniperl.map';
1400 /^\s*[\da-f:]+\s+(\w+)/i and $mapped{$1}++ foreach <MAP>;
1401 close MAP or die 'Cannot close miniperl.map';
1403 @missing = grep { !exists $mapped{$_} }
1405 @missing = grep { !exists $exportperlmalloc{$_} } @missing;
1406 delete $export{$_} foreach @missing;
1408 elsif ($PLATFORM eq 'MacOS') {
1409 open MACSYMS, 'macperl.sym' or die 'Cannot read macperl.sym';
1417 elsif ($PLATFORM eq 'netware') {
1418 foreach my $symbol (qw(
1545 fnInsertHashListAddrs
1556 try_symbol($symbol);
1560 # records of type boot_module for statically linked modules (except Dynaloader)
1561 $static_ext =~ s/\//__/g;
1562 $static_ext =~ s/\bDynaLoader\b//;
1563 my @stat_mods = map {"boot_$_"} grep {/\S/} split /\s+/, $static_ext;
1564 foreach my $symbol (@stat_mods)
1566 try_symbol($symbol);
1569 try_symbol("init_Win32CORE") if $static_ext =~ /\bWin32CORE\b/;
1571 # Now all symbols should be defined because
1572 # next we are going to output them.
1574 foreach my $symbol (sort keys %export) {
1575 output_symbol($symbol);
1578 if ($PLATFORM eq 'os2') {
1583 Perl_OS2_handler_install
1585 ; LAST_ORDINAL=$sym_ord
1592 $export{$symbol} = 1;
1597 if ($PLATFORM =~ /^win(?:32|ce)$/) {
1598 $symbol = "_$symbol" if $CCTYPE eq 'BORLAND';
1599 print "\t$symbol\n";
1600 # XXX: binary compatibility between compilers is an exercise
1601 # in frustration :-(
1602 # if ($CCTYPE eq "BORLAND") {
1603 # # workaround Borland quirk by exporting both the straight
1604 # # name and a name with leading underscore. Note the
1605 # # alias *must* come after the symbol itself, if both
1606 # # are to be exported. (Linker bug?)
1607 # print "\t_$symbol\n";
1608 # print "\t$symbol = _$symbol\n";
1610 # elsif ($CCTYPE eq 'GCC') {
1611 # # Symbols have leading _ whole process is $%@"% slow
1612 # # so skip aliases for now
1613 # nprint "\t$symbol\n";
1616 # # for binary coexistence, export both the symbol and
1617 # # alias with leading underscore
1618 # print "\t$symbol\n";
1619 # print "\t_$symbol = $symbol\n";
1622 elsif ($PLATFORM eq 'os2') {
1623 printf qq( %-31s \@%s\n),
1624 qq("$symbol"), $ordinal{$symbol} || ++$sym_ord;
1625 printf qq( %-31s \@%s\n),
1626 qq("$exportperlmalloc{$symbol}" = "$symbol"),
1627 $ordinal{$exportperlmalloc{$symbol}} || ++$sym_ord
1628 if $exportperlmalloc and exists $exportperlmalloc{$symbol};
1630 elsif ($PLATFORM eq 'aix' || $PLATFORM eq 'MacOS') {
1633 elsif ($PLATFORM eq 'netware') {
1634 print "\t$symbol,\n";
1640 # Oddities from PerlIO