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