Additional error checking.
[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 my $enabled = 0;
21
22 $enabled = 1 if $ENV{FIPSCANISTERINTERNAL} eq "y";
23
24 if ($enabled == 0 && $runasm)
25         {
26         system @ARGS;
27         exit $?
28         }
29
30
31 # Open symbol rename file.
32 open(IN, "$top/fips/fipssyms.h") || die "Can't open fipssyms.h";
33
34 # Skip to assembler symbols
35 while (<IN>)
36         {
37         last if (/assembler/)
38         }
39
40 # Store all renames.
41 while (<IN>)
42         {
43         if (/^#define\s+(\w+)\s+(\w+)\b/)
44                 {
45                 $edits{$1} = $2;
46                 }
47         }
48
49 my ($from, $to);
50
51 #rename target temporarily
52 rename($target, "tmptarg.s") || die "Can't rename $target";
53
54 #edit target
55 open(IN,"tmptarg.s") || die "Can't open temporary file";
56 open(OUT, ">$target") || die "Can't open output file $target";
57
58 while (<IN>)
59 {
60         while (($from, $to) = each %edits)
61                 {
62                 s/(\b_*)$from(\b)/$1$to$2/g;
63                 }
64         print OUT $_;
65 }
66
67 close OUT;
68
69 if ($runasm)
70         {
71         # run assembler
72         system @ARGS;
73
74         my $rv = $?;
75
76         # restore target
77         unlink $target;
78         rename "tmptarg.s", $target;
79
80         die "Error executing assembler!" if $rv != 0;
81         }
82 else
83         {
84         # Don't care about target
85         unlink "tmptarg.s";
86         }
87
88
89
90