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