This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
In makedef.pl, change readvar() to add items to a passed-in hash reference.
[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 -Dusershrplib is in effect,
7 # and by VMS for creating perlshr.exe.
8 #
9 # Reads from information stored in
10 #
11 #    config.h
12 #    config.sh
13 #    global.sym
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 #
21 # plus long lists of function names hard-coded directly in this script.
22 #
23 # Writes the result to STDOUT.
24 #
25 # Normally this script is invoked from a makefile (e.g. win32/Makefile),
26 # which redirects STDOUT to a suitable file, such as:
27 #
28 #    perl5.def   OS/2
29 #    perldll.def Windows
30 #    perl.exp    AIX
31 #    perl.imp    NetWare
32 #    makedef.lis VMS
33
34 BEGIN { unshift @INC, "lib" }
35 use Config;
36 use strict;
37
38 use vars qw($PLATFORM $CCTYPE $FILETYPE $TARG_DIR);
39
40 $CCTYPE = 'MSVC';
41 $TARG_DIR = '';
42
43 my %define;
44
45 while (@ARGV) {
46     my $flag = shift;
47     if ($flag =~ s/^CC_FLAGS=/ /) {
48         for my $fflag ($flag =~ /(?:^|\s)-D(\S+)/g) {
49             $fflag     .= '=1' unless $fflag =~ /^(\w+)=/;
50             $define{$1} = $2   if $fflag =~ /^(\w+)=(.+)$/;
51         }
52         next;
53     }
54     $define{$1} = 1 if ($flag =~ /^-D(\w+)$/);
55     $define{$1} = $2 if ($flag =~ /^-D(\w+)=(.+)$/);
56     $CCTYPE   = $1 if ($flag =~ /^CCTYPE=(\w+)$/);
57     $PLATFORM = $1 if ($flag =~ /^PLATFORM=(\w+)$/);
58     $FILETYPE = $1 if ($flag =~ /^FILETYPE=(\w+)$/);
59     $TARG_DIR = $1 if $flag =~ /^TARG_DIR=(.+)$/;
60 }
61
62 my @PLATFORM = qw(aix win32 wince os2 netware vms);
63 my %PLATFORM;
64 @PLATFORM{@PLATFORM} = ();
65
66 defined $PLATFORM || die "PLATFORM undefined, must be one of: @PLATFORM\n";
67 exists $PLATFORM{$PLATFORM} || die "PLATFORM must be one of: @PLATFORM\n";
68
69 # Add the compile-time options that miniperl was built with to %define.
70 # On Win32 these are not the same options as perl itself will be built
71 # with since miniperl is built with a canned config (one of the win32/
72 # config_H.*) and none of the BUILDOPT's that are set in the makefiles,
73 # but they do include some #define's that are hard-coded in various
74 # source files and header files and don't include any BUILDOPT's that
75 # the user might have chosen to disable because the canned configs are
76 # minimal configs that don't include any of those options.
77
78 my @options = sort(Config::bincompat_options(), Config::non_bincompat_options());
79 print STDERR "Options: (@options)\n";
80 $define{$_} = 1 foreach @options;
81
82 my %exportperlmalloc =
83     (
84        Perl_malloc              =>      "malloc",
85        Perl_mfree               =>      "free",
86        Perl_realloc             =>      "realloc",
87        Perl_calloc              =>      "calloc",
88     );
89
90 my $exportperlmalloc = $PLATFORM eq 'os2';
91
92 my $config_sh   = "config.sh";
93 my $config_h    = "config.h";
94 my $intrpvar_h  = "intrpvar.h";
95 my $perlvars_h  = "perlvars.h";
96 my $global_sym  = "global.sym";
97 my $globvar_sym = "globvar.sym";
98 my $perlio_sym  = "perlio.sym";
99 my $static_ext = "";
100
101 s/^/$TARG_DIR/ foreach($intrpvar_h, $perlvars_h, $global_sym, $globvar_sym,
102                        $perlio_sym, $config_sh);
103
104 unless ($PLATFORM eq 'win32' || $PLATFORM eq 'wince' || $PLATFORM eq 'netware') {
105     open(CFG,$config_sh) || die "Cannot open $config_sh: $!\n";
106     while (<CFG>) {
107         if (/^(?:ccflags|optimize)='(.+)'$/) {
108             $_ = $1;
109             $define{$1} = 1 while /-D(\w+)/g;
110         }
111         $define{$1} = $2
112             if /^(config_args|archname|perl_patchlevel)='(.+)'$/;
113     }
114     close(CFG);
115 }
116 if ($PLATFORM eq 'win32' || $PLATFORM eq 'wince') {
117     open(CFG, '<', $config_sh) || die "Cannot open $config_sh: $!\n";
118     if ((join '', <CFG>) =~ /^static_ext='(.*)'$/m) {
119         $static_ext = $1;
120     }
121     close(CFG);
122 }
123
124 open(CFG,$config_h) || die "Cannot open $config_h: $!\n";
125 while (<CFG>) {
126     $define{$1} = 1 if /^\s*\#\s*define\s+(MYMALLOC|MULTIPLICITY
127                                            |SPRINTF_RETURNS_STRLEN
128                                            |(?:PERL|USE|HAS)_\w+)\b/x;
129 }
130 close(CFG);
131
132 # perl.h logic duplication begins
133
134 if ($define{PERL_IMPLICIT_SYS}) {
135     $define{PL_OP_SLAB_ALLOC} = 1;
136 }
137
138 if ($define{USE_ITHREADS}) {
139     if (!$define{MULTIPLICITY}) {
140         $define{MULTIPLICITY} = 1;
141     }
142 }
143
144 $define{PERL_IMPLICIT_CONTEXT} ||=
145     $define{USE_ITHREADS} ||
146     $define{MULTIPLICITY} ;
147
148 if ($define{USE_ITHREADS} && $PLATFORM ne 'win32' && $^O ne 'darwin') {
149     $define{USE_REENTRANT_API} = 1;
150 }
151
152 # perl.h logic duplication ends
153
154 print STDERR "Defines: (" . join(' ', sort keys %define) . ")\n";
155
156 my $sym_ord = 0;
157 my %ordinal;
158
159 if ($PLATFORM eq 'os2') {
160     if (open my $fh, '<', 'perl5.def') {
161       while (<$fh>) {
162         last if /^\s*EXPORTS\b/;
163       }
164       while (<$fh>) {
165         $ordinal{$1} = $2 if /^\s*"(\w+)"\s*(?:=\s*"\w+"\s*)?\@(\d+)\s*$/;
166         # This allows skipping ordinals which were used in older versions
167         $sym_ord = $1 if /^\s*;\s*LAST_ORDINAL\s*=\s*(\d+)\s*$/;
168       }
169       $sym_ord < $_ and $sym_ord = $_ for values %ordinal; # Take the max
170     }
171 }
172
173 my %skip;
174 # All platforms export boot_DynaLoader unconditionally.
175 my %export = ( boot_DynaLoader => 1 );
176
177 sub try_symbols {
178     foreach my $symbol (@_) {
179         ++$export{$symbol} unless exists $skip{$symbol};
180     }
181 }
182
183 sub readvar {
184     # $hash is the hash that we're adding to. For one of our callers, it will
185     # actually be the skip hash but that doesn't affect the intent of what
186     # we're doing, as in that case we skip adding something to the skip hash
187     # for the second time.
188
189     my ($file, $hash, $proc) = @_;
190     open my $vars, '<', $file or die die "Cannot open $file: $!\n";
191
192     while (<$vars>) {
193         # All symbols have a Perl_ prefix because that's what embed.h sticks
194         # in front of them.  The A?I?S?C? is strictly speaking wrong.
195         next unless /\bPERLVAR(A?I?S?C?)\(([IGT])(\w+)/;
196
197         my $var = "PL_$3";
198         my $symbol = $proc ? &$proc($1,$2,$3) : $var;
199         ++$hash->{$symbol} unless exists $skip{$var};
200     }
201 }
202
203 if ($PLATFORM ne 'os2') {
204     ++$skip{$_} foreach qw(
205                      PL_cryptseen
206                      PL_opsave
207                      Perl_GetVars
208                      Perl_dump_fds
209                      Perl_my_bcopy
210                      Perl_my_bzero
211                      Perl_my_chsize
212                      Perl_my_htonl
213                      Perl_my_memcmp
214                      Perl_my_memset
215                      Perl_my_ntohl
216                      Perl_my_swap
217                          );
218     if ($PLATFORM eq 'vms') {
219         ++$skip{PL_statusvalue_posix};
220     } else {
221         ++$skip{PL_statusvalue_vms};
222         if ($PLATFORM ne 'aix') {
223             ++$skip{$_} foreach qw(
224                                 PL_DBcv
225                                 PL_generation
226                                 PL_lastgotoprobe
227                                 PL_modcount
228                                 PL_timesbuf
229                                 main
230                                  );
231         }
232     }
233 }
234
235 if ($PLATFORM ne 'vms') {
236     # VMS does its own thing for these symbols.
237     ++$skip{$_} foreach qw(
238                         PL_sig_handlers_initted
239                         PL_sig_ignoring
240                         PL_sig_defaulting
241                          );
242     if ($PLATFORM ne 'win32') {
243         ++$skip{$_} foreach qw(
244                             Perl_do_spawn
245                             Perl_do_spawn_nowait
246                             Perl_do_aspawn
247                              );
248     }
249 }
250
251 if ($PLATFORM eq 'os2') {
252     try_symbols(qw(
253                     ctermid
254                     get_sysinfo
255                     Perl_OS2_init
256                     Perl_OS2_init3
257                     Perl_OS2_term
258                     OS2_Perl_data
259                     dlopen
260                     dlsym
261                     dlerror
262                     dlclose
263                     dup2
264                     dup
265                     my_tmpfile
266                     my_tmpnam
267                     my_flock
268                     my_rmdir
269                     my_mkdir
270                     my_getpwuid
271                     my_getpwnam
272                     my_getpwent
273                     my_setpwent
274                     my_endpwent
275                     fork_with_resources
276                     croak_with_os2error
277                     setgrent
278                     endgrent
279                     getgrent
280                     malloc_mutex
281                     threads_mutex
282                     nthreads
283                     nthreads_cond
284                     os2_cond_wait
285                     os2_stat
286                     os2_execname
287                     async_mssleep
288                     msCounter
289                     InfoTable
290                     pthread_join
291                     pthread_create
292                     pthread_detach
293                     XS_Cwd_change_drive
294                     XS_Cwd_current_drive
295                     XS_Cwd_extLibpath
296                     XS_Cwd_extLibpath_set
297                     XS_Cwd_sys_abspath
298                     XS_Cwd_sys_chdir
299                     XS_Cwd_sys_cwd
300                     XS_Cwd_sys_is_absolute
301                     XS_Cwd_sys_is_relative
302                     XS_Cwd_sys_is_rooted
303                     XS_DynaLoader_mod2fname
304                     XS_File__Copy_syscopy
305                     Perl_Register_MQ
306                     Perl_Deregister_MQ
307                     Perl_Serve_Messages
308                     Perl_Process_Messages
309                     init_PMWIN_entries
310                     PMWIN_entries
311                     Perl_hab_GET
312                     loadByOrdinal
313                     pExtFCN
314                     os2error
315                     ResetWinError
316                     CroakWinError
317                     PL_do_undump
318                     ));
319     try_symbols(qw(
320                      os2_cond_wait
321                      pthread_join
322                      pthread_create
323                      pthread_detach
324                     ))
325       if $define{'USE_5005THREADS'} or $define{'USE_ITHREADS'};
326 }
327 elsif ($PLATFORM eq 'vms') {
328     try_symbols(qw(
329                         Perl_cando
330                         Perl_cando_by_name
331                         Perl_closedir
332                         Perl_csighandler_init
333                         Perl_do_rmdir
334                         Perl_fileify_dirspec
335                         Perl_fileify_dirspec_ts
336                         Perl_fileify_dirspec_utf8
337                         Perl_fileify_dirspec_utf8_ts
338                         Perl_flex_fstat
339                         Perl_flex_lstat
340                         Perl_flex_stat
341                         Perl_kill_file
342                         Perl_my_chdir
343                         Perl_my_chmod
344                         Perl_my_crypt
345                         Perl_my_endpwent
346                         Perl_my_fclose
347                         Perl_my_fdopen
348                         Perl_my_fgetname
349                         Perl_my_flush
350                         Perl_my_fwrite
351                         Perl_my_gconvert
352                         Perl_my_getenv
353                         Perl_my_getenv_len
354                         Perl_my_getlogin
355                         Perl_my_getpwnam
356                         Perl_my_getpwuid
357                         Perl_my_gmtime
358                         Perl_my_kill
359                         Perl_my_localtime
360                         Perl_my_mkdir
361                         Perl_my_sigaction 
362                         Perl_my_symlink
363                         Perl_my_time
364                         Perl_my_tmpfile
365                         Perl_my_trnlnm
366                         Perl_my_utime
367                         Perl_my_waitpid
368                         Perl_opendir
369                         Perl_pathify_dirspec
370                         Perl_pathify_dirspec_ts
371                         Perl_pathify_dirspec_utf8
372                         Perl_pathify_dirspec_utf8_ts
373                         Perl_readdir
374                         Perl_readdir_r
375                         Perl_rename
376                         Perl_rmscopy
377                         Perl_rmsexpand
378                         Perl_rmsexpand_ts
379                         Perl_rmsexpand_utf8
380                         Perl_rmsexpand_utf8_ts
381                         Perl_seekdir
382                         Perl_sig_to_vmscondition
383                         Perl_telldir
384                         Perl_tounixpath
385                         Perl_tounixpath_ts
386                         Perl_tounixpath_utf8
387                         Perl_tounixpath_utf8_ts
388                         Perl_tounixspec
389                         Perl_tounixspec_ts
390                         Perl_tounixspec_utf8
391                         Perl_tounixspec_utf8_ts
392                         Perl_tovmspath
393                         Perl_tovmspath_ts
394                         Perl_tovmspath_utf8
395                         Perl_tovmspath_utf8_ts
396                         Perl_tovmsspec
397                         Perl_tovmsspec_ts
398                         Perl_tovmsspec_utf8
399                         Perl_tovmsspec_utf8_ts
400                         Perl_trim_unixpath
401                         Perl_vms_case_tolerant
402                         Perl_vms_do_aexec
403                         Perl_vms_do_exec
404                         Perl_vms_image_init
405                         Perl_vms_realpath
406                         Perl_vmssetenv
407                         Perl_vmssetuserlnm
408                         Perl_vmstrnenv
409                         PerlIO_openn
410                      ));
411 }
412
413 unless ($define{UNLINK_ALL_VERSIONS}) {
414     ++$skip{Perl_unlnk};
415 }
416
417 unless ($define{'DEBUGGING'}) {
418     ++$skip{$_} foreach qw(
419                     Perl_debop
420                     Perl_debprofdump
421                     Perl_debstack
422                     Perl_debstackptrs
423                     Perl_pad_sv
424                     Perl_pad_setsv
425                     Perl_hv_assert
426                     PL_block_type
427                     PL_watchaddr
428                     PL_watchok
429                     PL_watch_pvx
430                          );
431 }
432
433 if ($define{'PERL_IMPLICIT_SYS'}) {
434     ++$skip{$_} foreach qw(
435                     Perl_my_popen
436                     Perl_my_pclose
437                          );
438     ++$export{$_} foreach qw(perl_get_host_info perl_alloc_override);
439     ++$export{perl_clone_host} if $define{USE_ITHREADS};
440 }
441 else {
442     ++$skip{$_} foreach qw(
443                     PL_Mem
444                     PL_MemShared
445                     PL_MemParse
446                     PL_Env
447                     PL_StdIO
448                     PL_LIO
449                     PL_Dir
450                     PL_Sock
451                     PL_Proc
452                     perl_alloc_using
453                     perl_clone_using
454                          );
455 }
456
457 unless ($define{'PERL_OLD_COPY_ON_WRITE'}) {
458     ++$skip{Perl_sv_setsv_cow};
459 }
460
461 unless ($define{'USE_REENTRANT_API'}) {
462     ++$skip{PL_reentrant_buffer};
463 }
464
465 if ($define{'MYMALLOC'}) {
466     try_symbols(qw(
467                     Perl_dump_mstats
468                     Perl_get_mstats
469                     Perl_strdup
470                     Perl_putenv
471                     MallocCfg_ptr
472                     MallocCfgP_ptr
473                     ));
474     if ($define{'USE_ITHREADS'}) {
475         try_symbols(qw(
476                         PL_malloc_mutex
477                         ));
478     }
479     else {
480         ++$skip{PL_malloc_mutex};
481     }
482 }
483 else {
484     ++$skip{$_} foreach qw(
485                     PL_malloc_mutex
486                     Perl_dump_mstats
487                     Perl_get_mstats
488                     MallocCfg_ptr
489                     MallocCfgP_ptr
490                          );
491 }
492
493 if ($define{'PERL_USE_SAFE_PUTENV'}) {
494     ++$skip{PL_use_safe_putenv};
495 }
496
497 unless ($define{'USE_ITHREADS'}) {
498     ++$skip{PL_thr_key};
499 }
500
501 # USE_5005THREADS symbols. Kept as reference for easier removal
502 ++$skip{$_} foreach qw(
503                     PL_sv_mutex
504                     PL_strtab_mutex
505                     PL_svref_mutex
506                     PL_cred_mutex
507                     PL_eval_mutex
508                     PL_fdpid_mutex
509                     PL_sv_lock_mutex
510                     PL_eval_cond
511                     PL_eval_owner
512                     PL_threads_mutex
513                     PL_nthreads
514                     PL_nthreads_cond
515                     PL_threadnum
516                     PL_threadsv_names
517                     PL_thrsv
518                     PL_vtbl_mutex
519                     Perl_condpair_magic
520                     Perl_new_struct_thread
521                     Perl_per_thread_magicals
522                     Perl_thread_create
523                     Perl_find_threadsv
524                     Perl_unlock_condpair
525                     Perl_magic_mutexfree
526                     Perl_sv_lock
527                      );
528
529 unless ($define{'USE_ITHREADS'}) {
530     ++$skip{$_} foreach qw(
531                     PL_op_mutex
532                     PL_regex_pad
533                     PL_regex_padav
534                     PL_dollarzero_mutex
535                     PL_hints_mutex
536                     PL_my_ctx_mutex
537                     PL_perlio_mutex
538                     Perl_clone_params_del
539                     Perl_clone_params_new
540                     Perl_parser_dup
541                     Perl_dirp_dup
542                     Perl_cx_dup
543                     Perl_si_dup
544                     Perl_any_dup
545                     Perl_ss_dup
546                     Perl_fp_dup
547                     Perl_gp_dup
548                     Perl_he_dup
549                     Perl_mg_dup
550                     Perl_re_dup_guts
551                     Perl_sv_dup
552                     Perl_sv_dup_inc
553                     Perl_rvpv_dup
554                     Perl_hek_dup
555                     Perl_sys_intern_dup
556                     perl_clone
557                     perl_clone_using
558                     Perl_stashpv_hvname_match
559                     Perl_regdupe_internal
560                     Perl_newPADOP
561                          );
562 }
563
564 unless ($define{'PERL_IMPLICIT_CONTEXT'}) {
565     ++$skip{$_} foreach qw(
566                     PL_my_cxt_index
567                     PL_my_cxt_list
568                     PL_my_cxt_size
569                     PL_my_cxt_keys
570                     Perl_croak_nocontext
571                     Perl_die_nocontext
572                     Perl_deb_nocontext
573                     Perl_form_nocontext
574                     Perl_load_module_nocontext
575                     Perl_mess_nocontext
576                     Perl_warn_nocontext
577                     Perl_warner_nocontext
578                     Perl_newSVpvf_nocontext
579                     Perl_sv_catpvf_nocontext
580                     Perl_sv_setpvf_nocontext
581                     Perl_sv_catpvf_mg_nocontext
582                     Perl_sv_setpvf_mg_nocontext
583                     Perl_my_cxt_init
584                     Perl_my_cxt_index
585                          );
586 }
587
588 unless ($define{'PL_OP_SLAB_ALLOC'}) {
589     ++$skip{$_} foreach qw(
590                      PL_OpPtr
591                      PL_OpSlab
592                      PL_OpSpace
593                      Perl_Slab_Alloc
594                      Perl_Slab_Free
595                          );
596 }
597
598 unless ($define{'PERL_DEBUG_READONLY_OPS'}) {
599     ++$skip{$_} foreach qw(
600                     PL_slab_count
601                     PL_slabs
602                          );
603 }
604
605 unless ($define{'THREADS_HAVE_PIDS'}) {
606     ++$skip{PL_ppid};
607 }
608
609 unless ($define{'PERL_NEED_APPCTX'}) {
610     ++$skip{PL_appctx};
611 }
612
613 unless ($define{'PERL_NEED_TIMESBASE'}) {
614     ++$skip{PL_timesbase};
615 }
616
617 unless ($define{'DEBUG_LEAKING_SCALARS'}) {
618     ++$skip{PL_sv_serial};
619 }
620
621 unless ($define{'DEBUG_LEAKING_SCALARS_FORK_DUMP'}) {
622     ++$skip{PL_dumper_fd};
623 }
624
625 unless ($define{'PERL_DONT_CREATE_GVSV'}) {
626     ++$skip{Perl_gv_SVadd};
627 }
628
629 if ($define{'SPRINTF_RETURNS_STRLEN'}) {
630     ++$skip{Perl_my_sprintf};
631 }
632
633 unless ($define{'PERL_USES_PL_PIDSTATUS'}) {
634     ++$skip{PL_pidstatus};
635 }
636
637 unless ($define{'PERL_TRACK_MEMPOOL'}) {
638     ++$skip{PL_memory_debug_header};
639 }
640
641 unless ($define{PERL_MAD}) {
642     ++$skip{$_} foreach qw(
643                     PL_madskills
644                     PL_xmlfp
645                          );
646 }
647
648 unless ($define{'MULTIPLICITY'}) {
649     ++$skip{$_} foreach qw(
650                     PL_interp_size
651                     PL_interp_size_5_16_0
652                          );
653 }
654
655 unless ($define{'PERL_GLOBAL_STRUCT'}) {
656     ++$skip{PL_global_struct_size};
657 }
658
659 unless ($define{'PERL_GLOBAL_STRUCT_PRIVATE'}) {
660     ++$skip{$_} foreach qw(
661                     PL_my_cxt_keys
662                     Perl_my_cxt_index
663                          );
664 }
665
666 unless ($define{HAS_MMAP}) {
667     ++$skip{PL_mmap_page_size};
668 }
669
670 if ($define{HAS_SIGACTION}) {
671     ++$skip{PL_sig_trapped};
672 }
673
674 unless ($define{USE_LOCALE_COLLATE}) {
675     ++$skip{$_} foreach qw(
676                     PL_collation_ix
677                     PL_collation_name
678                     PL_collation_standard
679                     PL_collxfrm_base
680                     PL_collxfrm_mult
681                     Perl_sv_collxfrm
682                     Perl_sv_collxfrm_flags
683                          );
684 }
685
686 unless ($define{USE_LOCALE_NUMERIC}) {
687     ++$skip{$_} foreach qw(
688                     PL_numeric_local
689                     PL_numeric_name
690                     PL_numeric_radix_sv
691                     PL_numeric_standard
692                          );
693 }
694
695 unless ($define{HAVE_INTERP_INTERN}) {
696     ++$skip{$_} foreach qw(
697                     Perl_sys_intern_clear
698                     Perl_sys_intern_dup
699                     Perl_sys_intern_init
700                     PL_sys_intern
701                          );
702 }
703
704 if ($define{HAS_SIGNBIT}) {
705     ++$skip{Perl_signbit};
706 }
707
708 if ($define{'PERL_GLOBAL_STRUCT'}) {
709     readvar($perlvars_h, \%skip);
710     ++$export{Perl_GetVars};
711     try_symbols(qw(PL_Vars PL_VarsPtr)) unless $CCTYPE eq 'GCC';
712 } else {
713     ++$skip{$_} foreach qw(Perl_init_global_struct Perl_free_global_struct);
714 }
715
716 # functions from *.sym files
717
718 my @syms = ($global_sym, $globvar_sym);
719
720 # Symbols that are the public face of the PerlIO layers implementation
721 # These are in _addition to_ the public face of the abstraction
722 # and need to be exported to allow XS modules to implement layers
723 my @layer_syms = qw(
724                     PerlIOBase_binmode
725                     PerlIOBase_clearerr
726                     PerlIOBase_close
727                     PerlIOBase_dup
728                     PerlIOBase_eof
729                     PerlIOBase_error
730                     PerlIOBase_fileno
731                     PerlIOBase_noop_fail
732                     PerlIOBase_noop_ok
733                     PerlIOBase_popped
734                     PerlIOBase_pushed
735                     PerlIOBase_read
736                     PerlIOBase_setlinebuf
737                     PerlIOBase_unread
738                     PerlIOBuf_bufsiz
739                     PerlIOBuf_close
740                     PerlIOBuf_dup
741                     PerlIOBuf_fill
742                     PerlIOBuf_flush
743                     PerlIOBuf_get_base
744                     PerlIOBuf_get_cnt
745                     PerlIOBuf_get_ptr
746                     PerlIOBuf_open
747                     PerlIOBuf_popped
748                     PerlIOBuf_pushed
749                     PerlIOBuf_read
750                     PerlIOBuf_seek
751                     PerlIOBuf_set_ptrcnt
752                     PerlIOBuf_tell
753                     PerlIOBuf_unread
754                     PerlIOBuf_write
755                     PerlIO_allocate
756                     PerlIO_apply_layera
757                     PerlIO_apply_layers
758                     PerlIO_arg_fetch
759                     PerlIO_debug
760                     PerlIO_define_layer
761                     PerlIO_find_layer
762                     PerlIO_isutf8
763                     PerlIO_layer_fetch
764                     PerlIO_list_alloc
765                     PerlIO_list_free
766                     PerlIO_modestr
767                     PerlIO_parse_layers
768                     PerlIO_pending
769                     PerlIO_perlio
770                     PerlIO_pop
771                     PerlIO_push
772                     PerlIO_sv_dup
773                     Perl_PerlIO_clearerr
774                     Perl_PerlIO_close
775                     Perl_PerlIO_context_layers
776                     Perl_PerlIO_eof
777                     Perl_PerlIO_error
778                     Perl_PerlIO_fileno
779                     Perl_PerlIO_fill
780                     Perl_PerlIO_flush
781                     Perl_PerlIO_get_base
782                     Perl_PerlIO_get_bufsiz
783                     Perl_PerlIO_get_cnt
784                     Perl_PerlIO_get_ptr
785                     Perl_PerlIO_read
786                     Perl_PerlIO_seek
787                     Perl_PerlIO_set_cnt
788                     Perl_PerlIO_set_ptrcnt
789                     Perl_PerlIO_setlinebuf
790                     Perl_PerlIO_stderr
791                     Perl_PerlIO_stdin
792                     Perl_PerlIO_stdout
793                     Perl_PerlIO_tell
794                     Perl_PerlIO_unread
795                     Perl_PerlIO_write
796 );
797 if ($PLATFORM eq 'netware') {
798     push(@layer_syms,'PL_def_layerlist','PL_known_layers','PL_perlio');
799 }
800
801 if ($define{'USE_PERLIO'}) {
802     # Export the symols that make up the PerlIO abstraction, regardless
803     # of its implementation - read from a file
804     push @syms, $perlio_sym;
805
806     # This part is then dependent on how the abstraction is implemented
807     if ($define{'USE_SFIO'}) {
808         # Old legacy non-stdio "PerlIO"
809         ++$skip{$_} foreach @layer_syms;
810         ++$skip{perlsio_binmode};
811         # SFIO defines most of the PerlIO routines as macros
812         # So undo most of what $perlio_sym has just done - d'oh !
813         # Perhaps it would be better to list the ones which do exist
814         # And emit them
815         ++$skip{$_} foreach qw(
816                          PerlIO_canset_cnt
817                          PerlIO_clearerr
818                          PerlIO_close
819                          PerlIO_eof
820                          PerlIO_error
821                          PerlIO_exportFILE
822                          PerlIO_fast_gets
823                          PerlIO_fdopen
824                          PerlIO_fileno
825                          PerlIO_findFILE
826                          PerlIO_flush
827                          PerlIO_get_base
828                          PerlIO_get_bufsiz
829                          PerlIO_get_cnt
830                          PerlIO_get_ptr
831                          PerlIO_getc
832                          PerlIO_getname
833                          PerlIO_has_base
834                          PerlIO_has_cntptr
835                          PerlIO_importFILE
836                          PerlIO_open
837                          PerlIO_printf
838                          PerlIO_putc
839                          PerlIO_puts
840                          PerlIO_read
841                          PerlIO_releaseFILE
842                          PerlIO_reopen
843                          PerlIO_rewind
844                          PerlIO_seek
845                          PerlIO_set_cnt
846                          PerlIO_set_ptrcnt
847                          PerlIO_setlinebuf
848                          PerlIO_sprintf
849                          PerlIO_stderr
850                          PerlIO_stdin
851                          PerlIO_stdout
852                          PerlIO_stdoutf
853                          PerlIO_tell
854                          PerlIO_ungetc
855                          PerlIO_vprintf
856                          PerlIO_write
857                          PerlIO_perlio
858                          Perl_PerlIO_clearerr
859                          Perl_PerlIO_close
860                          Perl_PerlIO_eof
861                          Perl_PerlIO_error
862                          Perl_PerlIO_fileno
863                          Perl_PerlIO_fill
864                          Perl_PerlIO_flush
865                          Perl_PerlIO_get_base
866                          Perl_PerlIO_get_bufsiz
867                          Perl_PerlIO_get_cnt
868                          Perl_PerlIO_get_ptr
869                          Perl_PerlIO_read
870                          Perl_PerlIO_seek
871                          Perl_PerlIO_set_cnt
872                          Perl_PerlIO_set_ptrcnt
873                          Perl_PerlIO_setlinebuf
874                          Perl_PerlIO_stderr
875                          Perl_PerlIO_stdin
876                          Perl_PerlIO_stdout
877                          Perl_PerlIO_tell
878                          Perl_PerlIO_unread
879                          Perl_PerlIO_write
880                          PL_def_layerlist
881                          PL_known_layers
882                          PL_perlio
883                              );
884     }
885     else {
886         # PerlIO with layers - export implementation
887         try_symbols(@layer_syms, 'perlsio_binmode');
888     }
889     if ($define{'USE_ITHREADS'}) {
890         try_symbols(qw(
891                         PL_perlio_mutex
892                         ));
893     }
894     else {
895         ++$skip{PL_perlio_mutex};
896     }
897 } else {
898         # -Uuseperlio
899         # Skip the PerlIO layer symbols - although
900         # nothing should have exported them anyway.
901         ++$skip{$_} foreach @layer_syms;
902         ++$skip{$_} foreach qw(
903                         perlsio_binmode
904                         PL_def_layerlist
905                         PL_known_layers
906                         PL_perlio
907                         PL_perlio_debug_fd
908                         PL_perlio_fd_refcnt
909                         PL_perlio_fd_refcnt_size
910                              );
911
912         # Also do NOT add abstraction symbols from $perlio_sym
913         # abstraction is done as #define to stdio
914         # Remaining remnants that _may_ be functions are handled below.
915 }
916
917 for my $syms (@syms) {
918     open (GLOBAL, "<$syms") || die "failed to open $syms: $!\n";
919     while (<GLOBAL>) {
920         next if (!/^[A-Za-z]/);
921         # Functions have a Perl_ prefix
922         # Variables have a PL_ prefix
923         chomp($_);
924         my $symbol = ($syms =~ /var\.sym$/i ? "PL_" : "");
925         $symbol .= $_;
926         ++$export{$symbol} unless exists $skip{$symbol};
927     }
928     close(GLOBAL);
929 }
930
931 # variables
932
933 if ($define{'MULTIPLICITY'} && $define{PERL_GLOBAL_STRUCT}) {
934     readvar($perlvars_h, \%export, sub { "Perl_" . $_[1] . $_[2] . "_ptr" });
935     # XXX AIX seems to want the perlvars.h symbols, for some reason
936     if ($PLATFORM eq 'aix' or $PLATFORM eq 'os2') {     # OS/2 needs PL_thr_key
937         readvar($perlvars_h, \%export);
938     }
939 }
940 else {
941     unless ($define{'PERL_GLOBAL_STRUCT'}) {
942         readvar($perlvars_h, \%export);
943     }
944     unless ($define{MULTIPLICITY}) {
945         readvar($intrpvar_h, \%export);
946     }
947 }
948
949 sub try_symbol {
950     my $symbol = shift;
951     ++$export{$symbol} unless $skip{$symbol};
952 }
953
954 # Oddities from PerlIO
955 try_symbols(qw(
956                     PerlIO_binmode
957                     PerlIO_getpos
958                     PerlIO_init
959                     PerlIO_setpos
960                     PerlIO_sprintf
961                     PerlIO_sv_dup
962                     PerlIO_tmpfile
963                     PerlIO_vsprintf
964              ));
965
966 if ($PLATFORM eq 'win32') {
967     try_symbol($_) foreach qw(
968                                  setgid
969                                  setuid
970                                  win32_free_childdir
971                                  win32_free_childenv
972                                  win32_get_childdir
973                                  win32_get_childenv
974                                  win32_spawnvp
975                             );
976 }
977
978 if ($PLATFORM =~ /^win(?:32|ce)$/) {
979     foreach my $symbol (qw(
980                             Perl_init_os_extras
981                             Perl_thread_create
982                             Perl_win32_init
983                             Perl_win32_term
984                             RunPerl
985                             win32_async_check
986                             win32_errno
987                             win32_environ
988                             win32_abort
989                             win32_fstat
990                             win32_stat
991                             win32_pipe
992                             win32_popen
993                             win32_pclose
994                             win32_rename
995                             win32_setmode
996                             win32_chsize
997                             win32_lseek
998                             win32_tell
999                             win32_dup
1000                             win32_dup2
1001                             win32_open
1002                             win32_close
1003                             win32_eof
1004                             win32_isatty
1005                             win32_read
1006                             win32_write
1007                             win32_mkdir
1008                             win32_rmdir
1009                             win32_chdir
1010                             win32_flock
1011                             win32_execv
1012                             win32_execvp
1013                             win32_htons
1014                             win32_ntohs
1015                             win32_htonl
1016                             win32_ntohl
1017                             win32_inet_addr
1018                             win32_inet_ntoa
1019                             win32_socket
1020                             win32_bind
1021                             win32_listen
1022                             win32_accept
1023                             win32_connect
1024                             win32_send
1025                             win32_sendto
1026                             win32_recv
1027                             win32_recvfrom
1028                             win32_shutdown
1029                             win32_closesocket
1030                             win32_ioctlsocket
1031                             win32_setsockopt
1032                             win32_getsockopt
1033                             win32_getpeername
1034                             win32_getsockname
1035                             win32_gethostname
1036                             win32_gethostbyname
1037                             win32_gethostbyaddr
1038                             win32_getprotobyname
1039                             win32_getprotobynumber
1040                             win32_getservbyname
1041                             win32_getservbyport
1042                             win32_select
1043                             win32_endhostent
1044                             win32_endnetent
1045                             win32_endprotoent
1046                             win32_endservent
1047                             win32_getnetent
1048                             win32_getnetbyname
1049                             win32_getnetbyaddr
1050                             win32_getprotoent
1051                             win32_getservent
1052                             win32_sethostent
1053                             win32_setnetent
1054                             win32_setprotoent
1055                             win32_setservent
1056                             win32_getenv
1057                             win32_putenv
1058                             win32_perror
1059                             win32_malloc
1060                             win32_calloc
1061                             win32_realloc
1062                             win32_free
1063                             win32_sleep
1064                             win32_times
1065                             win32_access
1066                             win32_alarm
1067                             win32_chmod
1068                             win32_open_osfhandle
1069                             win32_get_osfhandle
1070                             win32_ioctl
1071                             win32_link
1072                             win32_unlink
1073                             win32_utime
1074                             win32_gettimeofday
1075                             win32_uname
1076                             win32_wait
1077                             win32_waitpid
1078                             win32_kill
1079                             win32_str_os_error
1080                             win32_opendir
1081                             win32_readdir
1082                             win32_telldir
1083                             win32_seekdir
1084                             win32_rewinddir
1085                             win32_closedir
1086                             win32_longpath
1087                             win32_ansipath
1088                             win32_os_id
1089                             win32_getpid
1090                             win32_crypt
1091                             win32_dynaload
1092                             win32_clearenv
1093                             win32_stdin
1094                             win32_stdout
1095                             win32_stderr
1096                             win32_ferror
1097                             win32_feof
1098                             win32_strerror
1099                             win32_fprintf
1100                             win32_printf
1101                             win32_vfprintf
1102                             win32_vprintf
1103                             win32_fread
1104                             win32_fwrite
1105                             win32_fopen
1106                             win32_fdopen
1107                             win32_freopen
1108                             win32_fclose
1109                             win32_fputs
1110                             win32_fputc
1111                             win32_ungetc
1112                             win32_getc
1113                             win32_fileno
1114                             win32_clearerr
1115                             win32_fflush
1116                             win32_ftell
1117                             win32_fseek
1118                             win32_fgetpos
1119                             win32_fsetpos
1120                             win32_rewind
1121                             win32_tmpfile
1122                             win32_setbuf
1123                             win32_setvbuf
1124                             win32_flushall
1125                             win32_fcloseall
1126                             win32_fgets
1127                             win32_gets
1128                             win32_fgetc
1129                             win32_putc
1130                             win32_puts
1131                             win32_getchar
1132                             win32_putchar
1133                            ))
1134     {
1135         try_symbol($symbol);
1136     }
1137     if ($CCTYPE eq "BORLAND") {
1138         try_symbol('_matherr');
1139     }
1140 }
1141 elsif ($PLATFORM eq 'os2') {
1142     my (%mapped, @missing);
1143     open MAP, 'miniperl.map' or die 'Cannot read miniperl.map';
1144     /^\s*[\da-f:]+\s+(\w+)/i and $mapped{$1}++ foreach <MAP>;
1145     close MAP or die 'Cannot close miniperl.map';
1146
1147     @missing = grep { !exists $mapped{$_} }
1148                     keys %export;
1149     @missing = grep { !exists $exportperlmalloc{$_} } @missing;
1150     delete $export{$_} foreach @missing;
1151 }
1152 elsif ($PLATFORM eq 'netware') {
1153 foreach my $symbol (qw(
1154                         Perl_init_os_extras
1155                         Perl_thread_create
1156                         Perl_nw5_init
1157                         RunPerl
1158                         AllocStdPerl
1159                         FreeStdPerl
1160                         do_spawn2
1161                         do_aspawn
1162                         nw_uname
1163                         nw_stdin
1164                         nw_stdout
1165                         nw_stderr
1166                         nw_feof
1167                         nw_ferror
1168                         nw_fopen
1169                         nw_fclose
1170                         nw_clearerr
1171                         nw_getc
1172                         nw_fgets
1173                         nw_fputc
1174                         nw_fputs
1175                         nw_fflush
1176                         nw_ungetc
1177                         nw_fileno
1178                         nw_fdopen
1179                         nw_freopen
1180                         nw_fread
1181                         nw_fwrite
1182                         nw_setbuf
1183                         nw_setvbuf
1184                         nw_vfprintf
1185                         nw_ftell
1186                         nw_fseek
1187                         nw_rewind
1188                         nw_tmpfile
1189                         nw_fgetpos
1190                         nw_fsetpos
1191                         nw_dup
1192                         nw_access
1193                         nw_chmod
1194                         nw_chsize
1195                         nw_close
1196                         nw_dup2
1197                         nw_flock
1198                         nw_isatty
1199                         nw_link
1200                         nw_lseek
1201                         nw_stat
1202                         nw_mktemp
1203                         nw_open
1204                         nw_read
1205                         nw_rename
1206                         nw_setmode
1207                         nw_unlink
1208                         nw_utime
1209                         nw_write
1210                         nw_chdir
1211                         nw_rmdir
1212                         nw_closedir
1213                         nw_opendir
1214                         nw_readdir
1215                         nw_rewinddir
1216                         nw_seekdir
1217                         nw_telldir
1218                         nw_htonl
1219                         nw_htons
1220                         nw_ntohl
1221                         nw_ntohs
1222                         nw_accept
1223                         nw_bind
1224                         nw_connect
1225                         nw_endhostent
1226                         nw_endnetent
1227                         nw_endprotoent
1228                         nw_endservent
1229                         nw_gethostbyaddr
1230                         nw_gethostbyname
1231                         nw_gethostent
1232                         nw_gethostname
1233                         nw_getnetbyaddr
1234                         nw_getnetbyname
1235                         nw_getnetent
1236                         nw_getpeername
1237                         nw_getprotobyname
1238                         nw_getprotobynumber
1239                         nw_getprotoent
1240                         nw_getservbyname
1241                         nw_getservbyport
1242                         nw_getservent
1243                         nw_getsockname
1244                         nw_getsockopt
1245                         nw_inet_addr
1246                         nw_listen
1247                         nw_socket
1248                         nw_recv
1249                         nw_recvfrom
1250                         nw_select
1251                         nw_send
1252                         nw_sendto
1253                         nw_sethostent
1254                         nw_setnetent
1255                         nw_setprotoent
1256                         nw_setservent
1257                         nw_setsockopt
1258                         nw_inet_ntoa
1259                         nw_shutdown
1260                         nw_crypt
1261                         nw_execvp
1262                         nw_kill
1263                         nw_Popen
1264                         nw_Pclose
1265                         nw_Pipe
1266                         nw_times
1267                         nw_waitpid
1268                         nw_getpid
1269                         nw_spawnvp
1270                         nw_os_id
1271                         nw_open_osfhandle
1272                         nw_get_osfhandle
1273                         nw_abort
1274                         nw_sleep
1275                         nw_wait
1276                         nw_dynaload
1277                         nw_strerror
1278                         fnFpSetMode
1279                         fnInsertHashListAddrs
1280                         fnGetHashListAddrs
1281                         Perl_deb
1282                         Perl_sv_setsv
1283                         Perl_sv_catsv
1284                         Perl_sv_catpvn
1285                         Perl_sv_2pv
1286                         nw_freeenviron
1287                         Remove_Thread_Ctx
1288                            ))
1289     {
1290         try_symbol($symbol);
1291     }
1292 }
1293
1294 # records of type boot_module for statically linked modules (except Dynaloader)
1295 $static_ext =~ s/\//__/g;
1296 $static_ext =~ s/\bDynaLoader\b//;
1297 my @stat_mods = map {"boot_$_"} grep {/\S/} split /\s+/, $static_ext;
1298 foreach my $symbol (@stat_mods)
1299     {
1300         try_symbol($symbol);
1301     }
1302
1303 try_symbol("init_Win32CORE") if $static_ext =~ /\bWin32CORE\b/;
1304
1305 ###############################################################################
1306
1307 # Now all symbols should be defined because next we are going to output them.
1308
1309 # Start with platform specific headers:
1310
1311 if ($PLATFORM =~ /^win(?:32|ce)$/) {
1312     (my $dll = ($define{PERL_DLL} || "perl515")) =~ s/\.dll$//i;
1313     print "LIBRARY $dll\n";
1314     # The DESCRIPTION module definition file statement is not supported
1315     # by VC7 onwards.
1316     if ($CCTYPE =~ /^(?:MSVC60|GCC|BORLAND)$/) {
1317         print "DESCRIPTION 'Perl interpreter'\n";
1318     }
1319     print "EXPORTS\n";
1320 }
1321 elsif ($PLATFORM eq 'os2') {
1322     (my $v = $]) =~ s/(\d\.\d\d\d)(\d\d)$/$1_$2/;
1323     $v .= '-thread' if $define{archname} =~ /-thread/;
1324     (my $dll = $define{PERL_DLL}) =~ s/\.dll$//i;
1325     $v .= "\@$define{perl_patchlevel}" if $define{perl_patchlevel};
1326     my $d = "DESCRIPTION '\@#perl5-porters\@perl.org:$v#\@ Perl interpreter, configured as $define{config_args}'";
1327     $d = substr($d, 0, 249) . "...'" if length $d > 253;
1328     print <<"---EOP---";
1329 LIBRARY '$dll' INITINSTANCE TERMINSTANCE
1330 $d
1331 STACKSIZE 32768
1332 CODE LOADONCALL
1333 DATA LOADONCALL NONSHARED MULTIPLE
1334 EXPORTS
1335 ---EOP---
1336 }
1337 elsif ($PLATFORM eq 'aix') {
1338     my $OSVER = `uname -v`;
1339     chop $OSVER;
1340     my $OSREL = `uname -r`;
1341     chop $OSREL;
1342     if ($OSVER > 4 || ($OSVER == 4 && $OSREL >= 3)) {
1343         print "#! ..\n";
1344     } else {
1345         print "#!\n";
1346     }
1347 }
1348 elsif ($PLATFORM eq 'netware') {
1349         if ($FILETYPE eq 'def') {
1350         print "LIBRARY perl515\n";
1351         print "DESCRIPTION 'Perl interpreter for NetWare'\n";
1352         print "EXPORTS\n";
1353         }
1354 }
1355
1356 # Then the symbols
1357
1358 foreach my $symbol (sort keys %export) {
1359     if ($PLATFORM =~ /^win(?:32|ce)$/) {
1360         $symbol = "_$symbol" if $CCTYPE eq 'BORLAND';
1361         print "\t$symbol\n";
1362     }
1363     elsif ($PLATFORM eq 'os2') {
1364         printf qq(    %-31s \@%s\n),
1365           qq("$symbol"), $ordinal{$symbol} || ++$sym_ord;
1366         printf qq(    %-31s \@%s\n),
1367           qq("$exportperlmalloc{$symbol}" = "$symbol"),
1368           $ordinal{$exportperlmalloc{$symbol}} || ++$sym_ord
1369           if $exportperlmalloc and exists $exportperlmalloc{$symbol};
1370     }
1371     elsif ($PLATFORM eq 'netware') {
1372         print "\t$symbol,\n";
1373     } else {
1374         print "$symbol\n";
1375     }
1376 }
1377
1378 # Then platform specific footers.
1379
1380 if ($PLATFORM eq 'os2') {
1381     print <<EOP;
1382     dll_perlmain=main
1383     fill_extLibpath
1384     dir_subst
1385     Perl_OS2_handler_install
1386
1387 ; LAST_ORDINAL=$sym_ord
1388 EOP
1389 }
1390
1391 1;