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