Configure: save away the value of OPENSSL_LOCAL_CONFIG_DIR for reconf
[openssl.git] / Configure
index f43b5bfa36d25513eb39298939e33c33f282730f..b88f6aad4299c76dfed43ded3894008e99b074c5 100755 (executable)
--- a/Configure
+++ b/Configure
@@ -184,6 +184,45 @@ my $local_config_envname = 'OPENSSL_LOCAL_CONFIG_DIR';
 $config{sourcedir} = abs2rel($srcdir);
 $config{builddir} = abs2rel($blddir);
 
+# Collect reconfiguration information if needed
+my @argvcopy=@ARGV;
+
+if (grep /^reconf(igure)?$/, @argvcopy) {
+    if (-f "./configdata.pm") {
+       my $file = "./configdata.pm";
+       unless (my $return = do $file) {
+           die "couldn't parse $file: $@" if $@;
+            die "couldn't do $file: $!"    unless defined $return;
+            die "couldn't run $file"       unless $return;
+       }
+
+       @argvcopy = defined($configdata::config{perlargv}) ?
+           @{$configdata::config{perlargv}} : ();
+       die "Incorrect data to reconfigure, please do a normal configuration\n"
+           if (grep(/^reconf/,@argvcopy));
+       $ENV{CROSS_COMPILE} = $configdata::config{cross_compile_prefix}
+           if defined($configdata::config{cross_compile_prefix});
+       $ENV{CC} = $configdata::config{cc}
+           if defined($configdata::config{cc});
+       $ENV{BUILDFILE} = $configdata::config{build_file}
+           if defined($configdata::config{build_file});
+       $ENV{$local_config_envname} = $configdata::config{local_config_dir}
+           if defined($configdata::config{local_config_dir});
+
+       print "Reconfiguring with: ", join(" ",@argvcopy), "\n";
+       print "    CROSS_COMPILE = ",$ENV{CROSS_COMPILE},"\n"
+           if $ENV{CROSS_COMPILE};
+       print "    CC = ",$ENV{CC},"\n" if $ENV{CC};
+       print "    BUILDFILE = ",$ENV{BUILDFILE},"\n" if $ENV{BUILDFILE};
+       print "    $local_config_envname = ",$ENV{$local_config_envname},"\n"
+           if $ENV{$local_config_envname};
+    } else {
+       die "Insufficient data to reconfigure, please do a normal configuration\n";
+    }
+}
+
+$config{perlargv} = [ @argvcopy ];
+
 # Collect version numbers
 $config{version} = "unknown";
 $config{version_num} = "unknown";
