introduce $^U, a global bit to indicate whether system
[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 #
7 # reads global.sym, pp.sym, perlvars.h, intrpvar.h, thrdvar.h, config.h
8 # On OS/2 reads miniperl.map as well
9
10 my $PLATFORM;
11 my $CCTYPE;
12
13 my %bincompat5005 =
14       (Perl_call_argv           =>      "perl_call_argv",
15        Perl_call_method         =>      "perl_call_method",
16        Perl_call_pv             =>      "perl_call_pv",
17        Perl_call_sv             =>      "perl_call_sv",
18        Perl_get_av              =>      "perl_get_av",
19        Perl_get_cv              =>      "perl_get_cv",
20        Perl_get_hv              =>      "perl_get_hv",
21        Perl_get_sv              =>      "perl_get_sv",
22        Perl_init_i18nl10n       =>      "perl_init_i18nl10n",
23        Perl_init_i18nl14n       =>      "perl_init_i18nl14n",
24        Perl_new_collate         =>      "perl_new_collate",
25        Perl_new_ctype           =>      "perl_new_ctype",
26        Perl_new_numeric         =>      "perl_new_numeric",
27        Perl_require_pv          =>      "perl_require_pv",
28        Perl_safesyscalloc       =>      "Perl_safecalloc",
29        Perl_safesysfree         =>      "Perl_safefree",
30        Perl_safesysmalloc       =>      "Perl_safemalloc",
31        Perl_safesysrealloc      =>      "Perl_saferealloc",
32        Perl_set_numeric_local   =>      "perl_set_numeric_local",
33        Perl_set_numeric_standard  =>    "perl_set_numeric_standard",
34        Perl_malloc              =>      "malloc",
35        Perl_mfree               =>      "free",
36        Perl_realloc             =>      "realloc",
37        Perl_calloc              =>      "calloc",);
38
39 my $bincompat5005 = join("|", keys %bincompat5005);
40
41 while (@ARGV) {
42     my $flag = shift;
43     $define{$1} = 1 if ($flag =~ /^-D(\w+)$/);
44     $define{$1} = $2 if ($flag =~ /^-D(\w+)=(.+)$/);
45     $CCTYPE   = $1 if ($flag =~ /^CCTYPE=(\w+)$/);
46     $PLATFORM = $1 if ($flag =~ /^PLATFORM=(\w+)$/);
47 }
48
49 my @PLATFORM = qw(aix win32 os2);
50 my %PLATFORM;
51 @PLATFORM{@PLATFORM} = ();
52
53 defined $PLATFORM || die "PLATFORM undefined, must be one of: @PLATFORM\n";
54 exists $PLATFORM{$PLATFORM} || die "PLATFORM must be one of: @PLATFORM\n"; 
55
56 my $config_sh   = "config.sh";
57 my $config_h    = "config.h";
58 my $thrdvar_h   = "thrdvar.h";
59 my $intrpvar_h  = "intrpvar.h";
60 my $perlvars_h  = "perlvars.h";
61 my $global_sym  = "global.sym";
62 my $pp_sym      = "pp.sym";
63 my $globvar_sym = "globvar.sym";
64 my $perlio_sym  = "perlio.sym";
65
66 if ($PLATFORM eq 'aix') { 
67     # Nothing for now.
68 }
69 elsif ($PLATFORM eq 'win32') {
70     $CCTYPE = "MSVC" unless defined $CCTYPE;
71     foreach ($thrdvar_h, $intrpvar_h, $perlvars_h, $global_sym, $pp_sym, $globvar_sym) {
72         s!^!..\\!;
73     }
74 }
75
76 unless ($PLATFORM eq 'win32') {
77     open(CFG,$config_sh) || die "Cannot open $config_sh: $!\n";
78     while (<CFG>) {
79         if (/^(?:ccflags|optimize)='(.+)'$/) {
80             $_ = $1;
81             $define{$1} = 1 while /-D(\w+)/g;
82         }
83         if ($PLATFORM eq 'os2') {
84             $CONFIG_ARGS = $1 if /^(?:config_args)='(.+)'$/;
85             $ARCHNAME = $1 if /^(?:archname)='(.+)'$/;
86         }
87     }
88     close(CFG);
89 }
90
91 open(CFG,$config_h) || die "Cannot open $config_h: $!\n";
92 while (<CFG>) {
93     $define{$1} = 1 if /^\s*#\s*define\s+(MYMALLOC)\b/;
94     $define{$1} = 1 if /^\s*#\s*define\s+(USE_5005THREADS)\b/;
95     $define{$1} = 1 if /^\s*#\s*define\s+(USE_ITHREADS)\b/;
96     $define{$1} = 1 if /^\s*#\s*define\s+(USE_PERLIO)\b/;
97     $define{$1} = 1 if /^\s*#\s*define\s+(MULTIPLICITY)\b/;
98     $define{$1} = 1 if /^\s*#\s*define\s+(PERL_IMPLICIT_SYS)\b/;
99     $define{$1} = 1 if /^\s*#\s*define\s+(PERL_BINCOMPAT_5005)\b/;
100 }
101 close(CFG);
102
103 if ($PLATFORM eq 'win32') {
104     warn join(' ',keys %define)."\n";
105     print "LIBRARY Perl56\n";
106     print "DESCRIPTION 'Perl interpreter'\n";
107     print "EXPORTS\n";
108     if ($define{PERL_IMPLICIT_SYS}) {
109         output_symbol("perl_get_host_info");
110         output_symbol("perl_alloc_override");
111     }
112 }
113 elsif ($PLATFORM eq 'os2') {
114     ($v = $]) =~ s/(\d\.\d\d\d)(\d\d)$/$1_$2/;
115     $v .= '-thread' if $ARCHNAME =~ /-thread/;
116     #$sum = 0;
117     #for (split //, $v) {
118     #   $sum = ($sum * 33) + ord;
119     #   $sum &= 0xffffff;
120     #}
121     #$sum += $sum >> 5;
122     #$sum &= 0xffff;
123     #$sum = printf '%X', $sum;
124     ($dll = $define{PERL_DLL}) =~ s/\.dll$//i;
125     # print STDERR "'$dll' <= '$define{PERL_DLL}'\n";
126     print <<"---EOP---";
127 LIBRARY '$dll' INITINSTANCE TERMINSTANCE
128 DESCRIPTION '\@#perl5-porters\@perl.org:$v#\@ Perl interpreter, configured as $CONFIG_ARGS'
129 STACKSIZE 32768
130 CODE LOADONCALL
131 DATA LOADONCALL NONSHARED MULTIPLE
132 EXPORTS
133 ---EOP---
134 }
135 elsif ($PLATFORM eq 'aix') {
136     print "#!\n";
137 }
138
139 my %skip;
140 my %export;
141
142 sub skip_symbols {
143     my $list = shift;
144     foreach my $symbol (@$list) {
145         $skip{$symbol} = 1;
146     }
147 }
148
149 sub emit_symbols {
150     my $list = shift;
151     foreach my $symbol (@$list) {
152         my $skipsym = $symbol;
153         # XXX hack
154         if ($define{PERL_OBJECT} || $define{MULTIPLICITY}) {
155             $skipsym =~ s/^Perl_[GIT](\w+)_ptr$/PL_$1/;
156         }
157         emit_symbol($symbol) unless exists $skip{$skipsym};
158     }
159 }
160
161 if ($PLATFORM eq 'win32') {
162     skip_symbols [qw(
163                      PL_statusvalue_vms
164                      PL_archpat_auto
165                      PL_cryptseen
166                      PL_DBcv
167                      PL_generation
168                      PL_lastgotoprobe
169                      PL_linestart
170                      PL_modcount
171                      PL_pending_ident
172                      PL_sortcxix
173                      PL_sublex_info
174                      PL_timesbuf
175                      main
176                      Perl_ErrorNo
177                      Perl_GetVars
178                      Perl_do_exec3
179                      Perl_do_ipcctl
180                      Perl_do_ipcget
181                      Perl_do_msgrcv
182                      Perl_do_msgsnd
183                      Perl_do_semop
184                      Perl_do_shmio
185                      Perl_dump_fds
186                      Perl_init_thread_intern
187                      Perl_my_bzero
188                      Perl_my_htonl
189                      Perl_my_ntohl
190                      Perl_my_swap
191                      Perl_my_chsize
192                      Perl_same_dirent
193                      Perl_setenv_getix
194                      Perl_unlnk
195                      Perl_watch
196                      Perl_safexcalloc
197                      Perl_safexmalloc
198                      Perl_safexfree
199                      Perl_safexrealloc
200                      Perl_my_memcmp
201                      Perl_my_memset
202                      PL_cshlen
203                      PL_cshname
204                      PL_opsave
205                      Perl_do_exec
206                      Perl_getenv_len
207                      Perl_my_pclose
208                      Perl_my_popen
209                      )];
210 }
211 elsif ($PLATFORM eq 'aix') {
212     skip_symbols([qw(
213                      Perl_dump_fds
214                      Perl_ErrorNo
215                      Perl_GetVars
216                      Perl_my_bcopy
217                      Perl_my_bzero
218                      Perl_my_chsize
219                      Perl_my_htonl
220                      Perl_my_memcmp
221                      Perl_my_memset
222                      Perl_my_ntohl
223                      Perl_my_swap
224                      Perl_safexcalloc
225                      Perl_safexfree
226                      Perl_safexmalloc
227                      Perl_safexrealloc
228                      Perl_same_dirent
229                      Perl_unlnk
230                      PL_cryptseen
231                      PL_opsave
232                      PL_statusvalue_vms
233                      PL_sys_intern
234                      )]);
235 }
236 elsif ($PLATFORM eq 'os2') {
237     emit_symbols([qw(
238                     ctermid
239                     get_sysinfo
240                     Perl_OS2_init
241                     OS2_Perl_data
242                     dlopen
243                     dlsym
244                     dlerror
245                     my_tmpfile
246                     my_tmpnam
247                     my_flock
248                     malloc_mutex
249                     threads_mutex
250                     nthreads
251                     nthreads_cond
252                     os2_cond_wait
253                     os2_stat
254                     pthread_join
255                     pthread_create
256                     pthread_detach
257                     XS_Cwd_change_drive
258                     XS_Cwd_current_drive
259                     XS_Cwd_extLibpath
260                     XS_Cwd_extLibpath_set
261                     XS_Cwd_sys_abspath
262                     XS_Cwd_sys_chdir
263                     XS_Cwd_sys_cwd
264                     XS_Cwd_sys_is_absolute
265                     XS_Cwd_sys_is_relative
266                     XS_Cwd_sys_is_rooted
267                     XS_DynaLoader_mod2fname
268                     XS_File__Copy_syscopy
269                     Perl_Register_MQ
270                     Perl_Deregister_MQ
271                     Perl_Serve_Messages
272                     Perl_Process_Messages
273                     init_PMWIN_entries
274                     PMWIN_entries
275                     Perl_hab_GET
276                     )]);
277 }
278
279 unless ($define{'DEBUGGING'}) {
280     skip_symbols [qw(
281                     Perl_deb
282                     Perl_deb_growlevel
283                     Perl_debop
284                     Perl_debprofdump
285                     Perl_debstack
286                     Perl_debstackptrs
287                     Perl_runops_debug
288                     Perl_sv_peek
289                     PL_block_type
290                     PL_watchaddr
291                     PL_watchok
292                     )];
293 }
294
295 if ($define{'PERL_IMPLICIT_SYS'}) {
296     skip_symbols [qw(
297                     Perl_getenv_len
298                     Perl_my_popen
299                     Perl_my_pclose
300                     )];
301 }
302 else {
303     skip_symbols [qw(
304                     PL_Mem
305                     PL_MemShared
306                     PL_MemParse
307                     PL_Env
308                     PL_StdIO
309                     PL_LIO
310                     PL_Dir
311                     PL_Sock
312                     PL_Proc
313                     )];
314 }
315
316 if ($define{'MYMALLOC'}) {
317     emit_symbols [qw(
318                     Perl_dump_mstats
319                     Perl_malloc
320                     Perl_mfree
321                     Perl_realloc
322                     Perl_calloc
323                     )];
324     if ($define{'USE_5005THREADS'} || $define{'USE_ITHREADS'}) {
325         emit_symbols [qw(
326                         PL_malloc_mutex
327                         )];
328     }
329 }
330 else {
331     skip_symbols [qw(
332                     PL_malloc_mutex
333                     Perl_dump_mstats
334                     Perl_malloc
335                     Perl_mfree
336                     Perl_realloc
337                     Perl_calloc
338                     Perl_malloced_size
339                     )];
340 }
341
342 unless ($define{'USE_5005THREADS'}) {
343     skip_symbols [qw(
344                     PL_thr_key
345                     PL_sv_mutex
346                     PL_strtab_mutex
347                     PL_svref_mutex
348                     PL_cred_mutex
349                     PL_eval_mutex
350                     PL_eval_cond
351                     PL_eval_owner
352                     PL_threads_mutex
353                     PL_nthreads
354                     PL_nthreads_cond
355                     PL_threadnum
356                     PL_threadsv_names
357                     PL_thrsv
358                     PL_vtbl_mutex
359                     Perl_getTHR
360                     Perl_setTHR
361                     Perl_condpair_magic
362                     Perl_new_struct_thread
363                     Perl_per_thread_magicals
364                     Perl_thread_create
365                     Perl_find_threadsv
366                     Perl_unlock_condpair
367                     Perl_magic_mutexfree
368                     )];
369 }
370
371 unless ($define{'USE_ITHREADS'}) {
372     skip_symbols [qw(
373                     PL_ptr_table
374                     Perl_dirp_dup
375                     Perl_cx_dup
376                     Perl_si_dup
377                     Perl_any_dup
378                     Perl_ss_dup
379                     Perl_fp_dup
380                     Perl_gp_dup
381                     Perl_he_dup
382                     Perl_mg_dup
383                     Perl_re_dup
384                     Perl_sv_dup
385                     Perl_sys_intern_dup
386                     Perl_ptr_table_fetch
387                     Perl_ptr_table_new
388                     Perl_ptr_table_split
389                     Perl_ptr_table_store
390                     perl_clone
391                     perl_clone_using
392                     )];
393 }
394
395 unless ($define{'PERL_IMPLICIT_CONTEXT'}) {
396     skip_symbols [qw(
397                     Perl_croak_nocontext
398                     Perl_die_nocontext
399                     Perl_deb_nocontext
400                     Perl_form_nocontext
401                     Perl_mess_nocontext
402                     Perl_warn_nocontext
403                     Perl_warner_nocontext
404                     Perl_newSVpvf_nocontext
405                     Perl_sv_catpvf_nocontext
406                     Perl_sv_setpvf_nocontext
407                     Perl_sv_catpvf_mg_nocontext
408                     Perl_sv_setpvf_mg_nocontext
409                     )];
410 }
411
412 unless ($define{'PERL_IMPLICIT_SYS'}) {
413     skip_symbols [qw(
414                     perl_alloc_using
415                     perl_clone_using
416                     )];
417 }
418
419 unless ($define{'FAKE_THREADS'}) {
420     skip_symbols [qw(PL_curthr)];
421 }
422
423 sub readvar {
424     my $file = shift;
425     my $proc = shift || sub { "PL_$_[2]" };
426     open(VARS,$file) || die "Cannot open $file: $!\n";
427     my @syms;
428     while (<VARS>) {
429         # All symbols have a Perl_ prefix because that's what embed.h
430         # sticks in front of them.
431         push(@syms, &$proc($1,$2,$3)) if (/\bPERLVAR(A?I?C?)\(([IGT])(\w+)/);
432     } 
433     close(VARS); 
434     return \@syms;
435 }
436
437 if ($define{'USE_5005THREADS'}) {
438     my $thrd = readvar($thrdvar_h);
439     skip_symbols $thrd;
440 }
441
442 if ($define{'PERL_GLOBAL_STRUCT'}) {
443     my $global = readvar($perlvars_h);
444     skip_symbols $global;
445     emit_symbol('Perl_GetVars');
446     emit_symbols [qw(PL_Vars PL_VarsPtr)] unless $CCTYPE eq 'GCC';
447 }
448
449 # functions from *.sym files
450
451 my @syms = ($global_sym, $globvar_sym); # $pp_sym is not part of the API
452
453 if ($define{'USE_PERLIO'}) {
454      push @syms, $perlio_sym;
455 }
456
457 for my $syms (@syms) {
458     open (GLOBAL, "<$syms") || die "failed to open $syms: $!\n";
459     while (<GLOBAL>) {
460         next if (!/^[A-Za-z]/);
461         # Functions have a Perl_ prefix
462         # Variables have a PL_ prefix
463         chomp($_);
464         my $symbol = ($syms =~ /var\.sym$/i ? "PL_" : "");
465         $symbol .= $_;
466         emit_symbol($symbol) unless exists $skip{$symbol};
467     }
468     close(GLOBAL);
469 }
470
471 # variables
472
473 if ($define{'PERL_OBJECT'} || $define{'MULTIPLICITY'}) {
474     for my $f ($perlvars_h, $intrpvar_h, $thrdvar_h) {
475         my $glob = readvar($f, sub { "Perl_" . $_[1] . $_[2] . "_ptr" });
476         emit_symbols $glob;
477     }
478 }
479 else {
480     unless ($define{'PERL_GLOBAL_STRUCT'}) {
481         my $glob = readvar($perlvars_h);
482         emit_symbols $glob;
483     } 
484     unless ($define{'MULTIPLICITY'}) {
485         my $glob = readvar($intrpvar_h);
486         emit_symbols $glob;
487     } 
488     unless ($define{'MULTIPLICITY'} || $define{'USE_5005THREADS'}) {
489         my $glob = readvar($thrdvar_h);
490         emit_symbols $glob;
491     } 
492 }
493
494 sub try_symbol {
495     my $symbol = shift;
496
497     return if $symbol !~ /^[A-Za-z]/;
498     return if $symbol =~ /^\#/;
499     $symbol =~s/\r//g;
500     chomp($symbol);
501     return if exists $skip{$symbol};
502     emit_symbol($symbol);
503 }
504
505 while (<DATA>) {
506     try_symbol($_);
507 }
508
509 if ($PLATFORM eq 'win32') {
510     foreach my $symbol (qw(
511                             boot_DynaLoader
512                             Perl_getTHR
513                             Perl_init_os_extras
514                             Perl_setTHR
515                             Perl_thread_create
516                             Perl_win32_init
517                             RunPerl
518                             GetPerlInterpreter
519                             SetPerlInterpreter
520                             win32_errno
521                             win32_environ
522                             win32_stdin
523                             win32_stdout
524                             win32_stderr
525                             win32_ferror
526                             win32_feof
527                             win32_strerror
528                             win32_fprintf
529                             win32_printf
530                             win32_vfprintf
531                             win32_vprintf
532                             win32_fread
533                             win32_fwrite
534                             win32_fopen
535                             win32_fdopen
536                             win32_freopen
537                             win32_fclose
538                             win32_fputs
539                             win32_fputc
540                             win32_ungetc
541                             win32_getc
542                             win32_fileno
543                             win32_clearerr
544                             win32_fflush
545                             win32_ftell
546                             win32_fseek
547                             win32_fgetpos
548                             win32_fsetpos
549                             win32_rewind
550                             win32_tmpfile
551                             win32_abort
552                             win32_fstat
553                             win32_stat
554                             win32_pipe
555                             win32_popen
556                             win32_pclose
557                             win32_rename
558                             win32_setmode
559                             win32_lseek
560                             win32_tell
561                             win32_dup
562                             win32_dup2
563                             win32_open
564                             win32_close
565                             win32_eof
566                             win32_read
567                             win32_write
568                             win32_spawnvp
569                             win32_mkdir
570                             win32_rmdir
571                             win32_chdir
572                             win32_flock
573                             win32_execv
574                             win32_execvp
575                             win32_htons
576                             win32_ntohs
577                             win32_htonl
578                             win32_ntohl
579                             win32_inet_addr
580                             win32_inet_ntoa
581                             win32_socket
582                             win32_bind
583                             win32_listen
584                             win32_accept
585                             win32_connect
586                             win32_send
587                             win32_sendto
588                             win32_recv
589                             win32_recvfrom
590                             win32_shutdown
591                             win32_closesocket
592                             win32_ioctlsocket
593                             win32_setsockopt
594                             win32_getsockopt
595                             win32_getpeername
596                             win32_getsockname
597                             win32_gethostname
598                             win32_gethostbyname
599                             win32_gethostbyaddr
600                             win32_getprotobyname
601                             win32_getprotobynumber
602                             win32_getservbyname
603                             win32_getservbyport
604                             win32_select
605                             win32_endhostent
606                             win32_endnetent
607                             win32_endprotoent
608                             win32_endservent
609                             win32_getnetent
610                             win32_getnetbyname
611                             win32_getnetbyaddr
612                             win32_getprotoent
613                             win32_getservent
614                             win32_sethostent
615                             win32_setnetent
616                             win32_setprotoent
617                             win32_setservent
618                             win32_getenv
619                             win32_putenv
620                             win32_perror
621                             win32_setbuf
622                             win32_setvbuf
623                             win32_flushall
624                             win32_fcloseall
625                             win32_fgets
626                             win32_gets
627                             win32_fgetc
628                             win32_putc
629                             win32_puts
630                             win32_getchar
631                             win32_putchar
632                             win32_malloc
633                             win32_calloc
634                             win32_realloc
635                             win32_free
636                             win32_sleep
637                             win32_times
638                             win32_access
639                             win32_alarm
640                             win32_chmod
641                             win32_open_osfhandle
642                             win32_get_osfhandle
643                             win32_ioctl
644                             win32_link
645                             win32_unlink
646                             win32_utime
647                             win32_uname
648                             win32_wait
649                             win32_waitpid
650                             win32_kill
651                             win32_str_os_error
652                             win32_opendir
653                             win32_readdir
654                             win32_telldir
655                             win32_seekdir
656                             win32_rewinddir
657                             win32_closedir
658                             win32_longpath
659                             win32_os_id
660                             win32_getpid
661                             win32_crypt
662                             win32_dynaload
663                            ))
664     {
665         try_symbol($symbol);
666     }
667 }
668 elsif ($PLATFORM eq 'os2') {
669     open MAP, 'miniperl.map' or die 'Cannot read miniperl.map';
670     /^\s*[\da-f:]+\s+(\w+)/i and $mapped{$1}++ foreach <MAP>;
671     close MAP or die 'Cannot close miniperl.map';
672
673     @missing = grep { !exists $mapped{$_} and !exists $bincompat5005{$_} }
674                     keys %export;
675     delete $export{$_} foreach @missing;
676 }
677
678 # Now all symbols should be defined because
679 # next we are going to output them.
680
681 foreach my $symbol (sort keys %export) {
682     output_symbol($symbol);
683 }
684
685 sub emit_symbol {
686     my $symbol = shift;
687     chomp($symbol); 
688     $export{$symbol} = 1;
689 }
690
691 sub output_symbol {
692     my $symbol = shift;
693     $symbol = $bincompat5005{$symbol}
694         if $define{PERL_BINCOMPAT_5005} and $symbol =~ /^($bincompat5005)$/;
695     if ($PLATFORM eq 'win32') {
696         $symbol = "_$symbol" if $CCTYPE eq 'BORLAND';
697         print "\t$symbol\n";
698 # XXX: binary compatibility between compilers is an exercise
699 # in frustration :-(
700 #        if ($CCTYPE eq "BORLAND") {
701 #           # workaround Borland quirk by exporting both the straight
702 #           # name and a name with leading underscore.  Note the
703 #           # alias *must* come after the symbol itself, if both
704 #           # are to be exported. (Linker bug?)
705 #           print "\t_$symbol\n";
706 #           print "\t$symbol = _$symbol\n";
707 #       }
708 #       elsif ($CCTYPE eq 'GCC') {
709 #           # Symbols have leading _ whole process is $%@"% slow
710 #           # so skip aliases for now
711 #           nprint "\t$symbol\n";
712 #       }
713 #       else {
714 #           # for binary coexistence, export both the symbol and
715 #           # alias with leading underscore
716 #           print "\t$symbol\n";
717 #           print "\t_$symbol = $symbol\n";
718 #       }
719     }
720     elsif ($PLATFORM eq 'os2') {
721         print qq(    "$symbol"\n);
722     }
723     elsif ($PLATFORM eq 'aix') {
724         print "$symbol\n";
725     }
726 }
727
728 1;
729 __DATA__
730 # extra globals not included above.
731 perl_alloc
732 perl_alloc_using
733 perl_clone
734 perl_clone_using
735 perl_construct
736 perl_destruct
737 perl_free
738 perl_parse
739 perl_run