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