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