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