Configure: complete the changed fuzz option checks
[openssl.git] / Configure
index 20470a941ad3fa580a14214614a95bc588c8b56d..7bbb5b7697b348390a29eccf22d2244ff08ee3f0 100755 (executable)
--- a/Configure
+++ b/Configure
@@ -14,7 +14,7 @@ use strict;
 use File::Basename;
 use File::Spec::Functions qw/:DEFAULT abs2rel rel2abs/;
 use File::Path qw/mkpath/;
-use IPC::Cmd qw/can_run/;
+use if $^O ne "VMS", 'File::Glob' => qw/glob/;
 
 # see INSTALL for instructions.
 
@@ -211,7 +211,7 @@ die "erroneous version information in opensslv.h: ",
 # Collect target configurations
 
 my $pattern = catfile(dirname($0), "Configurations", "*.conf");
-foreach (sort glob($pattern) ) {
+foreach (sort glob($pattern)) {
     &read_config($_);
 }
 
@@ -224,7 +224,7 @@ if (defined $ENV{$local_config_envname}) {
         $pattern = catfile($ENV{$local_config_envname}, '*.conf');
     }
 
-    foreach (sort glob($pattern) ) {
+    foreach (sort glob($pattern)) {
         &read_config($_);
     }
 }
@@ -301,7 +301,8 @@ my @disablables = (
     "engine",
     "err",
     "filenames",
-    "fuzz",
+    "fuzz-libfuzzer",
+    "fuzz-afl",
     "gost",
     "heartbeats",
     "hw(-.+)?",
@@ -365,7 +366,8 @@ our %disabled = ( # "what"         => "comment"
                   "asan"               => "default",
                  "ec_nistp_64_gcc_128" => "default",
                  "egd"                 => "default",
-                 "fuzz"                => "default",
+                 "fuzz-libfuzzer"      => "default",
+                 "fuzz-afl"            => "default",
                  "md2"                 => "default",
                  "rc5"                 => "default",
                  "sctp"                => "default",
@@ -698,6 +700,14 @@ foreach (@argvcopy)
                        {
                        $withargs{zlib_include}=$1;
                        }
+               elsif (/^--with-fuzzer-lib=(.*)$/)
+                       {
+                       $withargs{fuzzer_lib}=$1;
+                       }
+               elsif (/^--with-fuzzer-include=(.*)$/)
+                       {
+                       $withargs{fuzzer_include}=$1;
+                       }
                elsif (/^--with-fipslibdir=(.*)$/)
                        {
                        $config{fipslibdir}="$1/";
@@ -913,7 +923,7 @@ $config{cross_compile_prefix} = $ENV{'CROSS_COMPILE'}
 $config{perl} =    $ENV{'PERL'}    || ($^O ne "VMS" ? $^X : "perl");
 $target{cc} =      $ENV{'CC'}      || $target{cc}      || "cc";
 $target{ranlib} =  $ENV{'RANLIB'}  || $target{ranlib}  ||
-                   (scalar can_run("$config{cross_compile_prefix}ranlib") ?
+                   (which("$config{cross_compile_prefix}ranlib") ?
                           "\$(CROSS_COMPILE)ranlib" : "true");
 $target{ar} =      $ENV{'AR'}      || $target{ar}      || "ar";
 $target{nm} =      $ENV{'NM'}      || $target{nm}      || "nm";
@@ -1042,11 +1052,15 @@ if ($disabled{"dynamic-engine"}) {
         $config{dynamic_engines} = 1;
 }
 
-unless ($disabled{fuzz}) {
+unless ($disabled{"fuzz-libfuzzer"}) {
     push @{$config{dirs}}, "fuzz";
     $config{cflags} .= "-fsanitize-coverage=edge,indirect-calls ";
 }
 
+unless ($disabled{"fuzz-afl"}) {
+    push @{$config{dirs}}, "fuzz";
+}
+
 unless ($disabled{asan}) {
     $config{cflags} .= "-fsanitize=address ";
 }
@@ -1057,7 +1071,8 @@ unless ($disabled{ubsan}) {
     $config{cflags} .= "-fsanitize=undefined -fno-sanitize-recover=all ";
 }
 
-unless ($disabled{fuzz} && $disabled{asan} && $disabled{ubsan}) {
+unless ($disabled{"fuzz-libfuzzer"} && $disabled{"fuzz-afl"}
+        && $disabled{asan} && $disabled{ubsan}) {
     $config{cflags} .= "-fno-omit-frame-pointer -g ";
 }
 #
@@ -1158,7 +1173,7 @@ if ($^O ne "VMS" && !$disabled{makedepend}) {
     }
     close(PIPE);
 
-    $config{makedepprog} = scalar can_run('makedepend') unless $config{makedepprog};
+    $config{makedepprog} = which('makedepend') unless $config{makedepprog};
     $disabled{makedepend} = "unavailable" unless $config{makedepprog};
 }
 
@@ -1379,6 +1394,7 @@ if ($builder eq "unified") {
             $template->fill_in(HASH => { config => \%config,
                                          target => \%target,
                                          disabled => \%disabled,
+                                         withargs => \%withargs,
                                          builddir => abs2rel($buildd, $blddir),
                                          sourcedir => abs2rel($sourced, $blddir),
                                          buildtop => abs2rel($blddir, $blddir),
@@ -1926,53 +1942,12 @@ for (@generated_headers) {
                catfile($srcdir, $_.".in"));
 }
 
-###
-### When the old "unixmake" scheme goes away, so does this function
-###
-sub build_Makefile {
-    run_dofile("Makefile","Makefile.in");
-
-    # Copy all Makefile.in to Makefile (except top-level)
-    use File::Find;
-    use IO::File;
-    find(
-        {
-            preprocess => sub {
-                grep(!/^\./, @_);
-            },
-            wanted => sub {
-                return if ($_ ne "Makefile.in" || $File::Find::dir eq ".");
-                my $in = IO::File->new($_, "r") or
-                    die sprintf "Error reading Makefile.in in %s: !$\n",
-                    $File::Find::dir;
-                my $out = IO::File->new("Makefile", "w") or
-                    die sprintf "Error writing Makefile in %s: !$\n",
-                    $File::Find::dir;
-                print $out "# Generated from $_, do not edit\n";
-                while (my $line = <$in>) { print $out $line }
-                $in->close() or
-                    die sprintf "Error reading Makefile.in in %s: !$\n",
-                    $File::Find::dir;
-                $out->close() or
-                    die sprintf "Error writing Makefile in %s: !$\n",
-                    $File::Find::dir;
-            },
-        },
-        ".");
-}
-
 my %builders = (
     unified => sub {
         run_dofile(catfile($blddir, $target{build_file}),
                    $config{build_file_template},
                    catfile($srcdir, "Configurations", "common.tmpl"));
     },
-    unixmake => sub {
-        build_Makefile();
-
-        run_dofile("util/domd", "util/domd.in");
-        chmod 0755, "util/domd";
-    },
     );
 
 $builders{$builder}->($builder_platform, @builder_opts);
@@ -2333,13 +2308,34 @@ sub run_dofile
     foreach (@templates) {
         die "Can't open $_, $!" unless -f $_;
     }
-    my $cmd = "$config{perl} \"-I.\" \"-Mconfigdata\" $dofile -o\"Configure\" \"".join("\" \"",@templates)."\" > \"$out.new\"";
+    my $cmd = "$config{perl} \"-I.\" \"-Mconfigdata\" \"$dofile\" -o\"Configure\" \"".join("\" \"",@templates)."\" > \"$out.new\"";
     #print STDERR "DEBUG[run_dofile]: \$cmd = $cmd\n";
     system($cmd);
     exit 1 if $? != 0;
     rename("$out.new", $out) || die "Can't rename $out.new, $!";
 }
 
+sub which
+{
+    my ($name)=@_;
+
+    if (eval { require IPC::Cmd; 1; }) {
+        IPC::Cmd->import();
+        return scalar IPC::Cmd::can_run($name);
+    } else {
+        # if there is $directories component in splitpath,
+        # then it's not something to test with $PATH...
+        return $name if (File::Spec->splitpath($name))[1];
+
+        foreach (File::Spec->path()) {
+            my $fullpath = catfile($_, "$name$target{exe_extension}");
+            if (-f $fullpath and -x $fullpath) {
+                return $fullpath;
+            }
+        }
+    }
+}
+
 # Configuration printer ##############################################
 
 sub print_table_entry