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