Configure: Improve incremental build time
authorOrgad Shaneh <orgads@gmail.com>
Sun, 31 Jul 2016 06:13:13 +0000 (09:13 +0300)
committerOrgad Shaneh <orgads@gmail.com>
Wed, 16 Nov 2016 07:08:27 +0000 (09:08 +0200)
When Makefile/opensslconf.h is unchanged, don't write it at all.

Currently every time Configure is executed, these files are overwritten.
Makefile leads to regeneration of buildinf.h, and opensslconf.h is itself
a central header.

As a result, Configure triggers full rebuild, even if nothing is changed.

Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/1370)

Configure

index c39f71a17910ea308a441cbf12d0053395cf1774..c26c9d78cd73fd7012c15ec1e6dd272fc1eb8668 100755 (executable)
--- a/Configure
+++ b/Configure
@@ -7,6 +7,7 @@ eval 'exec perl -S $0 ${1+"$@"}'
 
 require 5.000;
 use strict;
+use File::Compare;
 
 # see INSTALL for instructions.
 
@@ -1792,8 +1793,16 @@ while (<IN>)
        }
 close(IN);
 close(OUT);
-rename($Makefile,"$Makefile.bak") || die "unable to rename $Makefile\n" if -e $Makefile;
-rename("$Makefile.new",$Makefile) || die "unable to rename $Makefile.new\n";
+if ((compare($Makefile, "$Makefile.new"))
+       or file_newer('Configure', $Makefile)
+       or file_newer('config', $Makefile)
+       or file_newer('Makefile.org', $Makefile))
+       {
+       rename($Makefile,"$Makefile.bak") || die "unable to rename $Makefile\n" if -e $Makefile;
+       rename("$Makefile.new",$Makefile) || die "unable to rename $Makefile.new\n";
+       }
+else
+       { unlink("$Makefile.new"); }
 
 print "CC            =$cc\n";
 print "CFLAG         =$cflags\n";
@@ -1985,9 +1994,13 @@ print OUT "#ifdef  __cplusplus\n";
 print OUT "}\n";
 print OUT "#endif\n";
 close(OUT);
-rename("crypto/opensslconf.h","crypto/opensslconf.h.bak") || die "unable to rename crypto/opensslconf.h\n" if -e "crypto/opensslconf.h";
-rename("crypto/opensslconf.h.new","crypto/opensslconf.h") || die "unable to rename crypto/opensslconf.h.new\n";
-
+if (compare("crypto/opensslconf.h.new","crypto/opensslconf.h"))
+       {
+       rename("crypto/opensslconf.h","crypto/opensslconf.h.bak") || die "unable to rename crypto/opensslconf.h\n" if -e "crypto/opensslconf.h";
+       rename("crypto/opensslconf.h.new","crypto/opensslconf.h") || die "unable to rename crypto/opensslconf.h.new\n";
+       }
+else
+       { unlink("crypto/opensslconf.h.new"); }
 
 # Fix the date
 
@@ -2289,3 +2302,9 @@ sub test_sanity
        print STDERR "No sanity errors detected!\n" if $errorcnt == 0;
        return $errorcnt;
        }
+
+sub file_newer
+       {
+       my ($file1, $file2) = @_;
+       return (stat($file1))[9] > (stat($file2))[9]
+       }