This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
EBCDIC: special cases of special cases.
[perl5.git] / makedef.pl
1 #
2 # Create the export list for perl.
3 #
4 # Needed by WIN32 and OS/2 for creating perl.dll,
5 # and by AIX for creating libperl.a when -Dusershrplib is in effect,
6 # and by MacOS Classic.
7 #
8 # reads global.sym, pp.sym, perlvars.h, intrpvar.h, thrdvar.h, config.h
9 # On OS/2 reads miniperl.map as well
10
11 my $PLATFORM;
12 my $CCTYPE;
13
14 my %bincompat5005 =
15       (
16        Perl_call_atexit         =>      "perl_atexit",
17        Perl_eval_sv             =>      "perl_eval_sv",
18        Perl_eval_pv             =>      "perl_eval_pv",
19        Perl_call_argv           =>      "perl_call_argv",
20        Perl_call_method         =>      "perl_call_method",
21        Perl_call_pv             =>      "perl_call_pv",
22        Perl_call_sv             =>      "perl_call_sv",
23        Perl_get_av              =>      "perl_get_av",
24        Perl_get_cv              =>      "perl_get_cv",
25        Perl_get_hv              =>      "perl_get_hv",
26        Perl_get_sv              =>      "perl_get_sv",
27        Perl_init_i18nl10n       =>      "perl_init_i18nl10n",
28        Perl_init_i18nl14n       =>      "perl_init_i18nl14n",
29        Perl_new_collate         =>      "perl_new_collate",
30        Perl_new_ctype           =>      "perl_new_ctype",
31        Perl_new_numeric         =>      "perl_new_numeric",
32        Perl_require_pv          =>      "perl_require_pv",
33        Perl_safesyscalloc       =>      "Perl_safecalloc",
34        Perl_safesysfree         =>      "Perl_safefree",
35        Perl_safesysmalloc       =>      "Perl_safemalloc",
36        Perl_safesysrealloc      =>      "Perl_saferealloc",
37        Perl_set_numeric_local   =>      "perl_set_numeric_local",
38        Perl_set_numeric_standard  =>    "perl_set_numeric_standard",
39        Perl_malloc              =>      "malloc",
40        Perl_mfree               =>      "free",
41        Perl_realloc             =>      "realloc",
42        Perl_calloc              =>      "calloc",
43       );
44
45 my $bincompat5005 = join("|", keys %bincompat5005);
46
47 while (@ARGV) {
48     my $flag = shift;
49     $define{$1} = 1 if ($flag =~ /^-D(\w+)$/);
50     $define{$1} = $2 if ($flag =~ /^-D(\w+)=(.+)$/);
51     $CCTYPE   = $1 if ($flag =~ /^CCTYPE=(\w+)$/);
52     $PLATFORM = $1 if ($flag =~ /^PLATFORM=(\w+)$/);
53         if ($PLATFORM eq 'netware') {
54                 $FILETYPE = $1 if ($flag =~ /^FILETYPE=(\w+)$/);
55         }
56 }
57
58 my @PLATFORM = qw(aix win32 os2 MacOS netware);
59 my %PLATFORM;
60 @PLATFORM{@PLATFORM} = ();
61
62 defined $PLATFORM || die "PLATFORM undefined, must be one of: @PLATFORM\n";
63 exists $PLATFORM{$PLATFORM} || die "PLATFORM must be one of: @PLATFORM\n";
64
65 my $config_sh   = "config.sh";
66 my $config_h    = "config.h";
67 my $thrdvar_h   = "thrdvar.h";
68 my $intrpvar_h  = "intrpvar.h";
69 my $perlvars_h  = "perlvars.h";
70 my $global_sym  = "global.sym";
71 my $pp_sym      = "pp.sym";
72 my $globvar_sym = "globvar.sym";
73 my $perlio_sym  = "perlio.sym";
74
75 if ($PLATFORM eq 'aix') {
76     # Nothing for now.
77 }
78 elsif ($PLATFORM eq 'win32' || $PLATFORM eq 'netware') {
79     $CCTYPE = "MSVC" unless defined $CCTYPE;
80     foreach ($thrdvar_h, $intrpvar_h, $perlvars_h, $global_sym,
81                 $pp_sym, $globvar_sym, $perlio_sym) {
82         s!^!..\\!;
83     }
84 }
85 elsif ($PLATFORM eq 'MacOS') {
86     foreach ($thrdvar_h, $intrpvar_h, $perlvars_h, $global_sym,
87                 $pp_sym, $globvar_sym, $perlio_sym) {
88         s!^!::!;
89     }
90 }
91
92 unless ($PLATFORM eq 'win32' || $PLATFORM eq 'MacOS' || $PLATFORM eq 'netware') {
93     open(CFG,$config_sh) || die "Cannot open $config_sh: $!\n";
94     while (<CFG>) {
95         if (/^(?:ccflags|optimize)='(.+)'$/) {
96             $_ = $1;
97             $define{$1} = 1 while /-D(\w+)/g;
98         }
99         if ($PLATFORM eq 'os2') {
100             $CONFIG_ARGS = $1 if /^config_args='(.+)'$/;
101             $ARCHNAME =    $1 if /^archname='(.+)'$/;
102             $PATCHLEVEL =  $1 if /^perl_patchlevel='(.+)'$/;
103         }
104     }
105     close(CFG);
106 }
107
108 open(CFG,$config_h) || die "Cannot open $config_h: $!\n";
109 while (<CFG>) {
110     $define{$1} = 1 if /^\s*#\s*define\s+(MYMALLOC)\b/;
111     $define{$1} = 1 if /^\s*#\s*define\s+(MULTIPLICITY)\b/;
112     $define{$1} = 1 if /^\s*#\s*define\s+(PERL_\w+)\b/;
113     $define{$1} = 1 if /^\s*#\s*define\s+(USE_\w+)\b/;
114 }
115 close(CFG);
116
117 # perl.h logic duplication begins
118
119 if ($define{PERL_IMPLICIT_SYS}) {
120     $define{PL_OP_SLAB_ALLOC} = 1;
121 }
122
123 if ($define{USE_ITHREADS}) {
124     if (!$define{MULTIPLICITY}) {
125         $define{MULTIPLICITY} = 1;
126     }
127 }
128
129 $define{PERL_IMPLICIT_CONTEXT} ||=
130     $define{USE_ITHREADS} ||
131     $define{USE_5005THREADS}  ||
132     $define{MULTIPLICITY} ;
133
134 # perl.h logic duplication ends
135
136 my $sym_ord = 0;
137
138 if ($PLATFORM eq 'win32') {
139     warn join(' ',keys %define)."\n";
140     print "LIBRARY Perl57\n";
141     print "DESCRIPTION 'Perl interpreter'\n";
142     print "EXPORTS\n";
143     if ($define{PERL_IMPLICIT_SYS}) {
144         output_symbol("perl_get_host_info");
145         output_symbol("perl_alloc_override");
146         output_symbol("perl_clone_host");
147     }
148 }
149 elsif ($PLATFORM eq 'os2') {
150     if (open my $fh, '<', 'perl5.def') {
151       while (<$fh>) {
152         last if /^\s*EXPORTS\b/;
153       }
154       while (<$fh>) {
155         $ordinal{$1} = $2 if /^\s*"(\w+)"\s*\@(\d+)\s*$/;
156         # This allows skipping ordinals which were used in older versions
157         $sym_ord = $1 if /^\s*;\s*LAST_ORDINAL\s*=\s*(\d+)\s*$/;
158       }
159       $sym_ord < $_ and $sym_ord = $_ for values %ordinal; # Take the max
160     }
161     ($v = $]) =~ s/(\d\.\d\d\d)(\d\d)$/$1_$2/;
162     $v .= '-thread' if $ARCHNAME =~ /-thread/;
163     ($dll = $define{PERL_DLL}) =~ s/\.dll$//i;
164     $v .= "\@$PATCHLEVEL" if $PATCHLEVEL;
165     $d = "DESCRIPTION '\@#perl5-porters\@perl.org:$v#\@ Perl interpreter, configured as $CONFIG_ARGS'";
166     $d = substr($d, 0, 249) . "...'" if length $d > 253;
167     print <<"---EOP---";
168 LIBRARY '$dll' INITINSTANCE TERMINSTANCE
169 $d
170 STACKSIZE 32768
171 CODE LOADONCALL
172 DATA LOADONCALL NONSHARED MULTIPLE
173 EXPORTS
174 ---EOP---
175 }
176 elsif ($PLATFORM eq 'aix') {
177     $OSVER = `uname -v`;
178     chop $OSVER;
179     $OSREL = `uname -r`;
180     chop $OSREL;
181     if ($OSVER > 4 || ($OSVER == 4 && $OSREL >= 3)) {
182         print "#! ..\n";
183     } else {
184         print "#!\n";
185     }
186 }
187 elsif ($PLATFORM eq 'netware') {
188         if ($FILETYPE eq 'def') {
189         print "LIBRARY Perl57\n";
190         print "DESCRIPTION 'Perl interpreter for NetWare'\n";
191         print "EXPORTS\n";
192         }
193         if ($define{PERL_IMPLICIT_SYS}) {
194             output_symbol("perl_get_host_info");
195             output_symbol("perl_alloc_override");
196             output_symbol("perl_clone_host");
197         }
198 }
199
200 my %skip;
201 my %export;
202
203 sub skip_symbols {
204     my $list = shift;
205     foreach my $symbol (@$list) {
206         $skip{$symbol} = 1;
207     }
208 }
209
210 sub emit_symbols {
211     my $list = shift;
212     foreach my $symbol (@$list) {
213         my $skipsym = $symbol;
214         # XXX hack
215         if ($define{MULTIPLICITY}) {
216             $skipsym =~ s/^Perl_[GIT](\w+)_ptr$/PL_$1/;
217         }
218         emit_symbol($symbol) unless exists $skip{$skipsym};
219     }
220 }
221
222 if ($PLATFORM eq 'win32') {
223     skip_symbols [qw(
224                      PL_statusvalue_vms
225                      PL_archpat_auto
226                      PL_cryptseen
227                      PL_DBcv
228                      PL_generation
229                      PL_lastgotoprobe
230                      PL_linestart
231                      PL_modcount
232                      PL_pending_ident
233                      PL_sortcxix
234                      PL_sublex_info
235                      PL_timesbuf
236                      main
237                      Perl_ErrorNo
238                      Perl_GetVars
239                      Perl_do_exec3
240                      Perl_do_ipcctl
241                      Perl_do_ipcget
242                      Perl_do_msgrcv
243                      Perl_do_msgsnd
244                      Perl_do_semop
245                      Perl_do_shmio
246                      Perl_dump_fds
247                      Perl_init_thread_intern
248                      Perl_my_bzero
249                      Perl_my_bcopy
250                      Perl_my_htonl
251                      Perl_my_ntohl
252                      Perl_my_swap
253                      Perl_my_chsize
254                      Perl_same_dirent
255                      Perl_setenv_getix
256                      Perl_unlnk
257                      Perl_watch
258                      Perl_safexcalloc
259                      Perl_safexmalloc
260                      Perl_safexfree
261                      Perl_safexrealloc
262                      Perl_my_memcmp
263                      Perl_my_memset
264                      PL_cshlen
265                      PL_cshname
266                      PL_opsave
267                      Perl_do_exec
268                      Perl_getenv_len
269                      Perl_my_pclose
270                      Perl_my_popen
271                      )];
272 }
273 elsif ($PLATFORM eq 'aix') {
274     skip_symbols([qw(
275                      Perl_dump_fds
276                      Perl_ErrorNo
277                      Perl_GetVars
278                      Perl_my_bcopy
279                      Perl_my_bzero
280                      Perl_my_chsize
281                      Perl_my_htonl
282                      Perl_my_memcmp
283                      Perl_my_memset
284                      Perl_my_ntohl
285                      Perl_my_swap
286                      Perl_safexcalloc
287                      Perl_safexfree
288                      Perl_safexmalloc
289                      Perl_safexrealloc
290                      Perl_same_dirent
291                      Perl_unlnk
292                      Perl_sys_intern_clear
293                      Perl_sys_intern_dup
294                      Perl_sys_intern_init
295                      PL_cryptseen
296                      PL_opsave
297                      PL_statusvalue_vms
298                      PL_sys_intern
299                      )]);
300 }
301 elsif ($PLATFORM eq 'os2') {
302     emit_symbols([qw(
303                     ctermid
304                     get_sysinfo
305                     Perl_OS2_init
306                     Perl_OS2_init3
307                     Perl_OS2_term
308                     OS2_Perl_data
309                     dlopen
310                     dlsym
311                     dlerror
312                     dlclose
313                     my_tmpfile
314                     my_tmpnam
315                     my_flock
316                     my_rmdir
317                     my_mkdir
318                     my_getpwuid
319                     my_getpwnam
320                     my_getpwent
321                     my_setpwent
322                     my_endpwent
323                     setgrent
324                     endgrent
325                     getgrent
326                     malloc_mutex
327                     threads_mutex
328                     nthreads
329                     nthreads_cond
330                     os2_cond_wait
331                     os2_stat
332                     pthread_join
333                     pthread_create
334                     pthread_detach
335                     XS_Cwd_change_drive
336                     XS_Cwd_current_drive
337                     XS_Cwd_extLibpath
338                     XS_Cwd_extLibpath_set
339                     XS_Cwd_sys_abspath
340                     XS_Cwd_sys_chdir
341                     XS_Cwd_sys_cwd
342                     XS_Cwd_sys_is_absolute
343                     XS_Cwd_sys_is_relative
344                     XS_Cwd_sys_is_rooted
345                     XS_DynaLoader_mod2fname
346                     XS_File__Copy_syscopy
347                     Perl_Register_MQ
348                     Perl_Deregister_MQ
349                     Perl_Serve_Messages
350                     Perl_Process_Messages
351                     init_PMWIN_entries
352                     PMWIN_entries
353                     Perl_hab_GET
354                     loadByOrdinal
355                     pExtFCN
356                     os2error
357                     ResetWinError
358                     CroakWinError
359                     )]);
360 }
361 elsif ($PLATFORM eq 'MacOS') {
362     skip_symbols [qw(
363                     Perl_GetVars
364                     PL_cryptseen
365                     PL_cshlen
366                     PL_cshname
367                     PL_statusvalue_vms
368                     PL_sys_intern
369                     PL_opsave
370                     PL_timesbuf
371                     Perl_dump_fds
372                     Perl_my_bcopy
373                     Perl_my_bzero
374                     Perl_my_chsize
375                     Perl_my_htonl
376                     Perl_my_memcmp
377                     Perl_my_memset
378                     Perl_my_ntohl
379                     Perl_my_swap
380                     Perl_safexcalloc
381                     Perl_safexfree
382                     Perl_safexmalloc
383                     Perl_safexrealloc
384                     Perl_unlnk
385                     Perl_sys_intern_clear
386                     Perl_sys_intern_init
387                     )];
388 }
389 elsif ($PLATFORM eq 'netware') {
390         skip_symbols [qw(
391                         PL_statusvalue_vms
392                         PL_archpat_auto
393                         PL_cryptseen
394                         PL_DBcv
395                         PL_generation
396                         PL_lastgotoprobe
397                         PL_linestart
398                         PL_modcount
399                         PL_pending_ident
400                         PL_sortcxix
401                         PL_sublex_info
402                         PL_timesbuf
403                         main
404                         Perl_ErrorNo
405                         Perl_GetVars
406                         Perl_do_exec3
407                         Perl_do_ipcctl
408                         Perl_do_ipcget
409                         Perl_do_msgrcv
410                         Perl_do_msgsnd
411                         Perl_do_semop
412                         Perl_do_shmio
413                         Perl_dump_fds
414                         Perl_init_thread_intern
415                         Perl_my_bzero
416                         Perl_my_htonl
417                         Perl_my_ntohl
418                         Perl_my_swap
419                         Perl_my_chsize
420                         Perl_same_dirent
421                         Perl_setenv_getix
422                         Perl_unlnk
423                         Perl_watch
424                         Perl_safexcalloc
425                         Perl_safexmalloc
426                         Perl_safexfree
427                         Perl_safexrealloc
428                         Perl_my_memcmp
429                         Perl_my_memset
430                         PL_cshlen
431                         PL_cshname
432                         PL_opsave
433                         Perl_do_exec
434                         Perl_getenv_len
435                         Perl_my_pclose
436                         Perl_my_popen
437                         )];
438 }
439
440 unless ($define{'DEBUGGING'}) {
441     skip_symbols [qw(
442                     Perl_deb_growlevel
443                     Perl_debop
444                     Perl_debprofdump
445                     Perl_debstack
446                     Perl_debstackptrs
447                     Perl_sv_peek
448                     PL_block_type
449                     PL_watchaddr
450                     PL_watchok
451                     )];
452 }
453
454 if ($define{'PERL_IMPLICIT_SYS'}) {
455     skip_symbols [qw(
456                     Perl_getenv_len
457                     Perl_my_popen
458                     Perl_my_pclose
459                     )];
460 }
461 else {
462     skip_symbols [qw(
463                     PL_Mem
464                     PL_MemShared
465                     PL_MemParse
466                     PL_Env
467                     PL_StdIO
468                     PL_LIO
469                     PL_Dir
470                     PL_Sock
471                     PL_Proc
472                     )];
473 }
474
475 unless ($define{'PERL_FLEXIBLE_EXCEPTIONS'}) {
476     skip_symbols [qw(
477                     PL_protect
478                     Perl_default_protect
479                     Perl_vdefault_protect
480                     )];
481 }
482
483 unless ($define{'USE_REENTRANT_API'}) {
484     skip_symbols [qw(
485                     PL_reentrant_buffer
486                     )];
487 }
488
489 if ($define{'MYMALLOC'}) {
490     emit_symbols [qw(
491                     Perl_dump_mstats
492                     Perl_get_mstats
493                     Perl_strdup
494                     Perl_putenv
495                     )];
496     if ($define{'USE_5005THREADS'} || $define{'USE_ITHREADS'}) {
497         emit_symbols [qw(
498                         PL_malloc_mutex
499                         )];
500     }
501     else {
502         skip_symbols [qw(
503                         PL_malloc_mutex
504                         )];
505     }
506 }
507 else {
508     skip_symbols [qw(
509                     PL_malloc_mutex
510                     Perl_dump_mstats
511                     Perl_get_mstats
512                     Perl_malloced_size
513                     )];
514 }
515
516 unless ($define{'USE_5005THREADS'} || $define{'USE_ITHREADS'}) {
517     skip_symbols [qw(
518                     PL_thr_key
519                     )];
520 }
521
522 unless ($define{'USE_5005THREADS'}) {
523     skip_symbols [qw(
524                     PL_sv_mutex
525                     PL_strtab_mutex
526                     PL_svref_mutex
527                     PL_cred_mutex
528                     PL_eval_mutex
529                     PL_fdpid_mutex
530                     PL_sv_lock_mutex
531                     PL_eval_cond
532                     PL_eval_owner
533                     PL_threads_mutex
534                     PL_nthreads
535                     PL_nthreads_cond
536                     PL_threadnum
537                     PL_threadsv_names
538                     PL_thrsv
539                     PL_vtbl_mutex
540                     Perl_condpair_magic
541                     Perl_new_struct_thread
542                     Perl_per_thread_magicals
543                     Perl_thread_create
544                     Perl_find_threadsv
545                     Perl_unlock_condpair
546                     Perl_magic_mutexfree
547                     Perl_sv_lock
548                     )];
549 }
550
551 unless ($define{'USE_ITHREADS'}) {
552     skip_symbols [qw(
553                     PL_ptr_table
554                     PL_op_mutex
555                     PL_regex_pad
556                     PL_regex_padav
557                     PL_sharedsv_space
558                     PL_sharedsv_space_mutex
559                     Perl_dirp_dup
560                     Perl_cx_dup
561                     Perl_si_dup
562                     Perl_any_dup
563                     Perl_ss_dup
564                     Perl_fp_dup
565                     Perl_gp_dup
566                     Perl_he_dup
567                     Perl_mg_dup
568                     Perl_re_dup
569                     Perl_sv_dup
570                     Perl_sys_intern_dup
571                     Perl_ptr_table_clear
572                     Perl_ptr_table_fetch
573                     Perl_ptr_table_free
574                     Perl_ptr_table_new
575                     Perl_ptr_table_clear
576                     Perl_ptr_table_free
577                     Perl_ptr_table_split
578                     Perl_ptr_table_store
579                     perl_clone
580                     perl_clone_using
581                     Perl_sharedsv_find
582                     Perl_sharedsv_init
583                     Perl_sharedsv_lock
584                     Perl_sharedsv_new
585                     Perl_sharedsv_thrcnt_dec
586                     Perl_sharedsv_thrcnt_inc
587                     Perl_sharedsv_unlock
588                     )];
589 }
590
591 unless ($define{'PERL_IMPLICIT_CONTEXT'}) {
592     skip_symbols [qw(
593                     Perl_croak_nocontext
594                     Perl_die_nocontext
595                     Perl_deb_nocontext
596                     Perl_form_nocontext
597                     Perl_load_module_nocontext
598                     Perl_mess_nocontext
599                     Perl_warn_nocontext
600                     Perl_warner_nocontext
601                     Perl_newSVpvf_nocontext
602                     Perl_sv_catpvf_nocontext
603                     Perl_sv_setpvf_nocontext
604                     Perl_sv_catpvf_mg_nocontext
605                     Perl_sv_setpvf_mg_nocontext
606                     )];
607 }
608
609 unless ($define{'PERL_IMPLICIT_SYS'}) {
610     skip_symbols [qw(
611                     perl_alloc_using
612                     perl_clone_using
613                     )];
614 }
615
616 unless ($define{'FAKE_THREADS'}) {
617     skip_symbols [qw(PL_curthr)];
618 }
619
620 unless ($define{'PL_OP_SLAB_ALLOC'}) {
621     skip_symbols [qw(
622                      PL_OpPtr
623                      PL_OpSlab
624                      PL_OpSpace
625                     )];
626 }
627
628 sub readvar {
629     my $file = shift;
630     my $proc = shift || sub { "PL_$_[2]" };
631     open(VARS,$file) || die "Cannot open $file: $!\n";
632     my @syms;
633     while (<VARS>) {
634         # All symbols have a Perl_ prefix because that's what embed.h
635         # sticks in front of them.
636         push(@syms, &$proc($1,$2,$3)) if (/\bPERLVAR(A?I?C?)\(([IGT])(\w+)/);
637     }
638     close(VARS);
639     return \@syms;
640 }
641
642 if ($define{'USE_5005THREADS'}) {
643     my $thrd = readvar($thrdvar_h);
644     skip_symbols $thrd;
645 }
646
647 if ($define{'PERL_GLOBAL_STRUCT'}) {
648     my $global = readvar($perlvars_h);
649     skip_symbols $global;
650     emit_symbol('Perl_GetVars');
651     emit_symbols [qw(PL_Vars PL_VarsPtr)] unless $CCTYPE eq 'GCC';
652 }
653
654 # functions from *.sym files
655
656 my @syms = ($global_sym, $globvar_sym); # $pp_sym is not part of the API
657
658 my @layer_syms = qw(
659                          PerlIOBase_clearerr
660                          PerlIOBase_close
661                          PerlIOBase_dup
662                          PerlIOBase_eof
663                          PerlIOBase_error
664                          PerlIOBase_fileno
665                          PerlIOBase_pushed
666                          PerlIOBase_read
667                          PerlIOBase_setlinebuf
668                          PerlIOBase_unread
669                          PerlIOBuf_bufsiz
670                          PerlIOBuf_fill
671                          PerlIOBuf_flush
672                          PerlIOBuf_get_cnt
673                          PerlIOBuf_get_ptr
674                          PerlIOBuf_open
675                          PerlIOBuf_pushed
676                          PerlIOBuf_read
677                          PerlIOBuf_seek
678                          PerlIOBuf_set_ptrcnt
679                          PerlIOBuf_tell
680                          PerlIOBuf_unread
681                          PerlIOBuf_write
682                          PerlIO_allocate
683                          PerlIO_arg_fetch
684                          PerlIO_define_layer
685                          PerlIO_modestr
686                          PerlIO_pending
687                          PerlIO_push
688                          PerlIO_sv_dup
689                          PL_def_layerlist
690                          PL_known_layers
691                          PL_perlio
692 );
693
694 if ($define{'USE_PERLIO'}) {
695     push @syms, $perlio_sym;
696     if ($define{'USE_SFIO'}) {
697         skip_symbols \@layer_syms;
698         # SFIO defines most of the PerlIO routines as macros
699         skip_symbols [qw(
700                          PerlIO_canset_cnt
701                          PerlIO_clearerr
702                          PerlIO_close
703                          PerlIO_eof
704                          PerlIO_error
705                          PerlIO_exportFILE
706                          PerlIO_fast_gets
707                          PerlIO_fdopen
708                          PerlIO_fileno
709                          PerlIO_findFILE
710                          PerlIO_flush
711                          PerlIO_get_base
712                          PerlIO_get_bufsiz
713                          PerlIO_get_cnt
714                          PerlIO_get_ptr
715                          PerlIO_getc
716                          PerlIO_getname
717                          PerlIO_has_base
718                          PerlIO_has_cntptr
719                          PerlIO_importFILE
720                          PerlIO_open
721                          PerlIO_printf
722                          PerlIO_putc
723                          PerlIO_puts
724                          PerlIO_read
725                          PerlIO_releaseFILE
726                          PerlIO_reopen
727                          PerlIO_rewind
728                          PerlIO_seek
729                          PerlIO_set_cnt
730                          PerlIO_set_ptrcnt
731                          PerlIO_setlinebuf
732                          PerlIO_sprintf
733                          PerlIO_stderr
734                          PerlIO_stdin
735                          PerlIO_stdout
736                          PerlIO_stdoutf
737                          PerlIO_tell
738                          PerlIO_ungetc
739                          PerlIO_vprintf
740                          PerlIO_write
741                          )];
742     }
743 } else {
744         # Skip the PerlIO New Generation symbols.
745         skip_symbols \@layer_syms;
746 }
747
748 for my $syms (@syms) {
749     open (GLOBAL, "<$syms") || die "failed to open $syms: $!\n";
750     while (<GLOBAL>) {
751         next if (!/^[A-Za-z]/);
752         # Functions have a Perl_ prefix
753         # Variables have a PL_ prefix
754         chomp($_);
755         my $symbol = ($syms =~ /var\.sym$/i ? "PL_" : "");
756         $symbol .= $_;
757         emit_symbol($symbol) unless exists $skip{$symbol};
758     }
759     close(GLOBAL);
760 }
761
762 # variables
763
764 if ($define{'MULTIPLICITY'}) {
765     for my $f ($perlvars_h, $intrpvar_h, $thrdvar_h) {
766         my $glob = readvar($f, sub { "Perl_" . $_[1] . $_[2] . "_ptr" });
767         emit_symbols $glob;
768     }
769     # XXX AIX seems to want the perlvars.h symbols, for some reason
770     if ($PLATFORM eq 'aix') {
771         my $glob = readvar($perlvars_h);
772         emit_symbols $glob;
773     }
774 }
775 else {
776     unless ($define{'PERL_GLOBAL_STRUCT'}) {
777         my $glob = readvar($perlvars_h);
778         emit_symbols $glob;
779     }
780     unless ($define{'MULTIPLICITY'}) {
781         my $glob = readvar($intrpvar_h);
782         emit_symbols $glob;
783     }
784     unless ($define{'MULTIPLICITY'} || $define{'USE_5005THREADS'}) {
785         my $glob = readvar($thrdvar_h);
786         emit_symbols $glob;
787     }
788 }
789
790 sub try_symbol {
791     my $symbol = shift;
792
793     return if $symbol !~ /^[A-Za-z_]/;
794     return if $symbol =~ /^\#/;
795     $symbol =~s/\r//g;
796     chomp($symbol);
797     return if exists $skip{$symbol};
798     emit_symbol($symbol);
799 }
800
801 while (<DATA>) {
802     try_symbol($_);
803 }
804
805 if ($PLATFORM eq 'win32') {
806     foreach my $symbol (qw(
807                             setuid
808                             setgid
809                             boot_DynaLoader
810                             Perl_init_os_extras
811                             Perl_thread_create
812                             Perl_win32_init
813                             RunPerl
814                             win32_async_check
815                             win32_errno
816                             win32_environ
817                             win32_abort
818                             win32_fstat
819                             win32_stat
820                             win32_pipe
821                             win32_popen
822                             win32_pclose
823                             win32_rename
824                             win32_setmode
825                             win32_lseek
826                             win32_tell
827                             win32_dup
828                             win32_dup2
829                             win32_open
830                             win32_close
831                             win32_eof
832                             win32_read
833                             win32_write
834                             win32_spawnvp
835                             win32_mkdir
836                             win32_rmdir
837                             win32_chdir
838                             win32_flock
839                             win32_execv
840                             win32_execvp
841                             win32_htons
842                             win32_ntohs
843                             win32_htonl
844                             win32_ntohl
845                             win32_inet_addr
846                             win32_inet_ntoa
847                             win32_socket
848                             win32_bind
849                             win32_listen
850                             win32_accept
851                             win32_connect
852                             win32_send
853                             win32_sendto
854                             win32_recv
855                             win32_recvfrom
856                             win32_shutdown
857                             win32_closesocket
858                             win32_ioctlsocket
859                             win32_setsockopt
860                             win32_getsockopt
861                             win32_getpeername
862                             win32_getsockname
863                             win32_gethostname
864                             win32_gethostbyname
865                             win32_gethostbyaddr
866                             win32_getprotobyname
867                             win32_getprotobynumber
868                             win32_getservbyname
869                             win32_getservbyport
870                             win32_select
871                             win32_endhostent
872                             win32_endnetent
873                             win32_endprotoent
874                             win32_endservent
875                             win32_getnetent
876                             win32_getnetbyname
877                             win32_getnetbyaddr
878                             win32_getprotoent
879                             win32_getservent
880                             win32_sethostent
881                             win32_setnetent
882                             win32_setprotoent
883                             win32_setservent
884                             win32_getenv
885                             win32_putenv
886                             win32_perror
887                             win32_malloc
888                             win32_calloc
889                             win32_realloc
890                             win32_free
891                             win32_sleep
892                             win32_times
893                             win32_access
894                             win32_alarm
895                             win32_chmod
896                             win32_open_osfhandle
897                             win32_get_osfhandle
898                             win32_ioctl
899                             win32_link
900                             win32_unlink
901                             win32_utime
902                             win32_uname
903                             win32_wait
904                             win32_waitpid
905                             win32_kill
906                             win32_str_os_error
907                             win32_opendir
908                             win32_readdir
909                             win32_telldir
910                             win32_seekdir
911                             win32_rewinddir
912                             win32_closedir
913                             win32_longpath
914                             win32_os_id
915                             win32_getpid
916                             win32_crypt
917                             win32_dynaload
918                             win32_get_childenv
919                             win32_free_childenv
920                             win32_clearenv
921                             win32_get_childdir
922                             win32_free_childdir
923                             win32_stdin
924                             win32_stdout
925                             win32_stderr
926                             win32_ferror
927                             win32_feof
928                             win32_strerror
929                             win32_fprintf
930                             win32_printf
931                             win32_vfprintf
932                             win32_vprintf
933                             win32_fread
934                             win32_fwrite
935                             win32_fopen
936                             win32_fdopen
937                             win32_freopen
938                             win32_fclose
939                             win32_fputs
940                             win32_fputc
941                             win32_ungetc
942                             win32_getc
943                             win32_fileno
944                             win32_clearerr
945                             win32_fflush
946                             win32_ftell
947                             win32_fseek
948                             win32_fgetpos
949                             win32_fsetpos
950                             win32_rewind
951                             win32_tmpfile
952                             win32_setbuf
953                             win32_setvbuf
954                             win32_flushall
955                             win32_fcloseall
956                             win32_fgets
957                             win32_gets
958                             win32_fgetc
959                             win32_putc
960                             win32_puts
961                             win32_getchar
962                             win32_putchar
963                            ))
964     {
965         try_symbol($symbol);
966     }
967 }
968 elsif ($PLATFORM eq 'os2') {
969     open MAP, 'miniperl.map' or die 'Cannot read miniperl.map';
970     /^\s*[\da-f:]+\s+(\w+)/i and $mapped{$1}++ foreach <MAP>;
971     close MAP or die 'Cannot close miniperl.map';
972
973     @missing = grep { !exists $mapped{$_} and !exists $bincompat5005{$_} }
974                     keys %export;
975     delete $export{$_} foreach @missing;
976 }
977 elsif ($PLATFORM eq 'MacOS') {
978     open MACSYMS, 'macperl.sym' or die 'Cannot read macperl.sym';
979
980     while (<MACSYMS>) {
981         try_symbol($_);
982     }
983
984     close MACSYMS;
985 }
986 elsif ($PLATFORM eq 'netware') {
987 foreach my $symbol (qw(
988                         boot_DynaLoader
989                         Perl_init_os_extras
990                         Perl_thread_create
991                         Perl_nw5_init
992                         RunPerl
993                         AllocStdPerl
994                         FreeStdPerl
995                         do_spawn2
996                         do_aspawn
997                         nw_uname
998                         nw_stdin
999                         nw_stdout
1000                         nw_stderr
1001                         nw_feof
1002                         nw_ferror
1003                         nw_fopen
1004                         nw_fclose
1005                         nw_clearerr
1006                         nw_getc
1007                         nw_fgets
1008                         nw_fputc
1009                         nw_fputs
1010                         nw_fflush
1011                         nw_ungetc
1012                         nw_fileno
1013                         nw_fdopen
1014                         nw_freopen
1015                         nw_fread
1016                         nw_fwrite
1017                         nw_setbuf
1018                         nw_setvbuf
1019                         nw_vfprintf
1020                         nw_ftell
1021                         nw_fseek
1022                         nw_rewind
1023                         nw_tmpfile
1024                         nw_fgetpos
1025                         nw_fsetpos
1026                         nw_dup
1027                         nw_access
1028                         nw_chmod
1029                         nw_chsize
1030                         nw_close
1031                         nw_dup2
1032                         nw_flock
1033                         nw_isatty
1034                         nw_link
1035                         nw_lseek
1036                         nw_stat
1037                         nw_mktemp
1038                         nw_open
1039                         nw_read
1040                         nw_rename
1041                         nw_setmode
1042                         nw_unlink
1043                         nw_utime
1044                         nw_write
1045                         nw_chdir
1046                         nw_rmdir
1047                         nw_closedir
1048                         nw_opendir
1049                         nw_readdir
1050                         nw_rewinddir
1051                         nw_seekdir
1052                         nw_telldir
1053                         nw_htonl
1054                         nw_htons
1055                         nw_ntohl
1056                         nw_ntohs
1057                         nw_accept
1058                         nw_bind
1059                         nw_connect
1060                         nw_endhostent
1061                         nw_endnetent
1062                         nw_endprotoent
1063                         nw_endservent
1064                         nw_gethostbyaddr
1065                         nw_gethostbyname
1066                         nw_gethostent
1067                         nw_gethostname
1068                         nw_getnetbyaddr
1069                         nw_getnetbyname
1070                         nw_getnetent
1071                         nw_getpeername
1072                         nw_getprotobyname
1073                         nw_getprotobynumber
1074                         nw_getprotoent
1075                         nw_getservbyname
1076                         nw_getservbyport
1077                         nw_getservent
1078                         nw_getsockname
1079                         nw_getsockopt
1080                         nw_inet_addr
1081                         nw_listen
1082                         nw_socket
1083                         nw_recv
1084                         nw_recvfrom
1085                         nw_select
1086                         nw_send
1087                         nw_sendto
1088                         nw_sethostent
1089                         nw_setnetent
1090                         nw_setprotoent
1091                         nw_setservent
1092                         nw_setsockopt
1093                         nw_inet_ntoa
1094                         nw_shutdown
1095                         nw_crypt
1096                         nw_execvp
1097                         nw_kill
1098                         nw_Popen
1099                         nw_Pclose
1100                         nw_Pipe
1101                         nw_times
1102                         nw_waitpid
1103                         nw_getpid
1104                         nw_spawnvp
1105                         nw_os_id
1106                         nw_open_osfhandle
1107                         nw_get_osfhandle
1108                         nw_abort
1109                         nw_sleep
1110                         nw_wait
1111                         nw_dynaload
1112                         nw_strerror
1113                         fnFpSetMode
1114                         fnInsertHashListAddrs
1115                         fnGetHashListAddrs
1116                         Perl_deb
1117                            ))
1118     {
1119         try_symbol($symbol);
1120     }
1121 }
1122
1123 # Now all symbols should be defined because
1124 # next we are going to output them.
1125
1126 foreach my $symbol (sort keys %export) {
1127     output_symbol($symbol);
1128 }
1129
1130 if ($PLATFORM eq 'netware') {
1131         # This may not be the right way to do.  This is to make sure
1132         # that the last symbol will not contain a comma else
1133         # Watcom linker cribs
1134         print "\tdummy\n";
1135 } elsif ($PLATFORM eq 'os2') {
1136         print "; LAST_ORDINAL=$sym_ord\n";
1137 }
1138
1139 sub emit_symbol {
1140     my $symbol = shift;
1141     chomp($symbol);
1142     $export{$symbol} = 1;
1143 }
1144
1145 sub output_symbol {
1146     my $symbol = shift;
1147     $symbol = $bincompat5005{$symbol}
1148         if $define{PERL_BINCOMPAT_5005} and $symbol =~ /^($bincompat5005)$/;
1149     if ($PLATFORM eq 'win32') {
1150         $symbol = "_$symbol" if $CCTYPE eq 'BORLAND';
1151         print "\t$symbol\n";
1152 # XXX: binary compatibility between compilers is an exercise
1153 # in frustration :-(
1154 #        if ($CCTYPE eq "BORLAND") {
1155 #           # workaround Borland quirk by exporting both the straight
1156 #           # name and a name with leading underscore.  Note the
1157 #           # alias *must* come after the symbol itself, if both
1158 #           # are to be exported. (Linker bug?)
1159 #           print "\t_$symbol\n";
1160 #           print "\t$symbol = _$symbol\n";
1161 #       }
1162 #       elsif ($CCTYPE eq 'GCC') {
1163 #           # Symbols have leading _ whole process is $%@"% slow
1164 #           # so skip aliases for now
1165 #           nprint "\t$symbol\n";
1166 #       }
1167 #       else {
1168 #           # for binary coexistence, export both the symbol and
1169 #           # alias with leading underscore
1170 #           print "\t$symbol\n";
1171 #           print "\t_$symbol = $symbol\n";
1172 #       }
1173     }
1174     elsif ($PLATFORM eq 'os2') {
1175         printf qq(    %-31s \@%s\n),
1176           qq("$symbol"), $ordinal{$symbol} || ++$sym_ord;
1177     }
1178     elsif ($PLATFORM eq 'aix' || $PLATFORM eq 'MacOS') {
1179         print "$symbol\n";
1180     }
1181         elsif ($PLATFORM eq 'netware') {
1182         print "\t$symbol,\n";
1183         }
1184 }
1185
1186 1;
1187 __DATA__
1188 # extra globals not included above.
1189 Perl_cxinc
1190 perl_alloc
1191 perl_alloc_using
1192 perl_clone
1193 perl_clone_using
1194 perl_construct
1195 perl_destruct
1196 perl_free
1197 perl_parse
1198 perl_run
1199 PerlIOBase_clearerr
1200 PerlIOBase_close
1201 PerlIOBase_dup
1202 PerlIOBase_eof
1203 PerlIOBase_error
1204 PerlIOBase_fileno
1205 PerlIOBase_pushed
1206 PerlIOBase_read
1207 PerlIOBase_setlinebuf
1208 PerlIOBase_unread
1209 PerlIOBuf_bufsiz
1210 PerlIOBuf_fill
1211 PerlIOBuf_flush
1212 PerlIOBuf_get_cnt
1213 PerlIOBuf_get_ptr
1214 PerlIOBuf_open
1215 PerlIOBuf_pushed
1216 PerlIOBuf_read
1217 PerlIOBuf_seek
1218 PerlIOBuf_set_ptrcnt
1219 PerlIOBuf_tell
1220 PerlIOBuf_unread
1221 PerlIOBuf_write
1222 PerlIO_allocate
1223 PerlIO_apply_layers
1224 PerlIO_arg_fetch
1225 PerlIO_binmode
1226 PerlIO_define_layer
1227 PerlIO_define_layer
1228 PerlIO_getpos
1229 PerlIO_init
1230 PerlIO_modestr
1231 PerlIO_pending
1232 PerlIO_perlio
1233 PerlIO_push
1234 PerlIO_setpos
1235 PerlIO_sprintf
1236 PerlIO_sv_dup
1237 PerlIO_tmpfile
1238 PerlIO_vsprintf
1239 perlsio_binmode