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