Processing GNU-style "make variables" - separate CPP flags from C flags
[openssl.git] / Configure
index ba646f030a8480b1861bd035e266c655ff9f79c0..97696d75d2c5169a108f36b726eec833d3927ec1 100755 (executable)
--- a/Configure
+++ b/Configure
@@ -1,6 +1,6 @@
 #! /usr/bin/env perl
 # -*- mode: perl; -*-
-# Copyright 2016-2017 The OpenSSL Project Authors. All Rights Reserved.
+# Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
 #
 # Licensed under the OpenSSL license (the "License").  You may not use
 # this file except in compliance with the License.  You can obtain a copy
@@ -422,7 +422,6 @@ my %deprecated_disablables = (
 # All of the following is disabled by default (RC5 was enabled before 0.9.8):
 
 our %disabled = ( # "what"         => "comment"
-                  "aria"                => "default",
                   "asan"               => "default",
                  "crypto-mdebug"       => "default",
                  "crypto-mdebug-backtrace" => "default",
@@ -521,12 +520,15 @@ my $no_sse2=0;
 &usage if ($#ARGV < 0);
 
 my $user_cflags="";
+my $user_cppflags=();
 my @user_defines=();
+my @user_includes=();
 $config{openssl_api_defines}=[];
 $config{openssl_algorithm_defines}=[];
 $config{openssl_thread_defines}=[];
 $config{openssl_sys_defines}=[];
 $config{openssl_other_defines}=[];
+my $ldflags="";
 my $libs="";
 my $target="";
 $config{options}="";
@@ -730,7 +732,11 @@ while (@argvcopy)
                        {
                        read_config $1;
                        }
-               elsif (/^-[lL](.*)$/ or /^-Wl,/)
+               elsif (/^-L(.*)$/)
+                       {
+                       $ldflags.=$_." ";
+                       }
+               elsif (/^-l(.*)$/ or /^-Wl,/)
                        {
                        $libs.=$_." ";
                        }
@@ -758,6 +764,14 @@ while (@argvcopy)
                        {
                        push @user_defines, $1;
                        }
+               elsif (/^-I(.*)$/)
+                       {
+                       push @user_includes, $1;
+                       }
+               elsif (/^-Wp,$/)
+                       {
+                       $user_cppflags.=" ".$_;
+                       }
                else    # common if (/^[-+]/), just pass down...
                        {
                        $_ =~ s/%([0-9a-f]{1,2})/chr(hex($1))/gei;
@@ -1049,8 +1063,11 @@ $config{build_file} = $target{build_file};
 # or release_ attributes.
 # Do it in such a way that no spurious space is appended (hence the grep).
 $config{defines} = [];
+$config{includes} = [];
+$config{cppflags} = "";
 $config{cflags} = "";
 $config{cxxflags} = "";
+$config{lflags} = "";
 $config{ex_libs} = "";
 $config{shared_ldflag} = "";
 
@@ -1094,10 +1111,6 @@ if ($target =~ /linux.*-mips/ && !$disabled{asm} && $user_cflags !~ /-m(ips|arch
        $config{cflags}="-mips3 $config{cflags}" if ($target =~ /mips64/);
 }
 
-my $no_shared_warn=0;
-my $no_user_cflags=0;
-my $no_user_defines=0;
-
 # 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
@@ -1122,6 +1135,7 @@ if (!$disabled{dso} && $target{dso_scheme} ne "")
        }
 
 $config{ex_libs}="$libs$config{ex_libs}" if ($libs ne "");
+$config{lflags}="$config{lflags}$ldflags" if ($ldflags ne "");
 
 # If threads aren't disabled, check how possible they are
 unless ($disabled{threads}) {
@@ -1139,7 +1153,7 @@ unless ($disabled{threads}) {
             # system-dependent compiler options that are necessary.  We
             # can't truly check that the given options are correct, but
             # we expect the user to know what [s]He is doing.
-            if ($no_user_cflags && $no_user_defines) {
+            if (!$user_cflags && !@user_defines) {
                 die "You asked for multi-threading support, but didn't\n"
                     ,"provide any system-specific compiler options\n";
             }
@@ -1160,6 +1174,7 @@ if (defined($disabled{"deprecated"})) {
         $config{api} = $maxapi;
 }
 
+my $no_shared_warn=0;
 if ($target{shared_target} eq "")
        {
        $no_shared_warn = 1
@@ -1202,8 +1217,10 @@ unless ($disabled{"fuzz-libfuzzer"} && $disabled{"fuzz-afl"}
 # This saves the build files from having to check
 if ($disabled{pic})
        {
-       foreach (qw(shared_cflag shared_cxxflag shared_ldflag
-                   dso_cflags dso_cxxflags dso_lflags))
+       foreach (qw(shared_cflag shared_cxxflag shared_cppflag
+                    shared_defines shared_includes shared_ldflag
+                   dso_cflags dso_cxxflags dso_cppflags
+                    dso_defines dso_includes dso_lflags))
                {
                $target{$_} = "";
                }
@@ -1372,10 +1389,11 @@ unless ($disabled{"crypto-mdebug-backtrace"})
                }
        }
 
-if ($user_cflags ne "") { $config{cflags}="$config{cflags}$user_cflags"; $config{cxxflags}="$config{cxxflags}$user_cflags";}
-else                    { $no_user_cflags=1;  }
-if (@user_defines) { $config{defines}=[ @{$config{defines}}, @user_defines ]; }
-else               { $no_user_defines=1;    }
+$config{cppflags}.=$user_cppflags;
+push @{$config{defines}}, @user_defines;
+push @{$config{includes}}, @user_includes;
+$config{cflags}.=$user_cflags;
+$config{cxxflags}.=$user_cflags;
 
 # ALL MODIFICATIONS TO %config and %target MUST BE DONE FROM HERE ON
 
@@ -1504,6 +1522,7 @@ if ($builder eq "unified") {
 
     $config{build_infos} = [ ];
 
+    my %ordinals = ();
     foreach (@build_infos) {
         my $sourced = catdir($srcdir, $_->[0]);
         my $buildd = catdir($blddir, $_->[0]);
@@ -1525,7 +1544,6 @@ if ($builder eq "unified") {
         my @intermediates = ();
         my @rawlines = ();
 
-        my %ordinals = ();
         my %sources = ();
         my %shared_sources = ();
         my %includes = ();
@@ -1819,27 +1837,6 @@ EOF
                 if @doubles;
         }
 
-        foreach (keys %ordinals) {
-            my $dest = $_;
-            my $ddest = cleanfile($buildd, $_, $blddir);
-            if ($unified_info{rename}->{$ddest}) {
-                $ddest = $unified_info{rename}->{$ddest};
-            }
-            foreach (@{$ordinals{$dest}}) {
-                my %known_ordinals =
-                    (
-                     crypto =>
-                     cleanfile($sourced, catfile("util", "libcrypto.num"), $blddir),
-                     ssl =>
-                     cleanfile($sourced, catfile("util", "libssl.num"), $blddir)
-                    );
-                my $o = $known_ordinals{$_};
-                die "Ordinals for $ddest defined more than once\n"
-                    if $unified_info{ordinals}->{$ddest};
-                $unified_info{ordinals}->{$ddest} = [ $_, $o ];
-            }
-        }
-
         foreach (keys %sources) {
             my $dest = $_;
             my $ddest = cleanfile($buildd, $_, $blddir);
@@ -1961,13 +1958,6 @@ EOF
                 }
                 $d .= $e;
                 $unified_info{depends}->{$ddest}->{$d} = 1;
-                # If we depend on a header file or a perl module, let's make
-                # sure it can get included
-                if ($dest ne "" && $d =~ /\.(h|pm)$/) {
-                    my $i = dirname($d);
-                    push @{$unified_info{includes}->{$ddest}->{source}}, $i
-                        unless grep { $_ eq $i } @{$unified_info{includes}->{$ddest}->{source}};
-                }
             }
         }
 
@@ -1994,6 +1984,55 @@ EOF
         }
     }
 
+    my $ordinals_text = join(', ', sort keys %ordinals);
+    warn <<"EOF" if $ordinals_text;
+
+WARNING: ORDINALS were specified for $ordinals_text
+They are ignored and should be replaced with a combination of GENERATE,
+DEPEND and SHARED_SOURCE.
+EOF
+
+    # Massage the result
+
+    # If we depend on a header file or a perl module, add an inclusion of
+    # its directory to allow smoothe inclusion
+    foreach my $dest (keys %{$unified_info{depends}}) {
+        next if $dest eq "";
+        foreach my $d (keys %{$unified_info{depends}->{$dest}}) {
+            next unless $d =~ /\.(h|pm)$/;
+            if ($d eq "configdata.pm"
+                    || defined($unified_info{generate}->{$d})) {
+                my $i = cleandir($blddir, dirname($d));
+                push @{$unified_info{includes}->{$dest}->{build}}, $i
+                    unless grep { $_ eq $i } @{$unified_info{includes}->{$dest}->{build}};
+            } else {
+                my $i = cleandir($srcdir, dirname($d));
+                push @{$unified_info{includes}->{$dest}->{source}}, $i
+                    unless grep { $_ eq $i } @{$unified_info{includes}->{$dest}->{source}};
+            }
+        }
+    }
+
+    # Trickle down includes placed on libraries, engines and programs to
+    # their sources (i.e. object files)
+    foreach my $dest (keys %{$unified_info{engines}},
+                      keys %{$unified_info{libraries}},
+                      keys %{$unified_info{programs}}) {
+        foreach my $k (("source", "build")) {
+            next unless defined($unified_info{includes}->{$dest}->{$k});
+            my @incs = reverse @{$unified_info{includes}->{$dest}->{$k}};
+            foreach my $obj (grep /\.o$/,
+                             (keys %{$unified_info{sources}->{$dest}},
+                              keys %{$unified_info{shared_sources}->{$dest}})) {
+                foreach my $inc (@incs) {
+                    unshift @{$unified_info{includes}->{$obj}->{$k}}, $inc
+                        unless grep { $_ eq $inc } @{$unified_info{includes}->{$obj}->{$k}};
+                }
+            }
+        }
+        delete $unified_info{includes}->{$dest};
+    }
+
     ### Make unified_info a bit more efficient
     # One level structures
     foreach (("programs", "libraries", "engines", "scripts", "extra", "overrides")) {
@@ -2009,8 +2048,9 @@ EOF
     # Includes
     foreach my $dest (sort keys %{$unified_info{includes}}) {
         if (defined($unified_info{includes}->{$dest}->{build})) {
-            my @source_includes =
-                ( @{$unified_info{includes}->{$dest}->{source}} );
+            my @source_includes = ();
+            @source_includes = ( @{$unified_info{includes}->{$dest}->{source}} )
+                if defined($unified_info{includes}->{$dest}->{source});
             $unified_info{includes}->{$dest} =
                 [ @{$unified_info{includes}->{$dest}->{build}} ];
             foreach my $inc (@source_includes) {
@@ -2190,6 +2230,7 @@ print "DEFINES       =",join(" ", @{$target{defines}}, @{$config{defines}}),"\n"
 #print "RANLIB        =", $target{ranlib} eq '$(CROSS_COMPILE)ranlib' ?
 #                             "$config{cross_compile_prefix}ranlib" :
 #                             "$target{ranlib}", "\n";
+print "LDFLAGS       =$config{lflags} $target{lflags}\n";
 print "EX_LIBS       =$target{ex_libs} $config{ex_libs}\n";
 
 my %builders = (
@@ -2387,6 +2428,17 @@ sub read_config {
 
        %targets = read_eval_file($fname);
     }
+    my %preexisting = ();
+    foreach (sort keys %targets) {
+        $preexisting{$_} = 1 if $table{$_};
+    }
+    die <<"EOF",
+The following config targets from $fname
+shadow pre-existing config targets with the same name:
+EOF
+        map { "  $_\n" } sort keys %preexisting
+        if %preexisting;
+
 
     # For each target, check that it's configured with a hash table.
     foreach (keys %targets) {
@@ -2649,9 +2701,12 @@ sub print_table_entry
 
     my @sequence = (
        "sys_id",
+       "cpp",
+       "cppflags",
+       "defines",
+       "includes",
        "cc",
        "cflags",
-       "defines",
        "unistd",
        "ld",
        "lflags",