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