[Openvpn-devel,v2] Fix ACL_CHECK_ADD_COMPILE_FLAGS to work with clang

Message ID 1574183023-6136-1-git-send-email-selva.nair@gmail.com
State Accepted
Headers show
Series
  • [Openvpn-devel,v2] Fix ACL_CHECK_ADD_COMPILE_FLAGS to work with clang
Related show

Commit Message

Selva Nair Nov. 19, 2019, 5:03 p.m.
From: Selva Nair <selva.nair@gmail.com>

Some compilers (e.g., clang) only issue a warning for
unsupported options unless an additional flag such
as -Werror is used to convert the warning to an error.

The behaviour is unchanged when using gcc as it either
errors or ignores unknown options whether or not -Werror
is present.

Signed-off-by: Selva Nair <selva.nair@gmail.com>
---
v2: Do not extend the macro to take an extra argument.
Instead, add -Werror while doing the test.

The commit message and comment changed to match this.

 configure.ac | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Comments

David Sommerseth Nov. 19, 2019, 6:27 p.m. | #1
On 19/11/2019 18:03, selva.nair@gmail.com wrote:
> From: Selva Nair <selva.nair@gmail.com>
> 
> Some compilers (e.g., clang) only issue a warning for
> unsupported options unless an additional flag such
> as -Werror is used to convert the warning to an error.
> 
> The behaviour is unchanged when using gcc as it either
> errors or ignores unknown options whether or not -Werror
> is present.
> 
> Signed-off-by: Selva Nair <selva.nair@gmail.com>
> ---
> v2: Do not extend the macro to take an extra argument.
> Instead, add -Werror while doing the test.
> 
> The commit message and comment changed to match this.
> 
>  configure.ac | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 

Tested running ./configure and 'make' using gcc-4.3.8, gcc-8.3.1 and
clang-5.0.1.  With patch applied, everything works as expected and no
unexpected halts during these two steps.   Without this patch, clang-5.0.1
spits out lots of warnings related to -Wno-stringop-truncation.

Acked-By: David Sommerseth <davids@openvpn.net>
tincanteksup Nov. 19, 2019, 7:33 p.m. | #2
Typo below,

On 19/11/2019 17:03, selva.nair@gmail.com wrote:
> From: Selva Nair <selva.nair@gmail.com>
> 
> Some compilers (e.g., clang) only issue a warning for
> unsupported options unless an additional flag such
> as -Werror is used to convert the warning to an error.
> 
> The behaviour is unchanged when using gcc as it either
> errors or ignores unknown options whether or not -Werror
> is present.
> 
> Signed-off-by: Selva Nair <selva.nair@gmail.com>
> ---
> v2: Do not extend the macro to take an extra argument.
> Instead, add -Werror while doing the test.
> 
> The commit message and comment changed to match this.
> 
>   configure.ac | 9 ++++++---
>   1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/configure.ac b/configure.ac
> index 807804e5..f4a947d2 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -1275,11 +1275,14 @@ if test "${enable_pkcs11}" = "yes"; then
>   	)
>   fi
>   
> +# When testing a compiler option, we add -Werror to force
> +# an error when the option is unsupported. This is not
> +# required for gcc, but come compilers such as clang needs it.


come compilers --> some compilers




>   AC_DEFUN([ACL_CHECK_ADD_COMPILE_FLAGS], [
>       old_cflags="$CFLAGS"
> -    CFLAGS="$1 $CFLAGS"
> -    AC_MSG_CHECKING([whether the compiler acceppts $1])
> -    AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], [AC_MSG_RESULT([yes])],
> +    CFLAGS="$1 -Werror $CFLAGS"
> +    AC_MSG_CHECKING([whether the compiler accepts $1])
> +    AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], [AC_MSG_RESULT([yes])]; CFLAGS="$1 $old_cflags",
>           [AC_MSG_RESULT([no]); CFLAGS="$old_cflags"])]
>   )
>   
>
Gert Doering Nov. 27, 2019, 7:49 p.m. | #3
Your patch has been applied to the master branch.  Thanks :-)

I have fixed the "come compilers" typo on the fly.

Very lightly tested (Linux/gcc 8.3.0, and FreeBSD/clang 6.0.0).

commit acc18e8842570e66ef12ffee591968777ed5be6a
Author: Selva Nair
Date:   Tue Nov 19 12:03:43 2019 -0500

     Fix ACL_CHECK_ADD_COMPILE_FLAGS to work with clang

     Signed-off-by: Selva Nair <selva.nair@gmail.com>
     Acked-by: David Sommerseth <davids@openvpn.net>
     Message-Id: <1574183023-6136-1-git-send-email-selva.nair@gmail.com>
     URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg19170.html
     Signed-off-by: Gert Doering <gert@greenie.muc.de>


--
kind regards,

Gert Doering

Patch

diff --git a/configure.ac b/configure.ac
index 807804e5..f4a947d2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1275,11 +1275,14 @@  if test "${enable_pkcs11}" = "yes"; then
 	)
 fi
 
+# When testing a compiler option, we add -Werror to force
+# an error when the option is unsupported. This is not
+# required for gcc, but come compilers such as clang needs it.
 AC_DEFUN([ACL_CHECK_ADD_COMPILE_FLAGS], [
     old_cflags="$CFLAGS"
-    CFLAGS="$1 $CFLAGS"
-    AC_MSG_CHECKING([whether the compiler acceppts $1])
-    AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], [AC_MSG_RESULT([yes])],
+    CFLAGS="$1 -Werror $CFLAGS"
+    AC_MSG_CHECKING([whether the compiler accepts $1])
+    AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], [AC_MSG_RESULT([yes])]; CFLAGS="$1 $old_cflags",
         [AC_MSG_RESULT([no]); CFLAGS="$old_cflags"])]
 )