summaryrefslogtreecommitdiff
path: root/m4
diff options
context:
space:
mode:
authorAlexey Neyman <stilor@att.net>2018-01-07 02:31:15 (GMT)
committerAlexey Neyman <stilor@att.net>2018-04-07 19:02:33 (GMT)
commit896bc2d17313f32a968efb09917cc3eb2b4e3ed8 (patch)
tree3735dcf860ee30ffc86c04122bdc7fc0dd4b5be4 /m4
parent7c3422675909ea8b117f94a26170af06a265477e (diff)
Split local helper macros into separate m4's
... which are then picked up via aclocal. Signed-off-by: Alexey Neyman <stilor@att.net>
Diffstat (limited to 'm4')
-rw-r--r--m4/README7
-rw-r--r--m4/ax_require_defined.m437
-rw-r--r--m4/ctng_cpu_count.m410
-rw-r--r--m4/ctng_gperf.m423
-rw-r--r--m4/ctng_prog.m436
-rw-r--r--m4/ctng_prog_stat.m418
-rw-r--r--m4/ctng_set_kconfig_option.m47
-rw-r--r--m4/ctng_version_check.m447
-rw-r--r--m4/ctng_with_deprecated.m410
9 files changed, 195 insertions, 0 deletions
diff --git a/m4/README b/m4/README
new file mode 100644
index 0000000..a572d61
--- /dev/null
+++ b/m4/README
@@ -0,0 +1,7 @@
+These autoconf helper macros come from various sources:
+
+- ax_*.m4: autoconf-archive, version 2017.09.28 (copied)
+- pkg.m4: pkg-config, version 0.29.2 (run configure, then copy)
+- gettext.m4, iconv.m4, intlmacosx.m4, nls.m4: gettext 0.19.8
+- ctng_*.m4: obviously, implemented anew
+- po.m4: a local dummy stub for gettext's version
diff --git a/m4/ax_require_defined.m4 b/m4/ax_require_defined.m4
new file mode 100644
index 0000000..17c3eab
--- /dev/null
+++ b/m4/ax_require_defined.m4
@@ -0,0 +1,37 @@
+# ===========================================================================
+# https://www.gnu.org/software/autoconf-archive/ax_require_defined.html
+# ===========================================================================
+#
+# SYNOPSIS
+#
+# AX_REQUIRE_DEFINED(MACRO)
+#
+# DESCRIPTION
+#
+# AX_REQUIRE_DEFINED is a simple helper for making sure other macros have
+# been defined and thus are available for use. This avoids random issues
+# where a macro isn't expanded. Instead the configure script emits a
+# non-fatal:
+#
+# ./configure: line 1673: AX_CFLAGS_WARN_ALL: command not found
+#
+# It's like AC_REQUIRE except it doesn't expand the required macro.
+#
+# Here's an example:
+#
+# AX_REQUIRE_DEFINED([AX_CHECK_LINK_FLAG])
+#
+# LICENSE
+#
+# Copyright (c) 2014 Mike Frysinger <vapier@gentoo.org>
+#
+# 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 2
+
+AC_DEFUN([AX_REQUIRE_DEFINED], [dnl
+ m4_ifndef([$1], [m4_fatal([macro ]$1[ is not defined; is a m4 file missing?])])
+])dnl AX_REQUIRE_DEFINED
diff --git a/m4/ctng_cpu_count.m4 b/m4/ctng_cpu_count.m4
new file mode 100644
index 0000000..4ea50d8
--- /dev/null
+++ b/m4/ctng_cpu_count.m4
@@ -0,0 +1,10 @@
+# Find out how to count CPUs
+AC_DEFUN([CTNG_CPU_COUNT],
+ [AC_CACHE_CHECK([whether to use getconf or sysctl to count CPUs],
+ [acx_cv_cpu_count],
+ [getconf _NPROCESSORS_ONLN >/dev/null 2>&1 && \
+ acx_cv_cpu_count="getconf _NPROCESSORS_ONLN"
+ sysctl -n hw.ncpu >/dev/null 2>&1 && \
+ acx_cv_cpu_count="sysctl -n hw.ncpu"])
+ AC_SUBST(CPU_COUNT, "$acx_cv_cpu_count")
+ ])
diff --git a/m4/ctng_gperf.m4 b/m4/ctng_gperf.m4
new file mode 100644
index 0000000..0ec1a0e
--- /dev/null
+++ b/m4/ctng_gperf.m4
@@ -0,0 +1,23 @@
+# Check for GNU perf location and the type it uses in the prototypes
+# FIXME: remove AC_SUBST after switching to using autoheader
+AC_DEFUN([CTNG_PROG_GPERF],
+ [AX_REQUIRE_DEFINED([CTNG_CHECK_TOOL_REQ])
+ CTNG_CHECK_TOOL_REQ([GPERF], [gperf], [gperf])
+ # Gperf 3.1 started generating functions with size_t rather than unsigned int
+ AC_MSG_CHECKING([for the type used in gperf declarations])
+ cat > conftest.gperf.c <<_ASEOF
+#include <string.h>"
+const char * in_word_set(const char *, GPERF_LEN_TYPE);
+_ASEOF
+ echo foo,bar | ${GPERF} -L ANSI-C >> conftest.gperf.c
+ AS_IF([${CC} -c -o /dev/null conftest.gperf.c -DGPERF_LEN_TYPE='size_t' >/dev/null 2>&1],
+ [AC_MSG_RESULT([size_t])
+ GPERF_LEN_TYPE='size_t'],
+ [${CC} -c -o /dev/null conftest.gperf.c -DGPERF_LEN_TYPE='unsigned int' >/dev/null 2>&1],
+ [AC_MSG_RESULT([unsigned int])
+ GPERF_LEN_TYPE='unsigned int'],
+ [AC_MSG_ERROR([unable to determine gperf len type])])
+ rm -f conftest.gperf.c
+ AC_DEFINE_UNQUOTED([GPERF_LEN_TYPE], $GPERF_LEN_TYPE, [String length type used by gperf])
+ AC_SUBST([GPERF_LEN_TYPE])
+])
diff --git a/m4/ctng_prog.m4 b/m4/ctng_prog.m4
new file mode 100644
index 0000000..ebbe333
--- /dev/null
+++ b/m4/ctng_prog.m4
@@ -0,0 +1,36 @@
+# Several convenience wrappers for checking the programs
+
+# Check for required tool
+AC_DEFUN([CTNG_CHECK_TOOL_REQ],
+ [AC_CHECK_TOOLS([$1], [$2])
+ AS_IF(
+ [test -z "$$1"],
+ [AC_MSG_ERROR([missing required tool: $2])])
+ ])
+
+# Check for required tool, set variable to full pathname
+AC_DEFUN([CTNG_PATH_TOOL_REQ],
+ [AC_ARG_VAR([$1], [Specify the full path to GNU $3])
+ CTNG_CHECK_TOOL_REQ([$1], [$2])
+ AS_CASE(
+ [$$1],
+ [/*],,
+ [?*],[AC_MSG_CHECKING([for absolute path to $$1])
+ $1=$(which $$1)
+ AC_MSG_RESULT([$$1])])])
+
+# Check for required program
+AC_DEFUN([CTNG_CHECK_PROGS_REQ],
+ [AC_CHECK_PROGS([$1], [$2])
+ AS_IF(
+ [test -z "$$1"],
+ [AC_MSG_ERROR([missing required tool: $2])])
+ ])
+
+# Check for path to required program
+AC_DEFUN([CTNG_PATH_PROGS_REQ],
+ [AC_PATH_PROGS([$1], [$2])
+ AS_IF(
+ [test -z "$$1"],
+ [AC_MSG_ERROR([missing required tool: $2])])
+ ])
diff --git a/m4/ctng_prog_stat.m4 b/m4/ctng_prog_stat.m4
new file mode 100644
index 0000000..f7de93e
--- /dev/null
+++ b/m4/ctng_prog_stat.m4
@@ -0,0 +1,18 @@
+# Check that stat(1) is present and determine the syntax for the format
+# string (BSD or GNU).
+AC_DEFUN([CTNG_PROG_STAT],
+ [AX_REQUIRE_DEFINED([CTNG_CHECK_PROGS_REQ])
+ CTNG_CHECK_PROGS_REQ([stat], [stat])
+ AC_CACHE_CHECK([whether stat takes GNU or BSD format],
+ [acx_cv_stat_flavor],
+ [touch conftest
+ chmod 642 conftest
+ attr_bsd=$(stat -f '%Lp' conftest 2>/dev/null)
+ attr_gnu=$(stat -c '%a' conftest 2>/dev/null)
+ rm -f conftest
+ AS_IF([test "$attr_bsd" = "642"],
+ [acx_cv_stat_flavor=BSD],
+ [test "$attr_gnu" = "642"],
+ [acx_cv_stat_flavor=GNU],
+ [AC_MSG_ERROR([cannot determine stat(1) format option])])])
+ ])
diff --git a/m4/ctng_set_kconfig_option.m4 b/m4/ctng_set_kconfig_option.m4
new file mode 100644
index 0000000..9fae320
--- /dev/null
+++ b/m4/ctng_set_kconfig_option.m4
@@ -0,0 +1,7 @@
+# Set the kconfig option.
+AC_DEFUN([CTNG_SET_KCONFIG_OPTION],
+ [AS_IF(
+ [test -n "$$1"],
+ [AC_SUBST([KCONFIG_$1], ["def_bool y"])],
+ [AC_SUBST([KCONFIG_$1], ["bool"])])
+ ])
diff --git a/m4/ctng_version_check.m4 b/m4/ctng_version_check.m4
new file mode 100644
index 0000000..472194b
--- /dev/null
+++ b/m4/ctng_version_check.m4
@@ -0,0 +1,47 @@
+# Check if a given program is available with a particular version.
+# CTNG_PROG_VERSION(VAR, HELP, PROG, SRCH, VERSION_CHECK[, CONFIG_OPT])
+# Search for PROG under possible names of SRCH. Allow user overrides in variable
+# VAR; display HELP message. Try to find a version that satisfies VERSION_CHECK
+# regexp; if that is achieved, set CONFIG_OPT in the kconfig. Otherwise, settle
+# for any version found.
+# Sets acx_version_VAR_ok to ':' if the version met the criterion, or false otherwise.
+AC_DEFUN([CTNG_PROG_VERSION],
+ [AS_IF([test -z "$EGREP"],
+ [AC_MSG_ERROR([This macro can only be used after checking for EGREP])])
+ CTNG_WITH_DEPRECATED([$3], [$1])
+ AC_ARG_VAR([$1], [Specify the full path to $2])
+ acx_version_$1_ok=false
+ AC_CACHE_CHECK([for $3], [ac_cv_path_$1],
+ [AC_PATH_PROGS_FEATURE_CHECK([$1], [$4],
+ [[ver=$($ac_path_$1 --version 2>/dev/null| $EGREP $5)
+ test -z "$ac_cv_path_$1" && ac_cv_path_$1=$ac_path_$1
+ test -n "$ver" && ac_cv_path_$1="$ac_path_$1" ac_path_$1_found=: acx_version_$1_ok=:]])])
+ AS_IF([test -n "$1"],
+ [[ver=$($ac_path_$1 --version 2>/dev/null| $EGREP $5)
+ test -n "$ver" && acx_version_$1_ok=:]])
+ AC_MSG_CHECKING([for $2])
+ AS_IF([$acx_version_$1_ok],
+ [AC_MSG_RESULT([yes])],
+ [AC_MSG_RESULT([no])])
+ AC_SUBST([$1], [$ac_cv_path_$1])
+ AS_IF([test -n "$6"],
+ [AS_IF([$acx_version_$1_ok], [$6=y], [$6=])
+ CTNG_SET_KCONFIG_OPTION([$6])])
+ ])
+
+# Same as above, but make it a fatal error if the tool is not found at all
+# (i.e. "require any version, prefer version X or newer")
+AC_DEFUN([CTNG_PROG_VERSION_REQ_ANY],
+ [CTNG_PROG_VERSION([$1], [$2], [$3], [$4], [$5], [$6])
+ AS_IF([test -z "$$1"],
+ [AC_MSG_ERROR([Required tool not found: $3])])
+ ])
+
+# Same, but also require the version check to pass
+# (i.e. "require version X or newer")
+AC_DEFUN([CTNG_PROG_VERSION_REQ_STRICT],
+ [CTNG_PROG_VERSION([$1], [$2], [$3], [$4], [$5], [$6])
+ AS_IF([test -z "$$1" || ! $acx_version_$1_ok],
+ [AC_MSG_ERROR([Required tool not found: $2])])
+ ])
+
diff --git a/m4/ctng_with_deprecated.m4 b/m4/ctng_with_deprecated.m4
new file mode 100644
index 0000000..976bc3f
--- /dev/null
+++ b/m4/ctng_with_deprecated.m4
@@ -0,0 +1,10 @@
+# FIXME retire after 1.24
+#
+# CTNG_WITH_DEPRECATED(PROG, VAR)
+# Declare a deprecated --with option: instead of --with-PROG=xxx, must use VAR=xxx
+AC_DEFUN([CTNG_WITH_DEPRECATED],
+ [AC_ARG_WITH([$1],
+ [AS_HELP_STRING([--with-$1=PATH],
+ [Deprecated; use $2=PATH instead])],
+ [AC_MSG_ERROR([--with-$1=$withval deprecated; use $2=$withval instead])])
+ ])