More progress towards working tests.
[openssl.git] / util / mk1mf.pl
index e0e8d572436d4e5e3fb1c48d0aaa16a0430b9ce5..fb13f2e11faf6e73acd56922c2d6525b1b5550bb 100755 (executable)
@@ -2,8 +2,12 @@
 # A bit of an evil hack but it post processes the file ../MINFO which
 # is generated by `make files` in the top directory.
 # This script outputs one mega makefile that has no shell stuff or any
-# funny stuff
-#
+# funny stuff (if the target is not "copy").
+# If the target is "copy", then it tries to create a makefile that can be
+# safely used with the -j flag and that is compatible with the top-level
+# Makefile, in the sense that it uses the same options and assembler files etc.
+
+use Cwd;
 
 $INSTALLTOP="/usr/local/ssl";
 $OPENSSLDIR="/usr/local/ssl";
@@ -188,7 +192,7 @@ $mkdir="-mkdir" unless defined $mkdir;
 $ranlib="echo ranlib";
 
 $cc=(defined($VARS{'CC'}))?$VARS{'CC'}:'cc';
-$src_dir=(defined($VARS{'SRC'}))?$VARS{'SRC'}:'.';
+$src_dir=(defined($VARS{'SRC'}))?$VARS{'SRC'}:getcwd();
 $bin_dir=(defined($VARS{'BIN'}))?$VARS{'BIN'}:'';
 
 # $bin_dir.=$o causes a core dump on my sparc :-(
@@ -606,6 +610,7 @@ EOF
        }
 
 $defs= <<"EOF";
+# N.B. You MUST use -j on FreeBSD.
 # This makefile has been automatically generated from the OpenSSL distribution.
 # This single makefile will build the complete OpenSSL distribution and
 # by default leave the 'intertesting' output files in .${o}out and the stuff
@@ -748,6 +753,10 @@ $banner
 \$(INC_D):
        \$(MKDIR) \"\$(INC_D)\"
 
+# This needs to be invoked once, when the makefile is first constructed, or
+# after cleaning.
+init: \$(TMP_D) \$(LIB_D) \$(INC_D) \$(INCO_D) \$(BIN_D) \$(TEST_D) headers
+
 headers: \$(HEADER) \$(EXHEADER)
 
 lib: \$(LIBS_DEP) \$(E_SHLIB)
@@ -762,11 +771,6 @@ install: all
        \$(MKDIR) \"\$(INSTALLTOP)${o}lib\"
 $extra_install
 
-
-test: \$(T_EXE)
-       cd \$(BIN_D)
-       ..${o}ms${o}test
-
 clean:
        \$(RM) \$(TMP_D)$o*.*
 
@@ -782,7 +786,17 @@ reallyclean:
        \$(RM) -rf \$(INC_D)
 
 EOF
-    
+
+if ($orig_platform ne 'copy')
+       {
+        $rules .= <<"EOF";
+test: \$(T_EXE)
+       cd \$(BIN_D)
+       ..${o}ms${o}test
+
+EOF
+       }
+
 my $platform_cpp_symbol = "MK1MF_PLATFORM_$platform";
 $platform_cpp_symbol =~ s/-/_/g;
 if (open(IN,"crypto/buildinf.h"))
@@ -875,16 +889,18 @@ sub fix_asm
        return $asm . ' ';
        }
 
-$lib_obj{CRYPTO} .= fix_asm($mf_md5_asm, 'crypto/md5');
-$lib_obj{CRYPTO} .= fix_asm($mf_bn_asm, 'crypto/bn');
-# cpuid is included by the crypto dir
-#$lib_obj{CRYPTO} .= fix_asm($mf_cpuid_asm, 'crypto');
-# AES asm files end up included by the aes dir itself
-#$lib_obj{CRYPTO} .= fix_asm($mf_aes_asm, 'crypto/aes');
-$lib_obj{CRYPTO} .= fix_asm($mf_sha_asm, 'crypto/sha');
-$lib_obj{CRYPTO} .= fix_asm($mf_engines_asm, 'engines');
-$lib_obj{CRYPTO} .= fix_asm($mf_rc4_asm, 'crypto/rc4');
-$lib_obj{CRYPTO} .= fix_asm($mf_modes_asm, 'crypto/modes');
+if ($orig_platform eq 'copy') {
+       $lib_obj{CRYPTO} .= fix_asm($mf_md5_asm, 'crypto/md5');
+       $lib_obj{CRYPTO} .= fix_asm($mf_bn_asm, 'crypto/bn');
+       # cpuid is included by the crypto dir
+       #$lib_obj{CRYPTO} .= fix_asm($mf_cpuid_asm, 'crypto');
+       # AES asm files end up included by the aes dir itself
+       #$lib_obj{CRYPTO} .= fix_asm($mf_aes_asm, 'crypto/aes');
+       $lib_obj{CRYPTO} .= fix_asm($mf_sha_asm, 'crypto/sha');
+       $lib_obj{CRYPTO} .= fix_asm($mf_engines_asm, 'engines');
+       $lib_obj{CRYPTO} .= fix_asm($mf_rc4_asm, 'crypto/rc4');
+       $lib_obj{CRYPTO} .= fix_asm($mf_modes_asm, 'crypto/modes');
+}
 
 foreach (values %lib_nam)
        {
@@ -1012,6 +1028,8 @@ if ($fips)
 
 $rules.=&do_link_rule("\$(BIN_D)$o\$(E_EXE)$exep","\$(E_OBJ)","\$(LIBS_DEP)","\$(L_LIBS) \$(EX_LIBS)", ($fips && !$shlib) ? 2 : 0);
 
+$rules .= get_tests('test/Makefile') if $orig_platform eq 'copy';
+
 print $defs;
 
 if ($platform eq "linux-elf") {
@@ -1286,9 +1304,10 @@ sub cc_compile_target
        $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 "/";
-# FIXME: do dependencies instead of all headers.
-       $ret ="$target: \$(SRC_D)$o$source \$(HEADER) \$(EXHEADER)\n\t";
-       $ret.="\$(CC) ${ofile}$target $ex_flags -c \$(SRC_D)$o$source\n\n";
+       $ret ="$target: \$(SRC_D)$o$source\n\t";
+       $ret.="\$(CC) -MMD ${ofile}$target $ex_flags -c \$(SRC_D)$o$source\n\n";
+       $target =~ s/\.o$/.d/;
+       $ret.=".sinclude \"$target\"\n\n";
        return($ret);
        }
 
@@ -1353,7 +1372,8 @@ sub do_copy_rule
                if ($n =~ /bss_file/)
                        { $pp=".c"; }
                else    { $pp=$p; }
-               $ret.="$to${o}$n$pp: \$(SRC_D)$o$_$pp $to\n\t\$(SRC_D)${o}util${o}copy-if-different.pl \"\$(SRC_D)$o$_$pp\" \"$to${o}$n$pp\"\n\n";
+#              $ret.="$to${o}$n$pp: \$(SRC_D)$o$_$pp\n\t\$(PERL) \$(SRC_D)${o}util${o}copy-if-different.pl \"\$(SRC_D)$o$_$pp\" \"$to${o}$n$pp\"\n\n";
+               $ret.="$to${o}$n$pp: \$(SRC_D)$o$_$pp\n\t\$(CP) \"\$(SRC_D)$o$_$pp\" \"$to${o}$n$pp\"\n\n";
                }
        return($ret);
        }