11cb0ef41Sopenharmony_ci# ===========================================================================
21cb0ef41Sopenharmony_ci#    https://www.gnu.org/software/autoconf-archive/ax_check_gnu_make.html
31cb0ef41Sopenharmony_ci# ===========================================================================
41cb0ef41Sopenharmony_ci#
51cb0ef41Sopenharmony_ci# SYNOPSIS
61cb0ef41Sopenharmony_ci#
71cb0ef41Sopenharmony_ci#   AX_CHECK_GNU_MAKE([run-if-true],[run-if-false])
81cb0ef41Sopenharmony_ci#
91cb0ef41Sopenharmony_ci# DESCRIPTION
101cb0ef41Sopenharmony_ci#
111cb0ef41Sopenharmony_ci#   This macro searches for a GNU version of make. If a match is found:
121cb0ef41Sopenharmony_ci#
131cb0ef41Sopenharmony_ci#     * The makefile variable `ifGNUmake' is set to the empty string, otherwise
141cb0ef41Sopenharmony_ci#       it is set to "#". This is useful for including a special features in a
151cb0ef41Sopenharmony_ci#       Makefile, which cannot be handled by other versions of make.
161cb0ef41Sopenharmony_ci#     * The makefile variable `ifnGNUmake' is set to #, otherwise
171cb0ef41Sopenharmony_ci#       it is set to the empty string. This is useful for including a special
181cb0ef41Sopenharmony_ci#       features in a Makefile, which can be handled
191cb0ef41Sopenharmony_ci#       by other versions of make or to specify else like clause.
201cb0ef41Sopenharmony_ci#     * The variable `_cv_gnu_make_command` is set to the command to invoke
211cb0ef41Sopenharmony_ci#       GNU make if it exists, the empty string otherwise.
221cb0ef41Sopenharmony_ci#     * The variable `ax_cv_gnu_make_command` is set to the command to invoke
231cb0ef41Sopenharmony_ci#       GNU make by copying `_cv_gnu_make_command`, otherwise it is unset.
241cb0ef41Sopenharmony_ci#     * If GNU Make is found, its version is extracted from the output of
251cb0ef41Sopenharmony_ci#       `make --version` as the last field of a record of space-separated
261cb0ef41Sopenharmony_ci#       columns and saved into the variable `ax_check_gnu_make_version`.
271cb0ef41Sopenharmony_ci#     * Additionally if GNU Make is found, run shell code run-if-true
281cb0ef41Sopenharmony_ci#       else run shell code run-if-false.
291cb0ef41Sopenharmony_ci#
301cb0ef41Sopenharmony_ci#   Here is an example of its use:
311cb0ef41Sopenharmony_ci#
321cb0ef41Sopenharmony_ci#   Makefile.in might contain:
331cb0ef41Sopenharmony_ci#
341cb0ef41Sopenharmony_ci#     # A failsafe way of putting a dependency rule into a makefile
351cb0ef41Sopenharmony_ci#     $(DEPEND):
361cb0ef41Sopenharmony_ci#             $(CC) -MM $(srcdir)/*.c > $(DEPEND)
371cb0ef41Sopenharmony_ci#
381cb0ef41Sopenharmony_ci#     @ifGNUmake@ ifeq ($(DEPEND),$(wildcard $(DEPEND)))
391cb0ef41Sopenharmony_ci#     @ifGNUmake@ include $(DEPEND)
401cb0ef41Sopenharmony_ci#     @ifGNUmake@ else
411cb0ef41Sopenharmony_ci#     fallback code
421cb0ef41Sopenharmony_ci#     @ifGNUmake@ endif
431cb0ef41Sopenharmony_ci#
441cb0ef41Sopenharmony_ci#   Then configure.in would normally contain:
451cb0ef41Sopenharmony_ci#
461cb0ef41Sopenharmony_ci#     AX_CHECK_GNU_MAKE()
471cb0ef41Sopenharmony_ci#     AC_OUTPUT(Makefile)
481cb0ef41Sopenharmony_ci#
491cb0ef41Sopenharmony_ci#   Then perhaps to cause gnu make to override any other make, we could do
501cb0ef41Sopenharmony_ci#   something like this (note that GNU make always looks for GNUmakefile
511cb0ef41Sopenharmony_ci#   first):
521cb0ef41Sopenharmony_ci#
531cb0ef41Sopenharmony_ci#     if  ! test x$_cv_gnu_make_command = x ; then
541cb0ef41Sopenharmony_ci#             mv Makefile GNUmakefile
551cb0ef41Sopenharmony_ci#             echo .DEFAULT: > Makefile ;
561cb0ef41Sopenharmony_ci#             echo \  $_cv_gnu_make_command \$@ >> Makefile;
571cb0ef41Sopenharmony_ci#     fi
581cb0ef41Sopenharmony_ci#
591cb0ef41Sopenharmony_ci#   Then, if any (well almost any) other make is called, and GNU make also
601cb0ef41Sopenharmony_ci#   exists, then the other make wraps the GNU make.
611cb0ef41Sopenharmony_ci#
621cb0ef41Sopenharmony_ci# LICENSE
631cb0ef41Sopenharmony_ci#
641cb0ef41Sopenharmony_ci#   Copyright (c) 2008 John Darrington <j.darrington@elvis.murdoch.edu.au>
651cb0ef41Sopenharmony_ci#   Copyright (c) 2015 Enrico M. Crisostomo <enrico.m.crisostomo@gmail.com>
661cb0ef41Sopenharmony_ci#
671cb0ef41Sopenharmony_ci#   Copying and distribution of this file, with or without modification, are
681cb0ef41Sopenharmony_ci#   permitted in any medium without royalty provided the copyright notice
691cb0ef41Sopenharmony_ci#   and this notice are preserved. This file is offered as-is, without any
701cb0ef41Sopenharmony_ci#   warranty.
711cb0ef41Sopenharmony_ci
721cb0ef41Sopenharmony_ci#serial 12
731cb0ef41Sopenharmony_ci
741cb0ef41Sopenharmony_ciAC_DEFUN([AX_CHECK_GNU_MAKE],dnl
751cb0ef41Sopenharmony_ci  [AC_PROG_AWK
761cb0ef41Sopenharmony_ci  AC_CACHE_CHECK([for GNU make],[_cv_gnu_make_command],[dnl
771cb0ef41Sopenharmony_ci    _cv_gnu_make_command="" ;
781cb0ef41Sopenharmony_cidnl Search all the common names for GNU make
791cb0ef41Sopenharmony_ci    for a in "$MAKE" make gmake gnumake ; do
801cb0ef41Sopenharmony_ci      if test -z "$a" ; then continue ; fi ;
811cb0ef41Sopenharmony_ci      if "$a" --version 2> /dev/null | grep GNU 2>&1 > /dev/null ; then
821cb0ef41Sopenharmony_ci        _cv_gnu_make_command=$a ;
831cb0ef41Sopenharmony_ci        AX_CHECK_GNU_MAKE_HEADLINE=$("$a" --version 2> /dev/null | grep "GNU Make")
841cb0ef41Sopenharmony_ci        ax_check_gnu_make_version=$(echo ${AX_CHECK_GNU_MAKE_HEADLINE} | ${AWK} -F " " '{ print $(NF); }')
851cb0ef41Sopenharmony_ci        break ;
861cb0ef41Sopenharmony_ci      fi
871cb0ef41Sopenharmony_ci    done ;])
881cb0ef41Sopenharmony_cidnl If there was a GNU version, then set @ifGNUmake@ to the empty string, '#' otherwise
891cb0ef41Sopenharmony_ci  AS_VAR_IF([_cv_gnu_make_command], [""], [AS_VAR_SET([ifGNUmake], ["#"])],   [AS_VAR_SET([ifGNUmake], [""])])
901cb0ef41Sopenharmony_ci  AS_VAR_IF([_cv_gnu_make_command], [""], [AS_VAR_SET([ifnGNUmake], [""])],   [AS_VAR_SET([ifnGNUmake], ["#"])])
911cb0ef41Sopenharmony_ci  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}])])
921cb0ef41Sopenharmony_ci  AS_VAR_IF([_cv_gnu_make_command], [""],[$2],[$1])
931cb0ef41Sopenharmony_ci  AC_SUBST([ifGNUmake])
941cb0ef41Sopenharmony_ci  AC_SUBST([ifnGNUmake])
951cb0ef41Sopenharmony_ci])
96