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