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