Add fips/cmac directory to WIN32 build.
[openssl.git] / util / fipsas.pl
1
2 # FIPS assembly language preprocessor
3 # Renames all symbols in the file to
4 # their modified fips versions.
5
6
7 my @ARGS = @ARGV;
8
9 my $top = shift @ARGS;
10 my $target = shift @ARGS;
11
12 my $runasm = 1;
13
14 if ($ARGS[0] eq "norunasm")
15         {
16         $runasm = 0;
17         shift @ARGS;
18         }
19
20 # HACK to disable operation if no OPENSSL_FIPSSYMS option.
21 # will go away when tested more fully.
22
23 my $enabled = 0;
24
25 foreach (@ARGS) { $enabled = 1 if /-DOPENSSL_FIPSSYMS/ ; }
26
27 if ($enabled == 0 && $runasm)
28         {
29         system @ARGS;
30         exit $?
31         }
32
33
34 # Open symbol rename file.
35 open(IN, "$top/fips/fipssyms.h") || die "Can't open fipssyms.h";
36
37 # Skip to assembler symbols
38 while (<IN>)
39         {
40         last if (/assembler/)
41         }
42
43 # Store all renames.
44 while (<IN>)
45         {
46         if (/^#define\s+(\w+)\s+(\w+)\b/)
47                 {
48                 $edits{$1} = $2;
49                 }
50         }
51
52 my ($from, $to);
53
54 #rename target temporarily
55 rename($target, "tmptarg.s") || die "Can't rename $target\n";
56
57 #edit target
58 open IN,"tmptarg.s";
59 open OUT, ">$target";
60
61 while (<IN>)
62 {
63         while (($from, $to) = each %edits)
64                 {
65                 s/(\b_*)$from(\b)/$1$to$2/g;
66                 }
67         print OUT $_;
68 }
69
70 close OUT;
71
72 if ($runasm)
73         {
74         # run assembler
75         system @ARGS;
76
77         my $rv = $?;
78
79         # restore target
80         unlink $target;
81         rename "tmptarg.s", $target;
82
83         die "Error executing assembler!" if $rv != 0;
84         }
85 else
86         {
87         # Don't care about target
88         unlink "tmptarg.s";
89         }
90
91
92
93