And so it begins...
[oweals/openssl.git] / util / mksdef.pl
1
2 # Perl script to split libeay32.def into two distinct DEF files for use in
3 # fipdso mode. It works out symbols in each case by running "link" command and
4 # parsing the output to find the list of missing symbols then splitting
5 # libeay32.def based on the result.
6
7
8 # Get list of unknown symbols
9
10 my @deferr = `link @ARGV`;
11
12 my $preamble = "";
13 my @fipsdll;
14 my @fipsrest;
15 my %nosym;
16
17 # Add symbols to a hash for easy lookup
18
19 foreach (@deferr)
20         {
21         if (/^.*symbol (\S+)$/)
22                 {
23                 $nosym{$1} = 1;
24                 }
25         }
26
27 open (IN, "ms/libeay32.def") || die "Can't Open DEF file for splittling";
28
29 my $started = 0;
30
31 # Parse libeay32.def into two arrays depending on whether the symbol matches
32 # the missing list.
33
34
35 foreach (<IN>)
36         {
37         if (/^\s*(\S+)\s*\@/)
38                 {
39                 $started = 1;
40                 if (exists $nosym{$1})
41                         {
42                         push @fipsrest, $_;
43                         }
44                 else
45                         {
46                         push @fipsdll, "\t$1\n";
47                         }
48                 }
49         $preamble .= $_ unless $started;
50         }
51
52 close IN;
53
54 # Hack! Add some additional exports needed for libcryptofips.dll
55 #
56
57 push @fipsdll, "\tOPENSSL_showfatal\n";
58 push @fipsdll, "\tOPENSSL_cpuid_setup\n";
59
60 # Write out DEF files for each array
61
62 write_def("ms/libfips.def", "LIBFIPS", $preamble, \@fipsdll);
63 write_def("ms/libcryptofips.def", "LIBCRYPTOFIPS", $preamble, \@fipsrest);
64
65
66 sub write_def
67         {
68         my ($fnam, $defname, $preamble, $rdefs) = @_;
69         open (OUT, ">$fnam") || die "Can't Open DEF file $fnam for Writing\n";
70
71         $preamble =~ s/LIBEAY32/$defname/g;
72         $preamble =~ s/LIBEAY/$defname/g;
73
74         print OUT $preamble;
75         foreach (@$rdefs)
76                 {
77                 print OUT $_;
78                 }
79         close OUT;
80         }
81
82