diff options
author | Mike Gabriel <mike.gabriel@das-netzwerkteam.de> | 2017-06-30 13:58:47 +0200 |
---|---|---|
committer | Mike Gabriel <mike.gabriel@das-netzwerkteam.de> | 2017-07-12 23:25:56 +0200 |
commit | 322e39b79729bc72bd37265949a04962e427ef0a (patch) | |
tree | ab04a33a31551b63a2a66727b54a695cd0e78b2c /m4 | |
parent | e17207f183ea031d21a65ba31b026f9d0178afb6 (diff) | |
download | nx-libs-322e39b79729bc72bd37265949a04962e427ef0a.tar.gz nx-libs-322e39b79729bc72bd37265949a04962e427ef0a.tar.bz2 nx-libs-322e39b79729bc72bd37265949a04962e427ef0a.zip |
m4/nx-macros.m4: Add autotools macros derived from X.org and nxcomp* configure.in files.
Diffstat (limited to 'm4')
-rw-r--r-- | m4/nx-macros.m4 | 314 |
1 files changed, 314 insertions, 0 deletions
diff --git a/m4/nx-macros.m4 b/m4/nx-macros.m4 new file mode 100644 index 000000000..a878602e7 --- /dev/null +++ b/m4/nx-macros.m4 @@ -0,0 +1,314 @@ +dnl nx-macros.m4. Generated from xorg-macros.m4.in xorgversion.m4 by configure. +dnl +dnl Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved. +dnl Copyright (c) 2017, Mike Gabriel <mike.gabriel@das-netzwerkteam.de> +dnl +dnl Permission is hereby granted, free of charge, to any person obtaining a +dnl copy of this software and associated documentation files (the "Software"), +dnl to deal in the Software without restriction, including without limitation +dnl the rights to use, copy, modify, merge, publish, distribute, sublicense, +dnl and/or sell copies of the Software, and to permit persons to whom the +dnl Software is furnished to do so, subject to the following conditions: +dnl +dnl The above copyright notice and this permission notice (including the next +dnl paragraph) shall be included in all copies or substantial portions of the +dnl Software. +dnl +dnl THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +dnl IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +dnl FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +dnl THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +dnl LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +dnl FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +dnl DEALINGS IN THE SOFTWARE. + +# NX_COMPILER_BRAND +# ------------------- +# Checks for various brands of compilers and sets flags as appropriate: +# GNU gcc - relies on AC_PROG_CC (via AC_PROG_CC_C99) to set GCC to "yes" +# GNU g++ - relies on AC_PROG_CXX to set GXX to "yes" +# clang compiler - sets CLANGCC to "yes" +# Intel compiler - sets INTELCC to "yes" +# Sun/Oracle Solaris Studio cc - sets SUNCC to "yes" +# +# Derived from https://cgit.freedesktop.org/xorg/util/macros/ and adapted to +# nxcomp{,shad}. + +AC_DEFUN([NX_COMPILER_BRAND], [ +AC_LANG_CASE( + [C], [ + AC_REQUIRE([AC_PROG_CC_C99]) + ], + [C++], [ + AC_REQUIRE([AC_PROG_CXX]) + ] +) +AC_CHECK_DECL([__clang__], [CLANGCC="yes"], [CLANGCC="no"]) +AC_CHECK_DECL([__INTEL_COMPILER], [INTELCC="yes"], [INTELCC="no"]) +AC_CHECK_DECL([__SUNPRO_C], [SUNCC="yes"], [SUNCC="no"]) +]) # NX_COMPILER_BRAND + +# NX_TESTSET_CFLAG(<variable>, <flag>, [<alternative flag>, ...]) +# --------------- +# Test if the compiler works when passed the given flag as a command line argument. +# If it succeeds, the flag is appeneded to the given variable. If not, it tries the +# next flag in the list until there are no more options. +# +# Note that this does not guarantee that the compiler supports the flag as some +# compilers will simply ignore arguments that they do not understand, but we do +# attempt to weed out false positives by using -Werror=unknown-warning-option and +# -Werror=unused-command-line-argument +# +# Derived from https://cgit.freedesktop.org/xorg/util/macros/ and adapted to +# nxcomp{,shad}. + +AC_DEFUN([NX_TESTSET_CFLAG], [ +m4_if([$#], 0, [m4_fatal([NX_TESTSET_CFLAG was given with an unsupported number of arguments])]) +m4_if([$#], 1, [m4_fatal([NX_TESTSET_CFLAG was given with an unsupported number of arguments])]) + +AC_LANG_COMPILER_REQUIRE + +AC_LANG_CASE( + [C], [ + AC_REQUIRE([AC_PROG_CC_C99]) + define([PREFIX], [C]) + define([CACHE_PREFIX], [cc]) + define([COMPILER], [$CC]) + ], + [C++], [ + define([PREFIX], [CXX]) + define([CACHE_PREFIX], [cxx]) + define([COMPILER], [$CXX]) + ] +) + +[nx_testset_save_]PREFIX[FLAGS]="$PREFIX[FLAGS]" + +if test "x$[nx_testset_]CACHE_PREFIX[_unknown_warning_option]" = "x" ; then + PREFIX[FLAGS]="$PREFIX[FLAGS] -Werror=unknown-warning-option" + AC_CACHE_CHECK([if ]COMPILER[ supports -Werror=unknown-warning-option], + [nx_cv_]CACHE_PREFIX[_flag_unknown_warning_option], + AC_COMPILE_IFELSE([AC_LANG_SOURCE([int i;])], + [nx_cv_]CACHE_PREFIX[_flag_unknown_warning_option=yes], + [nx_cv_]CACHE_PREFIX[_flag_unknown_warning_option=no])) + [nx_testset_]CACHE_PREFIX[_unknown_warning_option]=$[nx_cv_]CACHE_PREFIX[_flag_unknown_warning_option] + PREFIX[FLAGS]="$[nx_testset_save_]PREFIX[FLAGS]" +fi + +if test "x$[nx_testset_]CACHE_PREFIX[_unused_command_line_argument]" = "x" ; then + if test "x$[nx_testset_]CACHE_PREFIX[_unknown_warning_option]" = "xyes" ; then + PREFIX[FLAGS]="$PREFIX[FLAGS] -Werror=unknown-warning-option" + fi + PREFIX[FLAGS]="$PREFIX[FLAGS] -Werror=unused-command-line-argument" + AC_CACHE_CHECK([if ]COMPILER[ supports -Werror=unused-command-line-argument], + [nx_cv_]CACHE_PREFIX[_flag_unused_command_line_argument], + AC_COMPILE_IFELSE([AC_LANG_SOURCE([int i;])], + [nx_cv_]CACHE_PREFIX[_flag_unused_command_line_argument=yes], + [nx_cv_]CACHE_PREFIX[_flag_unused_command_line_argument=no])) + [nx_testset_]CACHE_PREFIX[_unused_command_line_argument]=$[nx_cv_]CACHE_PREFIX[_flag_unused_command_line_argument] + PREFIX[FLAGS]="$[nx_testset_save_]PREFIX[FLAGS]" +fi + +found="no" +m4_foreach([flag], m4_cdr($@), [ + if test $found = "no" ; then + if test "x$nx_testset_]CACHE_PREFIX[_unknown_warning_option" = "xyes" ; then + PREFIX[FLAGS]="$PREFIX[FLAGS] -Werror=unknown-warning-option" + fi + + if test "x$nx_testset_]CACHE_PREFIX[_unused_command_line_argument" = "xyes" ; then + PREFIX[FLAGS]="$PREFIX[FLAGS] -Werror=unused-command-line-argument" + fi + + PREFIX[FLAGS]="$PREFIX[FLAGS] ]flag[" + +dnl Some hackery here since AC_CACHE_VAL can't handle a non-literal varname + AC_MSG_CHECKING([if ]COMPILER[ supports ]flag[]) + cacheid=AS_TR_SH([nx_cv_]CACHE_PREFIX[_flag_]flag[]) + AC_CACHE_VAL($cacheid, + [AC_LINK_IFELSE([AC_LANG_PROGRAM([int i;])], + [eval $cacheid=yes], + [eval $cacheid=no])]) + + PREFIX[FLAGS]="$[nx_testset_save_]PREFIX[FLAGS]" + + eval supported=\$$cacheid + AC_MSG_RESULT([$supported]) + if test "$supported" = "yes" ; then + $1="$$1 ]flag[" + found="yes" + fi + fi +]) +]) # NX_TESTSET_CFLAG + +# NX_COMPILER_FLAGS +# --------------- +# Defines BASE_CFLAGS or BASE_CXXFLAGS to contain a set of command line +# arguments supported by the selected compiler which do NOT alter the generated +# code. These arguments will cause the compiler to print various warnings +# during compilation AND turn a conservative set of warnings into errors. +# +# The set of flags supported by BASE_CFLAGS and BASE_CXXFLAGS will grow in +# future versions of util-macros as options are added to new compilers. +# +# Derived from https://cgit.freedesktop.org/xorg/util/macros/ and adapted to +# nxcomp{,shad}. + +AC_DEFUN([NX_COMPILER_FLAGS], [ +AC_REQUIRE([NX_COMPILER_BRAND]) + +AC_ARG_ENABLE(selective-werror, + AS_HELP_STRING([--disable-selective-werror], + [Turn off selective compiler errors. (default: enabled)]), + [SELECTIVE_WERROR=$enableval], + [SELECTIVE_WERROR=yes]) + +AC_LANG_CASE( + [C], [ + define([PREFIX], [C]) + ], + [C++], [ + define([PREFIX], [CXX]) + ] +) +# -v is too short to test reliably with NX_TESTSET_CFLAG +if test "x$SUNCC" = "xyes"; then + [BASE_]PREFIX[FLAGS]="-v" +else + [BASE_]PREFIX[FLAGS]="" +fi + +# This chunk of warnings were those that existed in the legacy CWARNFLAGS +NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wall]) +NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wpointer-arith]) +NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wmissing-declarations]) +NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wformat=2], [-Wformat]) + +AC_LANG_CASE( + [C], [ + NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wstrict-prototypes]) + NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wmissing-prototypes]) + NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wnested-externs]) + NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wbad-function-cast]) + NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wold-style-definition], [-fd]) + NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wdeclaration-after-statement]) + ] +) + +# This chunk adds additional warnings that could catch undesired effects. +NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wunused]) +NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wuninitialized]) +NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wshadow]) +NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wmissing-noreturn]) +NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wmissing-format-attribute]) +NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wredundant-decls]) +NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wlogical-op]) + +# These are currently disabled because they are noisy. They will be enabled +# in the future once the codebase is sufficiently modernized to silence +# them. For now, I don't want them to drown out the other warnings. +# NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wparentheses]) +# NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wcast-align]) +# NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wcast-qual]) + +# Turn some warnings into errors, so we don't accidently get successful builds +# when there are problems that should be fixed. + +if test "x$SELECTIVE_WERROR" = "xyes" ; then +NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=implicit], [-errwarn=E_NO_EXPLICIT_TYPE_GIVEN -errwarn=E_NO_IMPLICIT_DECL_ALLOWED]) +NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=nonnull]) +NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=init-self]) +NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=main]) +NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=missing-braces]) +NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=sequence-point]) +NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=return-type], [-errwarn=E_FUNC_HAS_NO_RETURN_STMT]) +NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=trigraphs]) +NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=array-bounds]) +NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=write-strings]) +NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=address]) +NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=int-to-pointer-cast], [-errwarn=E_BAD_PTR_INT_COMBINATION]) +NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=pointer-to-int-cast]) # Also -errwarn=E_BAD_PTR_INT_COMBINATION +else +AC_MSG_WARN([You have chosen not to turn some select compiler warnings into errors. This should not be necessary. Please report why you needed to do so in a bug report at $PACKAGE_BUGREPORT]) +NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wimplicit]) +NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wnonnull]) +NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Winit-self]) +NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wmain]) +NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wmissing-braces]) +NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wsequence-point]) +NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wreturn-type]) +NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wtrigraphs]) +NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Warray-bounds]) +NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wwrite-strings]) +NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Waddress]) +NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wint-to-pointer-cast]) +NX_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wpointer-to-int-cast]) +fi + +AC_SUBST([BASE_]PREFIX[FLAGS]) +]) # NX_COMPILER_FLAGS + +dnl Check to see if we're running under Cygwin32. + +AC_DEFUN([NX_BUILD_ON_CYGWIN32], +[AC_CACHE_CHECK([for Cygwin32 environment], nxconf_cv_cygwin32, +[AC_TRY_COMPILE(,[return __CYGWIN32__;], +nxconf_cv_cygwin32=yes, nxconf_cv_cygwin32=no) +rm -f conftest*]) +CYGWIN32= +test "$nxconf_cv_cygwin32" = yes && CYGWIN32=yes +]) # NX_BUILD_ON_CYGWIN32 + +dnl Check whether we're building on a AMD64. + +AC_DEFUN([NX_BUILD_ON_AMD64], +[AC_CACHE_CHECK([for Amd64 environment], nxconf_cv_amd64, +[AC_TRY_COMPILE(,[return (__amd64__ || __x86_64__);], +nxconf_cv_amd64=yes, nxconf_cv_amd64=no) +rm -f conftest*]) +AMD64= +test "$nxconf_cv_amd64" = yes && AMD64=yes +]) # NX_BUILD_ON_AMD64 + +dnl Check for Darwin environment. + +AC_DEFUN([NX_BUILD_ON_DARWIN], +[AC_CACHE_CHECK([for Darwin environment], nxconf_cv_darwin, +[AC_TRY_COMPILE(,[return __APPLE__;], +nxconf_cv_darwin=yes, nxconf_cv_darwin=no) +rm -f conftest*]) +DARWIN= +test "$nxconf_cv_darwin" = yes && DARWIN=yes +]) # NX_BUILD_ON_DARWIN + +# Check to see if we're running under Solaris. + +AC_DEFUN([NX_BUILD_ON_SUN], +[AC_CACHE_CHECK([for Solaris environment], nxconf_cv_sun, +[AC_TRY_COMPILE(,[return __sun;], +nxconf_cv_sun=yes, nxconf_cv_sun=no) +rm -f conftest*]) +SUN= +test "$nxconf_cv_sun" = yes && SUN=yes +]) # NX_BUILD_ON_SUN + +# Check to see if we're running under FreeBSD. + +AC_DEFUN([NX_BUILD_ON_FreeBSD], +[AC_CACHE_CHECK([for FreeBSD environment], nxconf_cv_freebsd, +[AC_TRY_COMPILE(,[return __FreeBSD__;], +nxconf_cv_freebsd=yes, nxconf_cv_freebsd=no) +rm -f conftest*]) +FreeBSD= +test "$nxconf_cv_freebsd" = yes && FreeBSD=yes +]) # NX_BUILD_ON_FreeBSD + +AC_DEFUN([NX_HAS_INADDRT], +[AC_CACHE_CHECK(for in_addr_t, nx_cv_inaddrt, +[AC_TRY_COMPILE([#include <netinet/in.h>],[in_addr_t t; t = 1; return t;], +nx_cv_inaddrt=yes, nx_cv_inaddrt=no) +rm -f conftest*]) +INADDRT= +test "$nx_cv_inaddrt" = yes && INADDRT=yes +]) # NX_HAS_INADDRT |