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