Windows build fixes.
[openssl.git] / util / mk1mf.pl
index ed65a057f0fe3bc6bd445d727b2dd1f7eb38cac3..a550523b624a53a0c5ca71e286c48ae26d046bcd 100755 (executable)
@@ -1,9 +1,13 @@
-#!/usr/local/bin/perl
+#!/usr/bin/env perl
 # 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'}: $platform eq 'copy' ? getcwd() : '.';
 $bin_dir=(defined($VARS{'BIN'}))?$VARS{'BIN'}:'';
 
 # $bin_dir.=$o causes a core dump on my sparc :-(
@@ -451,6 +455,14 @@ for (;;)
        }
 close(IN);
 
+if ($orig_platform eq 'copy')
+       {
+       # Remove opensslconf.h so it doesn't get updated if we configure a
+       # different branch.
+       $exheader =~ s/[^ ]+\/opensslconf.h//;
+       $header =~ s/[^ ]+\/opensslconf.h//;
+       }
+
 if ($fips)
        {
 
@@ -605,7 +617,10 @@ EOF
        $ex_libs .= " $zlib_lib" if $zlib_opt == 1;
        }
 
+my $asm_def = $orig_platform eq 'copy' ? "" : "ASM=$bin_dir$asm";
+
 $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
@@ -664,7 +679,7 @@ RANLIB=$ranlib
 MKDIR=$mkdir
 MKLIB=$bin_dir$mklib
 MLFLAGS=$mlflags
-ASM=$bin_dir$asm
+$asm_def
 
 # FIPS validated module and support file locations
 
@@ -748,6 +763,11 @@ $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
+       \$(PERL) \$(SRC_D)/util/copy-if-different.pl "\$(SRC_D)/crypto/opensslconf.h" "\$(INCO_D)/opensslconf.h"
+
 headers: \$(HEADER) \$(EXHEADER)
 
 lib: \$(LIBS_DEP) \$(E_SHLIB)
@@ -762,11 +782,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 +797,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"))
@@ -1014,6 +1039,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") {
@@ -1253,15 +1280,15 @@ sub perlasm_compile_target
 
        my($ret);
        $bname =~ s/(.*)\.[^\.]$/$1/;
-       $ret ="\$(TMP_D)$o$bname.asm: $source\n";
+       $ret ="\$(TMP_D)$o$bname$asm_suffix: $source\n";
        $ret.="\t\$(PERL) $source $asmtype \$(CFLAG) >\$\@\n";
        if ($fipscanisteronly)
                {
-               $ret .= "\t\$(PERL) util\\fipsas.pl . \$@ norunasm \$(CFLAG)\n";
+               $ret .= "\t\$(PERL) util$o.pl . \$@ norunasm \$(CFLAG)\n";
                }
        $ret .= "\n";
-       $ret.="$target: \$(TMP_D)$o$bname.asm\n";
-       $ret.="\t\$(ASM) $afile\$\@ \$(TMP_D)$o$bname.asm\n\n";
+       $ret.="$target: \$(TMP_D)$o$bname$asm_suffix\n";
+       $ret.="\t\$(ASM) $afile\$\@ \$(TMP_D)$o$bname$asm_suffix\n\n";
        return($ret);
        }
 
@@ -1288,9 +1315,12 @@ 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)";
+       $ret.= " -MMD" if $orig_platform eq "copy";
+       $ret.= " ${ofile}$target $ex_flags -c \$(SRC_D)$o$source\n\n";
+       $target =~ s/\.o$/.d/;
+       $ret.=".sinclude \"$target\"\n\n" if $orig_platform eq "copy";
        return($ret);
        }
 
@@ -1355,7 +1385,7 @@ 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";
                }
        return($ret);
        }