222ce06e7ec3cd3b51d7e0b7941c9386f2a779d5
[p5sagit/p5-mst-13.2.git] / win32 / makedef.pl
1 #!../miniperl
2
3 # Written: 10 April 1996 Gary Ng (71564.1743@compuserve.com)
4
5 # Create the export list for perl.
6 # Needed by WIN32 for creating perl.dll
7 # based on perl_exp.SH in the main perl distribution directory
8
9 # This simple program relys on 'global.sym' being up to date
10 # with all of the global symbols that a dynamicly link library
11 # might want to access.
12
13 # There is some symbol defined in global.sym and interp.sym
14 # that does not present in the WIN32 port but there is no easy
15 # way to find them so I just put a exception list here
16
17 my $CCTYPE = "MSVC";    # default
18
19 while (@ARGV)
20  {
21   my $flag = shift;
22   $define{$1} = 1 if ($flag =~ /^-D(\w+)$/);
23   $CCTYPE = $1 if ($flag =~ /^CCTYPE=(\w+)$/);
24  } 
25
26 open(CFG,'config.h') || die "Cannot open config.h:$!";
27 while (<CFG>)
28  {
29   $define{$1} = 1 if /^\s*#\s*define\s+(MYMALLOC)\b/;
30   $define{$1} = 1 if /^\s*#\s*define\s+(USE_THREADS)\b/;
31  }
32 close(CFG);
33
34 warn join(' ',keys %define)."\n";
35
36 if ($define{PERL_OBJECT}) {
37     print "LIBRARY PerlCore\n";
38     print "DESCRIPTION 'Perl interpreter'\n";
39     print "EXPORTS\n";
40     output_symbol("perl_alloc");
41     exit(0);
42 }
43
44 if ($CCTYPE ne 'GCC') 
45  {
46   print "LIBRARY Perl\n";
47   print "DESCRIPTION 'Perl interpreter, export autogenerated'\n";
48  }
49 else
50  {
51   $define{'PERL_GLOBAL_STRUCT'} = 1;
52   $define{'MULTIPLICITY'} = 1;
53  }
54
55 print "EXPORTS\n";
56
57 my %skip;
58 my %export;
59
60 sub skip_symbols
61 {
62  my $list = shift;
63  foreach my $symbol (@$list)
64   {
65    $skip{$symbol} = 1;
66   }
67 }
68
69 sub emit_symbols
70 {
71  my $list = shift;
72  foreach my $symbol (@$list)
73   {
74    emit_symbol($symbol) unless exists $skip{$symbol};
75   }
76 }
77
78 skip_symbols [qw(
79 PL_statusvalue_vms
80 PL_archpat_auto
81 PL_cryptseen
82 PL_DBcv
83 PL_generation
84 PL_lastgotoprobe
85 PL_linestart
86 PL_modcount
87 PL_pending_ident
88 PL_sortcxix
89 PL_sublex_info
90 PL_timesbuf
91 Perl_block_type
92 Perl_additem
93 Perl_cast_ulong
94 Perl_check_uni
95 Perl_checkcomma
96 Perl_chsize
97 Perl_ck_aelem
98 Perl_cx_dump
99 Perl_do_ipcctl
100 Perl_do_ipcget
101 Perl_do_msgrcv
102 Perl_do_msgsnd
103 Perl_do_semop
104 Perl_do_shmio
105 Perl_doeval
106 Perl_dofindlabel
107 Perl_dopoptoeval
108 Perl_dump_eval
109 Perl_dump_fds
110 Perl_dump_form
111 Perl_dump_gv
112 Perl_dump_mstats
113 Perl_dump_op
114 Perl_dump_packsubs
115 Perl_dump_pm
116 Perl_dump_sub
117 Perl_expectterm
118 Perl_fetch_gv
119 Perl_fetch_io
120 Perl_force_ident
121 Perl_force_next
122 Perl_force_word
123 Perl_hv_stashpv
124 Perl_intuit_more
125 Perl_init_thread_intern
126 Perl_know_next
127 Perl_modkids
128 Perl_mstats
129 Perl_my_bzero
130 Perl_my_htonl
131 Perl_my_ntohl
132 Perl_my_swap
133 Perl_my_chsize
134 Perl_newXSUB
135 Perl_no_fh_allowed
136 Perl_no_op
137 Perl_nointrp
138 Perl_nomem
139 Perl_pp_cswitch
140 Perl_pp_entersubr
141 Perl_pp_evalonce
142 Perl_pp_interp
143 Perl_pp_map
144 Perl_pp_nswitch
145 Perl_q
146 Perl_reall_srchlen
147 Perl_same_dirent
148 Perl_saw_return
149 Perl_scan_const
150 Perl_scan_formline
151 Perl_scan_heredoc
152 Perl_scan_ident
153 Perl_scan_inputsymbol
154 Perl_scan_pat
155 Perl_scan_prefix
156 Perl_scan_str
157 Perl_scan_subst
158 Perl_scan_trans
159 Perl_scan_word
160 Perl_setenv_getix
161 Perl_skipspace
162 Perl_sort_mutex
163 Perl_sublex_done
164 Perl_sublex_start
165 Perl_sv_ref
166 Perl_sv_setptrobj
167 Perl_too_few_arguments
168 Perl_too_many_arguments
169 Perl_unlnk
170 Perl_watch
171 Perl_yyname
172 Perl_yyrule
173 allgvs
174 curblock
175 curcsv
176 lastretstr
177 mystack_mark
178 perl_init_ext
179 perl_requirepv
180 stack
181 Perl_safexcalloc
182 Perl_safexmalloc
183 Perl_safexfree
184 Perl_safexrealloc
185 Perl_my_memcmp
186 Perl_my_memset
187 PL_cshlen
188 PL_cshname
189 PL_opsave
190 )];
191
192
193 if ($define{'MYMALLOC'})
194  {
195   skip_symbols [qw(
196     Perl_safefree
197     Perl_safemalloc
198     Perl_saferealloc
199     Perl_safecalloc)];
200   emit_symbols [qw(
201     Perl_malloc
202     Perl_free
203     Perl_realloc
204     Perl_calloc)];
205  }
206 else
207  {
208   skip_symbols [qw(
209     Perl_malloced_size)];
210  }
211
212 unless ($define{'USE_THREADS'})
213  {
214   skip_symbols [qw(
215 PL_thr_key
216 PL_sv_mutex
217 PL_strtab_mutex
218 PL_svref_mutex
219 PL_malloc_mutex
220 PL_cred_mutex
221 PL_eval_mutex
222 PL_eval_cond
223 PL_eval_owner
224 PL_threads_mutex
225 PL_nthreads
226 PL_nthreads_cond
227 PL_threadnum
228 PL_threadsv_names
229 PL_thrsv
230 Perl_vtbl_mutex
231 Perl_getTHR
232 Perl_setTHR
233 Perl_condpair_magic
234 Perl_new_struct_thread
235 Perl_per_thread_magicals
236 Perl_thread_create
237 Perl_find_threadsv
238 Perl_unlock_condpair
239 Perl_magic_mutexfree
240 )];
241  }
242
243 unless ($define{'FAKE_THREADS'})
244  {
245   skip_symbols [qw(PL_curthr)];
246  }
247
248 sub readvar
249 {
250  my $file = shift;
251  open(VARS,$file) || die "Cannot open $file:$!";
252  my @syms;
253  while (<VARS>)
254   {
255    # All symbols have a Perl_ prefix because that's what embed.h
256    # sticks in front of them.
257    push(@syms,"PL_".$1) if (/\bPERLVARI?C?\([IGT](\w+)/);
258   } 
259  close(VARS); 
260  return \@syms;
261 }
262
263 if ($define{'USE_THREADS'} || $define{'MULTIPLICITY'})
264  {
265   my $thrd = readvar("../thrdvar.h");
266   skip_symbols $thrd;
267  } 
268
269 if ($define{'MULTIPLICITY'})
270  {
271   my $interp = readvar("../intrpvar.h");
272   skip_symbols $interp;
273  } 
274
275 if ($define{'PERL_GLOBAL_STRUCT'})
276  {
277   my $global = readvar("../perlvars.h");
278   skip_symbols $global;
279   emit_symbols [qw(Perl_GetVars)];
280   emit_symbols [qw(PL_Vars PL_VarsPtr)] unless $CCTYPE eq 'GCC';
281  } 
282
283 unless ($define{'DEBUGGING'})
284  {
285   skip_symbols [qw(
286     Perl_deb
287     Perl_deb_growlevel
288     Perl_debop
289     Perl_debprofdump
290     Perl_debstack
291     Perl_debstackptrs
292     Perl_runops_debug
293     Perl_sv_peek
294     Perl_watchaddr
295     Perl_watchok)];
296  }
297
298 if ($define{'HAVE_DES_FCRYPT'})
299  {
300   emit_symbols [qw(win32_crypt)];
301  }
302
303 open (GLOBAL, "<../global.sym") || die "failed to open global.sym" . $!;
304 while (<GLOBAL>) 
305  {
306   next if (!/^[A-Za-z]/);
307   next if (/_amg[ \t]*$/);
308   # All symbols have a Perl_ prefix because that's what embed.h
309   # sticks in front of them.
310   chomp($_);
311   my $symbol = "Perl_$_";
312   emit_symbol($symbol) unless exists $skip{$symbol};
313  }
314 close(GLOBAL);
315
316 # also add symbols from interp.sym
317 # They are only needed if -DMULTIPLICITY is not set but it
318 # doesn't hurt to include them anyway.
319 # these don't have Perl prefix
320
321 unless ($define{'PERL_GLOBAL_STRUCT'})
322  {
323   my $glob = readvar("../perlvars.h");
324   emit_symbols $glob;
325  } 
326
327 unless ($define{'MULTIPLICITY'})
328  {
329   my $glob = readvar("../intrpvar.h");
330   emit_symbols $glob;
331  } 
332
333 unless ($define{'MULTIPLICITY'} || $define{'USE_THREADS'})
334  {
335   my $glob = readvar("../thrdvar.h");
336   emit_symbols $glob;
337  } 
338
339 while (<DATA>) {
340         my $symbol;
341         next if (!/^[A-Za-z]/);
342         next if (/^#/);
343         s/\r//g;
344         chomp($_);
345         $symbol = $_;
346         next if exists $skip{$symbol};
347         emit_symbol($symbol);
348 }
349
350 foreach my $symbol (sort keys %export)
351  {
352    output_symbol($symbol);
353  }
354
355 sub emit_symbol {
356         my $symbol = shift;
357         chomp($symbol); 
358         $export{$symbol} = 1;
359 }
360
361 sub output_symbol {
362     my $symbol = shift;
363     if ($CCTYPE eq "BORLAND") {
364             # workaround Borland quirk by exporting both the straight
365             # name and a name with leading underscore.  Note the
366             # alias *must* come after the symbol itself, if both
367             # are to be exported. (Linker bug?)
368             print "\t_$symbol\n";
369             print "\t$symbol = _$symbol\n";
370     }
371     elsif ($CCTYPE eq 'GCC') {
372             # Symbols have leading _ whole process is $%£"% slow
373             # so skip aliases for now
374             print "\t$symbol\n";
375     }
376     else {
377             # for binary coexistence, export both the symbol and
378             # alias with leading underscore
379             print "\t$symbol\n";
380             print "\t_$symbol = $symbol\n";
381     }
382 }
383
384 1;
385 __DATA__
386 # extra globals not included above.
387 perl_init_i18nl10n
388 perl_init_ext
389 perl_alloc
390 perl_atexit
391 perl_construct
392 perl_destruct
393 perl_free
394 perl_parse
395 perl_run
396 perl_get_sv
397 perl_get_av
398 perl_get_hv
399 perl_get_cv
400 perl_call_argv
401 perl_call_pv
402 perl_call_method
403 perl_call_sv
404 perl_require_pv
405 perl_eval_pv
406 perl_eval_sv
407 perl_new_ctype
408 perl_new_collate
409 perl_new_numeric
410 perl_set_numeric_standard
411 perl_set_numeric_local
412 boot_DynaLoader
413 Perl_thread_create
414 win32_errno
415 win32_environ
416 win32_stdin
417 win32_stdout
418 win32_stderr
419 win32_ferror
420 win32_feof
421 win32_strerror
422 win32_fprintf
423 win32_printf
424 win32_vfprintf
425 win32_vprintf
426 win32_fread
427 win32_fwrite
428 win32_fopen
429 win32_fdopen
430 win32_freopen
431 win32_fclose
432 win32_fputs
433 win32_fputc
434 win32_ungetc
435 win32_getc
436 win32_fileno
437 win32_clearerr
438 win32_fflush
439 win32_ftell
440 win32_fseek
441 win32_fgetpos
442 win32_fsetpos
443 win32_rewind
444 win32_tmpfile
445 win32_abort
446 win32_fstat
447 win32_stat
448 win32_pipe
449 win32_popen
450 win32_pclose
451 win32_rename
452 win32_setmode
453 win32_lseek
454 win32_tell
455 win32_dup
456 win32_dup2
457 win32_open
458 win32_close
459 win32_eof
460 win32_read
461 win32_write
462 win32_spawnvp
463 win32_mkdir
464 win32_rmdir
465 win32_chdir
466 win32_flock
467 win32_execv
468 win32_execvp
469 win32_htons
470 win32_ntohs
471 win32_htonl
472 win32_ntohl
473 win32_inet_addr
474 win32_inet_ntoa
475 win32_socket
476 win32_bind
477 win32_listen
478 win32_accept
479 win32_connect
480 win32_send
481 win32_sendto
482 win32_recv
483 win32_recvfrom
484 win32_shutdown
485 win32_closesocket
486 win32_ioctlsocket
487 win32_setsockopt
488 win32_getsockopt
489 win32_getpeername
490 win32_getsockname
491 win32_gethostname
492 win32_gethostbyname
493 win32_gethostbyaddr
494 win32_getprotobyname
495 win32_getprotobynumber
496 win32_getservbyname
497 win32_getservbyport
498 win32_select
499 win32_endhostent
500 win32_endnetent
501 win32_endprotoent
502 win32_endservent
503 win32_getnetent
504 win32_getnetbyname
505 win32_getnetbyaddr
506 win32_getprotoent
507 win32_getservent
508 win32_sethostent
509 win32_setnetent
510 win32_setprotoent
511 win32_setservent
512 win32_getenv
513 win32_perror
514 win32_setbuf
515 win32_setvbuf
516 win32_flushall
517 win32_fcloseall
518 win32_fgets
519 win32_gets
520 win32_fgetc
521 win32_putc
522 win32_puts
523 win32_getchar
524 win32_putchar
525 win32_malloc
526 win32_calloc
527 win32_realloc
528 win32_free
529 win32_sleep
530 win32_times
531 win32_alarm
532 win32_open_osfhandle
533 win32_get_osfhandle
534 win32_ioctl
535 win32_utime
536 win32_wait
537 win32_waitpid
538 win32_kill
539 win32_str_os_error
540 win32_opendir
541 win32_readdir
542 win32_telldir
543 win32_seekdir
544 win32_rewinddir
545 win32_closedir
546 Perl_win32_init
547 Perl_init_os_extras
548 Perl_getTHR
549 Perl_setTHR
550 RunPerl
551