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