From 5e0340d35e4dfd58209fd85c51c6e348840014c3 Mon Sep 17 00:00:00 2001 From: EleonoreMizo Date: Thu, 19 Dec 2019 13:39:25 +0100 Subject: [PATCH] Improved the GNU build system --- build/unix/Makefile.am | 10 +-- build/unix/configure.ac | 93 +++++++++++++++----------- build/unix/m4/ax_check_compile_flag.m4 | 53 +++++++++++++++ build/unix/m4/ax_check_link_flag.m4 | 53 +++++++++++++++ 4 files changed, 165 insertions(+), 44 deletions(-) create mode 100644 build/unix/m4/ax_check_compile_flag.m4 create mode 100644 build/unix/m4/ax_check_link_flag.m4 diff --git a/build/unix/Makefile.am b/build/unix/Makefile.am index d836f17..cc23cab 100644 --- a/build/unix/Makefile.am +++ b/build/unix/Makefile.am @@ -1,8 +1,10 @@ -warningflags = -Wall -Wextra -Wno-unused-parameter -Wno-expansion-to-defined -Wno-missing-field-initializers -Wshadow -Wno-unused-private-field +ACLOCAL_AMFLAGS = -I m4 + +warningflags = -Wall -Wextra -Wshadow -Wno-expansion-to-defined -Wno-missing-field-initializers includeflags = -I$(srcdir)/../../src -commonflags = -O3 $(MFLAGS) $(warningflags) $(includeflags) -AM_CXXFLAGS = -std=c++11 $(commonflags) -AM_LDFLAGS = -latomic -lpthread $(PLUGINLDFLAGS) +commonflags = $(DEBUGCFLAGS) $(MFLAGS) $(warningflags) $(includeflags) +AM_CXXFLAGS = -std=$(CXXSTD) $(commonflags) +AM_LDFLAGS = $(PLUGINLDFLAGS) lib_LTLIBRARIES = libfmtconv.la diff --git a/build/unix/configure.ac b/build/unix/configure.ac index 33e38b4..0a52132 100644 --- a/build/unix/configure.ac +++ b/build/unix/configure.ac @@ -1,6 +1,5 @@ AC_INIT([fmtconv], [r22], [http://forum.doom9.org/showthread.php?t=166504], [fmtconv], [http://forum.doom9.org/showthread.php?t=166504]) - -: ${CXXFLAGS=""} +AC_CONFIG_MACRO_DIR([m4]) AM_INIT_AUTOMAKE([foreign no-dist-gzip dist-xz subdir-objects no-define]) AM_SILENT_RULES([yes]) @@ -11,63 +10,77 @@ AC_PROG_CXX AC_CANONICAL_HOST +AC_ARG_ENABLE([debug], AS_HELP_STRING([--enable-debug], [Compilation options required for debugging. [default=no]])) + +AC_LANG_PUSH([C++]) +AS_IF([test "x$CXXSTD" = "x"], AX_CHECK_COMPILE_FLAG([-std=c++17], [CXXSTD="c++17"])) +AS_IF([test "x$CXXSTD" = "x"], AX_CHECK_COMPILE_FLAG([-std=c++11], [CXXSTD="c++11"])) +AS_IF([test "x$CXXSTD" = "x"], AC_MSG_ERROR([Minimum requirement: C++11])) +AX_CHECK_COMPILE_FLAG([-Wunused-private-field] , [CXXFLAGS="$CXXFLAGS -Wno-unused-private-field"] , , [-Werror]) +AX_CHECK_COMPILE_FLAG([-Wunused-command-line-argument], [CXXFLAGS="$CXXFLAGS -Wno-unused-command-line-argument"], , [-Werror]) +AC_LANG_POP([C++]) + +# It seems that -latomic is needed only for some versions of GCC < 5.3 +AX_CHECK_LINK_FLAG([-latomic], [LIBS="$LIBS -latomic"]) + +AS_IF( + [test "x$enable_debug" = "xyes"], + [DEBUGCFLAGS="-O0 -g3 -ggdb"], + [DEBUGCFLAGS="-O3 -g3 -DNDEBUG"] +) X86="false" PPC="false" ARM="false" AS_CASE( - [$host_cpu], - [i?86], [BITS="32" X86="true"], - [x86_64], [BITS="64" X86="true"], - [powerpc*], [PPC="true"], - [arm*], [BITS="32" ARM="true"], - [aarch64*], [BITS="64" ARM="true"] + [$host_cpu], + [i?86], [BITS="32" X86="true"], + [x86_64], [BITS="64" X86="true"], + [powerpc*], [ PPC="true"], + [arm*], [BITS="32" ARM="true"], + [aarch64*], [BITS="64" ARM="true"] ) AS_CASE( - [$host_os], - [cygwin*|mingw*], + [$host_os], + [cygwin*|mingw*], + [AS_IF( + [test "x$BITS" = "x32"], [ - AS_IF( - [test "x$BITS" = "x32"], - [ - AC_SUBST([PLUGINLDFLAGS], ["-Wl,--kill-at"]) - ] - ) + PLUGINLDFLAGS="-Wl,--kill-at" + STACKREALIGN="-mstackrealign" ] + )] ) AS_IF( - [test "x$X86" = "xtrue"], - [ - MFLAGS="-mfpmath=sse -msse2" - - AS_IF( - [test "x$BITS" = "x64"], - [ - MFLAGS="$MFLAGS -mcx16" - ] - ) - AC_SUBST([MFLAGS]) - ] + [test "x$X86" = "xtrue"], + [ + MFLAGS="-mfpmath=sse -msse2 -Wno-ignored-attributes" + + # We need this to use CMPXCHG16B for 2x64-bit CAS (compare and swap) + AS_IF([test "x$BITS" = "x64"], [MFLAGS="$MFLAGS -mcx16"]) + ] ) AS_IF( - [test "x$ARM" = "xtrue"], - [ - MFLAGS="-ftree-vectorize" - WARNPSABI=`( $CXX --help=warnings 2>/dev/null ) | grep -c Wpsabi` - AS_IF( - [test "x$WARNPSABI" != "x0"], - [ - MFLAGS="$MFLAGS -Wno-psabi" - ] - ) - AC_SUBST([MFLAGS]) - ] + [test "x$ARM" = "xtrue"], + [ + MFLAGS="-ftree-vectorize" + + AX_CHECK_COMPILE_FLAG([-mfpu=neon], [MFLAGS="$MFLAGS -mfpu=neon"]) + + # GCC 7 emits some warnings about ABI changes when using std::vector + AX_CHECK_COMPILE_FLAG([-Wpsabi -Werror], [MFLAGS="$MFLAGS -Wno-psabi"]) + ] ) +AC_SUBST([MFLAGS]) +AC_SUBST([DEBUGCFLAGS]) +AC_SUBST([CXXSTD]) +AC_SUBST([PLUGINLDFLAGS]) +AC_SUBST([STACKREALIGN]) AM_CONDITIONAL([X86], [test "x$X86" = "xtrue"]) AM_CONDITIONAL([ARM], [test "x$ARM" = "xtrue"]) diff --git a/build/unix/m4/ax_check_compile_flag.m4 b/build/unix/m4/ax_check_compile_flag.m4 new file mode 100644 index 0000000..bd753b3 --- /dev/null +++ b/build/unix/m4/ax_check_compile_flag.m4 @@ -0,0 +1,53 @@ +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_CHECK_COMPILE_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT]) +# +# DESCRIPTION +# +# Check whether the given FLAG works with the current language's compiler +# or gives an error. (Warnings, however, are ignored) +# +# ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on +# success/failure. +# +# If EXTRA-FLAGS is defined, it is added to the current language's default +# flags (e.g. CFLAGS) when the check is done. The check is thus made with +# the flags: "CFLAGS EXTRA-FLAGS FLAG". This can for example be used to +# force the compiler to issue an error when a bad flag is given. +# +# INPUT gives an alternative input source to AC_COMPILE_IFELSE. +# +# NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this +# macro in sync with AX_CHECK_{PREPROC,LINK}_FLAG. +# +# LICENSE +# +# Copyright (c) 2008 Guido U. Draheim +# Copyright (c) 2011 Maarten Bosmans +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 6 + +AC_DEFUN([AX_CHECK_COMPILE_FLAG], +[AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF +AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl +AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [ + ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS + _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1" + AC_COMPILE_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])], + [AS_VAR_SET(CACHEVAR,[yes])], + [AS_VAR_SET(CACHEVAR,[no])]) + _AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags]) +AS_VAR_IF(CACHEVAR,yes, + [m4_default([$2], :)], + [m4_default([$3], :)]) +AS_VAR_POPDEF([CACHEVAR])dnl +])dnl AX_CHECK_COMPILE_FLAGS diff --git a/build/unix/m4/ax_check_link_flag.m4 b/build/unix/m4/ax_check_link_flag.m4 new file mode 100644 index 0000000..03a30ce --- /dev/null +++ b/build/unix/m4/ax_check_link_flag.m4 @@ -0,0 +1,53 @@ +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_check_link_flag.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_CHECK_LINK_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT]) +# +# DESCRIPTION +# +# Check whether the given FLAG works with the linker or gives an error. +# (Warnings, however, are ignored) +# +# ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on +# success/failure. +# +# If EXTRA-FLAGS is defined, it is added to the linker's default flags +# when the check is done. The check is thus made with the flags: "LDFLAGS +# EXTRA-FLAGS FLAG". This can for example be used to force the linker to +# issue an error when a bad flag is given. +# +# INPUT gives an alternative input source to AC_LINK_IFELSE. +# +# NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this +# macro in sync with AX_CHECK_{PREPROC,COMPILE}_FLAG. +# +# LICENSE +# +# Copyright (c) 2008 Guido U. Draheim +# Copyright (c) 2011 Maarten Bosmans +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 6 + +AC_DEFUN([AX_CHECK_LINK_FLAG], +[AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF +AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_ldflags_$4_$1])dnl +AC_CACHE_CHECK([whether the linker accepts $1], CACHEVAR, [ + ax_check_save_flags=$LDFLAGS + LDFLAGS="$LDFLAGS $4 $1" + AC_LINK_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])], + [AS_VAR_SET(CACHEVAR,[yes])], + [AS_VAR_SET(CACHEVAR,[no])]) + LDFLAGS=$ax_check_save_flags]) +AS_VAR_IF(CACHEVAR,yes, + [m4_default([$2], :)], + [m4_default([$3], :)]) +AS_VAR_POPDEF([CACHEVAR])dnl +])dnl AX_CHECK_LINK_FLAGS