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