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