| 1 |
# =========================================================================== |
| 2 |
# https://www.gnu.org/software/autoconf-archive/ax_check_gnu_make.html |
| 3 |
# =========================================================================== |
| 4 |
# |
| 5 |
# SYNOPSIS |
| 6 |
# |
| 7 |
# AX_CHECK_GNU_MAKE([run-if-true],[run-if-false]) |
| 8 |
# |
| 9 |
# DESCRIPTION |
| 10 |
# |
| 11 |
# This macro searches for a GNU version of make. If a match is found: |
| 12 |
# |
| 13 |
# * The makefile variable `ifGNUmake' is set to the empty string, otherwise |
| 14 |
# it is set to "#". This is useful for including a special features in a |
| 15 |
# Makefile, which cannot be handled by other versions of make. |
| 16 |
# * The makefile variable `ifnGNUmake' is set to #, otherwise |
| 17 |
# it is set to the empty string. This is useful for including a special |
| 18 |
# features in a Makefile, which can be handled |
| 19 |
# by other versions of make or to specify else like clause. |
| 20 |
# * The variable `_cv_gnu_make_command` is set to the command to invoke |
| 21 |
# GNU make if it exists, the empty string otherwise. |
| 22 |
# * The variable `ax_cv_gnu_make_command` is set to the command to invoke |
| 23 |
# GNU make by copying `_cv_gnu_make_command`, otherwise it is unset. |
| 24 |
# * If GNU Make is found, its version is extracted from the output of |
| 25 |
# `make --version` as the last field of a record of space-separated |
| 26 |
# columns and saved into the variable `ax_check_gnu_make_version`. |
| 27 |
# * Additionally if GNU Make is found, run shell code run-if-true |
| 28 |
# else run shell code run-if-false. |
| 29 |
# |
| 30 |
# Here is an example of its use: |
| 31 |
# |
| 32 |
# Makefile.in might contain: |
| 33 |
# |
| 34 |
# # A failsafe way of putting a dependency rule into a makefile |
| 35 |
# $(DEPEND): |
| 36 |
# $(CC) -MM $(srcdir)/*.c > $(DEPEND) |
| 37 |
# |
| 38 |
# @ifGNUmake@ ifeq ($(DEPEND),$(wildcard $(DEPEND))) |
| 39 |
# @ifGNUmake@ include $(DEPEND) |
| 40 |
# @ifGNUmake@ else |
| 41 |
# fallback code |
| 42 |
# @ifGNUmake@ endif |
| 43 |
# |
| 44 |
# Then configure.in would normally contain: |
| 45 |
# |
| 46 |
# AX_CHECK_GNU_MAKE() |
| 47 |
# AC_OUTPUT(Makefile) |
| 48 |
# |
| 49 |
# Then perhaps to cause gnu make to override any other make, we could do |
| 50 |
# something like this (note that GNU make always looks for GNUmakefile |
| 51 |
# first): |
| 52 |
# |
| 53 |
# if ! test x$_cv_gnu_make_command = x ; then |
| 54 |
# mv Makefile GNUmakefile |
| 55 |
# echo .DEFAULT: > Makefile ; |
| 56 |
# echo \ $_cv_gnu_make_command \$@ >> Makefile; |
| 57 |
# fi |
| 58 |
# |
| 59 |
# Then, if any (well almost any) other make is called, and GNU make also |
| 60 |
# exists, then the other make wraps the GNU make. |
| 61 |
# |
| 62 |
# LICENSE |
| 63 |
# |
| 64 |
# Copyright (c) 2008 John Darrington <[email protected]> |
| 65 |
# Copyright (c) 2015 Enrico M. Crisostomo <[email protected]> |
| 66 |
# |
| 67 |
# Copying and distribution of this file, with or without modification, are |
| 68 |
# permitted in any medium without royalty provided the copyright notice |
| 69 |
# and this notice are preserved. This file is offered as-is, without any |
| 70 |
# warranty. |
| 71 |
|
| 72 |
#serial 12 |
| 73 |
|
| 74 |
AC_DEFUN([AX_CHECK_GNU_MAKE],dnl |
| 75 |
[AC_PROG_AWK |
| 76 |
AC_CACHE_CHECK([for GNU make],[_cv_gnu_make_command],[dnl |
| 77 |
_cv_gnu_make_command="" ; |
| 78 |
dnl Search all the common names for GNU make |
| 79 |
for a in "$MAKE" make gmake gnumake ; do |
| 80 |
if test -z "$a" ; then continue ; fi ; |
| 81 |
if "$a" --version 2> /dev/null | grep GNU 2>&1 > /dev/null ; then |
| 82 |
_cv_gnu_make_command=$a ; |
| 83 |
AX_CHECK_GNU_MAKE_HEADLINE=$("$a" --version 2> /dev/null | grep "GNU Make") |
| 84 |
ax_check_gnu_make_version=$(echo ${AX_CHECK_GNU_MAKE_HEADLINE} | ${AWK} -F " " '{ print $(NF); }') |
| 85 |
break ; |
| 86 |
fi |
| 87 |
done ;]) |
| 88 |
dnl If there was a GNU version, then set @ifGNUmake@ to the empty string, '#' otherwise |
| 89 |
AS_VAR_IF([_cv_gnu_make_command], [""], [AS_VAR_SET([ifGNUmake], ["#"])], [AS_VAR_SET([ifGNUmake], [""])]) |
| 90 |
AS_VAR_IF([_cv_gnu_make_command], [""], [AS_VAR_SET([ifnGNUmake], [""])], [AS_VAR_SET([ifnGNUmake], ["#"])]) |
| 91 |
AS_VAR_IF([_cv_gnu_make_command], [""], [AS_UNSET(ax_cv_gnu_make_command)], [AS_VAR_SET([ax_cv_gnu_make_command], [${_cv_gnu_make_command}])]) |
| 92 |
AS_VAR_IF([_cv_gnu_make_command], [""],[$2],[$1]) |
| 93 |
AC_SUBST([ifGNUmake]) |
| 94 |
AC_SUBST([ifnGNUmake]) |
| 95 |
]) |