summaryrefslogtreecommitdiff
path: root/m4
diff options
context:
space:
mode:
Diffstat (limited to 'm4')
-rw-r--r--m4/ax_check_user_namespace.m454
-rw-r--r--m4/ax_check_uts_namespace.m476
-rw-r--r--m4/ax_code_coverage.m4219
-rw-r--r--m4/ax_cxx_compile_stdcxx_11.m4163
-rw-r--r--m4/ax_pthread.m4332
-rw-r--r--m4/cares-confopts.m442
-rw-r--r--m4/xc-am-iface.m4253
7 files changed, 1139 insertions, 0 deletions
diff --git a/m4/ax_check_user_namespace.m4 b/m4/ax_check_user_namespace.m4
new file mode 100644
index 0000000..27ba698
--- /dev/null
+++ b/m4/ax_check_user_namespace.m4
@@ -0,0 +1,54 @@
+# -*- Autoconf -*-
+
+# SYNOPSIS
+#
+# AX_CHECK_USER_NAMESPACE
+#
+# DESCRIPTION
+#
+# This macro checks whether the local system supports Linux user namespaces.
+# If so, it calls AC_DEFINE(HAVE_USER_NAMESPACE).
+
+AC_DEFUN([AX_CHECK_USER_NAMESPACE],[dnl
+ AC_CACHE_CHECK([whether user namespaces are supported],
+ ax_cv_user_namespace,[
+ AC_LANG_PUSH([C])
+ AC_RUN_IFELSE([AC_LANG_SOURCE([[
+#define _GNU_SOURCE
+#include <fcntl.h>
+#include <sched.h>
+#include <signal.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+int userfn(void *d) {
+ usleep(100000); /* synchronize by sleep */
+ return (getuid() != 0);
+}
+char userst[1024*1024];
+int main() {
+ char buffer[1024];
+ int rc, status, fd;
+ pid_t child = clone(userfn, userst + 1024*1024, CLONE_NEWUSER|SIGCHLD, 0);
+ if (child < 0) return 1;
+
+ sprintf(buffer, "/proc/%d/uid_map", child);
+ fd = open(buffer, O_CREAT|O_WRONLY|O_TRUNC, 0755);
+ sprintf(buffer, "0 %d 1\n", getuid());
+ write(fd, buffer, strlen(buffer));
+ close(fd);
+
+ rc = waitpid(child, &status, 0);
+ if (rc <= 0) return 1;
+ if (!WIFEXITED(status)) return 1;
+ return WEXITSTATUS(status);
+}
+ ]])],[ax_cv_user_namespace=yes],[ax_cv_user_namespace=no],[ax_cv_user_namespace=no])
+ AC_LANG_POP([C])
+ ])
+ if test "$ax_cv_user_namespace" = yes; then
+ AC_DEFINE([HAVE_USER_NAMESPACE],[1],[Whether user namespaces are available])
+ fi
+]) # AX_CHECK_USER_NAMESPACE
diff --git a/m4/ax_check_uts_namespace.m4 b/m4/ax_check_uts_namespace.m4
new file mode 100644
index 0000000..cf7b145
--- /dev/null
+++ b/m4/ax_check_uts_namespace.m4
@@ -0,0 +1,76 @@
+# -*- Autoconf -*-
+
+# SYNOPSIS
+#
+# AX_CHECK_UTS_NAMESPACE
+#
+# DESCRIPTION
+#
+# This macro checks whether the local system supports Linux UTS namespaces.
+# Also requires user namespaces to be available, so that non-root users
+# can enter the namespace.
+# If so, it calls AC_DEFINE(HAVE_UTS_NAMESPACE).
+
+AC_DEFUN([AX_CHECK_UTS_NAMESPACE],[dnl
+ AC_CACHE_CHECK([whether UTS namespaces are supported],
+ ax_cv_uts_namespace,[
+ AC_LANG_PUSH([C])
+ AC_RUN_IFELSE([AC_LANG_SOURCE([[
+#define _GNU_SOURCE
+#include <sched.h>
+#include <signal.h>
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+int utsfn(void *d) {
+ char buffer[1024];
+ const char *name = "autoconftest";
+ int rc = sethostname(name, strlen(name));
+ if (rc != 0) return 1;
+ gethostname(buffer, 1024);
+ return (strcmp(buffer, name) != 0);
+}
+
+char st2[1024*1024];
+int fn(void *d) {
+ pid_t child;
+ int rc, status;
+ usleep(100000); /* synchronize by sleep */
+ if (getuid() != 0) return 1;
+ child = clone(utsfn, st2 + 1024*1024, CLONE_NEWUTS|SIGCHLD, 0);
+ if (child < 0) return 1;
+ rc = waitpid(child, &status, 0);
+ if (rc <= 0) return 1;
+ if (!WIFEXITED(status)) return 1;
+ return WEXITSTATUS(status);
+}
+char st[1024*1024];
+int main() {
+ char buffer[1024];
+ int rc, status, fd;
+ pid_t child = clone(fn, st + 1024*1024, CLONE_NEWUSER|SIGCHLD, 0);
+ if (child < 0) return 1;
+
+ sprintf(buffer, "/proc/%d/uid_map", child);
+ fd = open(buffer, O_CREAT|O_WRONLY|O_TRUNC, 0755);
+ sprintf(buffer, "0 %d 1\n", getuid());
+ write(fd, buffer, strlen(buffer));
+ close(fd);
+
+ rc = waitpid(child, &status, 0);
+ if (rc <= 0) return 1;
+ if (!WIFEXITED(status)) return 1;
+ return WEXITSTATUS(status);
+}
+]])
+ ],[ax_cv_uts_namespace=yes],[ax_cv_uts_namespace=no],[ax_cv_uts_namespace=no])
+ AC_LANG_POP([C])
+ ])
+ if test "$ax_cv_uts_namespace" = yes; then
+ AC_DEFINE([HAVE_UTS_NAMESPACE],[1],[Whether UTS namespaces are available])
+ fi
+]) # AX_CHECK_UTS_NAMESPACE
diff --git a/m4/ax_code_coverage.m4 b/m4/ax_code_coverage.m4
new file mode 100644
index 0000000..5120c3b
--- /dev/null
+++ b/m4/ax_code_coverage.m4
@@ -0,0 +1,219 @@
+# ===========================================================================
+# http://www.gnu.org/software/autoconf-archive/ax_code_coverage.html
+# ===========================================================================
+#
+# SYNOPSIS
+#
+# AX_CODE_COVERAGE()
+#
+# DESCRIPTION
+#
+# Defines CODE_COVERAGE_CFLAGS and CODE_COVERAGE_LDFLAGS which should be
+# included in the CFLAGS and LIBS/LDFLAGS variables of every build target
+# (program or library) which should be built with code coverage support.
+# Also defines CODE_COVERAGE_RULES which should be substituted in your
+# Makefile; and $enable_code_coverage which can be used in subsequent
+# configure output. CODE_COVERAGE_ENABLED is defined and substituted, and
+# corresponds to the value of the --enable-code-coverage option, which
+# defaults to being disabled.
+#
+# Test also for gcov program and create GCOV variable that could be
+# substituted.
+#
+# Note that all optimisation flags in CFLAGS must be disabled when code
+# coverage is enabled.
+#
+# Usage example:
+#
+# configure.ac:
+#
+# AX_CODE_COVERAGE
+#
+# Makefile.am:
+#
+# @CODE_COVERAGE_RULES@
+# my_program_LIBS = ... $(CODE_COVERAGE_LDFLAGS) ...
+# my_program_CFLAGS = ... $(CODE_COVERAGE_CFLAGS) ...
+#
+# This results in a "check-code-coverage" rule being added to any
+# Makefile.am which includes "@CODE_COVERAGE_RULES@" (assuming the module
+# has been configured with --enable-code-coverage). Running `make
+# check-code-coverage` in that directory will run the module's test suite
+# (`make check`) and build a code coverage report detailing the code which
+# was touched, then print the URI for the report.
+#
+# This code was derived from Makefile.decl in GLib, originally licenced
+# under LGPLv2.1+.
+#
+# LICENSE
+#
+# Copyright (c) 2012 Philip Withnall
+# Copyright (c) 2012 Xan Lopez
+# Copyright (c) 2012 Christian Persch
+# Copyright (c) 2012 Paolo Borelli
+# Copyright (c) 2012 Dan Winship
+# Copyright (c) 2015 Bastien ROUCARIES
+#
+# This library is free software; you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation; either version 2.1 of the License, or (at
+# your option) any later version.
+#
+# This library is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
+# General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#serial 5
+
+AC_DEFUN([AX_CODE_COVERAGE],[
+ dnl Check for --enable-code-coverage
+ AC_REQUIRE([AC_PROG_SED])
+
+ # allow to override gcov location
+ AC_ARG_WITH([gcov],
+ [AS_HELP_STRING([--with-gcov[=GCOV]], [use given GCOV for coverage (GCOV=gcov).])],
+ [_AX_CODE_COVERAGE_GCOV_PROG_WITH=$with_gcov],
+ [_AX_CODE_COVERAGE_GCOV_PROG_WITH=gcov])
+
+ AC_MSG_CHECKING([whether to build with code coverage support])
+ AC_ARG_ENABLE([code-coverage],
+ AS_HELP_STRING([--enable-code-coverage],
+ [Whether to enable code coverage support]),,
+ enable_code_coverage=no)
+
+ AM_CONDITIONAL([CODE_COVERAGE_ENABLED], [test x$enable_code_coverage = xyes])
+ AC_SUBST([CODE_COVERAGE_ENABLED], [$enable_code_coverage])
+ AC_MSG_RESULT($enable_code_coverage)
+
+ AS_IF([ test "$enable_code_coverage" = "yes" ], [
+ # check for gcov
+ AC_CHECK_TOOL([GCOV],
+ [$_AX_CODE_COVERAGE_GCOV_PROG_WITH],
+ [:])
+ AS_IF([test "X$GCOV" = "X:"],
+ [AC_MSG_ERROR([gcov is needed to do coverage])])
+ AC_SUBST([GCOV])
+
+ dnl Check if gcc is being used
+ AS_IF([ test "$GCC" = "no" ], [
+ AC_MSG_ERROR([not compiling with gcc, which is required for gcov code coverage])
+ ])
+
+ # List of supported lcov versions.
+ lcov_version_list="1.6 1.7 1.8 1.9 1.10 1.11"
+
+ AC_CHECK_PROG([LCOV], [lcov], [lcov])
+ AC_CHECK_PROG([GENHTML], [genhtml], [genhtml])
+
+ AS_IF([ test "$LCOV" ], [
+ AC_CACHE_CHECK([for lcov version], ax_cv_lcov_version, [
+ ax_cv_lcov_version=invalid
+ lcov_version=`$LCOV -v 2>/dev/null | $SED -e 's/^.* //'`
+ for lcov_check_version in $lcov_version_list; do
+ if test "$lcov_version" = "$lcov_check_version"; then
+ ax_cv_lcov_version="$lcov_check_version (ok)"
+ fi
+ done
+ ])
+ ], [
+ lcov_msg="To enable code coverage reporting you must have one of the following lcov versions installed: $lcov_version_list"
+ AC_MSG_ERROR([$lcov_msg])
+ ])
+
+ case $ax_cv_lcov_version in
+ ""|invalid[)]
+ lcov_msg="You must have one of the following versions of lcov: $lcov_version_list (found: $lcov_version)."
+ AC_MSG_ERROR([$lcov_msg])
+ LCOV="exit 0;"
+ ;;
+ esac
+
+ AS_IF([ test -z "$GENHTML" ], [
+ AC_MSG_ERROR([Could not find genhtml from the lcov package])
+ ])
+
+ dnl Build the code coverage flags
+ CODE_COVERAGE_CFLAGS="-O0 -g -fprofile-arcs -ftest-coverage"
+ CODE_COVERAGE_LDFLAGS="-lgcov"
+
+ AC_SUBST([CODE_COVERAGE_CFLAGS])
+ AC_SUBST([CODE_COVERAGE_LDFLAGS])
+
+CODE_COVERAGE_RULES='
+# Code coverage
+#
+# Optional:
+# - CODE_COVERAGE_DIRECTORY: Top-level directory for code coverage reporting.
+# (Default: $(top_builddir))
+# - CODE_COVERAGE_OUTPUT_FILE: Filename and path for the .info file generated
+# by lcov for code coverage. (Default:
+# $(PACKAGE_NAME)-$(PACKAGE_VERSION)-coverage.info)
+# - CODE_COVERAGE_OUTPUT_DIRECTORY: Directory for generated code coverage
+# reports to be created. (Default:
+# $(PACKAGE_NAME)-$(PACKAGE_VERSION)-coverage)
+# - CODE_COVERAGE_LCOV_OPTIONS_GCOVPATH: --gcov-tool pathtogcov
+# - CODE_COVERAGE_LCOV_OPTIONS_DEFAULT: Extra options to pass to the lcov instance.
+# (Default: $CODE_COVERAGE_LCOV_OPTIONS_GCOVPATH)
+# - CODE_COVERAGE_LCOV_OPTIONS: Extra options to pass to the lcov instance.
+# (Default: $CODE_COVERAGE_LCOV_OPTIONS_DEFAULT)
+# - CODE_COVERAGE_GENHTML_OPTIONS: Extra options to pass to the genhtml
+# instance. (Default: empty)
+# - CODE_COVERAGE_IGNORE_PATTERN: Extra glob pattern of files to ignore
+#
+# The generated report will be titled using the $(PACKAGE_NAME) and
+# $(PACKAGE_VERSION). In order to add the current git hash to the title,
+# use the git-version-gen script, available online.
+
+# Optional variables
+CODE_COVERAGE_DIRECTORY ?= $(top_builddir)
+CODE_COVERAGE_OUTPUT_FILE ?= $(PACKAGE_NAME)-$(PACKAGE_VERSION)-coverage.info
+CODE_COVERAGE_OUTPUT_DIRECTORY ?= $(PACKAGE_NAME)-$(PACKAGE_VERSION)-coverage
+CODE_COVERAGE_LCOV_OPTIONS_GCOVPATH ?= --gcov-tool "$(GCOV)"
+CODE_COVERAGE_LCOV_OPTIONS_DEFAULT ?= $(CODE_COVERAGE_LCOV_OPTIONS_GCOVPATH)
+CODE_COVERAGE_LCOV_OPTIONS ?= $(CODE_COVERAGE_LCOV_OPTIONS_DEFAULT)
+CODE_COVERAGE_GENHTML_OPTIONS ?=
+CODE_COVERAGE_IGNORE_PATTERN ?=
+
+code_coverage_quiet = $(code_coverage_quiet_$(V))
+code_coverage_quiet_ =
+code_coverage_quiet_0 = --quiet
+
+# Use recursive makes in order to ignore errors during check
+check-code-coverage:
+ -$(MAKE) $(AM_MAKEFLAGS) -k check
+ $(MAKE) $(AM_MAKEFLAGS) code-coverage-capture
+
+# Capture code coverage data
+code-coverage-capture: code-coverage-capture-hook
+ $(LCOV) $(code_coverage_quiet) --directory $(CODE_COVERAGE_DIRECTORY) --capture --output-file "$(CODE_COVERAGE_OUTPUT_FILE).tmp" --test-name "$(PACKAGE_NAME)-$(PACKAGE_VERSION)" --no-checksum --compat-libtool $(CODE_COVERAGE_LCOV_OPTIONS)
+ $(LCOV) $(code_coverage_quiet) --directory $(CODE_COVERAGE_DIRECTORY) --remove "$(CODE_COVERAGE_OUTPUT_FILE).tmp" "/tmp/*" $(CODE_COVERAGE_IGNORE_PATTERN) --output-file "$(CODE_COVERAGE_OUTPUT_FILE)"
+ -@rm -f $(CODE_COVERAGE_OUTPUT_FILE).tmp
+ LANG=C $(GENHTML) $(code_coverage_quiet) --prefix $(CODE_COVERAGE_DIRECTORY) --output-directory "$(CODE_COVERAGE_OUTPUT_DIRECTORY)" --title "$(PACKAGE_NAME)-$(PACKAGE_VERSION) Code Coverage" --legend --show-details "$(CODE_COVERAGE_OUTPUT_FILE)" $(CODE_COVERAGE_GENHTML_OPTIONS)
+ @echo "file://$(abs_builddir)/$(CODE_COVERAGE_OUTPUT_DIRECTORY)/index.html"
+
+# Hook rule executed before code-coverage-capture, overridable by the user
+code-coverage-capture-hook:
+
+clean: code-coverage-clean
+code-coverage-clean:
+ -$(LCOV) --directory $(top_builddir) -z
+ -rm -rf $(CODE_COVERAGE_OUTPUT_FILE) $(CODE_COVERAGE_OUTPUT_FILE).tmp $(CODE_COVERAGE_OUTPUT_DIRECTORY)
+ -find . -name "*.gcda" -o -name "*.gcov" -delete
+
+GITIGNOREFILES ?=
+GITIGNOREFILES += $(CODE_COVERAGE_OUTPUT_FILE) $(CODE_COVERAGE_OUTPUT_DIRECTORY)
+
+DISTCHECK_CONFIGURE_FLAGS ?=
+DISTCHECK_CONFIGURE_FLAGS += --disable-code-coverage
+
+.PHONY: check-code-coverage code-coverage-capture code-coverage-capture-hook code-coverage-clean
+'
+ AC_SUBST([CODE_COVERAGE_RULES])
+ ])
+
+ m4_ifdef([_AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE([CODE_COVERAGE_RULES])])
+])
diff --git a/m4/ax_cxx_compile_stdcxx_11.m4 b/m4/ax_cxx_compile_stdcxx_11.m4
new file mode 100644
index 0000000..229de30
--- /dev/null
+++ b/m4/ax_cxx_compile_stdcxx_11.m4
@@ -0,0 +1,163 @@
+# ============================================================================
+# http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_11.html
+# ============================================================================
+#
+# SYNOPSIS
+#
+# AX_CXX_COMPILE_STDCXX_11([ext|noext],[mandatory|optional])
+#
+# DESCRIPTION
+#
+# Check for baseline language coverage in the compiler for the C++11
+# standard; if necessary, add switches to CXXFLAGS to enable support.
+#
+# The first argument, if specified, indicates whether you insist on an
+# extended mode (e.g. -std=gnu++11) or a strict conformance mode (e.g.
+# -std=c++11). If neither is specified, you get whatever works, with
+# preference for an extended mode.
+#
+# The second argument, if specified 'mandatory' or if left unspecified,
+# indicates that baseline C++11 support is required and that the macro
+# should error out if no mode with that support is found. If specified
+# 'optional', then configuration proceeds regardless, after defining
+# HAVE_CXX11 if and only if a supporting mode is found.
+#
+# LICENSE
+#
+# Copyright (c) 2008 Benjamin Kosnik <bkoz@redhat.com>
+# Copyright (c) 2012 Zack Weinberg <zackw@panix.com>
+# Copyright (c) 2013 Roy Stogner <roystgnr@ices.utexas.edu>
+# Copyright (c) 2014, 2015 Google Inc.; contributed by Alexey Sokolov <sokolov@google.com>
+#
+# 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 9
+
+m4_define([_AX_CXX_COMPILE_STDCXX_11_testbody], [[
+ template <typename T>
+ struct check
+ {
+ static_assert(sizeof(int) <= sizeof(T), "not big enough");
+ };
+
+ struct Base {
+ virtual void f() {}
+ };
+ struct Child : public Base {
+ virtual void f() override {}
+ };
+
+ typedef check<check<bool>> right_angle_brackets;
+
+ int a;
+ decltype(a) b;
+
+ typedef check<int> check_type;
+ check_type c;
+ check_type&& cr = static_cast<check_type&&>(c);
+
+ auto d = a;
+ auto l = [](){};
+
+ // http://stackoverflow.com/questions/13728184/template-aliases-and-sfinae
+ // Clang 3.1 fails with headers of libstd++ 4.8.3 when using std::function because of this
+ namespace test_template_alias_sfinae {
+ struct foo {};
+
+ template<typename T>
+ using member = typename T::member_type;
+
+ template<typename T>
+ void func(...) {}
+
+ template<typename T>
+ void func(member<T>*) {}
+
+ void test();
+
+ void test() {
+ func<foo>(0);
+ }
+ }
+]])
+
+AC_DEFUN([AX_CXX_COMPILE_STDCXX_11], [dnl
+ m4_if([$1], [], [],
+ [$1], [ext], [],
+ [$1], [noext], [],
+ [m4_fatal([invalid argument `$1' to AX_CXX_COMPILE_STDCXX_11])])dnl
+ m4_if([$2], [], [ax_cxx_compile_cxx11_required=true],
+ [$2], [mandatory], [ax_cxx_compile_cxx11_required=true],
+ [$2], [optional], [ax_cxx_compile_cxx11_required=false],
+ [m4_fatal([invalid second argument `$2' to AX_CXX_COMPILE_STDCXX_11])])
+ AC_LANG_PUSH([C++])dnl
+ ac_success=no
+ AC_CACHE_CHECK(whether $CXX supports C++11 features by default,
+ ax_cv_cxx_compile_cxx11,
+ [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
+ [ax_cv_cxx_compile_cxx11=yes],
+ [ax_cv_cxx_compile_cxx11=no])])
+ if test x$ax_cv_cxx_compile_cxx11 = xyes; then
+ ac_success=yes
+ fi
+
+ m4_if([$1], [noext], [], [dnl
+ if test x$ac_success = xno; then
+ for switch in -std=gnu++11 -std=gnu++0x; do
+ cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch])
+ AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch,
+ $cachevar,
+ [ac_save_CXXFLAGS="$CXXFLAGS"
+ CXXFLAGS="$CXXFLAGS $switch"
+ AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
+ [eval $cachevar=yes],
+ [eval $cachevar=no])
+ CXXFLAGS="$ac_save_CXXFLAGS"])
+ if eval test x\$$cachevar = xyes; then
+ CXXFLAGS="$CXXFLAGS $switch"
+ ac_success=yes
+ break
+ fi
+ done
+ fi])
+
+ m4_if([$1], [ext], [], [dnl
+ if test x$ac_success = xno; then
+ for switch in -std=c++11 -std=c++0x; do
+ cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch])
+ AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch,
+ $cachevar,
+ [ac_save_CXXFLAGS="$CXXFLAGS"
+ CXXFLAGS="$CXXFLAGS $switch"
+ AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
+ [eval $cachevar=yes],
+ [eval $cachevar=no])
+ CXXFLAGS="$ac_save_CXXFLAGS"])
+ if eval test x\$$cachevar = xyes; then
+ CXXFLAGS="$CXXFLAGS $switch"
+ ac_success=yes
+ break
+ fi
+ done
+ fi])
+ AC_LANG_POP([C++])
+ if test x$ax_cxx_compile_cxx11_required = xtrue; then
+ if test x$ac_success = xno; then
+ AC_MSG_ERROR([*** A compiler with support for C++11 language features is required.])
+ fi
+ else
+ if test x$ac_success = xno; then
+ HAVE_CXX11=0
+ AC_MSG_NOTICE([No compiler with C++11 support was found])
+ else
+ HAVE_CXX11=1
+ AC_DEFINE(HAVE_CXX11,1,
+ [define if the compiler supports basic C++11 syntax])
+ fi
+
+ AC_SUBST(HAVE_CXX11)
+ fi
+])
diff --git a/m4/ax_pthread.m4 b/m4/ax_pthread.m4
new file mode 100644
index 0000000..d383ad5
--- /dev/null
+++ b/m4/ax_pthread.m4
@@ -0,0 +1,332 @@
+# ===========================================================================
+# http://www.gnu.org/software/autoconf-archive/ax_pthread.html
+# ===========================================================================
+#
+# SYNOPSIS
+#
+# AX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
+#
+# DESCRIPTION
+#
+# This macro figures out how to build C programs using POSIX threads. It
+# sets the PTHREAD_LIBS output variable to the threads library and linker
+# flags, and the PTHREAD_CFLAGS output variable to any special C compiler
+# flags that are needed. (The user can also force certain compiler
+# flags/libs to be tested by setting these environment variables.)
+#
+# Also sets PTHREAD_CC to any special C compiler that is needed for
+# multi-threaded programs (defaults to the value of CC otherwise). (This
+# is necessary on AIX to use the special cc_r compiler alias.)
+#
+# NOTE: You are assumed to not only compile your program with these flags,
+# but also link it with them as well. e.g. you should link with
+# $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS $LIBS
+#
+# If you are only building threads programs, you may wish to use these
+# variables in your default LIBS, CFLAGS, and CC:
+#
+# LIBS="$PTHREAD_LIBS $LIBS"
+# CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
+# CC="$PTHREAD_CC"
+#
+# In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute constant
+# has a nonstandard name, defines PTHREAD_CREATE_JOINABLE to that name
+# (e.g. PTHREAD_CREATE_UNDETACHED on AIX).
+#
+# Also HAVE_PTHREAD_PRIO_INHERIT is defined if pthread is found and the
+# PTHREAD_PRIO_INHERIT symbol is defined when compiling with
+# PTHREAD_CFLAGS.
+#
+# ACTION-IF-FOUND is a list of shell commands to run if a threads library
+# is found, and ACTION-IF-NOT-FOUND is a list of commands to run it if it
+# is not found. If ACTION-IF-FOUND is not specified, the default action
+# will define HAVE_PTHREAD.
+#
+# Please let the authors know if this macro fails on any platform, or if
+# you have any other suggestions or comments. This macro was based on work
+# by SGJ on autoconf scripts for FFTW (http://www.fftw.org/) (with help
+# from M. Frigo), as well as ac_pthread and hb_pthread macros posted by
+# Alejandro Forero Cuervo to the autoconf macro repository. We are also
+# grateful for the helpful feedback of numerous users.
+#
+# Updated for Autoconf 2.68 by Daniel Richard G.
+#
+# LICENSE
+#
+# Copyright (c) 2008 Steven G. Johnson <stevenj@alum.mit.edu>
+# Copyright (c) 2011 Daniel Richard G. <skunk@iSKUNK.ORG>
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation, either version 3 of the License, or (at your
+# option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+# Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# As a special exception, the respective Autoconf Macro's copyright owner
+# gives unlimited permission to copy, distribute and modify the configure
+# scripts that are the output of Autoconf when processing the Macro. You
+# need not follow the terms of the GNU General Public License when using
+# or distributing such scripts, even though portions of the text of the
+# Macro appear in them. The GNU General Public License (GPL) does govern
+# all other use of the material that constitutes the Autoconf Macro.
+#
+# This special exception to the GPL applies to versions of the Autoconf
+# Macro released by the Autoconf Archive. When you make and distribute a
+# modified version of the Autoconf Macro, you may extend this special
+# exception to the GPL to apply to your modified version as well.
+
+#serial 21
+
+AU_ALIAS([ACX_PTHREAD], [AX_PTHREAD])
+AC_DEFUN([AX_PTHREAD], [
+AC_REQUIRE([AC_CANONICAL_HOST])
+AC_LANG_PUSH([C])
+ax_pthread_ok=no
+
+# We used to check for pthread.h first, but this fails if pthread.h
+# requires special compiler flags (e.g. on True64 or Sequent).
+# It gets checked for in the link test anyway.
+
+# First of all, check if the user has set any of the PTHREAD_LIBS,
+# etcetera environment variables, and if threads linking works using
+# them:
+if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then
+ save_CFLAGS="$CFLAGS"
+ CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
+ save_LIBS="$LIBS"
+ LIBS="$PTHREAD_LIBS $LIBS"
+ AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS])
+ AC_TRY_LINK_FUNC([pthread_join], [ax_pthread_ok=yes])
+ AC_MSG_RESULT([$ax_pthread_ok])
+ if test x"$ax_pthread_ok" = xno; then
+ PTHREAD_LIBS=""
+ PTHREAD_CFLAGS=""
+ fi
+ LIBS="$save_LIBS"
+ CFLAGS="$save_CFLAGS"
+fi
+
+# We must check for the threads library under a number of different
+# names; the ordering is very important because some systems
+# (e.g. DEC) have both -lpthread and -lpthreads, where one of the
+# libraries is broken (non-POSIX).
+
+# Create a list of thread flags to try. Items starting with a "-" are
+# C compiler flags, and other items are library names, except for "none"
+# which indicates that we try without any flags at all, and "pthread-config"
+# which is a program returning the flags for the Pth emulation library.
+
+ax_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config"
+
+# The ordering *is* (sometimes) important. Some notes on the
+# individual items follow:
+
+# pthreads: AIX (must check this before -lpthread)
+# none: in case threads are in libc; should be tried before -Kthread and
+# other compiler flags to prevent continual compiler warnings
+# -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
+# -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
+# lthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
+# -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads)
+# -pthreads: Solaris/gcc
+# -mthreads: Mingw32/gcc, Lynx/gcc
+# -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
+# doesn't hurt to check since this sometimes defines pthreads too;
+# also defines -D_REENTRANT)
+# ... -mt is also the pthreads flag for HP/aCC
+# pthread: Linux, etcetera
+# --thread-safe: KAI C++
+# pthread-config: use pthread-config program (for GNU Pth library)
+
+case ${host_os} in
+ solaris*)
+
+ # On Solaris (at least, for some versions), libc contains stubbed
+ # (non-functional) versions of the pthreads routines, so link-based
+ # tests will erroneously succeed. (We need to link with -pthreads/-mt/
+ # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather
+ # a function called by this macro, so we could check for that, but
+ # who knows whether they'll stub that too in a future libc.) So,
+ # we'll just look for -pthreads and -lpthread first:
+
+ ax_pthread_flags="-pthreads pthread -mt -pthread $ax_pthread_flags"
+ ;;
+
+ darwin*)
+ ax_pthread_flags="-pthread $ax_pthread_flags"
+ ;;
+esac
+
+# Clang doesn't consider unrecognized options an error unless we specify
+# -Werror. We throw in some extra Clang-specific options to ensure that
+# this doesn't happen for GCC, which also accepts -Werror.
+
+AC_MSG_CHECKING([if compiler needs -Werror to reject unknown flags])
+save_CFLAGS="$CFLAGS"
+ax_pthread_extra_flags="-Werror"
+CFLAGS="$CFLAGS $ax_pthread_extra_flags -Wunknown-warning-option -Wsizeof-array-argument"
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([int foo(void);],[foo()])],
+ [AC_MSG_RESULT([yes])],
+ [ax_pthread_extra_flags=
+ AC_MSG_RESULT([no])])
+CFLAGS="$save_CFLAGS"
+
+if test x"$ax_pthread_ok" = xno; then
+for flag in $ax_pthread_flags; do
+
+ case $flag in
+ none)
+ AC_MSG_CHECKING([whether pthreads work without any flags])
+ ;;
+
+ -*)
+ AC_MSG_CHECKING([whether pthreads work with $flag])
+ PTHREAD_CFLAGS="$flag"
+ ;;
+
+ pthread-config)
+ AC_CHECK_PROG([ax_pthread_config], [pthread-config], [yes], [no])
+ if test x"$ax_pthread_config" = xno; then continue; fi
+ PTHREAD_CFLAGS="`pthread-config --cflags`"
+ PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
+ ;;
+
+ *)
+ AC_MSG_CHECKING([for the pthreads library -l$flag])
+ PTHREAD_LIBS="-l$flag"
+ ;;
+ esac
+
+ save_LIBS="$LIBS"
+ save_CFLAGS="$CFLAGS"
+ LIBS="$PTHREAD_LIBS $LIBS"
+ CFLAGS="$CFLAGS $PTHREAD_CFLAGS $ax_pthread_extra_flags"
+
+ # Check for various functions. We must include pthread.h,
+ # since some functions may be macros. (On the Sequent, we
+ # need a special flag -Kthread to make this header compile.)
+ # We check for pthread_join because it is in -lpthread on IRIX
+ # while pthread_create is in libc. We check for pthread_attr_init
+ # due to DEC craziness with -lpthreads. We check for
+ # 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_LINK_IFELSE([AC_LANG_PROGRAM([#include <pthread.h>
+ static void routine(void *a) { a = 0; }
+ 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) /* ; */])],
+ [ax_pthread_ok=yes],
+ [])
+
+ LIBS="$save_LIBS"
+ CFLAGS="$save_CFLAGS"
+
+ AC_MSG_RESULT([$ax_pthread_ok])
+ if test "x$ax_pthread_ok" = xyes; then
+ break;
+ fi
+
+ PTHREAD_LIBS=""
+ PTHREAD_CFLAGS=""
+done
+fi
+
+# Various other checks:
+if test "x$ax_pthread_ok" = xyes; then
+ save_LIBS="$LIBS"
+ LIBS="$PTHREAD_LIBS $LIBS"
+ save_CFLAGS="$CFLAGS"
+ CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
+
+ # Detect AIX lossage: JOINABLE attribute is called UNDETACHED.
+ AC_MSG_CHECKING([for joinable pthread attribute])
+ attr_name=unknown
+ for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <pthread.h>],
+ [int attr = $attr; return attr /* ; */])],
+ [attr_name=$attr; break],
+ [])
+ done
+ AC_MSG_RESULT([$attr_name])
+ if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then
+ AC_DEFINE_UNQUOTED([PTHREAD_CREATE_JOINABLE], [$attr_name],
+ [Define to necessary symbol if this constant
+ uses a non-standard name on your system.])
+ fi
+
+ AC_MSG_CHECKING([if more special flags are required for pthreads])
+ flag=no
+ case ${host_os} in
+ aix* | freebsd* | darwin*) flag="-D_THREAD_SAFE";;
+ osf* | hpux*) flag="-D_REENTRANT";;
+ solaris*)
+ if test "$GCC" = "yes"; then
+ flag="-D_REENTRANT"
+ else
+ # TODO: What about Clang on Solaris?
+ flag="-mt -D_REENTRANT"
+ fi
+ ;;
+ esac
+ AC_MSG_RESULT([$flag])
+ if test "x$flag" != xno; then
+ PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS"
+ fi
+
+ AC_CACHE_CHECK([for PTHREAD_PRIO_INHERIT],
+ [ax_cv_PTHREAD_PRIO_INHERIT], [
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <pthread.h>]],
+ [[int i = PTHREAD_PRIO_INHERIT;]])],
+ [ax_cv_PTHREAD_PRIO_INHERIT=yes],
+ [ax_cv_PTHREAD_PRIO_INHERIT=no])
+ ])
+ AS_IF([test "x$ax_cv_PTHREAD_PRIO_INHERIT" = "xyes"],
+ [AC_DEFINE([HAVE_PTHREAD_PRIO_INHERIT], [1], [Have PTHREAD_PRIO_INHERIT.])])
+
+ LIBS="$save_LIBS"
+ CFLAGS="$save_CFLAGS"
+
+ # More AIX lossage: compile with *_r variant
+ if test "x$GCC" != xyes; then
+ case $host_os in
+ aix*)
+ AS_CASE(["x/$CC"],
+ [x*/c89|x*/c89_128|x*/c99|x*/c99_128|x*/cc|x*/cc128|x*/xlc|x*/xlc_v6|x*/xlc128|x*/xlc128_v6],
+ [#handle absolute path differently from PATH based program lookup
+ AS_CASE(["x$CC"],
+ [x/*],
+ [AS_IF([AS_EXECUTABLE_P([${CC}_r])],[PTHREAD_CC="${CC}_r"])],
+ [AC_CHECK_PROGS([PTHREAD_CC],[${CC}_r],[$CC])])])
+ ;;
+ esac
+ fi
+fi
+
+test -n "$PTHREAD_CC" || PTHREAD_CC="$CC"
+
+AC_SUBST([PTHREAD_LIBS])
+AC_SUBST([PTHREAD_CFLAGS])
+AC_SUBST([PTHREAD_CC])
+
+# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
+if test x"$ax_pthread_ok" = xyes; then
+ ifelse([$1],,[AC_DEFINE([HAVE_PTHREAD],[1],[Define if you have POSIX threads libraries and header files.])],[$1])
+ :
+else
+ ax_pthread_ok=no
+ $2
+fi
+AC_LANG_POP
+])dnl AX_PTHREAD
diff --git a/m4/cares-confopts.m4 b/m4/cares-confopts.m4
index 9d12a9b..135036a 100644
--- a/m4/cares-confopts.m4
+++ b/m4/cares-confopts.m4
@@ -219,6 +219,44 @@ AC_HELP_STRING([--disable-symbol-hiding],[Disable hiding of library internal sym
])
+dnl CARES_CHECK_OPTION_EXPOSE_STATICS
+dnl -------------------------------------------------
+dnl Verify if configure has been invoked with option
+dnl --enable-expose-statics or --disable-expose-statics,
+dnl setting shell variable want_expose_statics value.
+
+AC_DEFUN([CARES_CHECK_OPTION_EXPOSE_STATICS], [
+ AC_MSG_CHECKING([whether to expose internal static functions for testing])
+ OPT_EXPOSE_STATICS="default"
+ AC_ARG_ENABLE(expose-statics,
+AC_HELP_STRING([--enable-expose-statics],[Enable exposure of internal static functions for testing])
+AC_HELP_STRING([--disable-expose-statics],[Disable exposure of internal static functions for testing]),
+ OPT_EXPOSE_STATICS=$enableval)
+ case "$OPT_EXPOSE_STATICS" in
+ no)
+ dnl --disable-expose-statics option used.
+ want_expose_statics="no"
+ AC_MSG_RESULT([no])
+ ;;
+ default)
+ dnl configure's expose-statics option not specified.
+ dnl Handle this as if --disable-expose-statics option was given.
+ want_expose_statics="no"
+ AC_MSG_RESULT([no])
+ ;;
+ *)
+ dnl --enable-expose-statics option used.
+ want_expose_statics="yes"
+ AC_MSG_RESULT([yes])
+ ;;
+ esac
+ if test "$want_expose_statics" = "yes"; then
+ AC_DEFINE_UNQUOTED(CARES_EXPOSE_STATICS, 1,
+ [Defined for build that exposes internal static functions for testing.])
+ fi
+])
+
+
dnl CARES_CHECK_OPTION_WARNINGS
dnl -------------------------------------------------
dnl Verify if configure has been invoked with option
@@ -350,5 +388,9 @@ AC_DEFUN([CARES_CONFIGURE_SYMBOL_HIDING], [
fi
AM_CONDITIONAL(DOING_CARES_SYMBOL_HIDING, test x$doing_symbol_hiding = xyes)
AC_SUBST(CFLAG_CARES_SYMBOL_HIDING)
+ if test "$doing_symbol_hiding" = "yes"; then
+ AC_DEFINE_UNQUOTED(CARES_SYMBOL_HIDING, 1,
+ [Defined for build with symbol hiding.])
+ fi
])
diff --git a/m4/xc-am-iface.m4 b/m4/xc-am-iface.m4
new file mode 100644
index 0000000..1571c21
--- /dev/null
+++ b/m4/xc-am-iface.m4
@@ -0,0 +1,253 @@
+#---------------------------------------------------------------------------
+#
+# xc-am-iface.m4
+#
+# Copyright (c) 2013 Daniel Stenberg <daniel@haxx.se>
+#
+# Permission to use, copy, modify, and distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+#
+#---------------------------------------------------------------------------
+
+# serial 1
+
+
+dnl _XC_AUTOMAKE_BODY
+dnl -------------------------------------------------
+dnl Private macro.
+dnl
+dnl This macro performs embedding of automake initialization
+dnl code into configure script. When automake version 1.14 or
+dnl newer is used at configure script generation time, this
+dnl results in 'subdir-objects' automake option being used.
+dnl When using automake versions older than 1.14 this option
+dnl is not used when generating configure script.
+dnl
+dnl Existence of automake _AM_PROG_CC_C_O m4 private macro
+dnl is used to differentiate automake version 1.14 from older
+dnl ones which lack this macro.
+
+m4_define([_XC_AUTOMAKE_BODY],
+[dnl
+## --------------------------------------- ##
+## Start of automake initialization code ##
+## --------------------------------------- ##
+m4_ifdef([_AM_PROG_CC_C_O],
+[
+AM_INIT_AUTOMAKE([subdir-objects])
+],[
+AM_INIT_AUTOMAKE
+])dnl
+## ------------------------------------- ##
+## End of automake initialization code ##
+## ------------------------------------- ##
+dnl
+m4_define([$0], [])[]dnl
+])
+
+
+dnl XC_AUTOMAKE
+dnl -------------------------------------------------
+dnl Public macro.
+dnl
+dnl This macro embeds automake machinery into configure
+dnl script regardless of automake version used in order
+dnl to generate configure script.
+dnl
+dnl When using automake version 1.14 or newer, automake
+dnl initialization option 'subdir-objects' is used to
+dnl generate the configure script, otherwise this option
+dnl is not used.
+
+AC_DEFUN([XC_AUTOMAKE],
+[dnl
+AC_PREREQ([2.50])dnl
+dnl
+AC_BEFORE([$0],[AM_INIT_AUTOMAKE])dnl
+dnl
+_XC_AUTOMAKE_BODY
+dnl
+m4_ifdef([AM_INIT_AUTOMAKE],
+ [m4_undefine([AM_INIT_AUTOMAKE])])dnl
+dnl
+m4_define([$0], [])[]dnl
+])
+
+
+dnl _XC_AMEND_DISTCLEAN_BODY ([LIST-OF-SUBDIRS])
+dnl -------------------------------------------------
+dnl Private macro.
+dnl
+dnl This macro performs shell code embedding into
+dnl configure script in order to modify distclean
+dnl and maintainer-clean targets of makefiles which
+dnl are located in given list of subdirs.
+dnl
+dnl See XC_AMEND_DISTCLEAN comments for details.
+
+m4_define([_XC_AMEND_DISTCLEAN_BODY],
+[dnl
+## ---------------------------------- ##
+## Start of distclean amending code ##
+## ---------------------------------- ##
+
+for xc_subdir in [$1]
+do
+
+if test ! -f "$xc_subdir/Makefile"; then
+ echo "$xc_msg_err $xc_subdir/Makefile file not found. $xc_msg_abrt" >&2
+ exit 1
+fi
+
+# Fetch dependency tracking file list from Makefile include lines.
+
+xc_inc_lines=`grep '^include .*(DEPDIR)' "$xc_subdir/Makefile" 2>/dev/null`
+xc_cnt_words=`echo "$xc_inc_lines" | wc -w | tr -d "$xc_space$xc_tab"`
+
+# --disable-dependency-tracking might have been used, consequently
+# there is nothing to amend without a dependency tracking file list.
+
+if test $xc_cnt_words -gt 0; then
+
+AC_MSG_NOTICE([amending $xc_subdir/Makefile])
+
+# Build Makefile specific patch hunk.
+
+xc_p="$xc_subdir/xc_patch.tmp"
+
+xc_rm_depfiles=`echo "$xc_inc_lines" \
+ | $SED 's%include% -rm -f%' 2>/dev/null`
+
+xc_dep_subdirs=`echo "$xc_inc_lines" \
+ | $SED 's%include[[ ]][[ ]]*%%' 2>/dev/null \
+ | $SED 's%(DEPDIR)/.*%(DEPDIR)%' 2>/dev/null \
+ | sort | uniq`
+
+echo "$xc_rm_depfiles" >$xc_p
+
+for xc_dep_dir in $xc_dep_subdirs; do
+ echo "${xc_tab}@xm_dep_cnt=\`ls $xc_dep_dir | wc -l 2>/dev/null\`; \\" >>$xc_p
+ echo "${xc_tab}if test \$\$xm_dep_cnt -eq 0 && test -d $xc_dep_dir; then \\" >>$xc_p
+ echo "${xc_tab} rm -rf $xc_dep_dir; \\" >>$xc_p
+ echo "${xc_tab}fi" >>$xc_p
+done
+
+# Build Makefile patching sed scripts.
+
+xc_s1="$xc_subdir/xc_script_1.tmp"
+xc_s2="$xc_subdir/xc_script_2.tmp"
+xc_s3="$xc_subdir/xc_script_3.tmp"
+
+cat >$xc_s1 <<\_EOT
+/^distclean[[ ]]*:/,/^[[^ ]][[^ ]]*:/{
+ s/^.*(DEPDIR)/___xc_depdir_line___/
+}
+/^maintainer-clean[[ ]]*:/,/^[[^ ]][[^ ]]*:/{
+ s/^.*(DEPDIR)/___xc_depdir_line___/
+}
+_EOT
+
+cat >$xc_s2 <<\_EOT
+/___xc_depdir_line___$/{
+ N
+ /___xc_depdir_line___$/D
+}
+_EOT
+
+cat >$xc_s3 <<_EOT
+/^___xc_depdir_line___/{
+ r $xc_p
+ d
+}
+_EOT
+
+# Apply patch to Makefile and cleanup.
+
+$SED -f "$xc_s1" "$xc_subdir/Makefile" >"$xc_subdir/Makefile.tmp1"
+$SED -f "$xc_s2" "$xc_subdir/Makefile.tmp1" >"$xc_subdir/Makefile.tmp2"
+$SED -f "$xc_s3" "$xc_subdir/Makefile.tmp2" >"$xc_subdir/Makefile.tmp3"
+
+if test -f "$xc_subdir/Makefile.tmp3"; then
+ mv -f "$xc_subdir/Makefile.tmp3" "$xc_subdir/Makefile"
+fi
+
+test -f "$xc_subdir/Makefile.tmp1" && rm -f "$xc_subdir/Makefile.tmp1"
+test -f "$xc_subdir/Makefile.tmp2" && rm -f "$xc_subdir/Makefile.tmp2"
+test -f "$xc_subdir/Makefile.tmp3" && rm -f "$xc_subdir/Makefile.tmp3"
+
+test -f "$xc_p" && rm -f "$xc_p"
+test -f "$xc_s1" && rm -f "$xc_s1"
+test -f "$xc_s2" && rm -f "$xc_s2"
+test -f "$xc_s3" && rm -f "$xc_s3"
+
+fi
+
+done
+
+## -------------------------------- ##
+## End of distclean amending code ##
+## -------------------------------- ##
+dnl
+m4_define([$0], [])[]dnl
+])
+
+
+dnl XC_AMEND_DISTCLEAN ([LIST-OF-SUBDIRS])
+dnl -------------------------------------------------
+dnl Public macro.
+dnl
+dnl This macro embeds shell code into configure script
+dnl that amends, at configure runtime, the distclean
+dnl and maintainer-clean targets of Makefiles located
+dnl in all subdirs given in the mandatory white-space
+dnl separated list argument.
+dnl
+dnl Embedding only takes place when using automake 1.14
+dnl or newer, otherwise amending code is not included
+dnl in generated configure script.
+dnl
+dnl distclean and maintainer-clean targets are modified
+dnl to avoid unconditional removal of dependency subdirs
+dnl which triggers distclean and maintainer-clean errors
+dnl when using automake 'subdir-objects' option along
+dnl with per-target objects and source files existing in
+dnl multiple subdirs used for different build targets.
+dnl
+dnl New behavior first removes each dependency tracking
+dnl file independently, and only removes each dependency
+dnl subdir when it finds out that it no longer holds any
+dnl dependency tracking file.
+dnl
+dnl When configure option --disable-dependency-tracking
+dnl is used no amending takes place given that there are
+dnl no dependency tracking files.
+
+AC_DEFUN([XC_AMEND_DISTCLEAN],
+[dnl
+AC_PREREQ([2.50])dnl
+dnl
+m4_ifdef([_AC_OUTPUT_MAIN_LOOP],
+ [m4_provide_if([_AC_OUTPUT_MAIN_LOOP], [],
+ [m4_fatal([call to AC_OUTPUT needed before $0])])])dnl
+dnl
+m4_if([$#], [1], [], [m4_fatal([$0: wrong number of arguments])])dnl
+m4_if([$1], [], [m4_fatal([$0: missing argument])])dnl
+dnl
+AC_REQUIRE([XC_CONFIGURE_PREAMBLE])dnl
+dnl
+m4_ifdef([_AM_PROG_CC_C_O],
+[
+_XC_AMEND_DISTCLEAN_BODY([$1])
+])dnl
+m4_define([$0], [])[]dnl
+])
+