[v2,2/4] Rewrite find_cxx_header config configure.ac

Message ID 20221102145559.1962008-3-adhemerval.zanella@linaro.org
State Committed
Headers
Series Initial fixes for clang build support |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent

Commit Message

Adhemerval Zanella Netto Nov. 2, 2022, 2:55 p.m. UTC
  With clang If the main file is <stdin>, the first non-main-file
dependency is not listed in the -MP output.  Although it was fixed
on clang-16 [1], this change adds portability for older version.

[1] https://github.com/llvm/llvm-project/commit/ff9576f74514b836e1ba0268409a2ecb919d7118
---
 configure    | 4 ++--
 configure.ac | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
  

Comments

Fangrui Song Nov. 6, 2022, 11:31 p.m. UTC | #1
On 2022-11-02, Adhemerval Zanella wrote:
>With clang If the main file is <stdin>, the first non-main-file
>dependency is not listed in the -MP output.  Although it was fixed
>on clang-16 [1], this change adds portability for older version.

s/If/if/

>[1] https://github.com/llvm/llvm-project/commit/ff9576f74514b836e1ba0268409a2ecb919d7118
>---
> configure    | 4 ++--
> configure.ac | 4 ++--
> 2 files changed, 4 insertions(+), 4 deletions(-)
>
>diff --git a/configure b/configure
>index fc3d7842de..e23ea95a49 100755
>--- a/configure
>+++ b/configure
>@@ -5669,8 +5669,8 @@ fi
> # copy of those headers in Makerules.
> if test -n "$CXX"; then
>   find_cxx_header () {
>-    echo "#include <$1>" | $CXX -M -MP -x c++ - 2>/dev/null \
>-	 | sed -n "\,$1:,{s/:\$//;p}"
>+    echo "#include <$1>" | $CXX -H -fsyntax-only -x c++ - 2>&1 \
>+	 | awk '$1 == "."{print $2}'
>   }
>   CXX_CSTDLIB_HEADER="$(find_cxx_header cstdlib)"
>   CXX_CMATH_HEADER="$(find_cxx_header cmath)"
>diff --git a/configure.ac b/configure.ac
>index 9fc1fb1c1c..7275b53345 100644
>--- a/configure.ac
>+++ b/configure.ac
>@@ -1137,8 +1137,8 @@ AC_SUBST(CXX_SYSINCLUDES)
> # copy of those headers in Makerules.
> if test -n "$CXX"; then
>   find_cxx_header () {
>-    echo "#include <$1>" | $CXX -M -MP -x c++ - 2>/dev/null \
>-	 | sed -n "\,$1:,{s/:\$//;p}"
>+    echo "#include <$1>" | $CXX -H -fsyntax-only -x c++ - 2>&1 \
>+	 | awk '$1 == "."{print $2}'
>   }
>   CXX_CSTDLIB_HEADER="$(find_cxx_header cstdlib)"
>   CXX_CMATH_HEADER="$(find_cxx_header cmath)"
>-- 
>2.34.1
>

Thanks.

Reviewed-by: Fangrui Song <maskray@google.com>
  
Florian Weimer Nov. 7, 2022, 1:22 p.m. UTC | #2
* Adhemerval Zanella via Libc-alpha:

> diff --git a/configure b/configure
> index fc3d7842de..e23ea95a49 100755
> --- a/configure
> +++ b/configure
> @@ -5669,8 +5669,8 @@ fi
>  # copy of those headers in Makerules.
>  if test -n "$CXX"; then
>    find_cxx_header () {
> -    echo "#include <$1>" | $CXX -M -MP -x c++ - 2>/dev/null \
> -	 | sed -n "\,$1:,{s/:\$//;p}"
> +    echo "#include <$1>" | $CXX -H -fsyntax-only -x c++ - 2>&1 \
> +	 | awk '$1 == "."{print $2}'
>    }
>    CXX_CSTDLIB_HEADER="$(find_cxx_header cstdlib)"
>    CXX_CMATH_HEADER="$(find_cxx_header cmath)"

Shouldn't this use $ac_cv_prog_AWK?

Thanks,
Florian
  
Adhemerval Zanella Netto Nov. 7, 2022, 1:36 p.m. UTC | #3
On 07/11/22 10:22, Florian Weimer wrote:
> * Adhemerval Zanella via Libc-alpha:
> 
>> diff --git a/configure b/configure
>> index fc3d7842de..e23ea95a49 100755
>> --- a/configure
>> +++ b/configure
>> @@ -5669,8 +5669,8 @@ fi
>>  # copy of those headers in Makerules.
>>  if test -n "$CXX"; then
>>    find_cxx_header () {
>> -    echo "#include <$1>" | $CXX -M -MP -x c++ - 2>/dev/null \
>> -	 | sed -n "\,$1:,{s/:\$//;p}"
>> +    echo "#include <$1>" | $CXX -H -fsyntax-only -x c++ - 2>&1 \
>> +	 | awk '$1 == "."{print $2}'
>>    }
>>    CXX_CSTDLIB_HEADER="$(find_cxx_header cstdlib)"
>>    CXX_CMATH_HEADER="$(find_cxx_header cmath)"
> 
> Shouldn't this use $ac_cv_prog_AWK?

It should be $AWK in fact, I will fix it before commit.
  

Patch

diff --git a/configure b/configure
index fc3d7842de..e23ea95a49 100755
--- a/configure
+++ b/configure
@@ -5669,8 +5669,8 @@  fi
 # copy of those headers in Makerules.
 if test -n "$CXX"; then
   find_cxx_header () {
-    echo "#include <$1>" | $CXX -M -MP -x c++ - 2>/dev/null \
-	 | sed -n "\,$1:,{s/:\$//;p}"
+    echo "#include <$1>" | $CXX -H -fsyntax-only -x c++ - 2>&1 \
+	 | awk '$1 == "."{print $2}'
   }
   CXX_CSTDLIB_HEADER="$(find_cxx_header cstdlib)"
   CXX_CMATH_HEADER="$(find_cxx_header cmath)"
diff --git a/configure.ac b/configure.ac
index 9fc1fb1c1c..7275b53345 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1137,8 +1137,8 @@  AC_SUBST(CXX_SYSINCLUDES)
 # copy of those headers in Makerules.
 if test -n "$CXX"; then
   find_cxx_header () {
-    echo "#include <$1>" | $CXX -M -MP -x c++ - 2>/dev/null \
-	 | sed -n "\,$1:,{s/:\$//;p}"
+    echo "#include <$1>" | $CXX -H -fsyntax-only -x c++ - 2>&1 \
+	 | awk '$1 == "."{print $2}'
   }
   CXX_CSTDLIB_HEADER="$(find_cxx_header cstdlib)"
   CXX_CMATH_HEADER="$(find_cxx_header cmath)"