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