tweak RefHash to make intent clearer (suggested by John Dlugosz)
[p5sagit/p5-mst-13.2.git] / win32 / makedef.pl
1 #!../miniperl
2
3 # Create the export list for perl. Needed by WIN32 for creating perl.dll.
4
5 # reads global.sym, pp.sym, perlvars.h, intrpvar.h, thrdvar.h, config.h
6
7 my $CCTYPE = "MSVC";    # default
8
9 while (@ARGV)
10  {
11   my $flag = shift;
12   $define{$1} = 1 if ($flag =~ /^-D(\w+)$/);
13   $CCTYPE = $1 if ($flag =~ /^CCTYPE=(\w+)$/);
14  } 
15
16 open(CFG,'config.h') || die "Cannot open config.h:$!";
17 while (<CFG>)
18  {
19   $define{$1} = 1 if /^\s*#\s*define\s+(MYMALLOC)\b/;
20   $define{$1} = 1 if /^\s*#\s*define\s+(USE_THREADS)\b/;
21   $define{$1} = 1 if /^\s*#\s*define\s+(MULTIPLICITY)\b/;
22  }
23 close(CFG);
24
25 warn join(' ',keys %define)."\n";
26
27 if ($define{PERL_OBJECT}) {
28     print "LIBRARY PerlCore\n";
29     print "DESCRIPTION 'Perl interpreter'\n";
30     print "EXPORTS\n";
31     output_symbol("perl_alloc");
32     exit(0);
33 }
34
35 if ($CCTYPE ne 'GCC') 
36  {
37   print "LIBRARY Perl\n";
38   print "DESCRIPTION 'Perl interpreter, export autogenerated'\n";
39  }
40 else
41  {
42   $define{'PERL_GLOBAL_STRUCT'} = 1;
43   $define{'MULTIPLICITY'} = 1;
44  }
45
46 print "EXPORTS\n";
47
48 my %skip;
49 my %export;
50
51 sub skip_symbols
52 {
53  my $list = shift;
54  foreach my $symbol (@$list)
55   {
56    $skip{$symbol} = 1;
57   }
58 }
59
60 sub emit_symbols
61 {
62  my $list = shift;
63  foreach my $symbol (@$list)
64   {
65    emit_symbol($symbol) unless exists $skip{$symbol};
66   }
67 }
68
69 skip_symbols [qw(
70 PL_statusvalue_vms
71 PL_archpat_auto
72 PL_cryptseen
73 PL_DBcv
74 PL_generation
75 PL_lastgotoprobe
76 PL_linestart
77 PL_modcount
78 PL_pending_ident
79 PL_sortcxix
80 PL_sublex_info
81 PL_timesbuf
82 main
83 Perl_ErrorNo
84 Perl_GetVars
85 Perl_do_exec3
86 Perl_do_ipcctl
87 Perl_do_ipcget
88 Perl_do_msgrcv
89 Perl_do_msgsnd
90 Perl_do_semop
91 Perl_do_shmio
92 Perl_dump_fds
93 Perl_init_thread_intern
94 Perl_my_bzero
95 Perl_my_htonl
96 Perl_my_ntohl
97 Perl_my_swap
98 Perl_my_chsize
99 Perl_same_dirent
100 Perl_setenv_getix
101 Perl_unlnk
102 Perl_watch
103 Perl_safexcalloc
104 Perl_safexmalloc
105 Perl_safexfree
106 Perl_safexrealloc
107 Perl_my_memcmp
108 Perl_my_memset
109 PL_cshlen
110 PL_cshname
111 PL_opsave
112 )];
113
114
115 if ($define{'MYMALLOC'})
116  {
117   emit_symbols [qw(
118     Perl_dump_mstats
119     Perl_malloc
120     Perl_mfree
121     Perl_realloc
122     Perl_calloc)];
123  }
124 else
125  {
126   skip_symbols [qw(
127     Perl_dump_mstats
128     Perl_malloc
129     Perl_mfree
130     Perl_realloc
131     Perl_calloc
132     Perl_malloced_size)];
133  }
134
135 unless ($define{'USE_THREADS'})
136  {
137   skip_symbols [qw(
138 PL_thr_key
139 PL_sv_mutex
140 PL_strtab_mutex
141 PL_svref_mutex
142 PL_malloc_mutex
143 PL_cred_mutex
144 PL_eval_mutex
145 PL_eval_cond
146 PL_eval_owner
147 PL_threads_mutex
148 PL_nthreads
149 PL_nthreads_cond
150 PL_threadnum
151 PL_threadsv_names
152 PL_thrsv
153 PL_vtbl_mutex
154 Perl_getTHR
155 Perl_setTHR
156 Perl_condpair_magic
157 Perl_new_struct_thread
158 Perl_per_thread_magicals
159 Perl_thread_create
160 Perl_find_threadsv
161 Perl_unlock_condpair
162 Perl_magic_mutexfree
163 )];
164  }
165 unless ($define{'USE_THREADS'} or $define{'PERL_IMPLICIT_CONTEXT'})
166  {
167   skip_symbols [qw(
168                    Perl_croak_nocontext
169                    Perl_die_nocontext
170                    Perl_form_nocontext
171                    Perl_warn_nocontext
172                    Perl_newSVpvf_nocontext
173                    Perl_sv_catpvf_nocontext
174                    Perl_sv_setpvf_nocontext
175                    Perl_sv_catpvf_mg_nocontext
176                    Perl_sv_setpvf_mg_nocontext
177                    )];
178  }
179
180 unless ($define{'FAKE_THREADS'})
181  {
182   skip_symbols [qw(PL_curthr)];
183  }
184
185 sub readvar
186 {
187  my $file = shift;
188  open(VARS,$file) || die "Cannot open $file:$!";
189  my @syms;
190  while (<VARS>)
191   {
192    # All symbols have a Perl_ prefix because that's what embed.h
193    # sticks in front of them.
194    push(@syms,"PL_".$1) if (/\bPERLVARI?C?\([IGT](\w+)/);
195   } 
196  close(VARS); 
197  return \@syms;
198 }
199
200 if ($define{'USE_THREADS'} || $define{'MULTIPLICITY'})
201  {
202   my $thrd = readvar("../thrdvar.h");
203   skip_symbols $thrd;
204  } 
205
206 if ($define{'MULTIPLICITY'})
207  {
208   my $interp = readvar("../intrpvar.h");
209   skip_symbols $interp;
210  } 
211
212 if ($define{'PERL_GLOBAL_STRUCT'})
213  {
214   my $global = readvar("../perlvars.h");
215   skip_symbols $global;
216   emit_symbols [qw(Perl_GetVars)];
217   emit_symbols [qw(PL_Vars PL_VarsPtr)] unless $CCTYPE eq 'GCC';
218  } 
219
220 unless ($define{'DEBUGGING'})
221  {
222   skip_symbols [qw(
223     Perl_deb
224     Perl_deb_growlevel
225     Perl_debop
226     Perl_debprofdump
227     Perl_debstack
228     Perl_debstackptrs
229     Perl_runops_debug
230     Perl_sv_peek
231     PL_block_type
232     PL_watchaddr
233     PL_watchok)];
234  }
235
236 if ($define{'HAVE_DES_FCRYPT'})
237  {
238   emit_symbols [qw(win32_crypt)];
239  }
240
241 # functions from *.sym files
242
243 for my $syms ('../global.sym','../pp.sym', '../globvar.sym')
244  {
245   open (GLOBAL, "<$syms") || die "failed to open $syms" . $!;
246   while (<GLOBAL>) 
247    {
248     next if (!/^[A-Za-z]/);
249     # Functions have a Perl_ prefix
250     # Variables have a PL_ prefix
251     chomp($_);
252     my $symbol = ($syms =~ /var\.sym$/i ? "PL_" : "");
253     $symbol .= $_;
254     emit_symbol($symbol) unless exists $skip{$symbol};
255    }
256   close(GLOBAL);
257  }
258
259 # variables
260
261 unless ($define{'PERL_GLOBAL_STRUCT'})
262  {
263   my $glob = readvar("../perlvars.h");
264   emit_symbols $glob;
265  } 
266
267 unless ($define{'MULTIPLICITY'})
268  {
269   my $glob = readvar("../intrpvar.h");
270   emit_symbols $glob;
271  } 
272
273 unless ($define{'MULTIPLICITY'} || $define{'USE_THREADS'})
274  {
275   my $glob = readvar("../thrdvar.h");
276   emit_symbols $glob;
277  } 
278
279 while (<DATA>) {
280         my $symbol;
281         next if (!/^[A-Za-z]/);
282         next if (/^#/);
283         s/\r//g;
284         chomp($_);
285         $symbol = $_;
286         next if exists $skip{$symbol};
287         emit_symbol($symbol);
288 }
289
290 foreach my $symbol (sort keys %export)
291  {
292    output_symbol($symbol);
293  }
294
295 sub emit_symbol {
296         my $symbol = shift;
297         chomp($symbol); 
298         $export{$symbol} = 1;
299 }
300
301 sub output_symbol {
302     my $symbol = shift;
303     if ($CCTYPE eq "BORLAND") {
304             # workaround Borland quirk by exporting both the straight
305             # name and a name with leading underscore.  Note the
306             # alias *must* come after the symbol itself, if both
307             # are to be exported. (Linker bug?)
308             print "\t_$symbol\n";
309             print "\t$symbol = _$symbol\n";
310     }
311     elsif ($CCTYPE eq 'GCC') {
312             # Symbols have leading _ whole process is $%£"% slow
313             # so skip aliases for now
314             print "\t$symbol\n";
315     }
316     else {
317             # for binary coexistence, export both the symbol and
318             # alias with leading underscore
319             print "\t$symbol\n";
320             print "\t_$symbol = $symbol\n";
321     }
322 }
323
324 1;
325 __DATA__
326 # extra globals not included above.
327 perl_alloc
328 perl_construct
329 perl_destruct
330 perl_free
331 perl_parse
332 perl_run
333 boot_DynaLoader
334 Perl_thread_create
335 win32_errno
336 win32_environ
337 win32_stdin
338 win32_stdout
339 win32_stderr
340 win32_ferror
341 win32_feof
342 win32_strerror
343 win32_fprintf
344 win32_printf
345 win32_vfprintf
346 win32_vprintf
347 win32_fread
348 win32_fwrite
349 win32_fopen
350 win32_fdopen
351 win32_freopen
352 win32_fclose
353 win32_fputs
354 win32_fputc
355 win32_ungetc
356 win32_getc
357 win32_fileno
358 win32_clearerr
359 win32_fflush
360 win32_ftell
361 win32_fseek
362 win32_fgetpos
363 win32_fsetpos
364 win32_rewind
365 win32_tmpfile
366 win32_abort
367 win32_fstat
368 win32_stat
369 win32_pipe
370 win32_popen
371 win32_pclose
372 win32_rename
373 win32_setmode
374 win32_lseek
375 win32_tell
376 win32_dup
377 win32_dup2
378 win32_open
379 win32_close
380 win32_eof
381 win32_read
382 win32_write
383 win32_spawnvp
384 win32_mkdir
385 win32_rmdir
386 win32_chdir
387 win32_flock
388 win32_execv
389 win32_execvp
390 win32_htons
391 win32_ntohs
392 win32_htonl
393 win32_ntohl
394 win32_inet_addr
395 win32_inet_ntoa
396 win32_socket
397 win32_bind
398 win32_listen
399 win32_accept
400 win32_connect
401 win32_send
402 win32_sendto
403 win32_recv
404 win32_recvfrom
405 win32_shutdown
406 win32_closesocket
407 win32_ioctlsocket
408 win32_setsockopt
409 win32_getsockopt
410 win32_getpeername
411 win32_getsockname
412 win32_gethostname
413 win32_gethostbyname
414 win32_gethostbyaddr
415 win32_getprotobyname
416 win32_getprotobynumber
417 win32_getservbyname
418 win32_getservbyport
419 win32_select
420 win32_endhostent
421 win32_endnetent
422 win32_endprotoent
423 win32_endservent
424 win32_getnetent
425 win32_getnetbyname
426 win32_getnetbyaddr
427 win32_getprotoent
428 win32_getservent
429 win32_sethostent
430 win32_setnetent
431 win32_setprotoent
432 win32_setservent
433 win32_getenv
434 win32_putenv
435 win32_perror
436 win32_setbuf
437 win32_setvbuf
438 win32_flushall
439 win32_fcloseall
440 win32_fgets
441 win32_gets
442 win32_fgetc
443 win32_putc
444 win32_puts
445 win32_getchar
446 win32_putchar
447 win32_malloc
448 win32_calloc
449 win32_realloc
450 win32_free
451 win32_sleep
452 win32_times
453 win32_alarm
454 win32_open_osfhandle
455 win32_get_osfhandle
456 win32_ioctl
457 win32_utime
458 win32_uname
459 win32_wait
460 win32_waitpid
461 win32_kill
462 win32_str_os_error
463 win32_opendir
464 win32_readdir
465 win32_telldir
466 win32_seekdir
467 win32_rewinddir
468 win32_closedir
469 win32_longpath
470 Perl_win32_init
471 Perl_init_os_extras
472 Perl_getTHR
473 Perl_setTHR
474 RunPerl
475