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