Rethink the method to place user cflags last
[openssl.git] / Configure
index 5afa63dd2a6578f51642fc1b4db487b71f68fe17..e28fd10dc7ad1b657cd695487fc581905d89ae58 100755 (executable)
--- a/Configure
+++ b/Configure
@@ -32,10 +32,6 @@ my $usage="Usage: Configure [no-<cipher> ...] [enable-<cipher> ...] [experimenta
 #               This becomes the value of OPENSSLDIR in Makefile and in C.
 #               (Default: PREFIX/ssl)
 #
-# --install_prefix  Additional prefix for package builders (empty by
-#               default).  This needn't be set in advance, you can
-#               just as well use "make INSTALL_PREFIX=/whatever install".
-#
 # --cross-compile-prefix Add specified prefix to binutils components.
 #
 # --api         One of 0.9.8, 1.0.0 or 1.1.0.  Do not compile support for
@@ -80,7 +76,7 @@ my $usage="Usage: Configure [no-<cipher> ...] [enable-<cipher> ...] [experimenta
 # Minimum warning options... any contributions to OpenSSL should at least get
 # past these.
 
-my $gcc_devteam_warn = "-Wall -pedantic -DPEDANTIC -Wno-long-long -Wsign-compare -Wmissing-prototypes -Wshadow -Wformat -Wtype-limits -Werror -DREF_CHECK -DDEBUG_UNUSED";
+my $gcc_devteam_warn = "-Wall -pedantic -DPEDANTIC -Wno-long-long -Wsign-compare -Wmissing-prototypes -Wshadow -Wformat -Wtype-limits -Werror -DREF_DEBUG -DDEBUG_UNUSED";
 
 # These are used in addition to $gcc_devteam_warn when the compiler is clang.
 # TODO(openssl-team): fix problems and investigate if (at least) the
@@ -91,9 +87,6 @@ my $gcc_devteam_warn = "-Wall -pedantic -DPEDANTIC -Wno-long-long -Wsign-compare
 # -Wextended-offsetof
 my $clang_devteam_warn = "-Wno-unused-parameter -Wno-missing-field-initializers -Wno-language-extension-token -Wno-extended-offsetof -Wconditional-uninitialized -Qunused-arguments -Wincompatible-pointer-types-discards-qualifiers -Wmissing-variable-declarations";
 
-# Warn that "make depend" should be run?
-my $warn_make_depend = 0;
-
 # These are used in addition to $gcc_devteam_warn unless this is a mingw build.
 # This adds backtrace information to the memory leak info.
 my $memleak_devteam_backtrace = "-rdynamic -DCRYPTO_MDEBUG_BACKTRACE";
@@ -187,7 +180,6 @@ $config{prefix}="";
 $config{openssldir}="";
 $config{processor}="";
 $config{libdir}="";
-$config{install_prefix}= "$ENV{'INSTALL_PREFIX'}";
 $config{cross_compile_prefix}="";
 $config{fipslibdir}="/usr/local/ssl/fips-2.0/lib/";
 my $nofipscanistercheck=0;
@@ -321,6 +313,7 @@ my %disabled = ( # "what"         => "comment" [or special keyword "experimental
                 "unit-test"      => "default",
                 "zlib"           => "default",
                 "crypto-mdebug"  => "default",
+                "heartbeats"     => "default",
               );
 my @experimental = ();
 
@@ -398,6 +391,15 @@ my @default_depdefines =
 # We will collect such requests in @experimental.
 # To avoid accidental use of experimental features, applications will have to use -DOPENSSL_EXPERIMENTAL_FOO.
 
+my @generated_headers = (
+    "include/openssl/opensslconf.h",
+    "crypto/include/internal/bn_conf.h"
+    );
+
+my @generated_by_make_headers = (
+    "crypto/buildinf.h"
+    );
+
 
 my $no_sse2=0;
 
@@ -416,7 +418,6 @@ $config{openssl_other_defines}=[];
 my $libs="";
 my $target="";
 $config{options}="";
-my $make_depend=0;
 my %withargs=();
 my $build_prefix = "release_";
 
