Generate dependency information
authorTanzinul Islam <tanzinul.islam@gmail.com>
Thu, 10 Dec 2020 14:53:07 +0000 (14:53 +0000)
committerDmitry Belyavskiy <beldmit@gmail.com>
Mon, 19 Apr 2021 09:05:55 +0000 (11:05 +0200)
The Clang-based `bcc32c.exe` doesn't implement the `-Hp` option, so we
have to use [`cpp32.exe`][1] instead.  Therefore, change the dependency-
emitting command to use `$(CPP)` instead of `$(CC)`, which which also
uncovered the [existing bug of `2>&1` before `> $dep`][2].  Also
C++Builder's `make.exe` doesn't implement `2>&1` in its command runner,
so wrap the whole line in a `cmd /C`.

[1]: http://docwiki.embarcadero.com/RADStudio/Sydney/en/CPP32.EXE,_the_C_Compiler_Preprocessor
[2]: https://ss64.com/nt/syntax-redirection.html

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/13540)

Configurations/10-main.conf
Configurations/50-cppbuilder.conf
Configurations/windows-makefile.tmpl
Configure
util/add-depends.pl

index 4d42c7f..f5e5754 100644 (file)
@@ -1275,9 +1275,10 @@ my %targets = (
         inherit_from     => [ "BASE_Windows" ],
         template         => 1,
         CC               => "cl",
         inherit_from     => [ "BASE_Windows" ],
         template         => 1,
         CC               => "cl",
-        CPP              => '$(CC) /EP /C',
+        CPP              => '"$(CC)" /EP /C',
         CFLAGS           => "/W3 /wd4090 /nologo",
         coutflag         => "/Fo",
         CFLAGS           => "/W3 /wd4090 /nologo",
         coutflag         => "/Fo",
+        cpp_depend_flags => "/Zs /showIncludes",
         LD               => "link",
         LDFLAGS          => "/nologo /debug",
         ldoutflag        => "/out:",
         LD               => "link",
         LDFLAGS          => "/nologo /debug",
         ldoutflag        => "/out:",
index 40b89b4..7ca9729 100644 (file)
@@ -5,6 +5,7 @@ my %targets = (
         bn_ops           => "BN_LLONG",
         thread_scheme    => "winthreads",
         cc               => "bcc32c",
         bn_ops           => "BN_LLONG",
         thread_scheme    => "winthreads",
         cc               => "bcc32c",
+        CPP              => "cpp32 -oCON -Sc -Sr",
         defines          => add("WIN32_LEAN_AND_MEAN", "OPENSSL_SYS_WIN32",
                                 "L_ENDIAN", "DSO_WIN32", "_stricmp=stricmp",
                                 "_strnicmp=strnicmp", "_malloca=malloc",
         defines          => add("WIN32_LEAN_AND_MEAN", "OPENSSL_SYS_WIN32",
                                 "L_ENDIAN", "DSO_WIN32", "_stricmp=stricmp",
                                 "_strnicmp=strnicmp", "_malloca=malloc",
@@ -17,6 +18,7 @@ my %targets = (
         bin_cflags       => "-tWC",
         lib_cflags       => shared("-tWD -D_WINDLL -D_DLL"),
         coutflag         => "-o",
         bin_cflags       => "-tWC",
         lib_cflags       => shared("-tWD -D_WINDLL -D_DLL"),
         coutflag         => "-o",
+        cpp_depend_flags => "-Hp",
         LD               => "ilink32",
         LDFLAGS          => picker(default => "-ap -x -Gn -q",
                                    debug   => '-j"$(BDS)\lib\win32c\debug" ' .
         LD               => "ilink32",
         LDFLAGS          => picker(default => "-ap -x -Gn -q",
                                    debug   => '-j"$(BDS)\lib\win32c\debug" ' .
index 521f72d..bcb092d 100644 (file)
@@ -226,7 +226,7 @@ libdir={- file_name_is_absolute($libdir)
 ##### User defined commands and flags ################################
 
 CC="{- $config{CC} -}"
 ##### User defined commands and flags ################################
 
 CC="{- $config{CC} -}"
-CPP="{- $config{CPP} -}"
+CPP={- $config{CPP} -}
 CPPFLAGS={- our $cppflags1 = join(" ",
                                   (map { "-D".$_} @{$config{CPPDEFINES}}),
                                   (map { " -I".$_} @{$config{CPPINCLUDES}}),
 CPPFLAGS={- our $cppflags1 = join(" ",
                                   (map { "-D".$_} @{$config{CPPDEFINES}}),
                                   (map { " -I".$_} @{$config{CPPINCLUDES}}),
@@ -836,7 +836,7 @@ $obj: $deps
        \$(CC) $cflags $defs -c \$(COUTFLAG)\$\@ $srcs
 EOF
      $recipe .= <<"EOF"        unless $disabled{makedepend};
        \$(CC) $cflags $defs -c \$(COUTFLAG)\$\@ $srcs
 EOF
      $recipe .= <<"EOF"        unless $disabled{makedepend};
-       \$(CC) $cflags $defs /Zs /showIncludes $srcs 2>&1 > $dep
+       cmd /C "\$(CPP) $cflags $defs $target{cpp_depend_flags} $srcs > $dep 2>&1"
 EOF
      return $recipe;
  }
 EOF
      return $recipe;
  }
index e36c5d9..76c27ba 100755 (executable)
--- a/Configure
+++ b/Configure
@@ -1533,10 +1533,10 @@ unless ($disabled{asm}) {
 
 # Check for makedepend capabilities.
 if (!$disabled{makedepend}) {
 
 # Check for makedepend capabilities.
 if (!$disabled{makedepend}) {
-    if ($config{target} =~ /^(VC|vms)-/) {
-        # For VC- and vms- targets, there's nothing more to do here.  The
+    if ($config{target} =~ /^(VC|BC|vms)-/) {
+        # For VC-, BC- and vms- targets, there's nothing more to do here.  The
         # functionality is hard coded in the corresponding build files for
         # functionality is hard coded in the corresponding build files for
-        # cl (Windows) and CC/DECC (VMS).
+        # cl/cpp32 (Windows) and CC/DECC (VMS).
     } elsif (($predefined_C{__GNUC__} // -1) >= 3
              && !($predefined_C{__APPLE_CC__} && !$predefined_C{__clang__})) {
         # We know that GNU C version 3 and up as well as all clang
     } elsif (($predefined_C{__GNUC__} // -1) >= 3
              && !($predefined_C{__APPLE_CC__} && !$predefined_C{__clang__})) {
         # We know that GNU C version 3 and up as well as all clang
index 1a87cdd..6fdc5e5 100644 (file)
@@ -161,8 +161,7 @@ my %procedures = (
         },
     'VC' =>
         sub {
         },
     'VC' =>
         sub {
-            # For the moment, we only support Visual C on native Windows, or
-            # compatible compilers.  With those, the flags /Zs /showIncludes
+            # On Windows, with Microsoft Visual C the flags /Zs /showIncludes
             # give us the necessary output to be able to create dependencies
             # that nmake (or any 'make' implementation) should be able to read,
             # with a bit of help.  The output we're interested in looks like
             # give us the necessary output to be able to create dependencies
             # that nmake (or any 'make' implementation) should be able to read,
             # with a bit of help.  The output we're interested in looks like
@@ -170,6 +169,15 @@ my %procedures = (
             #
             #   Note: including file: {whatever header file}
             #
             #
             #   Note: including file: {whatever header file}
             #
+            # With Embarcadero C++Builder's preprocessor (cpp32.exe) the -Hp
+            # flag gives us the preprocessed output annotated with the following
+            # note whenever a #include file is read:
+            #
+            #    Including ->->{whatever header file}
+            #
+            # where each "->" indicates the nesting level of the #include.  The
+            # logic here is otherwise the same as the 'VC' case.
+            #
             # Since there's no object file name at all in that information,
             # we must construct it ourselves.
 
             # Since there's no object file name at all in that information,
             # we must construct it ourselves.
 
@@ -180,13 +188,14 @@ my %procedures = (
             # warnings, so we simply discard anything that doesn't start with
             # the Note:
 
             # warnings, so we simply discard anything that doesn't start with
             # the Note:
 
-            if (/^Note: including file: */) {
+            if (/^Note: including file: */ or /^Including (->)*/) {
                 (my $tail = $') =~ s/\s*\R$//;
 
                 # VC gives us absolute paths for all include files, so to
                 # remove system header dependencies, we need to check that
                 (my $tail = $') =~ s/\s*\R$//;
 
                 # VC gives us absolute paths for all include files, so to
                 # remove system header dependencies, we need to check that
-                # they don't match $abs_srcdir or $abs_blddir.
-                $tail = canonpath($tail);
+                # they don't match $abs_srcdir or $abs_blddir.  C++Builder gives
+                # us relative paths when possible, so convert to absolute paths.
+                $tail = rel2abs($tail);
 
                 unless (defined $depconv_cache{$tail}) {
                     my $dep = $tail;
 
                 unless (defined $depconv_cache{$tail}) {
                     my $dep = $tail;