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