@@ -311,6 +350,7 @@ my @disablables = (
     "md2",
     "md4",
     "mdc2",
+    "msan",
     "multiblock",
     "nextprotoneg",
     "ocb",
@@ -364,11 +404,15 @@ my %deprecated_disablables = (
 
 our %disabled = ( # "what"         => "comment"
                   "asan"               => "default",
+                 "crypto-mdebug"       => "default",
+                 "crypto-mdebug-backtrace" => "default",
                  "ec_nistp_64_gcc_128" => "default",
                  "egd"                 => "default",
                  "fuzz-libfuzzer"      => "default",
                  "fuzz-afl"            => "default",
+                 "heartbeats"          => "default",
                  "md2"                 => "default",
+                  "msan"                => "default",
                  "rc5"                 => "default",
                  "sctp"                => "default",
                  "ssl-trace"           => "default",
@@ -379,9 +423,6 @@ our %disabled = ( # "what"         => "comment"
                  "weak-ssl-ciphers"    => "default",
                  "zlib"                => "default",
                  "zlib-dynamic"        => "default",
-                 "crypto-mdebug"       => "default",
-                 "crypto-mdebug-backtrace" => "default",
-                 "heartbeats"          => "default",
                );
 
 # Note: => pair form used for aesthetics, not to truly make a hash table
@@ -435,10 +476,12 @@ my @disable_cascades = (
     # no-autoalginit is only useful when building non-shared
     "autoalginit"       => [ "shared", "apps" ],
 
-    "stdio"             => [ "apps" ],
+    "stdio"             => [ "apps", "capieng" ],
     "apps"              => [ "tests" ],
     "comp"             => [ "zlib" ],
     sub { !$disabled{"unit-test"} } => [ "heartbeats" ],
+
+    sub { !$disabled{"msan"} } => [ "asm" ],
     );
 
 # Avoid protocol support holes.  Also disable all versions below N, if version
@@ -479,58 +522,6 @@ my $target="";
 $config{options}="";
 $config{build_type} = "release";
 
-my @argvcopy=@ARGV;
-
-if (grep /^reconf(igure)?$/, @argvcopy) {
-    if (-f "./configdata.pm") {
-       my $file = "./configdata.pm";
-       unless (my $return = do $file) {
-           die "couldn't parse $file: $@" if $@;
-            die "couldn't do $file: $!"    unless defined $return;
-            die "couldn't run $file"       unless $return;
-       }
-
-       @argvcopy = defined($configdata::config{perlargv}) ?
-           @{$configdata::config{perlargv}} : ();
-       die "Incorrect data to reconfigure, please do a normal configuration\n"
-           if (grep(/^reconf/,@argvcopy));
-       $ENV{CROSS_COMPILE} = $configdata::config{cross_compile_prefix}
-           if defined($configdata::config{cross_compile_prefix});
-       $ENV{CROSS_COMPILE} = $configdata::config{cc}
-           if defined($configdata::config{cc});
-
-       print "Reconfiguring with: ", join(" ",@argvcopy), "\n";
-       print "    CROSS_COMPILE = ",$ENV{CROSS_COMPILE},"\n"
-           if $ENV{CROSS_COMPILE};
-       print "    CC = ",$ENV{CC},"\n" if $ENV{CC};
-    } elsif (open IN, "<Makefile") {
-        #
-        # THIS SECTION IS TEMPORARY, it helps transitioning from Makefile
-        # centered information gathering the reading configdata.pm
-        #
-        while (<IN>) {
-            s|\R$||;
-            if (/^CONFIGURE_ARGS=\s*(.*)\s*/) {
-                # Older form, we split the string and hope for the best
-                @argvcopy = split /\s+/, $_;
-                die "Incorrect data to reconfigure, please do a normal configuration\n"
-                    if (grep(/^reconf/,@argvcopy));
-            } elsif (/^CROSS_COMPILE=\s*(.*)/) {
-                $ENV{CROSS_COMPILE}=$1;
-            } elsif (/^CC=\s*(?:\$\(CROSS_COMPILE\))?(.*?)$/) {
-                $ENV{CC}=$1;
-            }
-        }
-        #
-        # END OF TEMPORARY SECTION
-        #
-    } else {
-       die "Insufficient data to reconfigure, please do a normal configuration\n";
-    }
-}
-
-$config{perlargv} = [ @argvcopy ];
-
 my %unsupported_options = ();
 my %deprecated_options = ();
 foreach (@argvcopy)
@@ -721,6 +712,13 @@ foreach (@argvcopy)
                        {
                        $libs.=$_." ";
                        }
+               elsif (/^-static$/)
+                       {
+                       $libs.=$_." ";
+                       $disabled{"pic"} = "forced";
+                       $disabled{"shared"} = "forced";
+                       $disabled{"threads"} = "forced";
+                       }
                elsif (/^-D(.*)$/)
                        {
                        push @user_defines, $1;
@@ -927,6 +925,13 @@ $target{nm} =      $ENV{'NM'}      || $target{nm}      || "nm";
 $target{rc} =
     $ENV{'RC'}  || $ENV{'WINDRES'} || $target{rc}      || "windres";
 
+# Allow overriding the build file name
+$target{build_file} = $ENV{BUILDFILE} || $target{build_file} || "Makefile";
+
+# Cache information necessary for reconfiguration
+$config{cc} = $target{cc};
+$config{build_file} = $target{build_file};
+
 # For cflags, lflags, plib_lflags, ex_libs and defines, add the debug_
 # or release_ attributes.
 # Do it in such a way that no spurious space is appended (hence the grep).
@@ -1063,8 +1068,12 @@ unless ($disabled{ubsan}) {
     $config{cflags} .= "-fsanitize=undefined -fno-sanitize-recover=all ";
 }
 
+unless ($disabled{msan}) {
+  $config{cflags} .= "-fsanitize=memory ";
+}
+
 unless ($disabled{"fuzz-libfuzzer"} && $disabled{"fuzz-afl"}
-        && $disabled{asan} && $disabled{ubsan}) {
+        && $disabled{asan} && $disabled{ubsan} && $disabled{msan}) {
     $config{cflags} .= "-fno-omit-frame-pointer -g ";
 }
 #
@@ -1108,6 +1117,9 @@ unless ($disabled{asm}) {
        push @{$config{defines}}, "SHA256_ASM" if ($target{sha1_asm_src} =~ /sha256/);
        push @{$config{defines}}, "SHA512_ASM" if ($target{sha1_asm_src} =~ /sha512/);
     }
+    if ($target{rc4_asm_src} ne $table{DEFAULTS}->{rc4_asm_src}) {
+       push @{$config{defines}}, "RC4_ASM";
+    }
     if ($target{md5_asm_src}) {
        push @{$config{defines}}, "MD5_ASM";
     }
@@ -1276,26 +1288,39 @@ my $buildinfo_debug = defined($ENV{CONFIGURE_DEBUG_BUILDINFO});
 if ($builder eq "unified") {
     # Store the name of the template file we will build the build file from
     # in %config.  This may be useful for the build file itself.
-    my $build_file_template;
-
-    for my $filename (( $builder_platform."-".$target{build_file}.".tmpl",
-                        $target{build_file}.".tmpl" )) {
-        if (defined $ENV{$local_config_envname}) {
-            if ($^O eq 'VMS') {
-                # VMS environment variables are logical names,
-                # which can be used as is
-                $build_file_template = $local_config_envname . ':' . $filename;
-            } else {
-                $build_file_template = catfile($ENV{$local_config_envname},
-                                               $filename);
-            }
-        }
+    my @build_file_template_names =
+       ( $builder_platform."-".$target{build_file}.".tmpl",
+         $target{build_file}.".tmpl" );
+    my @build_file_templates = ();
+
+    # First, look in the user provided directory, if given
+    if (defined $ENV{$local_config_envname}) {
+       @build_file_templates =
+           map {
+               if ($^O eq 'VMS') {
+                   # VMS environment variables are logical names,
+                   # which can be used as is
+                   $local_config_envname . ':' . $_;
+               } else {
+                   catfile($ENV{$local_config_envname}, $_);
+               }
+           }
+           @build_file_template_names;
+    }
+    # Then, look in our standard directory
+    push @build_file_templates,
+       ( map { catfile($srcdir, "Configurations", $_) }
+         @build_file_template_names );
 
+    my $build_file_template;
+    for $_ (@build_file_templates) {
+       $build_file_template = $_;
         last if -f $build_file_template;
 
-        $build_file_template = catfile($srcdir, "Configurations", $filename);
-
-        last if -f $build_file_template;
+        $build_file_template = undef;
+    }
+    if (!defined $build_file_template) {
+       die "*** Couldn't find any of:\n", join("\n", @build_file_templates), "\n";
     }
     $config{build_file_template} = $build_file_template;
 
@@ -1336,9 +1361,6 @@ if ($builder eq "unified") {
     }
 
     my @build_infos = ( [ ".", "build.info" ] );
-    push @build_infos, [ "fuzz", "build.info.fuzz" ]
-        unless $disabled{"fuzz-afl"} && $disabled{"fuzz-libfuzzer"};
-
     foreach (@{$config{dirs}}) {
         push @build_infos, [ $_, "build.info" ]
             if (-f catfile($srcdir, $_, "build.info"));
@@ -1363,9 +1385,13 @@ if ($builder eq "unified") {
         my $f = $_->[1];
         # The basic things we're trying to build
         my @programs = ();
+        my @programs_install = ();
         my @libraries = ();
+        my @libraries_install = ();
         my @engines = ();
+        my @engines_install = ();
         my @scripts = ();
+        my @scripts_install = ();
         my @extra = ();
         my @overrides = ();
         my @intermediates = ();
@@ -1429,18 +1455,42 @@ if ($builder eq "unified") {
             qr/^\s*ENDIF\s*$/
             => sub { die "ENDIF out of scope" if ! @skip;
                      pop @skip; },
-            qr/^\s*PROGRAMS\s*=\s*(.*)\s*$/
-            => sub { push @programs, tokenize($1)
-                         if !@skip || $skip[$#skip] > 0 },
-            qr/^\s*LIBS\s*=\s*(.*)\s*$/
-            => sub { push @libraries, tokenize($1)
-                         if !@skip || $skip[$#skip] > 0 },
-            qr/^\s*ENGINES\s*=\s*(.*)\s*$/
-            => sub { push @engines, tokenize($1)
-                         if !@skip || $skip[$#skip] > 0 },
-            qr/^\s*SCRIPTS\s*=\s*(.*)\s*$/
-            => sub { push @scripts, tokenize($1)
-                         if !@skip || $skip[$#skip] > 0 },
+            qr/^\s*PROGRAMS(_NO_INST)?\s*=\s*(.*)\s*$/
+            => sub {
+                if (!@skip || $skip[$#skip] > 0) {
+                    my $install = $1;
+                    my @x = tokenize($2);
+                    push @programs, @x;
+                    push @programs_install, @x unless $install;
+                }
+            },
+            qr/^\s*LIBS(_NO_INST)?\s*=\s*(.*)\s*$/
+            => sub {
+                if (!@skip || $skip[$#skip] > 0) {
+                    my $install = $1;
+                    my @x = tokenize($2);
+                    push @libraries, @x;
+                    push @libraries_install, @x unless $install;
+                }
+            },
+            qr/^\s*ENGINES(_NO_INST)?\s*=\s*(.*)\s*$/
+            => sub {
+                if (!@skip || $skip[$#skip] > 0) {
+                    my $install = $1;
+                    my @x = tokenize($2);
+                    push @engines, @x;
+                    push @engines_install, @x unless $install;
+                }
+            },
+            qr/^\s*SCRIPTS(_NO_INST)?\s*=\s*(.*)\s*$/
+            => sub {
+                if (!@skip || $skip[$#skip] > 0) {
+                    my $install = $1;
+                    my @x = tokenize($2);
+                    push @scripts, @x;
+                    push @scripts_install, @x unless $install;
+                }
+            },
             qr/^\s*EXTRA\s*=\s*(.*)\s*$/
             => sub { push @extra, tokenize($1)
                          if !@skip || $skip[$#skip] > 0 },
@@ -1526,6 +1576,14 @@ if ($builder eq "unified") {
             $unified_info{programs}->{$program} = 1;
         }
 
+        foreach (@programs_install) {
+            my $program = cleanfile($buildd, $_, $blddir);
+            if ($unified_info{rename}->{$program}) {
+                $program = $unified_info{rename}->{$program};
+            }
+            $unified_info{install}->{programs}->{$program} = 1;
+        }
+
         foreach (@libraries) {
             my $library = cleanfile($buildd, $_, $blddir);
             if ($unified_info{rename}->{$library}) {
@@ -1534,6 +1592,14 @@ if ($builder eq "unified") {
             $unified_info{libraries}->{$library} = 1;
         }
 
+        foreach (@libraries_install) {
+            my $library = cleanfile($buildd, $_, $blddir);
+            if ($unified_info{rename}->{$library}) {
+                $library = $unified_info{rename}->{$library};
+            }
+            $unified_info{install}->{libraries}->{$library} = 1;
+        }
+
         die <<"EOF" if scalar @engines and !$config{dynamic_engines};
 ENGINES can only be used if configured with 'dynamic-engine'.
 This is usually a fault in a build.info file.
@@ -1546,6 +1612,14 @@ EOF
             $unified_info{engines}->{$library} = 1;
         }
 
+        foreach (@engines_install) {
+            my $library = cleanfile($buildd, $_, $blddir);
+            if ($unified_info{rename}->{$library}) {
+                $library = $unified_info{rename}->{$library};
+            }
+            $unified_info{install}->{engines}->{$library} = 1;
+        }
+
         foreach (@scripts) {
             my $script = cleanfile($buildd, $_, $blddir);
             if ($unified_info{rename}->{$script}) {
@@ -1554,6 +1628,14 @@ EOF
             $unified_info{scripts}->{$script} = 1;
         }
 
+        foreach (@scripts_install) {
+            my $script = cleanfile($buildd, $_, $blddir);
+            if ($unified_info{rename}->{$script}) {
+                $script = $unified_info{rename}->{$script};
+            }
+            $unified_info{install}->{scripts}->{$script} = 1;
+        }
+
         foreach (@extra) {
             my $extra = cleanfile($buildd, $_, $blddir);
             $unified_info{extra}->{$extra} = 1;
@@ -1752,7 +1834,7 @@ EOF
         $unified_info{$_} = [ sort keys %{$unified_info{$_}} ];
     }
     # Two level structures
-    foreach my $l1 (("sources", "shared_sources", "ldadd", "depends")) {
+    foreach my $l1 (("install", "sources", "shared_sources", "ldadd", "depends")) {
         foreach my $l2 (sort keys %{$unified_info{$l1}}) {
             $unified_info{$l1}->{$l2} =
                 [ sort keys %{$unified_info{$l1}->{$l2}} ];