From c56f76ddaab7cc1844526146e2a4ad1d83c73fb8 Mon Sep 17 00:00:00 2001 From: Bastian Triller Date: Tue, 1 Apr 2025 23:37:31 +0200 Subject: [PATCH 1/7] CFE-3629 - just poking around Set CFLAGS before AC_PROG_CC as it might add -g/-O options if CFLAGS is unset. Don't add CFLAGS to CORE_FLAGS because I don't know, but maybe CFLAGS is populated otherwise. --- configure.ac | 49 +++++++++++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/configure.ac b/configure.ac index ce459022..b5581d40 100644 --- a/configure.ac +++ b/configure.ac @@ -84,6 +84,28 @@ dnl It is restored later. dnl ENV_CFLAGS="$CFLAGS" +dnl ###################################################################### +dnl Enable debugging +dnl ###################################################################### + +AC_ARG_ENABLE(debug, + AS_HELP_STRING([--enable-debug], [Enable debugging]), + [debug=$enableval], + [debug=no]) +AM_CONDITIONAL([NDEBUG], [test x"$debug" = x"no"]) + +AC_MSG_CHECKING([for debug option]) +if test x"$debug" = x"yes" +then + AC_MSG_RESULT(yes) + CFLAGS="-g3 -O0" +else + AC_MSG_RESULT(no) + CFLAGS="-O2 -DNDEBUG" +fi + +CFLAGS="$CFLAGS $ENV_CFLAGS" + dnl ###################################################################### dnl Checks for programs. dnl ###################################################################### @@ -227,31 +249,6 @@ AS_CASE([${target_os}], # flags than vanilla Windows version, so they are false positives. [CFLAGS="$CFLAGS -Wno-format"]) -dnl ###################################################################### -dnl Enable debugging -dnl ###################################################################### - -AC_ARG_ENABLE(debug, - AS_HELP_STRING([--enable-debug], [Enable debugging]), - [debug=$enableval], - [debug=no]) -AM_CONDITIONAL([NDEBUG], [test x"$debug" = x"no"]) - -dnl Even though CFLAGS should contain the command-line CFLAGS -dnl as last, some macro seem to messes the order up and insert -dnl its own optimisation flags as well. So we append ENV_CFLAGS -dnl at the end manually, causing a bit of flag duplication. - -AC_MSG_CHECKING([for debug option]) -if test x"$debug" = x"yes" -then - AC_MSG_RESULT(yes) - CFLAGS="$CFLAGS -g3 -O0 $ENV_CFLAGS" -else - AC_MSG_RESULT(no) - CFLAGS="$CFLAGS -O2 -DNDEBUG $ENV_CFLAGS" -fi - dnl ###################################################################### dnl Checks for libraries. dnl ###################################################################### @@ -1275,7 +1272,7 @@ dnl Collect all the options dnl ###################################################################### CORE_CPPFLAGS="$PCRE2_CPPFLAGS $OPENSSL_CPPFLAGS $LIBYAML_CPPFLAGS $CPPFLAGS" -CORE_CFLAGS="$PCRE2_CFLAGS $OPENSSL_CFLAGS $LIBYAML_CFLAGS $CFLAGS" +CORE_CFLAGS="$PCRE2_CFLAGS $OPENSSL_CFLAGS $LIBYAML_CFLAGS" CORE_LDFLAGS="$PCRE2_LDFLAGS $OPENSSL_LDFLAGS $LIBYAML_LDFLAGS $LDFLAGS" CORE_LIBS="$PCRE2_LIBS $OPENSSL_LIBS $LIBYAML_LIBS $LIBS" From 3eae2bcd9057fa134c7ffc94c24a483f873c1a96 Mon Sep 17 00:00:00 2001 From: Bastian Triller Date: Fri, 11 Apr 2025 00:14:36 +0200 Subject: [PATCH 2/7] Fix redefinition errors --- libcompat/strcasecmp.c | 2 +- libcompat/strcasestr.c | 2 +- libcompat/strdup.c | 2 +- libcompat/strerror.c | 2 +- libcompat/strlcat.c | 2 ++ libcompat/strlcpy.c | 2 ++ libcompat/strncasecmp.c | 2 +- libcompat/strndup.c | 2 +- libcompat/strnlen.c | 3 +-- libcompat/strrstr.c | 3 +-- libcompat/strsep.c | 2 +- libcompat/strsignal.c | 3 +-- libcompat/strstr.c | 2 +- 13 files changed, 15 insertions(+), 14 deletions(-) diff --git a/libcompat/strcasecmp.c b/libcompat/strcasecmp.c index c24d3632..eec5a0d9 100644 --- a/libcompat/strcasecmp.c +++ b/libcompat/strcasecmp.c @@ -27,7 +27,6 @@ #if !HAVE_DECL_STRCASECMP int strcasecmp(const char *s1, const char *s2); -#endif int strcasecmp(const char *s1, const char *s2) { @@ -58,3 +57,4 @@ int strcasecmp(const char *s1, const char *s2) } return 0; } +#endif diff --git a/libcompat/strcasestr.c b/libcompat/strcasestr.c index da68d0f1..64e1fd11 100644 --- a/libcompat/strcasestr.c +++ b/libcompat/strcasestr.c @@ -30,7 +30,6 @@ #if !HAVE_DECL_STRCASESTR char *strcasestr(const char *haystack, const char *needle); -#endif char *strcasestr(const char *haystack, const char *needle) { @@ -45,3 +44,4 @@ char *strcasestr(const char *haystack, const char *needle) } return NULL; } +#endif diff --git a/libcompat/strdup.c b/libcompat/strdup.c index b04be3b1..5c4f0ebb 100644 --- a/libcompat/strdup.c +++ b/libcompat/strdup.c @@ -30,7 +30,6 @@ #if !HAVE_DECL_STRDUP char *strdup(const char *str); -#endif char *strdup(const char *str) { @@ -44,3 +43,4 @@ char *strdup(const char *str) memcpy(sp, str, len); return sp; } +#endif diff --git a/libcompat/strerror.c b/libcompat/strerror.c index 629e5033..c3d35a03 100644 --- a/libcompat/strerror.c +++ b/libcompat/strerror.c @@ -29,7 +29,6 @@ #if !HAVE_DECL_STRERROR char *strerror(int err); -#endif char *strerror(int err) { @@ -38,3 +37,4 @@ char *strerror(int err) snprintf(buffer, 20, "Error number %d\n", err); return buffer; } +#endif diff --git a/libcompat/strlcat.c b/libcompat/strlcat.c index 9c78a982..01f50a6b 100644 --- a/libcompat/strlcat.c +++ b/libcompat/strlcat.c @@ -23,6 +23,7 @@ #include #include +#if !HAVE_DECL_STRLCAT size_t strlcat(char *dst, const char *src, size_t siz); /* @@ -59,3 +60,4 @@ strlcat(char *dst, const char *src, size_t siz) return(dlen + (s - src)); /* count does not include NUL */ } +#endif diff --git a/libcompat/strlcpy.c b/libcompat/strlcpy.c index a19e3273..c72b04f6 100644 --- a/libcompat/strlcpy.c +++ b/libcompat/strlcpy.c @@ -23,6 +23,7 @@ #include #include +#if !HAVE_DECL_STRLCPY size_t strlcpy(char *dst, const char *src, size_t siz); /* @@ -55,3 +56,4 @@ strlcpy(char *dst, const char *src, size_t siz) return(s - src - 1); /* count does not include NUL */ } +#endif diff --git a/libcompat/strncasecmp.c b/libcompat/strncasecmp.c index 8511030a..0dd40693 100644 --- a/libcompat/strncasecmp.c +++ b/libcompat/strncasecmp.c @@ -27,7 +27,6 @@ #if !HAVE_DECL_STRCASECMP int strncasecmp(const char *s1, const char *s2); -#endif int strncasecmp(const char *s1, const char *s2, size_t n) { @@ -58,3 +57,4 @@ int strncasecmp(const char *s1, const char *s2, size_t n) } return 0; } +#endif diff --git a/libcompat/strndup.c b/libcompat/strndup.c index c9849a0e..cd8c537f 100644 --- a/libcompat/strndup.c +++ b/libcompat/strndup.c @@ -32,7 +32,6 @@ size_t strnlen(const char *str, size_t maxlen); #if !HAVE_DECL_STRNDUP char *strndup(const char *str, size_t n); -#endif char * strndup(const char *str, size_t maxlen) @@ -49,3 +48,4 @@ strndup(const char *str, size_t maxlen) return copy; } +#endif diff --git a/libcompat/strnlen.c b/libcompat/strnlen.c index ccd99795..566d05e3 100644 --- a/libcompat/strnlen.c +++ b/libcompat/strnlen.c @@ -26,7 +26,6 @@ #if !HAVE_DECL_STRNLEN size_t strnlen(const char *str, size_t maxlen); -#endif size_t strnlen(const char *str, size_t maxlen) @@ -38,4 +37,4 @@ strnlen(const char *str, size_t maxlen) return (size_t)(cp - str); } - +#endif diff --git a/libcompat/strrstr.c b/libcompat/strrstr.c index e6cb9192..91b73381 100644 --- a/libcompat/strrstr.c +++ b/libcompat/strrstr.c @@ -38,7 +38,6 @@ #if !HAVE_DECL_STRRSTR char *strrstr(const char *haystack, const char *needle); -#endif char *strrstr(const char *str, const char *pat) { size_t len, patlen; @@ -57,4 +56,4 @@ char *strrstr(const char *str, const char *pat) { return (char *) p; return NULL; } - +#endif diff --git a/libcompat/strsep.c b/libcompat/strsep.c index f6850261..1dd88e8c 100644 --- a/libcompat/strsep.c +++ b/libcompat/strsep.c @@ -36,7 +36,6 @@ #if !HAVE_DECL_STRSEP char *strsep(char **stringp, const char *delim); -#endif /* * Get next token from string *stringp, where tokens are possibly-empty @@ -75,3 +74,4 @@ strsep(char **stringp, const char *delim) } /* NOTREACHED */ } +#endif diff --git a/libcompat/strsignal.c b/libcompat/strsignal.c index 9379eea3..b37d3189 100644 --- a/libcompat/strsignal.c +++ b/libcompat/strsignal.c @@ -33,7 +33,6 @@ int rpl_snprintf(char *, size_t, const char *, ...); #if !HAVE_DECL_STRSIGNAL char *strsignal(int sig); -#endif #include @@ -44,4 +43,4 @@ char *strsignal(int sig) snprintf(SIGNAL_TEXT, 16, "Signal #%d", sig); return SIGNAL_TEXT; } - +#endif diff --git a/libcompat/strstr.c b/libcompat/strstr.c index a4617b31..c8b23fa2 100644 --- a/libcompat/strstr.c +++ b/libcompat/strstr.c @@ -29,7 +29,6 @@ #if !HAVE_DECL_STRSTR char *strstr(const char *haystack, const char *needle); -#endif char *strstr(const char *haystack, const char *needle) { @@ -45,3 +44,4 @@ char *strstr(const char *haystack, const char *needle) return NULL; } +#endif From b65966d27511cb046d64cbd787f71dfbdee4d401 Mon Sep 17 00:00:00 2001 From: Bastian Triller Date: Fri, 11 Apr 2025 00:24:37 +0200 Subject: [PATCH 3/7] Fix CFLAGS --- m4/acinclude.m4 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/m4/acinclude.m4 b/m4/acinclude.m4 index acae012a..52d29d04 100644 --- a/m4/acinclude.m4 +++ b/m4/acinclude.m4 @@ -105,7 +105,7 @@ for flag in $acx_pthread_flags; do save_LIBS="$LIBS" save_CFLAGS="$CFLAGS" LIBS="$PTHREAD_LIBS $LIBS" - CFLAGS="$CFLAGS $PTHREAD_CFLAGS" + CFLAGS="$PTHREAD_CFLAGS" # Check for various functions. We must include pthread.h, # since some functions may be macros. (On the Sequent, we From e32beb0aa0128cbef54653a4b1cacf4b94a9a92c Mon Sep 17 00:00:00 2001 From: Bastian Triller Date: Fri, 11 Apr 2025 00:38:16 +0200 Subject: [PATCH 4/7] Fix pointer-sign warnings --- libutils/buffer.c | 4 ++-- libutils/json-yaml.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libutils/buffer.c b/libutils/buffer.c index 861bf1cd..b29f270e 100644 --- a/libutils/buffer.c +++ b/libutils/buffer.c @@ -715,7 +715,7 @@ const char* BufferSearchAndReplace(Buffer *buffer, const char *pattern, * with twice the size of the input and expand it if needed. */ bool had_enough_space = false; size_t out_size = BufferSize(buffer) * 2; - char *result = xmalloc(out_size); + unsigned char *result = xmalloc(out_size); while (!had_enough_space) { ret = pcre2_substitute(regex, (PCRE2_SPTR) BufferData(buffer), BufferSize(buffer), @@ -746,7 +746,7 @@ const char* BufferSearchAndReplace(Buffer *buffer, const char *pattern, substitute, BufferData(buffer)); } } - BufferSet(buffer, result, out_size); + BufferSet(buffer, (const char *) result, out_size); pcre2_match_data_free(match_data); pcre2_code_free(regex); diff --git a/libutils/json-yaml.c b/libutils/json-yaml.c index cca1954a..083b92ac 100644 --- a/libutils/json-yaml.c +++ b/libutils/json-yaml.c @@ -161,7 +161,7 @@ static void JsonParseYamlData(yaml_parser_t *parser, JsonElement *element, const if (key == NULL) { // save key - key = xstrdup(event.data.scalar.value); + key = xstrdup((char *) event.data.scalar.value); } else { @@ -343,7 +343,7 @@ JsonParseError JsonParseYamlString(const char **data, JsonElement **json_out) return JSON_PARSE_ERROR_LIBYAML_FAILURE; } - yaml_parser_set_input_string(&parser, *data, strlen(*data)); + yaml_parser_set_input_string(&parser, (unsigned char *) *data, strlen(*data)); JsonElement *holder = JsonArrayCreate(1); JsonParseYamlData(&parser, holder, 0); From 0e7fa7bfb932fed79f3d1e3cda6c7c8f2f8cc0a7 Mon Sep 17 00:00:00 2001 From: Bastian Triller Date: Fri, 11 Apr 2025 00:38:29 +0200 Subject: [PATCH 5/7] Fix format truncation warning --- libutils/file_lib.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libutils/file_lib.c b/libutils/file_lib.c index 271ae627..d4572bf2 100644 --- a/libutils/file_lib.c +++ b/libutils/file_lib.c @@ -1446,7 +1446,8 @@ static bool DeleteDirectoryTreeInternal(const char *basepath, const char *path) } char subpath[PATH_MAX]; - snprintf(subpath, sizeof(subpath), "%s" FILE_SEPARATOR_STR "%s", path, dirp->d_name); + NDEBUG_UNUSED int ret = snprintf(subpath, sizeof(subpath), "%s" FILE_SEPARATOR_STR "%s", path, dirp->d_name); + assert(ret >= 0 && (size_t) ret < sizeof(subpath)); struct stat lsb; if (lstat(subpath, &lsb) == -1) From d1b03348bf1fcf65b762ad3fe6d58efd52891664 Mon Sep 17 00:00:00 2001 From: Bastian Triller Date: Fri, 11 Apr 2025 22:38:29 +0200 Subject: [PATCH 6/7] Remove more duplicate flags --- configure.ac | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index b5581d40..64d41ee8 100644 --- a/configure.ac +++ b/configure.ac @@ -1271,10 +1271,10 @@ dnl ###################################################################### dnl Collect all the options dnl ###################################################################### -CORE_CPPFLAGS="$PCRE2_CPPFLAGS $OPENSSL_CPPFLAGS $LIBYAML_CPPFLAGS $CPPFLAGS" +CORE_CPPFLAGS="$PCRE2_CPPFLAGS $OPENSSL_CPPFLAGS $LIBYAML_CPPFLAGS" CORE_CFLAGS="$PCRE2_CFLAGS $OPENSSL_CFLAGS $LIBYAML_CFLAGS" -CORE_LDFLAGS="$PCRE2_LDFLAGS $OPENSSL_LDFLAGS $LIBYAML_LDFLAGS $LDFLAGS" -CORE_LIBS="$PCRE2_LIBS $OPENSSL_LIBS $LIBYAML_LIBS $LIBS" +CORE_LDFLAGS="$PCRE2_LDFLAGS $OPENSSL_LDFLAGS $LIBYAML_LDFLAGS" +CORE_LIBS="$PCRE2_LIBS $OPENSSL_LIBS $LIBYAML_LIBS" dnl ###################################################################### dnl Make them available to subprojects. From feca3ca298c4e1d72198d3b784ee0e0ddd39f62f Mon Sep 17 00:00:00 2001 From: Bastian Triller Date: Sat, 26 Apr 2025 15:39:04 +0200 Subject: [PATCH 7/7] Keep autogen/configure CFLAGS In case CFLAGS were given to configure, keep them for later stages. Check for clang compiler so strchrnul() can be used for macOS >= 15.4. Replace some obsolete autoconf macros. Make -Werror works in configure. --- autogen.sh | 4 +-- configure.ac | 63 +++++++++++++++++++++++++++--------------- libutils/Makefile.am | 3 -- libutils/mustache.c | 2 +- m4/acinclude.m4 | 34 +++++++++++++++++------ m4/cf3_gcc_flags.m4 | 34 ++++++++++++----------- tests/unit/Makefile.am | 12 ++------ 7 files changed, 89 insertions(+), 63 deletions(-) diff --git a/autogen.sh b/autogen.sh index dbbc62f3..4d61d8a2 100755 --- a/autogen.sh +++ b/autogen.sh @@ -53,9 +53,9 @@ test -z "$srcdir" && srcdir=. cd "$srcdir" echo "$0: Running autoreconf ..." -autoreconf -Wno-portability --force --install -I m4 || exit +autoreconf -Wno-portability --force --install -I m4 || exit -cd - >/dev/null # back to original directory +cd - >/dev/null # back to original directory if [ -z "$NO_CONFIGURE" ] then diff --git a/configure.ac b/configure.ac index 64d41ee8..c32a3f23 100644 --- a/configure.ac +++ b/configure.ac @@ -84,6 +84,10 @@ dnl It is restored later. dnl ENV_CFLAGS="$CFLAGS" +# Do not use autoconf's CFLAGS defaults set via AC_PROG_CC macro +# https://www.gnu.org/software/autoconf/manual/autoconf-2.67/html_node/C-Compiler.html +CFLAGS= + dnl ###################################################################### dnl Enable debugging dnl ###################################################################### @@ -98,26 +102,39 @@ AC_MSG_CHECKING([for debug option]) if test x"$debug" = x"yes" then AC_MSG_RESULT(yes) - CFLAGS="-g3 -O0" + AM_CFLAGS="$AM_CFLAGS -g3 -O0" else AC_MSG_RESULT(no) - CFLAGS="-O2 -DNDEBUG" + AM_CFLAGS="$AM_CFLAGS -O2 -DNDEBUG" fi -CFLAGS="$CFLAGS $ENV_CFLAGS" - dnl ###################################################################### dnl Checks for programs. dnl ###################################################################### AC_PROG_GREP AC_PROG_EGREP -AC_PROG_CC +# check for clang first so we can use this info on macOS +AC_PROG_CC([clang gcc cc]) AC_PROG_MKDIR_P AC_EXEEXT AS_CASE([${target_os}], [darwin*], [ + # Since 15.4, macOS has strchrnul(), but only allows it for deployment version + # >= 15.4. Add -mmacosx-version-min parameter to CFLAGS if we're using clang + AS_IF([test "x$CC" = "xclang"], [ + AC_CHECK_PROG([xcrun], [xcrun], [xcrun]) + if test "x$xcrun" = "xxcrun" ; then + AC_MSG_CHECKING([for macOS SDK version]) + MACOS_SDK_VERSION=`xcrun --show-sdk-version` + AC_MSG_RESULT([$MACOS_SDK_VERSION]) + case "${MACOS_SDK_VERSION}" in + *.*) test "${MACOS_SDK_VERSION%.*}" -ge 15 && test "${MACOS_SDK_VERSION#*.}" -ge 4 && AM_CFLAGS="$AM_CFLAGS -mmacosx-version-min=$MACOS_SDK_VERSION";; + esac + fi + ]) + AC_CHECK_PROG([BREW], [brew], [brew]) AC_MSG_CHECKING([for OS X Homebrew]) AS_IF([test "x$BREW" = "xbrew"], [ @@ -163,14 +180,14 @@ AC_ARG_WITH([pthreads], if test "x$with_pthreads" != x && test "x$with_pthreads" != "xyes" && test "x$with_pthreads" != "xno"; then LIBS="$LIBS -L$with_pthreads/lib" - CPPFLAGS="-I$with_pthreads/include $CPPFLAGS" + AM_CPPFLAGS="-I$with_pthreads/include $AM_CPPFLAGS" fi ACX_PTHREAD([], [AC_MSG_ERROR(pthread-compatible library is required to build CFEngine)]) CC="$PTHREAD_CC" -CFLAGS="$PTHREAD_CFLAGS $CFLAGS" +AM_CFLAGS="$PTHREAD_CFLAGS $AM_CFLAGS" LIBS="$PTHREAD_LIBS $LIBS" dnl ###################################################################### @@ -247,7 +264,7 @@ AS_CASE([${target_os}], [mingw*], # Disable printf format warnings, because our wrapper supports more # flags than vanilla Windows version, so they are false positives. - [CFLAGS="$CFLAGS -Wno-format"]) + [AM_CFLAGS="$AM_CFLAGS -Wno-format"]) dnl ###################################################################### dnl Checks for libraries. @@ -485,7 +502,7 @@ AC_TYPE_OFF_T # off_t, which causes a conflict. # if test "x$ac_cv_sys_large_files" = x1; then - CPPFLAGS="-D_LARGE_FILES=1 $CPPFLAGS" + AM_CPPFLAGS="-D_LARGE_FILES=1 $AM_CPPFLAGS" fi dnl ###################################################################### @@ -995,7 +1012,7 @@ case "$target_os" in AC_DEFINE(_PSTAT64, 1, [Enable wide data structures everywhere]) ;; aix*) - CPPFLAGS="$CPPFLAGS -w" + AM_CPPFLAGS="$AM_CPPFLAGS -w" ;; linux*|*bsd*|*gnu*) AC_CHECK_LIB(nss_nis, yp_get_default_domain) @@ -1207,7 +1224,7 @@ dnl ##################################################################### AC_PATH_PROG(HOSTNAME, hostname, "", $PATH) AC_DEFINE_UNQUOTED(AUTOCONF_HOSTNAME, "`$HOSTNAME`", [Special CFEngine symbol]) -AC_DEFINE_UNQUOTED(AUTOCONF_SYSNAME, "$target_os", [Speial CFEngine symbol]) +AC_DEFINE_UNQUOTED(AUTOCONF_SYSNAME, "$target_os", [Special CFEngine symbol]) dnl ##################################################################### @@ -1258,8 +1275,8 @@ if test "x$use_coverage" = "xyes"; then changequote([,]) dnl Add the special gcc flags - CFLAGS="$CFLAGS -fprofile-arcs -ftest-coverage" - LDFLAGS="$LDFLAGS -lgcov" + AM_CFLAGS="$AM_CFLAGS -fprofile-arcs -ftest-coverage" + AM_LDFLAGS="$AM_LDFLAGS -lgcov" # Need to set ENABLE_COVERAGE so that tests/unit/Makefile.am can adapt for one # test which needs gcov stubs if core not built with coverage. AM_CONDITIONAL([ENABLE_COVERAGE], true) @@ -1271,19 +1288,19 @@ dnl ###################################################################### dnl Collect all the options dnl ###################################################################### -CORE_CPPFLAGS="$PCRE2_CPPFLAGS $OPENSSL_CPPFLAGS $LIBYAML_CPPFLAGS" -CORE_CFLAGS="$PCRE2_CFLAGS $OPENSSL_CFLAGS $LIBYAML_CFLAGS" -CORE_LDFLAGS="$PCRE2_LDFLAGS $OPENSSL_LDFLAGS $LIBYAML_LDFLAGS" -CORE_LIBS="$PCRE2_LIBS $OPENSSL_LIBS $LIBYAML_LIBS" +AM_CPPFLAGS="$PCRE2_CPPFLAGS $OPENSSL_CPPFLAGS $LIBYAML_CPPFLAGS $AM_CPPFLAGS" +AM_CFLAGS="$PCRE2_CFLAGS $OPENSSL_CFLAGS $LIBYAML_CFLAGS $AM_CFLAGS $ENV_CFLAGS" +AM_LDFLAGS="$PCRE2_LDFLAGS $OPENSSL_LDFLAGS $LIBYAML_LDFLAGS $AM_LDFLAGS" +AM_LIBS="$PCRE2_LIBS $OPENSSL_LIBS $LIBYAML_LIBS $AM_LIBS" dnl ###################################################################### dnl Make them available to subprojects. dnl ###################################################################### -AC_SUBST([CORE_CPPFLAGS]) -AC_SUBST([CORE_CFLAGS]) -AC_SUBST([CORE_LDFLAGS]) -AC_SUBST([CORE_LIBS]) +AC_SUBST([AM_CFLAGS]) +AC_SUBST([AM_CPPFLAGS]) +AC_SUBST([AM_LDFLAGS]) +AC_SUBST([AM_LIBS]) # # Populate contents of config.post.h @@ -1310,7 +1327,7 @@ dnl ###################################################################### dnl Summarize dnl ###################################################################### -AC_MSG_RESULT( ) +AC_MSG_RESULT AC_MSG_RESULT(Summary:) AC_MSG_RESULT(> Version: AC_PACKAGE_VERSION) @@ -1327,7 +1344,7 @@ else AC_MSG_RESULT([-> libyaml: disabled]) fi -AC_MSG_RESULT( ) +AC_MSG_RESULT dnl ###################################################################### dnl Now make the Makefiles diff --git a/libutils/Makefile.am b/libutils/Makefile.am index 86d374ef..645cd805 100644 --- a/libutils/Makefile.am +++ b/libutils/Makefile.am @@ -23,9 +23,6 @@ noinst_LTLIBRARIES = libutils.la # TODO remove the openssl dependency! It's only there for base64 encoding. -AM_CFLAGS = $(CORE_CFLAGS) $(PCRE2_CFLAGS) $(OPENSSL_CFLAGS) -AM_CPPFLAGS = $(CORE_CPPFLAGS) $(PCRE2_CPPFLAGS) $(OPENSSL_CPPFLAGS) -AM_LDFLAGS = $(CORE_LDFLAGS) $(PCRE2_LDFLAGS) $(OPENSSL_LDFLAGS) libutils_la_LIBADD = ../libcompat/libcompat.la $(PCRE2_LIBS) $(OPENSSL_LIBS) $(SYSTEMD_LOGGING_LIBS) $(LIBYAML_LIBS) diff --git a/libutils/mustache.c b/libutils/mustache.c index 580834f8..07bd9cdc 100644 --- a/libutils/mustache.c +++ b/libutils/mustache.c @@ -579,7 +579,7 @@ static bool IsKeyExtensionVar(TagType tag_type, const char *tag_start, return true; } - /* the special case of unescaped form using {{{@}}} iff "{{" and "}}" are + /* the special case of unescaped form using {{{@}}} if "{{" and "}}" are * used as delimiters */ if ((delim_start_len == 2) && (delim_end_len == 2) && StringEqual(delim_start, "{{") && diff --git a/m4/acinclude.m4 b/m4/acinclude.m4 index 52d29d04..37898c78 100644 --- a/m4/acinclude.m4 +++ b/m4/acinclude.m4 @@ -3,7 +3,7 @@ dnl From http://ac-archive.sourceforge.net/ac-archive/acx_pthread.html AC_DEFUN([ACX_PTHREAD], [ AC_REQUIRE([AC_CANONICAL_HOST]) AC_LANG_SAVE -AC_LANG_C +AC_LANG(C) acx_pthread_ok=no # We used to check for pthread.h first, but this fails if pthread.h @@ -105,7 +105,7 @@ for flag in $acx_pthread_flags; do save_LIBS="$LIBS" save_CFLAGS="$CFLAGS" LIBS="$PTHREAD_LIBS $LIBS" - CFLAGS="$PTHREAD_CFLAGS" + CFLAGS="$CFLAGS $PTHREAD_CFLAGS" # Check for various functions. We must include pthread.h, # since some functions may be macros. (On the Sequent, we @@ -116,11 +116,24 @@ for flag in $acx_pthread_flags; do # pthread_cleanup_push because it is one of the few pthread # functions on Solaris that doesn't have a non-functional libc stub. # We try pthread_create on general principles. - AC_TRY_LINK([#include ], - [pthread_t th; pthread_join(th, 0); - pthread_attr_init(0); pthread_cleanup_push(0, 0); - pthread_create(0,0,0,0); pthread_cleanup_pop(0); ], - [acx_pthread_ok=yes]) + # https://github.com/autoconf-archive/autoconf-archive/blob/master/m4/ax_pthread.m4 + AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include + static void *some_global = NULL; + static void routine(void *a) { + /* To avoid any unused-parameter or + unused-but-set-parameter warning. */ + some_global = a; + } + static void *start_routine(void *a) { return a; }]], + [pthread_t th; pthread_attr_t attr; + pthread_create(&th,0,start_routine,0); + pthread_join(th, 0); + pthread_attr_init(&attr); + pthread_cleanup_push(routine, 0); + pthread_cleanup_pop(0);])], + [acx_pthread_ok=yes], + [acx_pthread_ok=no] + ) LIBS="$save_LIBS" CFLAGS="$save_CFLAGS" @@ -146,8 +159,11 @@ if test "x$acx_pthread_ok" = xyes; then AC_MSG_CHECKING([for joinable pthread attribute]) attr_name=unknown for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do - AC_TRY_LINK([#include ], [int attr=$attr; return attr;], - [attr_name=$attr; break]) + AC_LINK_IFELSE([AC_LANG_PROGRAM( + [#include ], + [int attr = $attr; return attr /* ; */])], + [attr_name=$attr; break]) + done AC_MSG_RESULT($attr_name) if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then diff --git a/m4/cf3_gcc_flags.m4 b/m4/cf3_gcc_flags.m4 index 86dcab56..adfcbd20 100644 --- a/m4/cf3_gcc_flags.m4 +++ b/m4/cf3_gcc_flags.m4 @@ -28,10 +28,10 @@ AC_PREPROC_IFELSE([AC_LANG_SOURCE([[ #if defined __HP_cc #This is HP-UX ANSI C #endif -]])], [ -HP_UX_AC="no"], [ -CFLAGS="$CFLAGS -Agcc" -CPPFLAGS="$CPPFLAGS -Agcc" +]])], +[HP_UX_AC="no"], +[AM_CFLAGS="$AM_CFLAGS -Agcc" +AM_CPPFLAGS="$AM_CPPFLAGS -Agcc" HP_UX_AC="yes"]) AC_MSG_CHECKING(for HP-UX aC) @@ -43,33 +43,35 @@ fi AC_MSG_CHECKING(for GCC specific compile flags) if test x"$GCC" = "xyes" && test x"$HP_UX_AC" != x"yes"; then - CFLAGS="$CFLAGS -g -Wall" - CPPFLAGS="$CPPFLAGS -std=gnu99" + AM_CFLAGS="$AM_CFLAGS -Wall" AC_MSG_RESULT(yes) save_CFLAGS="$CFLAGS" CFLAGS="$CFLAGS -Wno-pointer-sign" AC_MSG_CHECKING(for -Wno-pointer-sign) AC_COMPILE_IFELSE([AC_LANG_SOURCE([int main() {}])], - [AC_MSG_RESULT(yes)], - [AC_MSG_RESULT(no) - CFLAGS="$save_CFLAGS"]) + [AC_MSG_RESULT(yes) + AM_CFLAGS="$AM_CFLAGS -Wno-pointer-sign"], + [AC_MSG_RESULT(no)]) + CFLAGS="$save_CFLAGS" save_CFLAGS="$CFLAGS" CFLAGS="$CFLAGS -Werror=implicit-function-declaration" AC_MSG_CHECKING(for -Werror=implicit-function-declaration) AC_COMPILE_IFELSE([AC_LANG_SOURCE([int main() {}])], - [AC_MSG_RESULT(yes)], - [AC_MSG_RESULT(no) - CFLAGS="$save_CFLAGS"]) + [AC_MSG_RESULT(yes) + AM_CFLAGS="$AM_CFLAGS -Werror=implicit-function-declaration"], + [AC_MSG_RESULT(no)]) + CFLAGS="$save_CFLAGS" save_CFLAGS="$CFLAGS" CFLAGS="$CFLAGS -Wunused-parameter" AC_MSG_CHECKING(for -Wunused-parameter) AC_COMPILE_IFELSE([AC_LANG_SOURCE([int main() {}])], - [AC_MSG_RESULT(yes)], - [AC_MSG_RESULT(no) - CFLAGS="$save_CFLAGS"]) + [AC_MSG_RESULT(yes) + AM_CFLAGS="$AM_CFLAGS -Wunused-parameter"], + [AC_MSG_RESULT(no)]) + CFLAGS="$save_CFLAGS" dnl Clang does not like 'const const' construct arising from dnl expansion of TYPED_SET_DECLARE macro @@ -83,7 +85,7 @@ if test x"$GCC" = "xyes" && test x"$HP_UX_AC" != x"yes"; then #endif int main() {}])], [AC_MSG_RESULT(yes) - CFLAGS="$save_CFLAGS -Wno-duplicate-decl-specifier"], + AM_CFLAGS="$AM_CFLAGS -Wno-duplicate-decl-specifier"], [AC_MSG_RESULT(no)]) else AC_MSG_RESULT(no) diff --git a/tests/unit/Makefile.am b/tests/unit/Makefile.am index 3ba73816..5b6d4afc 100644 --- a/tests/unit/Makefile.am +++ b/tests/unit/Makefile.am @@ -23,10 +23,9 @@ # Just recursively include in dist tarball all data we need for unit tests EXTRA_DIST = data -AM_CPPFLAGS = $(CORE_CPPFLAGS) \ - $(ENTERPRISE_CFLAGS) \ +AM_CPPFLAGS += $(ENTERPRISE_CFLAGS) \ -I$(srcdir)/../../libutils \ - -DTESTDATADIR='"$(srcdir)/data"' + -DTESTDATADIR='"$(srcdir)/$(EXTRA_DIST)"' LDADD = libtest.la @@ -34,10 +33,6 @@ LDADD = libtest.la # the generic LIBS one. In case the functions are mocked in the test # implementation, then we are pretty sure that they will be overriden by # our local implementation. So we include *everything*... -LIBS = $(CORE_LIBS) -AM_LDFLAGS = $(CORE_LDFLAGS) - -AM_CFLAGS = $(CORE_CFLAGS) $(PTHREAD_CFLAGS) check_LTLIBRARIES = libtest.la @@ -116,7 +111,7 @@ refcount_test_SOURCES = refcount_test.c buffer_test_SOURCES = buffer_test.c # Workaround for object file basename conflicts, search the web for # "automake created with both libtool and without" -buffer_test_CPPFLAGS = $(AM_CPPFLAGS) +# buffer_test_CPPFLAGS = $(AM_CPPFLAGS) csv_parser_test_SOURCES = csv_parser_test.c csv_parser_test_LDADD = libtest.la @@ -137,7 +132,6 @@ file_lib_test_SOURCES = file_lib_test.c file_lib_test_CPPFLAGS = $(AM_CPPFLAGS) -DTEST_SYMLINK_ATOMICITY ipaddress_test_SOURCES = ipaddress_test.c -ipaddress_test_CPPFLAGS = $(AM_CPPFLAGS) logging_timestamp_test_SOURCES = logging_timestamp_test.c \ ../../libutils/logging.h