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