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