autoconf tests for the 'minmax' module.
[gnulib.git] / m4 / minmax.m4
1 # minmax.m4 serial 1
2 dnl Copyright (C) 2005 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 AC_DEFUN([gl_MINMAX],
8 [
9   AC_REQUIRE([gl_PREREQ_MINMAX])
10 ])
11
12 # Prerequisites of lib/minmax.h.
13 AC_DEFUN([gl_PREREQ_MINMAX],
14 [
15   gl_MINMAX_IN_HEADER([limits.h])
16   gl_MINMAX_IN_HEADER([sys/param.h])
17 ])
18
19 dnl gl_MINMAX_IN_HEADER(HEADER)
20 AC_DEFUN([gl_MINMAX_IN_HEADER],
21 [
22   define([header],[translit([$1],[./-],
23                                  [___])])
24   define([HEADER],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-],
25                                  [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])])
26   AC_CACHE_CHECK([whether <$1> defines MIN and MAX],
27     [gl_cv_minmax_in_]header,
28     [AC_TRY_COMPILE([#include <$1>
29 int x = MIN (42, 17);], [],
30        [gl_cv_minmax_in_]header[=yes],
31        [gl_cv_minmax_in_]header[=no])])
32   if test $gl_cv_minmax_in_[]header = yes; then
33     AC_DEFINE([HAVE_MINMAX_IN_]HEADER, 1,
34       [Define to 1 if <$1> defines the MIN and MAX macros.])
35   fi
36   undefine([HEADER])
37   undefine([header])
38 ])