@@ -450,7 +451,7 @@ if (grep /^reconf(igure)?$/, @argvcopy) {
         # centered information gathering the reading configdata.pm
         #
         while (<IN>) {
-            chomp;
+            s|\R$||;
             if (/^CONFIGURE_ARGS=\s*(.*)\s*/) {
                 # Older form, we split the string and hope for the best
                 @argvcopy = split /\s+/, $_;
@@ -598,10 +599,6 @@ foreach (@argvcopy)
                        {
                        $config{openssldir}=$1;
                        }
-               elsif (/^--install.prefix=(.*)$/)
-                       {
-                       $config{install_prefix}=$1;
-                       }
                elsif (/^--with-zlib-lib=(.*)$/)
                        {
                        $withargs{zlib_lib}=$1;
@@ -637,7 +634,7 @@ foreach (@argvcopy)
                else    # common if (/^[-+]/), just pass down...
                        {
                        $_ =~ s/%([0-9a-f]{1,2})/chr(hex($1))/gei;
-                       $user_cflags.=$_." ";
+                       $user_cflags.=" ".$_;
                        }
                }
        elsif ($_ =~ /^([^:]+):(.+)$/)
@@ -865,10 +862,10 @@ push @{$config{defines}},
     map { (my $x = $_) =~ s/^OPENSSL_NO_/OPENSSL_EXPERIMENTAL_/; $x }
         @{$config{openssl_experimental_defines}};
 
-if ($target =~ /^mingw/ && `$target{cc} --target-help 2>&1` !~ m/-mno-cygwin/m)
+if ($target =~ /^mingw/ && `$target{cc} --target-help 2>&1` =~ m/-mno-cygwin/m)
        {
-       $config{cflags} =~ s/-mno-cygwin\s*//;
-       $target{shared_ldflag} =~ s/-mno-cygwin\s*//;
+       $config{cflags} .= " -mno-cygwin";
+       $target{shared_ldflag} .= " -mno-cygwin";
        }
 
 if ($target =~ /linux.*-mips/ && !$no_asm && $user_cflags !~ /-m(ips|arch=)/) {
@@ -881,11 +878,6 @@ my $no_shared_warn=0;
 my $no_user_cflags=0;
 my $no_user_defines=0;
 
-if ($user_cflags ne "")        { $config{cflags}="$user_cflags$config{cflags}"; }
-else                   { $no_user_cflags=1;       }
-if (@user_defines)     { $config{defines}=[ @user_defines, @{$config{defines}} ]; }
-else                   { $no_user_defines=1;       }
-
 # The DSO code currently always implements all functions so that no
 # applications will have to worry about that from a compilation point
 # of view. However, the "method"s may return zero unless that platform
@@ -1161,6 +1153,13 @@ if ($strict_warnings)
                }
        }
 
+if ($user_cflags ne "") { $config{cflags}="$config{cflags}$user_cflags"; }
+else                    { $no_user_cflags=1;  }
+if (@user_defines) { $config{defines}=[ @{$config{defines}}, @user_defines ]; }
+else               { $no_user_defines=1;    }
+
+# ALL MODIFICATIONS TO %config and %target MUST BE DONE FROM HERE ON
+
 # If we use the unified build, collect information from build.info files
 my %unified_info = ();
 
@@ -1327,7 +1326,7 @@ if ($builder eq "unified") {
                 my $lineiterator = shift;
                 my $target_kind = $1;
                 while (defined $lineiterator->()) {
-                    chomp;
+                    s|\R$||;
                     if (/^\s*ENDRAW\[((?:\\.|[^\\\]])+)\]\s*$/) {
                         die "ENDRAW doesn't match BEGINRAW"
                             if $1 ne $target_kind;
@@ -1485,9 +1484,15 @@ EOF
             foreach (@{$depends{$dest}}) {
                 my $d = cleanfile($sourced, $_, $blddir);
 
-                # If it isn't found in the source, let's assume it's generated
-                # and that the Makefile template has the lines
-                if (! -f $d) {
+                # If we know it's generated, or assume it is because we can't
+                # find it in the source tree, we set file we depend on to be
+                # in the build tree rather than the source tree, and assume
+                # and that there are lines to build it in a BEGINRAW..ENDRAW
+                # section or in the Makefile template.
+                if (! -f $d
+                    || !(grep { $d eq $_ }
+                         map { cleanfile($srcdir, $_, $blddir) }
+                         (@generated_headers, @generated_by_make_headers))) {
                     $d = cleanfile($buildd, $_, $blddir);
                 }
                 # Take note if the file to depend on is being renamed
@@ -1701,14 +1706,10 @@ print "THIRTY_TWO_BIT mode\n" if $config{b32};
 print "BN_LLONG mode\n" if $config{bn_ll};
 print "RC4 uses $config{rc4_int}\n" if $config{rc4_int} != $def_int;
 
-mkpath(catdir($blddir, "include/openssl"));
-run_dofile(catfile($blddir, "include/openssl/opensslconf.h"),
-           catfile($srcdir, "include/openssl/opensslconf.h.in"));
-
-mkpath(catdir($blddir, "crypto/include/internal"));
-foreach my $alg ( 'bn' ) {
-    run_dofile(catfile($blddir, "crypto/include/internal/${alg}_conf.h"),
-               catfile($srcdir, "crypto/include/internal/${alg}_conf.h.in"));
+for (@generated_headers) {
+    mkpath(catdir($blddir, dirname($_)));
+    run_dofile(catfile($blddir, $_),
+               catfile($srcdir, $_.".in"));
 }
 
 ###
@@ -1751,42 +1752,12 @@ my %builders = (
         run_dofile(catfile($blddir, $target{build_file}),
                    $config{build_file_template},
                    catfile($srcdir, "Configurations", "common.tmpl"));
-
-        my $make_command = "$make PERL=\'$config{perl}\'";
-        my $make_targets = "";
-        my $need_make_depend =
-            join(" ", @{$config{depdefines}}) ne join(" ", @default_depdefines);
-        $make_targets .= " depend"
-            if $need_make_depend && $make_depend;
-
-        (system $make_command.$make_targets) == 0
-            or die "make $make_targets failed"
-            if $make_targets ne "";
-
-        if ($need_make_depend && !$make_depend) {
-            $warn_make_depend++;
-        }
     },
     unixmake => sub {
         build_Makefile();
 
         run_dofile("util/domd", "util/domd.in");
         chmod 0755, "util/domd";
-
-        my $make_command = "$make PERL=\'$config{perl}\'";
-        my $make_targets = "";
-        my $need_make_depend =
-            join(" ", @{$config{depdefines}}) ne join(" ", @default_depdefines);
-        $make_targets .= " depend"
-            if $need_make_depend && $make_depend;
-
-        (system $make_command.$make_targets) == 0
-            or die "make $make_targets failed"
-            if $make_targets ne "";
-
-        if ($need_make_depend && !$make_depend) {
-            $warn_make_depend++;
-        }
     },
     mk1mf => sub {
         my $platform = shift;
@@ -1879,14 +1850,6 @@ shared libraries, please let us know (but please first make sure you have
 tried with a current version of OpenSSL).
 EOF
 
-print <<"EOF" if ($warn_make_depend);
-
-*** Because of configuration changes, you MUST do the following before
-*** building:
-
-       make depend
-EOF
-
 ###### TO BE REMOVED BEFORE FINAL RELEASE
 ######
 ###### If the user hasn't chosen --unified, try to nudge them.
@@ -2211,6 +2174,7 @@ sub print_table_entry
        "shared_target",
        "shared_cflag",
        "shared_ldflag",
+       "shared_rcflag",
        "shared_extension",
        "obj_extension",
        "exe_extension",
@@ -2321,7 +2285,7 @@ sub collect_from_file {
         my $saved_line = "";
         $_ = "";
         while (<$fh>) {
-            chomp;
+            s|\R$||;
             if (defined $line_concat) {
                 $_ = $line_concat->($saved_line, $_);
                 $saved_line = "";
@@ -2352,7 +2316,7 @@ sub collect_from_array {
         my $saved_line = "";
         $_ = "";
         while (defined($_ = shift @array)) {
-            chomp;
+            s|\R$||;
             if (defined $line_concat) {
                 $_ = $line_concat->($saved_line, $_);
                 $saved_line = "";
@@ -2377,7 +2341,7 @@ sub collect_information {
     my %collectors = @_;
 
     while(defined($_ = $lineiterator->())) {
-        chomp;
+        s|\R$||;
         my $found = 0;
         foreach my $re (keys %collectors) {
             if ($re ne "OTHERWISE" && /$re/) {