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