linux-elf bugfix
[openssl.git] / util / mk1mf.pl
index 355143b703d84815746cde04b3ef91c67fa0be8b..ffb3c1083421cfaa705bd22d5e4588187690683d 100755 (executable)
@@ -8,11 +8,12 @@
 $INSTALLTOP="/usr/local/ssl";
 $OPTIONS="";
 $ssl_version="";
+$banner="\t\@echo Building OpenSSL";
 
 open(IN,"<Makefile.ssl") || die "unable to open Makefile.ssl!\n";
 while(<IN>) {
     $ssl_version=$1 if (/^VERSION=(.*)$/);
-    $options=$1 if (/^OPTIONS=(.*)$/);
+    $OPTIONS=$1 if (/^OPTIONS=(.*)$/);
     $INSTALLTOP=$1 if (/^INSTALLTOP=(.*$)/);
 }
 close(IN);
@@ -45,7 +46,7 @@ foreach (@ARGV)
        if (!&read_options && !defined($ops{$_}))
                {
                print STDERR "unknown option - $_\n";
-               print STDERR "usage: perl mk1mf.pl [system] [options]\n";
+               print STDERR "usage: perl mk1mf.pl [options] [system]\n";
                print STDERR "\nwhere [system] can be one of the following\n";
                foreach $i (sort keys %ops)
                { printf STDERR "\t%-10s\t%s\n",$i,$ops{$i}; }
@@ -58,6 +59,8 @@ and [options] can be one of
        no-ssl2 no-ssl3                         - Skip this version of SSL
        just-ssl                                - remove all non-ssl keys/digest
        no-asm                                  - No x86 asm
+       nasm                                    - Use NASM for x86 asm
+       gaswin                                  - Use GNU as with Mingw32
        no-socks                                - No socket code
        no-err                                  - No error strings
        dll/shlib                               - Build shared libraries (MS)
@@ -270,6 +273,8 @@ LFLAGS=$lflags
 
 BN_ASM_OBJ=$bn_asm_obj
 BN_ASM_SRC=$bn_asm_src
+BNCO_ASM_OBJ=$bnco_asm_obj
+BNCO_ASM_SRC=$bnco_asm_src
 DES_ENC_OBJ=$des_enc_obj
 DES_ENC_SRC=$des_enc_src
 BF_ENC_OBJ=$bf_enc_obj
@@ -357,6 +362,10 @@ all: banner \$(TMP_D) \$(BIN_D) \$(TEST_D) \$(LIB_D) \$(INCO_D) headers lib exe
 banner:
 $banner
 
+# Generate perlasm output files
+%.cpp:
+       (cd \$(\@D)/..; PERL=perl make -f Makefile.ssl asm/\$(\@F))
+
 \$(TMP_D):
        \$(MKDIR) \$(TMP_D)
 # NB: uncomment out these lines if BIN_D, TEST_D and LIB_D are different
@@ -376,6 +385,7 @@ $banner
        \$(MKDIR) \$(INC_D)
 
 headers: \$(HEADER) \$(EXHEADER)
+       @
 
 lib: \$(LIBS_DEP)
 
@@ -400,6 +410,42 @@ vclean:
        \$(RM) \$(OUT_D)$o*.*
 
 EOF
+    
+my $platform_cpp_symbol = "MK1MF_PLATFORM_$platform";
+$platform_cpp_symbol =~ s/-/_/g;
+if (open(IN,"crypto/buildinf.h"))
+       {
+       # Remove entry for this platform in existing file buildinf.h.
+
+       my $old_buildinf_h = "";
+       while (<IN>)
+               {
+               if (/^\#ifdef $platform_cpp_symbol$/)
+                       {
+                       while (<IN>) { last if (/^\#endif/); }
+                       }
+               else
+                       {
+                       $old_buildinf_h .= $_;
+                       }
+               }
+       close(IN);
+
+       open(OUT,">crypto/buildinf.h") || die "Can't open buildinf.h";
+       print OUT $old_buildinf_h;
+       close(OUT);
+       }
+
+open (OUT,">>crypto/buildinf.h") || die "Can't open buildinf.h";
+printf OUT <<EOF;
+#ifdef $platform_cpp_symbol
+  /* auto-generated/updated by util/mk1mf.pl for crypto/cversion.c */
+  #define CFLAGS "$cc $cflags"
+  #define PLATFORM "$platform"
+EOF
+printf OUT "  #define DATE \"%s\"\n", scalar gmtime();
+printf OUT "#endif\n";
+close(OUT);
 
 #############################################
 # We parse in input file and 'store' info for later printing.
@@ -500,6 +546,11 @@ foreach (values %lib_nam)
                $lib_obj =~ s/\s\S*\/bn_asm\S*/ \$(BN_ASM_OBJ)/;
                $rules.=&do_asm_rule($bn_asm_obj,$bn_asm_src);
                }
+       if (($bnco_asm_obj ne "") && ($_ eq "CRYPTO"))
+               {
+               $lib_obj .= "\$(BNCO_ASM_OBJ)";
+               $rules.=&do_asm_rule($bnco_asm_obj,$bnco_asm_src);
+               }
        if (($des_enc_obj ne "") && ($_ eq "CRYPTO"))
                {
                $lib_obj =~ s/\s\S*des_enc\S*/ \$(DES_ENC_OBJ)/;
@@ -678,6 +729,7 @@ sub do_defs
                        { $pf=".c"; }
                else    { $pf=$postfix; }
                if ($_ =~ /BN_ASM/)     { $t="$_ "; }
+               elsif ($_ =~ /BNCO_ASM/){ $t="$_ "; }
                elsif ($_ =~ /DES_ENC/) { $t="$_ "; }
                elsif ($_ =~ /BF_ENC/)  { $t="$_ "; }
                elsif ($_ =~ /CAST_ENC/){ $t="$_ "; }
@@ -729,8 +781,7 @@ sub cc_compile_target
        local($target,$source,$ex_flags)=@_;
        local($ret);
        
-       # EAY EAY
-       $ex_flags.=' -DCFLAGS="\"$(CC) $(CFLAG)\"" -DPLATFORM="\"$(PLATFORM)\""' if ($source =~ /cversion/ and $dcflags ne 'n');
+       $ex_flags.=" -DMK1MF_BUILD -D$platform_cpp_symbol" if ($source =~ /cversion/);
        $target =~ s/\//$o/g if $o ne "/";
        $source =~ s/\//$o/g if $o ne "/";
        $ret ="$target: \$(SRC_D)$o$source\n\t";
@@ -813,6 +864,8 @@ sub read_options
        elsif (/^no-dh$/)       { $no_dh=1; }
        elsif (/^no-hmac$/)     { $no_hmac=1; }
        elsif (/^no-asm$/)      { $no_asm=1; }
+       elsif (/^nasm$/)        { $nasm=1; }
+       elsif (/^gaswin$/)      { $gaswin=1; }
        elsif (/^no-ssl2$/)     { $no_ssl2=1; }
        elsif (/^no-ssl3$/)     { $no_ssl3=1; }
        elsif (/^no-err$/)      { $no_err=1; }
@@ -831,6 +884,6 @@ sub read_options
        elsif (/^-[lL].*$/)     { $l_flags.="$_ "; }
        elsif ((!/^-help/) && (!/^-h/) && (!/^-\?/) && /^-.*$/)
                { $c_flags.="$_ "; }
-       else { return(1); }
-       return(0);
+       else { return(0); }
+       return(1);
        }