Get closer to a working single Makefile with test support.
[openssl.git] / util / mk1mf.pl
index 087671b6c3cc0ed34832ac3ac5a2cceb0dd10cad..7860375c56adca1a483c618f481b3dbd79ac04f0 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
 # 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";
 
 $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';
 $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 :-(
 $bin_dir=(defined($VARS{'BIN'}))?$VARS{'BIN'}:'';
 
 # $bin_dir.=$o causes a core dump on my sparc :-(
@@ -748,6 +752,10 @@ $banner
 \$(INC_D):
        \$(MKDIR) \"\$(INC_D)\"
 
 \$(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) headers
+
 headers: \$(HEADER) \$(EXHEADER)
 
 lib: \$(LIBS_DEP) \$(E_SHLIB)
 headers: \$(HEADER) \$(EXHEADER)
 
 lib: \$(LIBS_DEP) \$(E_SHLIB)
@@ -762,11 +770,6 @@ install: all
        \$(MKDIR) \"\$(INSTALLTOP)${o}lib\"
 $extra_install
 
        \$(MKDIR) \"\$(INSTALLTOP)${o}lib\"
 $extra_install
 
-
-test: \$(T_EXE)
-       cd \$(BIN_D)
-       ..${o}ms${o}test
-
 clean:
        \$(RM) \$(TMP_D)$o*.*
 
 clean:
        \$(RM) \$(TMP_D)$o*.*
 
@@ -782,7 +785,17 @@ reallyclean:
        \$(RM) -rf \$(INC_D)
 
 EOF
        \$(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"))
 my $platform_cpp_symbol = "MK1MF_PLATFORM_$platform";
 $platform_cpp_symbol =~ s/-/_/g;
 if (open(IN,"crypto/buildinf.h"))
@@ -1014,6 +1027,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.=&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") {
 print $defs;
 
 if ($platform eq "linux-elf") {
@@ -1288,9 +1303,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 "/";
        $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);
        }
 
        return($ret);
        }