1193645Ssimon
2193645Ssimon# Perl script to split libeay32.def into two distinct DEF files for use in
3193645Ssimon# fipdso mode. It works out symbols in each case by running "link" command and
4193645Ssimon# parsing the output to find the list of missing symbols then splitting
5193645Ssimon# libeay32.def based on the result.
6193645Ssimon
7193645Ssimon
8193645Ssimon# Get list of unknown symbols
9193645Ssimon
10193645Ssimonmy @deferr = `link @ARGV`;
11193645Ssimon
12193645Ssimonmy $preamble = "";
13193645Ssimonmy @fipsdll;
14193645Ssimonmy @fipsrest;
15193645Ssimonmy %nosym;
16193645Ssimon
17193645Ssimon# Add symbols to a hash for easy lookup
18193645Ssimon
19193645Ssimonforeach (@deferr)
20193645Ssimon	{
21193645Ssimon	if (/^.*symbol (\S+)$/)
22193645Ssimon		{
23193645Ssimon		$nosym{$1} = 1;
24193645Ssimon		}
25193645Ssimon	}
26193645Ssimon
27193645Ssimonopen (IN, "ms/libeay32.def") || die "Can't Open DEF file for spliting";
28193645Ssimon
29193645Ssimonmy $started = 0;
30193645Ssimon
31193645Ssimon# Parse libeay32.def into two arrays depending on whether the symbol matches
32193645Ssimon# the missing list.
33193645Ssimon
34193645Ssimon
35193645Ssimonforeach (<IN>)
36193645Ssimon	{
37193645Ssimon	if (/^\s*(\S+)\s*(\@\S+)\s*$/)
38193645Ssimon		{
39193645Ssimon		$started = 1;
40193645Ssimon		if (exists $nosym{$1})
41193645Ssimon			{
42193645Ssimon			push @fipsrest, $_;
43193645Ssimon			}
44193645Ssimon		else
45193645Ssimon			{
46193645Ssimon			my $imptmp = sprintf "     %-39s %s\n",
47193645Ssimon					"$1=libosslfips.$1", $2;
48193645Ssimon			push @fipsrest, $imptmp;
49193645Ssimon			push @fipsdll, "\t$1\n";
50193645Ssimon			}
51193645Ssimon		}
52193645Ssimon	$preamble .= $_ unless $started;
53193645Ssimon	}
54193645Ssimon
55193645Ssimonclose IN;
56193645Ssimon
57193645Ssimon# Hack! Add some additional exports needed for libcryptofips.dll
58193645Ssimon#
59193645Ssimon
60193645Ssimonpush @fipsdll, "\tOPENSSL_showfatal\n";
61193645Ssimonpush @fipsdll, "\tOPENSSL_cpuid_setup\n";
62193645Ssimon
63193645Ssimon# Write out DEF files for each array
64193645Ssimon
65193645Ssimonwrite_def("ms/libosslfips.def", "LIBOSSLFIPS", $preamble, \@fipsdll);
66193645Ssimonwrite_def("ms/libeayfips.def", "", $preamble, \@fipsrest);
67193645Ssimon
68193645Ssimon
69193645Ssimonsub write_def
70193645Ssimon	{
71193645Ssimon	my ($fnam, $defname, $preamble, $rdefs) = @_;
72193645Ssimon	open (OUT, ">$fnam") || die "Can't Open DEF file $fnam for Writing\n";
73193645Ssimon
74193645Ssimon	if ($defname ne "")
75193645Ssimon		{
76193645Ssimon		$preamble =~ s/LIBEAY32/$defname/g;
77193645Ssimon		$preamble =~ s/LIBEAY/$defname/g;
78193645Ssimon		}
79193645Ssimon	print OUT $preamble;
80193645Ssimon	foreach (@$rdefs)
81193645Ssimon		{
82193645Ssimon		print OUT $_;
83193645Ssimon		}
84193645Ssimon	close OUT;
85193645Ssimon	}
86193645Ssimon
87193645Ssimon
88