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