b002e2940efed6983d0be094b0ceda6421d51ed5
[pspp] / m4 / minmax.m4
1 # minmax.m4 serial 2
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 dnl The parameter has to be a literal header name; it cannot be macro,
21 dnl nor a shell variable.
22 AC_DEFUN([gl_MINMAX_IN_HEADER],
23 [
24   define([header],[translit([$1],[./-],
25                                  [___])])
26   define([HEADER],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-],
27                                  [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])])
28   AC_CACHE_CHECK([whether <$1> defines MIN and MAX],
29     [gl_cv_minmax_in_]header,
30     [AC_TRY_COMPILE([#include <$1>
31 int x = MIN (42, 17);], [],
32        [gl_cv_minmax_in_]header[=yes],
33        [gl_cv_minmax_in_]header[=no])])
34   if test $gl_cv_minmax_in_[]header = yes; then
35     AC_DEFINE([HAVE_MINMAX_IN_]HEADER, 1,
36       [Define to 1 if <$1> defines the MIN and MAX macros.])
37   fi
38   undefine([HEADER])
39   undefine([header])
40 ])