Commit 8c3bc594 authored by Richard Levitte's avatar Richard Levitte
Browse files

Processing GNU-style "make variables" - separate CPP flags from C flags



C preprocessor flags get separated from C flags, which has the
advantage that we don't get loads of macro definitions and inclusion
directory specs when linking shared libraries, DSOs and programs.

This is a step to add support for "make variables" when configuring.

Reviewed-by: default avatarTim Hudson <tjh@openssl.org>
Reviewed-by: default avatarRich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/5177)
parent df05f155
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -4,6 +4,8 @@ my %targets=(
	template	=> 1,

	cflags		=> "",
	cppflags	=> "",
	lflags		=> "",
	defines		=> [],
	thread_scheme	=> "(unknown)", # Assume we don't know
	thread_defines	=> [],
+228 −136

File changed.

Preview size limit exceeded, changes collapsed.

+13 −5
Original line number Diff line number Diff line
@@ -45,6 +45,19 @@ In each table entry, the following keys are significant:
                           Note: if the same feature is both enabled
                           and disabled, disable wins.

        cpp             => The C preprocessor command, normally not
                           given, as the build file defaults are
                           usually good enough.
        cppflags        => The C preprocessor flags.
        defines         => As an alternative, macro definitions may be
                           given here instead of in `cppflags'.  If
                           given here, they MUST be as an array of the
                           string such as "MACRO=value", or just
                           "MACRO" for definitions without value.
        includes        => As an alternative, inclusion directories
                           may be given here instead of in `cppflags'.
                           If given here, the MUST be an array of
                           strings, one directory specification each.
        cc              => The C compiler command, usually one of "cc",
                           "gcc" or "clang".  This command is normally
                           also used to link object files and
@@ -59,11 +72,6 @@ In each table entry, the following keys are significant:
        cxxflags        => Flags that are used at all times when
                           compiling C++ object files.  If unset, it
                           gets the same value as cflags.
        defines         => As an alternative, macro definitions may be
                           present here instead of in `cflags'.  If
                           given here, they MUST be as an array of the
                           string such as "MACRO=value", or just
                           "MACRO" for definitions without value.
        shared_cflag    => Extra compilation flags used when
                           compiling for shared libraries, typically
                           something like "-fPIC".
+26 −7
Original line number Diff line number Diff line
@@ -172,11 +172,20 @@ OPENSSLDIR_C={- $osslprefix -}DATAROOT:[000000]
ENGINESDIR_C={- $osslprefix -}ENGINES{- $sover_dirname.$target{pointer_size} -}:

CC= {- $target{cc} -}
CFLAGS= /DEFINE=({- join(",", @{$target{defines}}, @{$config{defines}},"OPENSSLDIR=\"\"\"\$(OPENSSLDIR_C)\"\"\"","ENGINESDIR=\"\"\"\$(ENGINESDIR_C)\"\"\"") -}) {- $target{cflags} -} {- $config{cflags} -}
CFLAGS_Q=$(CFLAGS)
DEPFLAG= /DEFINE=({- join(",", @{$config{depdefines}}) -})
DEFINES={- our $defines = join(",",
                               '__dummy', # To make comma processing easier
                               @{$target{defines}}, @{$config{defines}}) -}
CPPFLAGS={- our $cppflags = join('', $target{cppflags}, $config{cppflags}) -}
CPPFLAGS_Q={- $cppflags =~ s|"|""|g; $defines =~ s|"|""|g;
              $cppflags."/DEFINE($defines)" -}
CFLAGS={- $target{cflags} -} {- $config{cflags} -}
LDFLAGS= {- $target{lflags} -}
EX_LIBS= {- $target{ex_libs} ? ",".$target{ex_libs} : "" -}{- $config{ex_libs} ? ",".$config{ex_libs} : "" -}
LIB_DEFINES={- join("",
                    (map { ",$_" }
                     @{$target{shared_defines}},
                     'OPENSSLDIR="""$(OPENSSLDIR_C)"""',
                     'ENGINESDIR="""$(ENGINESDIR_C)"""')) -}
LIB_CFLAGS={- $target{lib_cflags} // "" -}
DSO_CFLAGS={- $target{dso_cflags} // "" -}
BIN_CFLAGS={- $target{bin_cflags} // "" -}
@@ -605,16 +614,26 @@ EOF
      my $srcs =
          join(", ",
               map { abs2rel(rel2abs($_), rel2abs($forward)) } @{$args{srcs}});
      my $ecflags;
      my $cflags = '$(CFLAGS)';
      if ($args{installed}) {
          $ecflags = { lib => '$(LIB_CFLAGS)',
          $cflags .= { lib => '$(LIB_CFLAGS)',
                       dso => '$(DSO_CFLAGS)',
                       bin => '$(BIN_CFLAGS)' } -> {$args{intent}};
      } else {
          $ecflags = { lib => '$(NO_INST_LIB_CFLAGS)',
          $cflags .= { lib => '$(NO_INST_LIB_CFLAGS)',
                       dso => '$(NO_INST_DSO_CFLAGS)',
                       bin => '$(NO_INST_BIN_CFLAGS)' } -> {$args{intent}};
      }
      $cflags .= '$(CPPFLAGS)';
      $cflags .= { lib => '$(LIB_CPPFLAGS)',
		   dso => '$(DSO_CPPFLAGS)',
		   bin => '$(BIN_CPPFLAGS)' } -> {$args{intent}};
      my $defines = '$(DEFINES)';
      $defines .= { lib => '$(LIB_DEFINES)',
		    dso => '$(DSO_DEFINES)',
		    bin => '$(BIN_DEFINES)' } -> {$args{intent}};
      $cflags .= '/DEFINE=('.$defines.')';
      
      my $incs_on = "\@ !";
      my $incs_off = "\@ !";
      my $incs = "";
@@ -645,7 +664,7 @@ $obj.OBJ : $deps
        ${before}
        SET DEFAULT $forward
        $incs_on
        \$(CC) \$(CFLAGS)${ecflags}${incs}${depbuild} /OBJECT=${objd}${objn}.OBJ /REPOSITORY=$backward $srcs
        \$(CC) ${cflags}${incs}${depbuild} /OBJECT=${objd}${objn}.OBJ /REPOSITORY=$backward $srcs
        $incs_off
        SET DEFAULT $backward
        ${after}
+31 −7
Original line number Diff line number Diff line
@@ -184,20 +184,33 @@ HTMLSUFFIX=html
ECHO = echo

CROSS_COMPILE= {- $config{cross_compile_prefix} -}
CPPFLAGS={- our $cppflags = join(" ",
                                 (map { "-D".$_}
                                  @{$target{defines}}, @{$config{defines}}),
                                 (map { "-I".$_}
                                  @{$target{includes}}, @{$config{includes}}),
                                 $target{cppflags}, $config{cppflags}) -}
CPPFLAGS_Q={- $cppflags =~ s|([\\"])|\\$1|g; $cppflags -}
CC= $(CROSS_COMPILE){- $target{cc} -}
CFLAGS={- our $cflags2 = join(" ",(map { "-D".$_} @{$target{defines}}, @{$config{defines}}),"-DOPENSSLDIR=\"\\\"\$(OPENSSLDIR)\\\"\"","-DENGINESDIR=\"\\\"\$(ENGINESDIR)\\\"\"") -} {- $target{cflags} -} {- $config{cflags} -}
CFLAGS_Q={- $cflags2 =~ s|([\\"])|\\$1|g; $cflags2 -} {- $config{cflags} -}
CFLAGS={- $target{cflags} -} {- $config{cflags} -}
CXX= $(CROSS_COMPILE){- $target{cxx} -}
CXXFLAGS={- our $cxxflags2 = join(" ",(map { "-D".$_} @{$target{defines}}, @{$config{defines}}),"-DOPENSSLDIR=\"\\\"\$(OPENSSLDIR)\\\"\"","-DENGINESDIR=\"\\\"\$(ENGINESDIR)\\\"\"") -} {- $target{cxxflags} -} {- $config{cxxflags} -} -std=c++11
CXXFLAGS={- $target{cxxflags} -} {- $config{cxxflags} -} -std=c++11
LDFLAGS= {- $config{lflags} -} {- $target{lflags} -}
PLIB_LDFLAGS= {- $target{plib_lflags} -}
EX_LIBS= {- $target{ex_libs} -} {- $config{ex_libs} -}
LIB_CPPFLAGS={- join(" ",
                     (map { "-D".$_}
                      'OPENSSLDIR="\"$(OPENSSLDIR)\""',
                      'ENGINESDIR="\"$(ENGINESDIR)\""'),
                     $target{shared_cppflag} || "") -}
LIB_CFLAGS={- $target{shared_cflag} || "" -}
LIB_CXXFLAGS={- $target{shared_cxxflag} || "" -}
LIB_LDFLAGS={- $target{shared_ldflag}." ".$config{shared_ldflag} -}
DSO_CPPFLAGS={- $target{dso_cppflags} || "" -}
DSO_CFLAGS={- $target{dso_cflags} || "" -}
DSO_CXXFLAGS={- $target{dso_cxxflags} || "" -}
DSO_LDFLAGS={- $target{dso_lflags} || "" -}
BIN_CPPFLAGS={- $target{bin_cppflags} || "" -}
BIN_CFLAGS={- $target{bin_cflags} || "" -}
BIN_CXXFLAGS={- $target{bin_cxxflags} || "" -}
BIN_LDFLAGS={- $target{bin_lflags} || "" -}
@@ -844,7 +857,7 @@ EOF
$target: $args{generator}->[0] $deps
	( trap "rm -f \$@.*" INT 0; \\
	  $generator \$@.S; \\
	  \$(CC) $incs \$(CFLAGS) -E \$@.S | \\
	  \$(CC) $incs \$(CFLAGS) \$(CPPFLAGS) -E \$@.S | \\
	  \$(PERL) -ne '/^#(line)?\\s*[0-9]+/ or print' > \$@.i && \\
	  mv -f \$@.i \$@ )
EOF
@@ -857,7 +870,7 @@ EOF
          }
          return <<"EOF";
$args{src}: $args{generator}->[0] $deps
	\$(CC) $incs \$(CFLAGS) -E $args{generator}->[0] | \\
	\$(CC) $incs \$(CFLAGS) \$(CPPFLAGS) -E $args{generator}->[0] | \\
	\$(PERL) -ne '/^#(line)?\\s*[0-9]+/ or print' > \$@
EOF
      }
@@ -884,23 +897,34 @@ EOF
          }
      }
      my $cmd = '$(CC)';
      my $cmdflags = '$(CFLAGS) -c';
      my $cmdflags = '$(CFLAGS)';
      my $cmdcompile = ' -c';
      my $makedepprog = $disabled{makedepend} ? undef : $config{makedepprog};
      if (grep /\.rc$/, @srcs) {
          $cmd = '$(RC)';
          $cmdflags = '$(RCFLAGS)';
          $cmdcompile = '';
          $makedepprog = undef;
      } elsif (grep /\.(cc|cpp)$/, @srcs) {
          $cmd = '$(CXX)';
          $cmdflags = '$(CXXFLAGS) -c';
          $cmdflags = '$(CXXFLAGS)';
          $cmdflags .= ' ' . { lib => '$(LIB_CXXFLAGS)',
                               dso => '$(DSO_CXXFLAGS)',
                               bin => '$(BIN_CXXFLAGS)' } -> {$args{intent}};
          $cmdflags .= ' $(CPPFLAGS)';
          $cmdflags .= ' ' . { lib => '$(LIB_CPPFLAGS)',
                               dso => '$(DSO_CPPFLAGS)',
                               bin => '$(BIN_CPPFLAGS)' } -> {$args{intent}};
      } else {
          $cmdflags .= ' ' . { lib => '$(LIB_CFLAGS)',
                               dso => '$(DSO_CFLAGS)',
                               bin => '$(BIN_CFLAGS)' } -> {$args{intent}};
          $cmdflags .= ' $(CPPFLAGS)';
          $cmdflags .= ' ' . { lib => '$(LIB_CPPFLAGS)',
                               dso => '$(DSO_CPPFLAGS)',
                               bin => '$(BIN_CPPFLAGS)' } -> {$args{intent}};
      }
      $cmdflags .= $cmdcompile;
      my $recipe = <<"EOF";
$obj$objext: $deps
EOF
Loading