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