[03/11] Rewrite find_cxx_header config configure.ac
Checks
Context |
Check |
Description |
dj/TryBot-apply_patch |
success
|
Patch applied to master at the time it was sent
|
Commit Message
clang does not support -MP option to create phony target for each
dependency other than the main file. Use -fsyntax-only with a
more comprensible regex to get the the cxx header.
---
configure | 4 ++--
configure.ac | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
Comments
On 2022-10-28, Adhemerval Zanella via Libc-alpha wrote:
>clang does not support -MP option to create phony target for each
>dependency other than the main file. Use -fsyntax-only with a
>more comprensible regex to get the the cxx header.
Clang has supported -MP for many years.
The problem was that when the main file is <stdin>, the first non-main-file dependency is not listed
in the -MP output.
echo "#include <cstdlib>" | fclang++ -M -MP -x c++ - 2>/dev/null | sed -n "\,cstdlib:,{s/:\$//;p}"
I just fixed this in https://github.com/llvm/llvm-project/commit/ff9576f74514b836e1ba0268409a2ecb919d7118
which shall be included in Clang 16.
>---
> configure | 4 ++--
> configure.ac | 4 ++--
> 2 files changed, 4 insertions(+), 4 deletions(-)
>
>diff --git a/configure b/configure
>index ff2c406b3b..26bd8200dd 100755
>--- a/configure
>+++ b/configure
>@@ -5579,8 +5579,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 \
>+ | sed -rn "\,^\.? .,{s/^\.*\. //p}"
That said, the patch looks good to support more Clang versions.
For portability, prefer -E to -r and add `;` before `}` (FreeBSD sed doesn't allow `p}`).
Actually no ERE is needed and sed -n "\,^\. .,{s/^\. //;p;}" should work.
Alternatively, use 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 eb5bc6a131..a009e7a17f 100644
>--- a/configure.ac
>+++ b/configure.ac
>@@ -1136,8 +1136,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 \
>+ | sed -rn "\,^\.? .,{s/[^\.]*\. //p}"
> }
> CXX_CSTDLIB_HEADER="$(find_cxx_header cstdlib)"
> CXX_CMATH_HEADER="$(find_cxx_header cmath)"
>--
>2.34.1
>
On 29/10/22 01:03, Fangrui Song wrote:
> On 2022-10-28, Adhemerval Zanella via Libc-alpha wrote:
>> clang does not support -MP option to create phony target for each
>> dependency other than the main file. Use -fsyntax-only with a
>> more comprensible regex to get the the cxx header.
>
> Clang has supported -MP for many years.
> The problem was that when the main file is <stdin>, the first non-main-file dependency is not listed
> in the -MP output.
>
> echo "#include <cstdlib>" | fclang++ -M -MP -x c++ - 2>/dev/null | sed -n "\,cstdlib:,{s/:\$//;p}"
>
> I just fixed this in https://github.com/llvm/llvm-project/commit/ff9576f74514b836e1ba0268409a2ecb919d7118
> which shall be included in Clang 16.
You are right, I did not write down my finding and I have to hasty
(and wrongly) described the patch.
>
>
>
>> ---
>> configure | 4 ++--
>> configure.ac | 4 ++--
>> 2 files changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/configure b/configure
>> index ff2c406b3b..26bd8200dd 100755
>> --- a/configure
>> +++ b/configure
>> @@ -5579,8 +5579,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 \
>> + | sed -rn "\,^\.? .,{s/^\.*\. //p}"
>
> That said, the patch looks good to support more Clang versions.
>
> For portability, prefer -E to -r and add `;` before `}` (FreeBSD sed doesn't allow `p}`).
>
> Actually no ERE is needed and sed -n "\,^\. .,{s/^\. //;p;}" should work.
> Alternatively, use awk '$1 == "."{print $2}'
The awk does seems to be simpler solution indeed.
>
>> }
>> CXX_CSTDLIB_HEADER="$(find_cxx_header cstdlib)"
>> CXX_CMATH_HEADER="$(find_cxx_header cmath)"
>> diff --git a/configure.ac b/configure.ac
>> index eb5bc6a131..a009e7a17f 100644
>> --- a/configure.ac
>> +++ b/configure.ac
>> @@ -1136,8 +1136,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 \
>> + | sed -rn "\,^\.? .,{s/[^\.]*\. //p}"
>> }
>> CXX_CSTDLIB_HEADER="$(find_cxx_header cstdlib)"
>> CXX_CMATH_HEADER="$(find_cxx_header cmath)"
>> --
>> 2.34.1
>>
@@ -5579,8 +5579,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 \
+ | sed -rn "\,^\.? .,{s/^\.*\. //p}"
}
CXX_CSTDLIB_HEADER="$(find_cxx_header cstdlib)"
CXX_CMATH_HEADER="$(find_cxx_header cmath)"
@@ -1136,8 +1136,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 \
+ | sed -rn "\,^\.? .,{s/[^\.]*\. //p}"
}
CXX_CSTDLIB_HEADER="$(find_cxx_header cstdlib)"
CXX_CMATH_HEADER="$(find_cxx_header cmath)"