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