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