refdes_renum: warn of possible number clash with non-conforming values
[geda-gaf/whiteaudio.git] / m4 / geda-awk.m4
blob885d27350128b39c0a1a7db929e8a2eef62cb320
1 # geda-awk.m4                                           -*-Autoconf-*-
2 # serial 1
4 dnl Improved checks for awk executable path and features
5 dnl Copyright (C) 2008  Dan McMahill <dan@mcmahill.net>
6 dnl Copyright (C) 2009  Peter Brett <peter@peter-b.co.uk>
7 dnl
8 dnl This program is free software; you can redistribute it and/or modify
9 dnl it under the terms of the GNU General Public License as published by
10 dnl the Free Software Foundation; either version 2 of the License, or
11 dnl (at your option) any later version.
12 dnl
13 dnl This program is distributed in the hope that it will be useful,
14 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
15 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 dnl GNU General Public License for more details.
17 dnl
18 dnl You should have received a copy of the GNU General Public License
19 dnl along with this program; if not, write to the Free Software
20 dnl Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 AC_DEFUN([AX_PROG_AWK],
24   AC_PREREQ([2.60])dnl
25   AC_PROVIDE([AC_PROG_AWK])dnl
26   AC_ARG_VAR([AWK], [Path to awk executable])
27   AC_PATH_PROGS([AWK], [mawk gawk nawk awk], [no])
28   if test "X$AWK" = "Xno"; then
29     AC_MSG_ERROR([The awk tool could not be found. Ensure it is installed and in your
30 path.])
31   fi
32 ])dnl AX_PROG_AWK
34 dnl AX_AWK_IFELSE (PROGRAM, INPUT, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
35 AC_DEFUN([AX_AWK_IFELSE],
37   AC_PREREQ([2.60])dnl
38   AC_REQUIRE([AC_PROG_AWK])dnl
39   cat > conftest.awk <<EOF
40 [#]line __oline__ "configure"
41 [$1]
42 EOF
43   cat > conftest.txt <<EOF
44 [$2]
45 EOF
46   if ($AWK -f conftest.awk conftest.txt >/dev/null; exit) 2>&AC_FD_CC; then
47     ifelse([$3], , :,
48            [rm -fr conftest*;
49 $3])
50   else
51     echo "configure:__oline__: $AWK -f conftest.awk conftest.txt" >&AC_FD_CC
52     echo "configure:__oline__: failed program was:" >&AC_FD_CC
53     cat conftest.awk >&AC_FD_CC
54     echo "configure:__oline__: failed input file was:" >&AC_FD_CC
55     cat conftest.txt >&AC_FD_CC
56     ifelse([$4], , ,
57            [rm -fr conftest*;
58 $4])
59   fi
60 ])dnl AX_AWK_IFELSE
62 dnl Check for some miscellaneous Awk features used by gEDA.
63 AC_DEFUN([AX_AWK_FEATURES],
65   AC_PREREQ([2.60])dnl
66   AC_REQUIRE([AC_PROG_AWK])dnl
68   AC_MSG_CHECKING([whether $AWK has gsub])
69   AX_AWK_IFELSE([{gsub(/foo/,"bar");}], [foo bar],
70     [AWK_GSUB="yes"],[AWK_GSUB="no"])
71   AC_MSG_RESULT([$AWK_GSUB])
73   AC_MSG_CHECKING([whether $AWK has toupper])
74   AX_AWK_IFELSE([{print toupper("test")}], [foo bar],
75     [AWK_TOUPPER=yes],[AWK_TOUPPER=no])
76   AC_MSG_RESULT([$AWK_TOUPPER])
78   if (test "X$AWK_GSUB" = "Xno" || test "X$AWK_TOUPPER" = "Xno"); then
79     AC_MSG_ERROR([Your awk ($AWK) is missing the `gsub' and/or `toupper' functions.
80 Consider installing gawk.])
81   fi
82 ])dnl AX_AWK_FEATURES