util/fipslink.pl: allow for single-step link.
[openssl.git] / util / fipsas.pl
index c6964e19cfadd68ea9306b678565771427fc6241..1694c59a411fc52582574f262c2e902c3606d241 100644 (file)
@@ -8,20 +8,29 @@ my @ARGS = @ARGV;
 
 my $top = shift @ARGS;
 my $target = shift @ARGS;
+my $tmptarg = $target;
 
-# HACK to disable operation if no OPENSSL_FIPSSYMS option.
-# will go away when tested more fully.
+$tmptarg =~ s/\.[^\\\/\.]+$/.tmp/;
+
+my $runasm = 1;
+
+if ($ARGS[0] eq "norunasm")
+       {
+       $runasm = 0;
+       shift @ARGS;
+       }
 
 my $enabled = 0;
 
-foreach (@ARGS) { $enabled = 1 if /-DOPENSSL_FIPSSYMS/ ; }
+$enabled = 1 if $ENV{FIPSCANISTERINTERNAL} eq "y";
 
-if ($enabled == 0)
+if ($enabled == 0 && $runasm)
        {
        system @ARGS;
        exit $?
        }
 
+
 # Open symbol rename file.
 open(IN, "$top/fips/fipssyms.h") || die "Can't open fipssyms.h";
 
@@ -42,29 +51,43 @@ while (<IN>)
 
 my ($from, $to);
 
+#delete any temp file lying around
+
+unlink $tmptarg;
+
 #rename target temporarily
-rename($target, "tmptarg.s") || die "Can't rename $target\n";
+rename($target, $tmptarg) || die "Can't rename $target";
 
 #edit target
-open IN,"tmptarg.s";
-open OUT, ">$target";
+open(IN,$tmptarg) || die "Can't open temporary file";
+open(OUT, ">$target") || die "Can't open output file $target";
 
 while (<IN>)
 {
        while (($from, $to) = each %edits)
                {
-               s/(\b)$from(\b)/$1$to$2/g;
+               s/(\b_*)$from(\b)/$1$to$2/g;
                }
        print OUT $_;
 }
-# run assembler
-system @ARGS;
 
-my $rv = $?;
+close OUT;
 
-# restore target
-unlink $target;
-rename "tmptarg.s", $target;
+if ($runasm)
+       {
+       # run assembler
+       system @ARGS;
+
+       my $rv = $?;
 
-die "Error executing assembler!" if $rv != 0;
+       # restore target
+       unlink $target;
+       rename $tmptarg, $target;
 
+       die "Error executing assembler!" if $rv != 0;
+       }
+else
+       {
+       # Don't care about target
+       unlink $tmptarg;
+       }