This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
.github - switch to v3 actions
[perl5.git] / makedef.pl
1 #./perl -w
2 #
3 # Create the export list for perl.
4 #
5 # Needed by WIN32 and OS/2 for creating perl.dll,
6 # and by AIX for creating libperl.a when -Duseshrplib is in effect,
7 # and by VMS for creating perlshr.exe.
8 #
9 # Reads from information stored in
10 #
11 #    %Config::Config (ie config.sh)
12 #    config.h
13 #    embed.fnc
14 #    globvar.sym
15 #    intrpvar.h
16 #    miniperl.map (on OS/2)
17 #    perl5.def    (on OS/2; this is the old version of the file being made)
18 #    perlio.sym
19 #    perlvars.h
20 #    regen/opcodes
21 #
22 # plus long lists of function names hard-coded directly in this script.
23 #
24 # Writes the result to STDOUT.
25 #
26 # Normally this script is invoked from a makefile (e.g. win32/Makefile),
27 # which redirects STDOUT to a suitable file, such as:
28 #
29 #    perl5.def   OS/2
30 #    perldll.def Windows
31 #    perl.exp    AIX
32 #    makedef.lis VMS
33
34 use strict;
35 use Config;
36
37 my $fold;
38 my %ARGS;
39 my %define;
40
41 BEGIN {
42     %ARGS = (CCTYPE => 'MSVC', TARG_DIR => '');
43
44     sub process_cc_flags {
45         foreach (map {split /\s+/, $_} @_) {
46             $define{$1} = $2 // 1 if /^-D(\w+)(?:=(.+))?/;
47         }
48     }
49
50     while (@ARGV) {
51         my $flag = shift;
52         if ($flag =~ /^(?:CC_FLAGS=)?(-D\w.*)/) {
53             process_cc_flags($1);
54         } elsif ($flag =~ /^(CCTYPE|FILETYPE|PLATFORM|TARG_DIR)=(.+)$/) {
55             $ARGS{$1} = $2;
56         } elsif ($flag eq '--sort-fold') {
57             ++$fold;
58         }
59     }
60     my @PLATFORM = qw(aix win32 os2 vms test);
61     my %PLATFORM;
62     @PLATFORM{@PLATFORM} = ();
63
64     die "PLATFORM undefined, must be one of: @PLATFORM\n"
65         unless defined $ARGS{PLATFORM};
66     die "PLATFORM must be one of: @PLATFORM\n"
67         unless exists $PLATFORM{$ARGS{PLATFORM}};
68 }
69 use constant PLATFORM => $ARGS{PLATFORM};
70
71 require "./$ARGS{TARG_DIR}regen/embed_lib.pl";
72
73 # Is the following guard strictly necessary? Added during refactoring
74 # to keep the same behaviour when merging other code into here.
75 process_cc_flags(@Config{qw(ccflags optimize)})
76     if $ARGS{PLATFORM} ne 'win32';
77
78 # Add the compile-time options that miniperl was built with to %define.
79 # On Win32 these are not the same options as perl itself will be built
80 # with since miniperl is built with a canned config (one of the win32/
81 # config_H.*) and none of the BUILDOPT's that are set in the makefiles,
82 # but they do include some #define's that are hard-coded in various
83 # source files and header files and don't include any BUILDOPT's that
84 # the user might have chosen to disable because the canned configs are
85 # minimal configs that don't include any of those options.
86
87 my @options = sort(Config::bincompat_options(), Config::non_bincompat_options());
88 print STDERR "Options: (@options)\n" unless $ARGS{PLATFORM} eq 'test';
89 $define{$_} = 1 foreach @options;
90
91 my %exportperlmalloc =
92     (
93        Perl_malloc              =>      "malloc",
94        Perl_mfree               =>      "free",
95        Perl_realloc             =>      "realloc",
96        Perl_calloc              =>      "calloc",
97     );
98
99 my $exportperlmalloc = $ARGS{PLATFORM} eq 'os2';
100
101 my $config_h = 'config.h';
102 open(CFG, '<', $config_h) || die "Cannot open $config_h: $!\n";
103 while (<CFG>) {
104     $define{$1} = 1 if /^\s*\#\s*define\s+(MYMALLOC|MULTIPLICITY
105                                            |KILL_BY_SIGPRC
106                                            |(?:PERL|USE|HAS)_\w+)\b/x;
107 }
108 close(CFG);
109
110 #==========================================================================
111 # perl.h logic duplication begins
112
113 if ($define{USE_ITHREADS}) {
114     if (!$define{MULTIPLICITY}) {
115         $define{MULTIPLICITY} = 1;
116     }
117 }
118
119 $define{MULTIPLICITY} ||=
120     $define{USE_ITHREADS} ||
121     $define{PERL_IMPLICIT_CONTEXT} ;
122
123 if ($define{USE_ITHREADS} && $ARGS{PLATFORM} ne 'win32') {
124     $define{USE_REENTRANT_API} = 1;
125 }
126
127 if (! $define{NO_LOCALE}) {
128     if ( ! $define{NO_POSIX_2008_LOCALE}
129         && $define{HAS_NEWLOCALE}
130         && $define{HAS_USELOCALE}
131         && $define{HAS_DUPLOCALE}
132         && $define{HAS_FREELOCALE})
133     {
134         $define{HAS_POSIX_2008_LOCALE} = 1;
135         $define{USE_LOCALE} = 1;
136     }
137     elsif ($define{HAS_SETLOCALE}) {
138         $define{USE_LOCALE} = 1;
139     }
140 }
141
142 # https://en.wikipedia.org/wiki/Microsoft_Visual_C%2B%2B#Internal_version_numbering
143 my $cctype = $ARGS{CCTYPE} =~ s/MSVC//r;
144 if ($define{USE_ITHREADS} && ! $define{NO_LOCALE_THREADS}) {
145     $define{USE_LOCALE_THREADS} = 1;
146 }
147
148 if (   $define{HAS_POSIX_2008_LOCALE}
149     && (  ! $define{HAS_SETLOCALE} || (     $define{USE_LOCALE_THREADS}
150                                        && ! $define{NO_POSIX_2008_LOCALE})))
151 {
152     $define{USE_POSIX_2008_LOCALE} = 1;
153 }
154
155 if ($define{USE_LOCALE_THREADS} && ! $define{NO_THREAD_SAFE_LOCALE})
156 {
157     if (    $define{USE_POSIX_2008_LOCALE}
158         || ($ARGS{PLATFORM} eq 'win32' && (   $cctype !~ /\D/
159                                            && $cctype >= 80)))
160     {
161         $define{USE_THREAD_SAFE_LOCALE} = 1;
162     }
163 }
164
165 if ($define{USE_POSIX_2008_LOCALE} && $define{HAS_QUERYLOCALE})
166 {
167     $define{USE_QUERYLOCALE} = 1;
168
169     # Don't need glibc only code from perl.h
170 }
171
172 if ($define{USE_POSIX_2008_LOCALE} && ! $define{USE_QUERYLOCALE})
173 {
174     $define{USE_PL_CURLOCALES} = 1;
175     $define{USE_PL_CUR_LC_ALL} = 1;
176 }
177
178 if ($ARGS{PLATFORM} eq 'win32' && $define{USE_THREAD_SAFE_LOCALE})
179 {
180     $define{USE_PL_CUR_LC_ALL} = 1;
181
182     if ($cctype < 140) {
183         $define{TS_W32_BROKEN_LOCALECONV} = 1;
184     }
185 }
186
187 if ($define{MULTIPLICITY} && (   $define{USE_POSIX_2008_LOCALE}
188                                 || (   $define{WIN32}
189                                     && $define{USE_THREAD_SAFE_LOCALE})))
190 {
191     $define{USE_PERL_SWITCH_LOCALE_CONTEXT}
192 }
193
194 # perl.h logic duplication ends
195 #==========================================================================
196
197 print STDERR "Defines: (" . join(' ', sort keys %define) . ")\n"
198      unless $ARGS{PLATFORM} eq 'test';
199
200 my $sym_ord = 0;
201 my %ordinal;
202
203 if ($ARGS{PLATFORM} eq 'os2') {
204     if (open my $fh, '<', 'perl5.def') {
205       while (<$fh>) {
206         last if /^\s*EXPORTS\b/;
207       }
208       while (<$fh>) {
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*$/;
212       }
213       $sym_ord < $_ and $sym_ord = $_ for values %ordinal; # Take the max
214     }
215 }
216
217 my %skip;
218 # All platforms export boot_DynaLoader unconditionally.
219 my %export = ( boot_DynaLoader => 1 );
220
221 # d_thread_local not perl_thread_local - see hints/darwin.sh
222 ++$export{PL_current_context}
223     if defined $Config{d_thread_local} && $define{USE_ITHREADS};
224
225 sub try_symbols {
226     foreach my $symbol (@_) {
227         ++$export{$symbol} unless exists $skip{$symbol};
228     }
229 }
230
231 sub readvar {
232     # $hash is the hash that we're adding to. For one of our callers, it will
233     # actually be the skip hash but that doesn't affect the intent of what
234     # we're doing, as in that case we skip adding something to the skip hash
235     # for the second time.
236
237     my $file = $ARGS{TARG_DIR} . shift;
238     my $hash = shift;
239     my $proc = shift;
240     open my $vars, '<', $file or die "Cannot open $file: $!\n";
241
242     while (<$vars>) {
243         # All symbols have a Perl_ prefix because that's what embed.h sticks
244         # in front of them.  The A?I?S?C? is strictly speaking wrong.
245         next unless /\bPERLVAR(A?I?S?C?)\(([IGT]),\s*(\w+)/;
246
247         my $var = "PL_$3";
248         my $symbol = $proc ? &$proc($1,$2,$3) : $var;
249         ++$hash->{$symbol} unless exists $skip{$var};
250     }
251 }
252
253 if ($ARGS{PLATFORM} ne 'os2') {
254     ++$skip{$_} foreach qw(
255                      PL_opsave
256                      Perl_dump_fds
257                      Perl_my_bcopy
258                      Perl_my_bzero
259                      Perl_my_chsize
260                      Perl_my_htonl
261                      Perl_my_memcmp
262                      Perl_my_memset
263                      Perl_my_ntohl
264                      Perl_my_swap
265                          );
266     if ($ARGS{PLATFORM} eq 'vms') {
267         ++$skip{PL_statusvalue_posix};
268         # This is a wrapper if we have symlink, not a replacement
269         # if we don't.
270         ++$skip{Perl_my_symlink} unless $Config{d_symlink};
271     } else {
272         ++$skip{PL_statusvalue_vms};
273         ++$skip{PL_perllib_sep};
274         if ($ARGS{PLATFORM} ne 'aix') {
275             ++$skip{$_} foreach qw(
276                                 PL_DBcv
277                                 PL_generation
278                                 PL_lastgotoprobe
279                                 PL_modcount
280                                 main
281                                  );
282         }
283     }
284 }
285
286 if ($ARGS{PLATFORM} ne 'vms') {
287     # VMS does its own thing for these symbols.
288     ++$skip{$_} foreach qw(
289                         PL_sig_handlers_initted
290                         PL_sig_ignoring
291                         PL_sig_defaulting
292                          );
293     if ($ARGS{PLATFORM} ne 'win32') {
294         ++$skip{$_} foreach qw(
295                             Perl_do_spawn
296                             Perl_do_spawn_nowait
297                             Perl_do_aspawn
298                              );
299     }
300 }
301
302 if ($ARGS{PLATFORM} ne 'win32') {
303     ++$skip{$_} foreach qw(
304                     Perl_get_win32_message_utf8ness
305                     Perl_Win_utf8_string_to_wstring
306                     Perl_Win_wstring_to_utf8_string
307                          );
308 }
309
310 unless ($define{UNLINK_ALL_VERSIONS}) {
311     ++$skip{Perl_unlnk};
312 }
313
314 unless ($define{'DEBUGGING'}) {
315     ++$skip{$_} foreach qw(
316                     Perl_debop
317                     Perl_debprofdump
318                     Perl_debstack
319                     Perl_debstackptrs
320                     Perl_pad_sv
321                     Perl_pad_setsv
322                     Perl_set_padlist
323                     Perl_hv_assert
324                     PL_watchaddr
325                     PL_watchok
326                          );
327 }
328
329 if ($define{'PERL_IMPLICIT_SYS'}) {
330     ++$skip{$_} foreach qw(
331                     Perl_my_popen
332                     Perl_my_pclose
333                          );
334     ++$export{$_} foreach qw(perl_get_host_info perl_alloc_override);
335     ++$export{perl_clone_host} if $define{USE_ITHREADS};
336 }
337 else {
338     ++$skip{$_} foreach qw(
339                     PL_Mem
340                     PL_MemShared
341                     PL_MemParse
342                     PL_Env
343                     PL_StdIO
344                     PL_LIO
345                     PL_Dir
346                     PL_Sock
347                     PL_Proc
348                     perl_alloc_using
349                     perl_clone_using
350                          );
351 }
352
353 if (!$define{'PERL_COPY_ON_WRITE'} || $define{'PERL_NO_COW'}) {
354     ++$skip{Perl_sv_setsv_cow};
355 }
356
357 unless ($define{PERL_SAWAMPERSAND}) {
358     ++$skip{PL_sawampersand};
359 }
360
361 unless ($define{'USE_REENTRANT_API'}) {
362     ++$skip{PL_reentrant_buffer};
363 }
364
365 if ($define{'MYMALLOC'}) {
366     try_symbols(qw(
367                     Perl_dump_mstats
368                     Perl_get_mstats
369                     Perl_strdup
370                     Perl_putenv
371                     MallocCfg_ptr
372                     MallocCfgP_ptr
373                     ));
374     unless ($define{USE_ITHREADS}) {
375         ++$skip{PL_malloc_mutex}
376     }
377 }
378 else {
379     ++$skip{$_} foreach qw(
380                     PL_malloc_mutex
381                     Perl_dump_mstats
382                     Perl_get_mstats
383                     MallocCfg_ptr
384                     MallocCfgP_ptr
385                          );
386 }
387
388 unless ($define{'USE_ITHREADS'}) {
389     ++$skip{PL_thr_key};
390     ++$skip{PL_user_prop_mutex};
391     ++$skip{PL_user_def_props_aTHX};
392 }
393
394 unless ($define{'USE_ITHREADS'}) {
395     ++$skip{$_} foreach qw(
396                     PL_keyword_plugin_mutex
397                     PL_check_mutex
398                     PL_cur_locale_obj
399                     PL_op_mutex
400                     PL_regex_pad
401                     PL_regex_padav
402                     PL_dollarzero_mutex
403                     PL_env_mutex
404                     PL_hints_mutex
405                     PL_locale_mutex
406                     PL_locale_mutex_depth
407                     PL_my_ctx_mutex
408                     PL_perlio_mutex
409                     PL_stashpad
410                     PL_stashpadix
411                     PL_stashpadmax
412                     PL_veto_switch_non_tTHX_context
413                     Perl_alloccopstash
414                     Perl_allocfilegv
415                     Perl_clone_params_del
416                     Perl_clone_params_new
417                     Perl_parser_dup
418                     Perl_dirp_dup
419                     Perl_cx_dup
420                     Perl_si_dup
421                     Perl_any_dup
422                     Perl_ss_dup
423                     Perl_fp_dup
424                     Perl_gp_dup
425                     Perl_he_dup
426                     Perl_mg_dup
427                     Perl_re_dup_guts
428                     Perl_sv_dup
429                     Perl_sv_dup_inc
430                     Perl_rvpv_dup
431                     Perl_hek_dup
432                     Perl_sys_intern_dup
433                     perl_clone
434                     perl_clone_using
435                     Perl_stashpv_hvname_match
436                     Perl_regdupe_internal
437                     Perl_newPADOP
438                          );
439 }
440
441 unless ($define{USE_POSIX_2008_LOCALE})
442 {
443     ++$skip{$_} foreach qw(
444         PL_C_locale_obj
445         PL_scratch_locale_obj
446         PL_underlying_numeric_obj
447     );
448 }
449 unless ($define{USE_PL_CURLOCALES})
450 {
451     ++$skip{$_} foreach qw(
452         PL_curlocales
453     );
454 }
455
456 unless ($define{USE_PL_CUR_LC_ALL})
457 {
458     ++$skip{$_} foreach qw(
459         PL_cur_LC_ALL
460     );
461 }
462
463 unless ($define{USE_PERL_SWITCH_LOCALE_CONTEXT})
464 {
465     ++$skip{$_} foreach qw(
466         Perl_switch_locale_context
467     );
468 }
469
470 unless ($define{'MULTIPLICITY'}) {
471     ++$skip{$_} foreach qw(
472                     PL_my_cxt_index
473                     PL_my_cxt_list
474                     PL_my_cxt_size
475                     PL_my_cxt_keys
476                     PL_my_cxt_keys_size
477                     Perl_croak_nocontext
478                     Perl_die_nocontext
479                     Perl_deb_nocontext
480                     Perl_form_nocontext
481                     Perl_load_module_nocontext
482                     Perl_mess_nocontext
483                     Perl_warn_nocontext
484                     Perl_warner_nocontext
485                     Perl_newSVpvf_nocontext
486                     Perl_sv_catpvf_nocontext
487                     Perl_sv_setpvf_nocontext
488                     Perl_sv_catpvf_mg_nocontext
489                     Perl_sv_setpvf_mg_nocontext
490                     Perl_my_cxt_init
491                     Perl_my_cxt_index
492                          );
493 }
494
495 unless ($define{'USE_DTRACE'}) {
496     ++$skip{$_} foreach qw(
497                     Perl_dtrace_probe_call
498                     Perl_dtrace_probe_load
499                     Perl_dtrace_probe_op
500                     Perl_dtrace_probe_phase
501                 );
502 }
503
504 unless ($define{'DEBUG_LEAKING_SCALARS'}) {
505     ++$skip{PL_sv_serial};
506 }
507
508 unless ($define{'DEBUG_LEAKING_SCALARS_FORK_DUMP'}) {
509     ++$skip{PL_dumper_fd};
510 }
511
512 unless ($define{'PERL_DONT_CREATE_GVSV'}) {
513     ++$skip{Perl_gv_SVadd};
514 }
515
516 unless ($define{'PERL_USES_PL_PIDSTATUS'}) {
517     ++$skip{PL_pidstatus};
518 }
519
520 unless ($define{'PERL_TRACK_MEMPOOL'}) {
521     ++$skip{PL_memory_debug_header};
522 }
523
524 unless ($define{'PERL_MEM_LOG'}) {
525     ++$skip{$_} foreach qw(
526                     PL_mem_log
527                     Perl_mem_log_alloc
528                     Perl_mem_log_realloc
529                     Perl_mem_log_free
530                     Perl_mem_log_new_sv
531                     Perl_mem_log_del_sv
532                 );
533 }
534
535 unless ($define{'MULTIPLICITY'}) {
536     ++$skip{$_} foreach qw(
537                     PL_interp_size
538                     PL_interp_size_5_18_0
539                     PL_sv_yes
540                     PL_sv_undef
541                     PL_sv_no
542                     PL_sv_zero
543                          );
544 }
545
546 unless ($define{HAS_MMAP}) {
547     ++$skip{PL_mmap_page_size};
548 }
549
550 if ($define{HAS_SIGACTION}) {
551     ++$skip{PL_sig_trapped};
552
553     if ($ARGS{PLATFORM} eq 'vms') {
554         # FAKE_PERSISTENT_SIGNAL_HANDLERS defined as !defined(HAS_SIGACTION)
555         ++$skip{PL_sig_ignoring};
556         ++$skip{PL_sig_handlers_initted} unless $define{KILL_BY_SIGPRC};
557     }
558 }
559
560 if ($ARGS{PLATFORM} eq 'vms' && !$define{KILL_BY_SIGPRC}) {
561     # FAKE_DEFAULT_SIGNAL_HANDLERS defined as KILL_BY_SIGPRC
562     ++$skip{Perl_csighandler_init};
563     ++$skip{Perl_my_kill};
564     ++$skip{Perl_sig_to_vmscondition};
565     ++$skip{PL_sig_defaulting};
566     ++$skip{PL_sig_handlers_initted} unless !$define{HAS_SIGACTION};
567 }
568
569 if ($define{'HAS_STRNLEN'})
570 {
571     ++$skip{Perl_my_strnlen};
572 }
573
574 unless ($define{USE_LOCALE_COLLATE}) {
575     ++$skip{$_} foreach qw(
576                     PL_collation_ix
577                     PL_collation_name
578                     PL_collation_standard
579                     PL_collxfrm_base
580                     PL_collxfrm_mult
581                     Perl_sv_collxfrm
582                     Perl_sv_collxfrm_flags
583                     PL_strxfrm_NUL_replacement
584                     PL_strxfrm_is_behaved
585                     PL_strxfrm_max_cp
586                     PL_in_utf8_COLLATE_locale
587                          );
588 }
589
590 unless ($define{USE_LOCALE_NUMERIC}) {
591     ++$skip{$_} foreach qw(
592                     PL_underlying_numeric_obj
593                          );
594 }
595
596 unless ($define{USE_LOCALE_CTYPE}) {
597     ++$skip{$_} foreach qw(
598                     PL_ctype_name
599                     PL_in_utf8_CTYPE_locale
600                     PL_in_utf8_turkic_locale
601                          );
602 }
603
604 unless ($define{'USE_C_BACKTRACE'}) {
605     ++$skip{Perl_get_c_backtrace_dump};
606     ++$skip{Perl_dump_c_backtrace};
607 }
608
609 unless ($define{HAVE_INTERP_INTERN}) {
610     ++$skip{$_} foreach qw(
611                     Perl_sys_intern_clear
612                     Perl_sys_intern_dup
613                     Perl_sys_intern_init
614                     PL_sys_intern
615                          );
616 }
617
618 if ($define{HAS_SIGNBIT}) {
619     ++$skip{Perl_signbit};
620 }
621
622 ++$skip{PL_op_exec_cnt}
623     unless $define{PERL_TRACE_OPS};
624
625 ++$skip{PL_hash_chars}
626     unless $define{PERL_USE_SINGLE_CHAR_HASH_CACHE};
627
628 # functions from *.sym files
629
630 my @syms = qw(globvar.sym);
631
632 # Symbols that are the public face of the PerlIO layers implementation
633 # These are in _addition to_ the public face of the abstraction
634 # and need to be exported to allow XS modules to implement layers
635 my @layer_syms = qw(
636                     PerlIOBase_binmode
637                     PerlIOBase_clearerr
638                     PerlIOBase_close
639                     PerlIOBase_dup
640                     PerlIOBase_eof
641                     PerlIOBase_error
642                     PerlIOBase_fileno
643                     PerlIOBase_open
644                     PerlIOBase_noop_fail
645                     PerlIOBase_noop_ok
646                     PerlIOBase_popped
647                     PerlIOBase_pushed
648                     PerlIOBase_read
649                     PerlIOBase_setlinebuf
650                     PerlIOBase_unread
651                     PerlIOBuf_bufsiz
652                     PerlIOBuf_close
653                     PerlIOBuf_dup
654                     PerlIOBuf_fill
655                     PerlIOBuf_flush
656                     PerlIOBuf_get_base
657                     PerlIOBuf_get_cnt
658                     PerlIOBuf_get_ptr
659                     PerlIOBuf_open
660                     PerlIOBuf_popped
661                     PerlIOBuf_pushed
662                     PerlIOBuf_read
663                     PerlIOBuf_seek
664                     PerlIOBuf_set_ptrcnt
665                     PerlIOBuf_tell
666                     PerlIOBuf_unread
667                     PerlIOBuf_write
668                     PerlIO_allocate
669                     PerlIO_apply_layera
670                     PerlIO_apply_layers
671                     PerlIO_arg_fetch
672                     PerlIO_debug
673                     PerlIO_define_layer
674                     PerlIO_find_layer
675                     PerlIO_isutf8
676                     PerlIO_layer_fetch
677                     PerlIO_list_alloc
678                     PerlIO_list_free
679                     PerlIO_modestr
680                     PerlIO_parse_layers
681                     PerlIO_pending
682                     PerlIO_perlio
683                     PerlIO_pop
684                     PerlIO_push
685                     PerlIO_sv_dup
686                     Perl_PerlIO_clearerr
687                     Perl_PerlIO_close
688                     Perl_PerlIO_context_layers
689                     Perl_PerlIO_eof
690                     Perl_PerlIO_error
691                     Perl_PerlIO_fileno
692                     Perl_PerlIO_fill
693                     Perl_PerlIO_flush
694                     Perl_PerlIO_get_base
695                     Perl_PerlIO_get_bufsiz
696                     Perl_PerlIO_get_cnt
697                     Perl_PerlIO_get_ptr
698                     Perl_PerlIO_read
699                     Perl_PerlIO_restore_errno
700                     Perl_PerlIO_save_errno
701                     Perl_PerlIO_seek
702                     Perl_PerlIO_set_cnt
703                     Perl_PerlIO_set_ptrcnt
704                     Perl_PerlIO_setlinebuf
705                     Perl_PerlIO_stderr
706                     Perl_PerlIO_stdin
707                     Perl_PerlIO_stdout
708                     Perl_PerlIO_tell
709                     Perl_PerlIO_unread
710                     Perl_PerlIO_write
711 );
712
713 # Export the symbols that make up the PerlIO abstraction, regardless
714 # of its implementation - read from a file
715 push @syms, 'perlio.sym';
716
717 # PerlIO with layers - export implementation
718 try_symbols(@layer_syms, 'perlsio_binmode');
719
720
721 unless ($define{'USE_QUADMATH'}) {
722   ++$skip{Perl_quadmath_format_needed};
723   ++$skip{Perl_quadmath_format_single};
724 }
725
726 unless ($Config{d_mbrlen}) {
727     ++$skip{PL_mbrlen_ps};
728 }
729
730 unless ($Config{d_mbrtowc}) {
731     ++$skip{PL_mbrtowc_ps};
732 }
733
734 unless ($Config{d_wcrtomb}) {
735     ++$skip{PL_wcrtomb_ps};
736 }
737
738 ###############################################################################
739
740 # At this point all skip lists should be completed, as we are about to test
741 # many symbols against them.
742
743 {
744     my %seen;
745     my ($embed) = setup_embed($ARGS{TARG_DIR});
746     my $excludedre = $define{'NO_MATHOMS'} ? qr/[emiIsb]/ : qr/[emiIs]/;
747
748     foreach (@$embed) {
749         my ($flags, $retval, $func, @args) = @$_;
750         next unless $func;
751         if (($flags =~ /[AXC]/ && $flags !~ $excludedre)
752             || (!$define{'NO_MATHOMS'} && $flags =~ /b/))
753         {
754             # public API, so export
755
756             # If a function is defined twice, for example before and after
757             # an #else, only export its name once. Important to do this test
758             # within the block, as the *first* definition may have flags which
759             # mean "don't export"
760             next if $seen{$func}++;
761             # Should we also skip adding the Perl_ prefix if $flags =~ /o/ ?
762             $func = "Perl_$func" if ($flags =~ /[psX]/ && $func !~ /^Perl_/);
763             ++$export{$func} unless exists $skip{$func};
764         }
765     }
766 }
767
768 foreach (@syms) {
769     my $syms = $ARGS{TARG_DIR} . $_;
770     open my $global, '<', $syms or die "failed to open $syms: $!\n";
771     while (<$global>) {
772         next unless /^([A-Za-z].*)/;
773         my $symbol = "$1";
774         ++$export{$symbol} unless exists $skip{$symbol};
775     }
776 }
777
778 # variables
779
780 readvar('perlvars.h', \%export);
781 unless ($define{MULTIPLICITY}) {
782     readvar('intrpvar.h', \%export);
783 }
784
785 # Oddities from PerlIO
786 # All have alternate implementations in perlio.c, so always exist.
787 # Should they be considered to be part of the API?
788 try_symbols(qw(
789                     PerlIO_binmode
790                     PerlIO_getpos
791                     PerlIO_init
792                     PerlIO_setpos
793                     PerlIO_tmpfile
794              ));
795
796 if ($ARGS{PLATFORM} eq 'win32') {
797     try_symbols(qw(
798                     win32_free_childdir
799                     win32_free_childenv
800                     win32_get_childdir
801                     win32_get_childenv
802                     win32_spawnvp
803                     Perl_init_os_extras
804                     Perl_win32_init
805                     Perl_win32_term
806                     RunPerl
807                     win32_async_check
808                     win32_errno
809                     win32_environ
810                     win32_abort
811                     win32_fstat
812                     win32_stat
813                     win32_pipe
814                     win32_popen
815                     win32_pclose
816                     win32_rename
817                     win32_setmode
818                     win32_chsize
819                     win32_lseek
820                     win32_tell
821                     win32_dup
822                     win32_dup2
823                     win32_open
824                     win32_close
825                     win32_eof
826                     win32_isatty
827                     win32_read
828                     win32_write
829                     win32_mkdir
830                     win32_rmdir
831                     win32_chdir
832                     win32_flock
833                     win32_execv
834                     win32_execvp
835                     win32_htons
836                     win32_ntohs
837                     win32_htonl
838                     win32_ntohl
839                     win32_inet_addr
840                     win32_inet_ntoa
841                     win32_socket
842                     win32_bind
843                     win32_listen
844                     win32_accept
845                     win32_connect
846                     win32_send
847                     win32_sendto
848                     win32_recv
849                     win32_recvfrom
850                     win32_shutdown
851                     win32_closesocket
852                     win32_ioctlsocket
853                     win32_setsockopt
854                     win32_getsockopt
855                     win32_getpeername
856                     win32_getsockname
857                     win32_gethostname
858                     win32_gethostbyname
859                     win32_gethostbyaddr
860                     win32_getprotobyname
861                     win32_getprotobynumber
862                     win32_getservbyname
863                     win32_getservbyport
864                     win32_select
865                     win32_endhostent
866                     win32_endnetent
867                     win32_endprotoent
868                     win32_endservent
869                     win32_getnetent
870                     win32_getnetbyname
871                     win32_getnetbyaddr
872                     win32_getprotoent
873                     win32_getservent
874                     win32_sethostent
875                     win32_setnetent
876                     win32_setprotoent
877                     win32_setservent
878                     win32_getenv
879                     win32_putenv
880                     win32_perror
881                     win32_malloc
882                     win32_calloc
883                     win32_realloc
884                     win32_free
885                     win32_sleep
886                     win32_pause
887                     win32_times
888                     win32_access
889                     win32_alarm
890                     win32_chmod
891                     win32_open_osfhandle
892                     win32_get_osfhandle
893                     win32_ioctl
894                     win32_link
895                     win32_unlink
896                     win32_utime
897                     win32_gettimeofday
898                     win32_uname
899                     win32_wait
900                     win32_waitpid
901                     win32_kill
902                     win32_str_os_error
903                     win32_opendir
904                     win32_readdir
905                     win32_telldir
906                     win32_seekdir
907                     win32_rewinddir
908                     win32_closedir
909                     win32_longpath
910                     win32_ansipath
911                     win32_os_id
912                     win32_getpid
913                     win32_crypt
914                     win32_dynaload
915                     win32_clearenv
916                     win32_stdin
917                     win32_stdout
918                     win32_stderr
919                     win32_ferror
920                     win32_feof
921                     win32_strerror
922                     win32_fprintf
923                     win32_printf
924                     win32_vfprintf
925                     win32_vprintf
926                     win32_fread
927                     win32_fwrite
928                     win32_fopen
929                     win32_fdopen
930                     win32_freopen
931                     win32_fclose
932                     win32_fputs
933                     win32_fputc
934                     win32_ungetc
935                     win32_getc
936                     win32_fileno
937                     win32_clearerr
938                     win32_fflush
939                     win32_ftell
940                     win32_fseek
941                     win32_fgetpos
942                     win32_fsetpos
943                     win32_rewind
944                     win32_tmpfile
945                     win32_setbuf
946                     win32_setvbuf
947                     win32_flushall
948                     win32_fcloseall
949                     win32_fgets
950                     win32_gets
951                     win32_fgetc
952                     win32_putc
953                     win32_puts
954                     win32_getchar
955                     win32_putchar
956                     win32_symlink
957                     win32_lstat
958                     win32_readlink
959                  ));
960 }
961 elsif ($ARGS{PLATFORM} eq 'vms') {
962     try_symbols(qw(
963                       Perl_cando
964                       Perl_cando_by_name
965                       Perl_closedir
966                       Perl_csighandler_init
967                       Perl_do_rmdir
968                       Perl_fileify_dirspec
969                       Perl_fileify_dirspec_ts
970                       Perl_fileify_dirspec_utf8
971                       Perl_fileify_dirspec_utf8_ts
972                       Perl_flex_fstat
973                       Perl_flex_lstat
974                       Perl_flex_stat
975                       Perl_kill_file
976                       Perl_my_chdir
977                       Perl_my_chmod
978                       Perl_my_crypt
979                       Perl_my_endpwent
980                       Perl_my_fclose
981                       Perl_my_fdopen
982                       Perl_my_fgetname
983                       Perl_my_flush
984                       Perl_my_fwrite
985                       Perl_my_gconvert
986                       Perl_my_getenv
987                       Perl_my_getenv_len
988                       Perl_my_getpwnam
989                       Perl_my_getpwuid
990                       Perl_my_gmtime
991                       Perl_my_kill
992                       Perl_my_killpg
993                       Perl_my_localtime
994                       Perl_my_mkdir
995                       Perl_my_sigaction
996                       Perl_my_symlink
997                       Perl_my_time
998                       Perl_my_tmpfile
999                       Perl_my_trnlnm
1000                       Perl_my_utime
1001                       Perl_my_waitpid
1002                       Perl_opendir
1003                       Perl_pathify_dirspec
1004                       Perl_pathify_dirspec_ts
1005                       Perl_pathify_dirspec_utf8
1006                       Perl_pathify_dirspec_utf8_ts
1007                       Perl_readdir
1008                       Perl_readdir_r
1009                       Perl_rename
1010                       Perl_rmscopy
1011                       Perl_rmsexpand
1012                       Perl_rmsexpand_ts
1013                       Perl_rmsexpand_utf8
1014                       Perl_rmsexpand_utf8_ts
1015                       Perl_seekdir
1016                       Perl_sig_to_vmscondition
1017                       Perl_telldir
1018                       Perl_tounixpath
1019                       Perl_tounixpath_ts
1020                       Perl_tounixpath_utf8
1021                       Perl_tounixpath_utf8_ts
1022                       Perl_tounixspec
1023                       Perl_tounixspec_ts
1024                       Perl_tounixspec_utf8
1025                       Perl_tounixspec_utf8_ts
1026                       Perl_tovmspath
1027                       Perl_tovmspath_ts
1028                       Perl_tovmspath_utf8
1029                       Perl_tovmspath_utf8_ts
1030                       Perl_tovmsspec
1031                       Perl_tovmsspec_ts
1032                       Perl_tovmsspec_utf8
1033                       Perl_tovmsspec_utf8_ts
1034                       Perl_trim_unixpath
1035                       Perl_vms_case_tolerant
1036                       Perl_vms_do_aexec
1037                       Perl_vms_do_exec
1038                       Perl_vms_image_init
1039                       Perl_vms_realpath
1040                       Perl_vmssetenv
1041                       Perl_vmssetuserlnm
1042                       Perl_vmstrnenv
1043                       PerlIO_openn
1044                  ));
1045 }
1046 elsif ($ARGS{PLATFORM} eq 'os2') {
1047     try_symbols(qw(
1048                       ctermid
1049                       get_sysinfo
1050                       Perl_OS2_init
1051                       Perl_OS2_init3
1052                       Perl_OS2_term
1053                       OS2_Perl_data
1054                       dlopen
1055                       dlsym
1056                       dlerror
1057                       dlclose
1058                       dup2
1059                       dup
1060                       my_tmpfile
1061                       my_tmpnam
1062                       my_flock
1063                       my_rmdir
1064                       my_mkdir
1065                       my_getpwuid
1066                       my_getpwnam
1067                       my_getpwent
1068                       my_setpwent
1069                       my_endpwent
1070                       fork_with_resources
1071                       croak_with_os2error
1072                       setgrent
1073                       endgrent
1074                       getgrent
1075                       malloc_mutex
1076                       threads_mutex
1077                       nthreads
1078                       nthreads_cond
1079                       os2_cond_wait
1080                       os2_stat
1081                       os2_execname
1082                       async_mssleep
1083                       msCounter
1084                       InfoTable
1085                       pthread_join
1086                       pthread_create
1087                       pthread_detach
1088                       XS_Cwd_change_drive
1089                       XS_Cwd_current_drive
1090                       XS_Cwd_extLibpath
1091                       XS_Cwd_extLibpath_set
1092                       XS_Cwd_sys_abspath
1093                       XS_Cwd_sys_chdir
1094                       XS_Cwd_sys_cwd
1095                       XS_Cwd_sys_is_absolute
1096                       XS_Cwd_sys_is_relative
1097                       XS_Cwd_sys_is_rooted
1098                       XS_DynaLoader_mod2fname
1099                       XS_File__Copy_syscopy
1100                       Perl_Register_MQ
1101                       Perl_Deregister_MQ
1102                       Perl_Serve_Messages
1103                       Perl_Process_Messages
1104                       init_PMWIN_entries
1105                       PMWIN_entries
1106                       Perl_hab_GET
1107                       loadByOrdinal
1108                       pExtFCN
1109                       os2error
1110                       ResetWinError
1111                       CroakWinError
1112                       PL_do_undump
1113                  ));
1114 }
1115
1116 # When added this code was only run for Win32 (and WinCE at the time)
1117 # Currently only Win32 links static extensions into the shared library.
1118 # For *nix (and presumably OS/2) with a shared libperl, Makefile.SH compiles
1119 # static extensions with -fPIC, but links them to perl, not libperl.so
1120 # The VMS build scripts don't yet implement static extensions at all.
1121
1122 if ($ARGS{PLATFORM} eq 'win32') {
1123     # records of type boot_module for statically linked modules (except Dynaloader)
1124     my $static_ext = $Config{static_ext} // "";
1125     $static_ext =~ s/\//__/g;
1126     $static_ext =~ s/\bDynaLoader\b//;
1127     try_symbols(map {"boot_$_"} grep {/\S/} split /\s+/, $static_ext);
1128     try_symbols("init_Win32CORE") if $static_ext =~ /\bWin32CORE\b/;
1129 }
1130
1131 if ($ARGS{PLATFORM} eq 'os2') {
1132     my (%mapped, @missing);
1133     open MAP, '<', 'miniperl.map' or die 'Cannot read miniperl.map';
1134     /^\s*[\da-f:]+\s+(\w+)/i and $mapped{$1}++ foreach <MAP>;
1135     close MAP or die 'Cannot close miniperl.map';
1136
1137     @missing = grep { !exists $mapped{$_} }
1138                     keys %export;
1139     @missing = grep { !exists $exportperlmalloc{$_} } @missing;
1140     delete $export{$_} foreach @missing;
1141 }
1142
1143 ###############################################################################
1144
1145 # Now all symbols should be defined because next we are going to output them.
1146
1147 # Start with platform specific headers:
1148
1149 if ($ARGS{PLATFORM} eq 'win32') {
1150     my $dll = $define{PERL_DLL} ? $define{PERL_DLL} =~ s/\.dll$//ir
1151         : "perl$Config{api_revision}$Config{api_version}";
1152     print "LIBRARY $dll\n";
1153     # The DESCRIPTION module definition file statement is not supported
1154     # by VC7 onwards.
1155     if ($ARGS{CCTYPE} eq 'GCC') {
1156         print "DESCRIPTION 'Perl interpreter'\n";
1157     }
1158     print "EXPORTS\n";
1159 }
1160 elsif ($ARGS{PLATFORM} eq 'os2') {
1161     (my $v = $]) =~ s/(\d\.\d\d\d)(\d\d)$/$1_$2/;
1162     $v .= '-thread' if $Config{archname} =~ /-thread/;
1163     (my $dll = $define{PERL_DLL}) =~ s/\.dll$//i;
1164     $v .= "\@$Config{perl_patchlevel}" if $Config{perl_patchlevel};
1165     my $d = "DESCRIPTION '\@#perl5-porters\@perl.org:$v#\@ Perl interpreter, configured as $Config{config_args}'";
1166     $d = substr($d, 0, 249) . "...'" if length $d > 253;
1167     print <<"---EOP---";
1168 LIBRARY '$dll' INITINSTANCE TERMINSTANCE
1169 $d
1170 STACKSIZE 32768
1171 CODE LOADONCALL
1172 DATA LOADONCALL NONSHARED MULTIPLE
1173 EXPORTS
1174 ---EOP---
1175 }
1176 elsif ($ARGS{PLATFORM} eq 'aix') {
1177     my $OSVER = `uname -v`;
1178     chop $OSVER;
1179     my $OSREL = `uname -r`;
1180     chop $OSREL;
1181     if ($OSVER > 4 || ($OSVER == 4 && $OSREL >= 3)) {
1182         print "#! ..\n";
1183     } else {
1184         print "#!\n";
1185     }
1186 }
1187
1188 # Then the symbols
1189
1190 my @symbols = $fold ? sort {lc $a cmp lc $b} keys %export : sort keys %export;
1191 foreach my $symbol (@symbols) {
1192     if (PLATFORM eq 'win32') {
1193         # Remembering the origin file of each symbol is an alternative to PL_ matching
1194         if (substr($symbol, 0, 3) eq 'PL_') {
1195             print "\t$symbol DATA\n";
1196         }
1197         else {
1198             print "\t$symbol\n";
1199         }
1200     }
1201     elsif (PLATFORM eq 'os2') {
1202         printf qq(    %-31s \@%s\n),
1203           qq("$symbol"), $ordinal{$symbol} || ++$sym_ord;
1204         printf qq(    %-31s \@%s\n),
1205           qq("$exportperlmalloc{$symbol}" = "$symbol"),
1206           $ordinal{$exportperlmalloc{$symbol}} || ++$sym_ord
1207           if $exportperlmalloc and exists $exportperlmalloc{$symbol};
1208     } else {
1209         print "$symbol\n";
1210     }
1211 }
1212
1213 # Then platform specific footers.
1214
1215 if ($ARGS{PLATFORM} eq 'os2') {
1216     print <<EOP;
1217     dll_perlmain=main
1218     fill_extLibpath
1219     dir_subst
1220     Perl_OS2_handler_install
1221
1222 ; LAST_ORDINAL=$sym_ord
1223 EOP
1224 }
1225
1226 1;