gsch2pcb: Make --m4-file and -m4-pcbdir arguments work again.
[geda-gaf/peter-b.git] / m4 / geda-guile.m4
blob085aa6623b6f3add709bdb7c837f7793861655d1
1 # geda-guile.m4                                           -*-Autoconf-*-
2 # serial 2
4 dnl Check for guile
5 dnl Copyright (C) 2009  Dan McMahill <dan@mcmahill.net>
6 dnl Copyright (C) 2010-2011  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_CHECK_GUILE],
24   AC_PREREQ([2.60])dnl
26   # First check for the libguile library
27   # ------------------------------------
29   # Argument is the minimum guile version.  For example
30   # AX_CHECK_GUILE([1.8.0]) makes sure we have at least version 1.8.0
31   GUILE_MIN_VER=[$1]
32   GUILE_MIN_MAJOR=`echo ${GUILE_MIN_VER} | sed 's;\..*;;g'`
33   # the double brackets are to get past m4's expansion
34   GUILE_MIN_MINOR=`echo ${GUILE_MIN_VER} | sed -e 's;[[^\.]]*\.;;' -e 's;\..*;;g'`
35   GUILE_MIN_TEENY=`echo ${GUILE_MIN_VER} | sed -e 's;.*\.;;'`
37   _found_pkg_config_guile=yes
38   PKG_CHECK_MODULES(GUILE, [guile-2.0] , ,
39     [_found_pkg_config_guile=no])
41   if test "${_found_pkg_config_guile}" = "no" ; then
42     _found_pkg_config_guile=yes
43     PKG_CHECK_MODULES(GUILE, [guile-1.8] , ,
44       [_found_pkg_config_guile=no])
45   fi
47   if test "${_found_pkg_config_guile}" = "no" ; then
48     AC_PATH_PROG([GUILE_CONFIG], [guile-config], [notfound])
50     if test "${GUILE_CONFIG}" = "notfound" ; then
51       AC_ERROR([${PKG_CONFIG} could not locate guile and guile-config was not found])
52     fi
54     AC_MSG_CHECKING([if guile is version ${GUILE_MIN_VER} or later])
55     GUILE_VER=`${GUILE_CONFIG} --version 2>&1 | awk '{print $NF}'`
57     GUILE_MAJOR=`echo ${GUILE_VER} | sed 's;\..*;;g'`
58     # the double brackets are to get past m4's expansion
59     GUILE_MINOR=`echo ${GUILE_VER} | sed -e 's;[[^\.]]*\.;;' -e 's;\..*;;g'`
60     GUILE_TEENY=`echo ${GUILE_VER} | sed -e 's;.*\.;;'`
62     _guile_ok=no
63     if test ${GUILE_MAJOR} -lt ${GUILE_MIN_MAJOR} ; then
64       # Our installed major version is less than the min major version
66       _guile_ok=no
68     elif test ${GUILE_MAJOR} -eq ${GUILE_MIN_MAJOR} ; then
69       # Our installed major version is equal the min major version
70       # so we need to check the minor version
72       if test ${GUILE_MINOR} -lt ${GUILE_MIN_MINOR} ; then
73         # majors match, minor is too small
74         _guile_ok=no
75       elif test  ${GUILE_MINOR} -eq ${GUILE_MIN_MINOR} ; then
76         # majors match, minors match, check teeny
77         if test ${GUILE_TEENY} -lt ${GUILE_MIN_TEENY} ; then
78           _guile_ok=no
79         else
80           _guile_ok=yes
81         fi
82       else
83         # majors match, minor is larger than min
84         _guile_ok=yes
85       fi
87     else
88       # Our installed major version is greater than the min major version
90       _guile_ok=yes
91     fi
93     if test "${_guile_ok}" = "yes" ; then
94         AC_MSG_RESULT([yes (${GUILE_VER})])
95         AC_MSG_CHECKING([for guile CFLAGS])
96         GUILE_CFLAGS=`${GUILE_CONFIG} compile`
97         AC_MSG_RESULT([${GUILE_CFLAGS}])
99         AC_MSG_CHECKING([for guile libs])
100         GUILE_LIBS=`${GUILE_CONFIG} link`
101         AC_MSG_RESULT([$GUILE_LIBS])
102     else
103         AC_MSG_ERROR([you need at least version ${GUILE_MIN_VER} of guile])
104     fi
105     AC_SUBST(GUILE_VER)
106     AC_SUBST(GUILE_CFLAGS)
107     AC_SUBST(GUILE_LIBS)
108   fi
110   # Check for the `guile' executable
111   # --------------------------------
112   AC_ARG_VAR([GUILE], [Path to guile executable])
113   AC_CHECK_PROG([GUILE], [guile], [guile], [no])
114   if test "X$GUILE" = "Xno"; then
115     AC_MSG_WARN([The `guile' interpreter could not be found. Some configuration checks
116 will not be able to be carried out.])
117   fi
119   # Check for the `guile-snarf' build tool
120   # --------------------------------------
121   AC_ARG_VAR([GUILE_SNARF], [path to guile-snarf utility])
123   AC_CHECK_PROGS([GUILE_SNARF], [guile-snarf guile-1.8-snarf], [no])
124   if test "x$GUILE_SNARF" = xno ; then
125     AC_MSG_ERROR([The `guile-snarf' tool could not be found. Please ensure that the
126 Guile development headers and tools are correctly installed, and rerun
127 configure.])
128   fi
130   # Check for behaviour of `scm_display_error'
131   # ------------------------------------------
132   if test "X$GUILE" != "Xno"; then
134     AC_MSG_CHECKING([whether scm_display_error expects a stack argument])
135     if $GUILE -c \
136 "(exit
137    (false-if-exception
138      (begin
139        (display-error (make-stack #t) (current-output-port) \"a\" \"b\" '() '())
140        #t)))" > /dev/null; then
141       AC_MSG_RESULT([yes])
142       AC_DEFINE([HAVE_SCM_DISPLAY_ERROR_STACK], 1,
143                 [Define to 1 if scm_display_error expects a stack as first argument.])
144     else
145       AC_MSG_RESULT([no])
146     fi
148     AC_MSG_CHECKING([whether scm_display_error expects a frame argument])
149     if $GUILE -c \
150 "(exit
151    (false-if-exception
152      (begin
153        (display-error (stack-ref (make-stack #t) 0)
154                       (current-output-port) \"a\" \"b\" '() '())
155        #t)))" > /dev/null; then
156       AC_MSG_RESULT([yes])
157       AC_DEFINE([HAVE_SCM_DISPLAY_ERROR_FRAME], 1,
158                 [Define to 1 if scm_display_error expects a frame as first argument.])
159     else
160       AC_MSG_RESULT([no])
161     fi
162   fi
164   # Check for functions in `libguile'
165   # ---------------------------------
167   # Save build-related variables
168   save_CFLAGS="${CFLAGS}"
169   save_LIBS="${LIBS}"
171   CFLAGS="${GUILE_CFLAGS} ${CFLAGS}"
172   LIBS="${GUILE_LIBS}"
174   AC_CHECK_FUNCS([scm_from_utf8_string])
175   AC_CHECK_FUNCS([scm_from_utf8_stringn])
176   AC_CHECK_FUNCS([scm_to_utf8_string])
177   AC_CHECK_FUNCS([scm_to_utf8_stringn])
178   AC_CHECK_FUNCS([scm_from_utf8_symbol])
179   AC_CHECK_FUNCS([scm_from_utf8_symboln])
181   # Restore build-related variables
182   CFLAGS="${save_CFLAGS}"
183   LIBS="${save_LIBS}"
185 ])dnl AX_CHECK_GUILE