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