1238106Sdes# ===========================================================================
2238106Sdes#              http://autoconf-archive.cryp.to/ac_pkg_swig.html
3238106Sdes# ===========================================================================
4238106Sdes#
5238106Sdes# SYNOPSIS
6238106Sdes#
7238106Sdes#   AC_PROG_SWIG([major.minor.micro])
8238106Sdes#
9238106Sdes# DESCRIPTION
10238106Sdes#
11238106Sdes#   This macro searches for a SWIG installation on your system. If found you
12238106Sdes#   should call SWIG via $(SWIG). You can use the optional first argument to
13238106Sdes#   check if the version of the available SWIG is greater than or equal to
14238106Sdes#   the value of the argument. It should have the format: N[.N[.N]] (N is a
15238106Sdes#   number between 0 and 999. Only the first N is mandatory.)
16238106Sdes#
17238106Sdes#   If the version argument is given (e.g. 1.3.17), AC_PROG_SWIG checks that
18238106Sdes#   the swig package is this version number or higher.
19238106Sdes#
20238106Sdes#   In configure.in, use as:
21238106Sdes#
22238106Sdes#     AC_PROG_SWIG(1.3.17)
23238106Sdes#     SWIG_ENABLE_CXX
24238106Sdes#     SWIG_MULTI_MODULE_SUPPORT
25238106Sdes#     SWIG_PYTHON
26238106Sdes#
27238106Sdes# LAST MODIFICATION
28238106Sdes#
29238106Sdes#   2008-04-12
30238106Sdes#
31238106Sdes# COPYLEFT
32238106Sdes#
33238106Sdes#   Copyright (c) 2008 Sebastian Huber <sebastian-huber@web.de>
34238106Sdes#   Copyright (c) 2008 Alan W. Irwin <irwin@beluga.phys.uvic.ca>
35238106Sdes#   Copyright (c) 2008 Rafael Laboissiere <rafael@laboissiere.net>
36238106Sdes#   Copyright (c) 2008 Andrew Collier <colliera@ukzn.ac.za>
37238106Sdes#
38238106Sdes#   This program is free software; you can redistribute it and/or modify it
39238106Sdes#   under the terms of the GNU General Public License as published by the
40238106Sdes#   Free Software Foundation; either version 2 of the License, or (at your
41238106Sdes#   option) any later version.
42238106Sdes#
43238106Sdes#   This program is distributed in the hope that it will be useful, but
44238106Sdes#   WITHOUT ANY WARRANTY; without even the implied warranty of
45238106Sdes#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
46238106Sdes#   Public License for more details.
47238106Sdes#
48238106Sdes#   You should have received a copy of the GNU General Public License along
49238106Sdes#   with this program. If not, see <http://www.gnu.org/licenses/>.
50238106Sdes#
51238106Sdes#   As a special exception, the respective Autoconf Macro's copyright owner
52238106Sdes#   gives unlimited permission to copy, distribute and modify the configure
53238106Sdes#   scripts that are the output of Autoconf when processing the Macro. You
54238106Sdes#   need not follow the terms of the GNU General Public License when using
55238106Sdes#   or distributing such scripts, even though portions of the text of the
56238106Sdes#   Macro appear in them. The GNU General Public License (GPL) does govern
57238106Sdes#   all other use of the material that constitutes the Autoconf Macro.
58238106Sdes#
59238106Sdes#   This special exception to the GPL applies to versions of the Autoconf
60238106Sdes#   Macro released by the Autoconf Macro Archive. When you make and
61238106Sdes#   distribute a modified version of the Autoconf Macro, you may extend this
62238106Sdes#   special exception to the GPL to apply to your modified version as well.
63238106Sdes
64238106SdesAC_DEFUN([AC_PROG_SWIG],[
65238106Sdes        AC_PATH_PROG([SWIG],[swig])
66238106Sdes        if test -z "$SWIG" ; then
67238106Sdes                AC_MSG_WARN([cannot find 'swig' program. You should look at http://www.swig.org])
68238106Sdes                SWIG='echo "Error: SWIG is not installed. You should look at http://www.swig.org" ; false'
69238106Sdes        elif test -n "$1" ; then
70238106Sdes                AC_MSG_CHECKING([for SWIG version])
71238106Sdes                [swig_version=`$SWIG -version 2>&1 | grep 'SWIG Version' | sed 's/.*\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*/\1/g'`]
72238106Sdes                AC_MSG_RESULT([$swig_version])
73238106Sdes                if test -n "$swig_version" ; then
74238106Sdes                        # Calculate the required version number components
75238106Sdes                        [required=$1]
76238106Sdes                        [required_major=`echo $required | sed 's/[^0-9].*//'`]
77238106Sdes                        if test -z "$required_major" ; then
78238106Sdes                                [required_major=0]
79238106Sdes                        fi
80238106Sdes                        [required=`echo $required | sed 's/[0-9]*[^0-9]//'`]
81238106Sdes                        [required_minor=`echo $required | sed 's/[^0-9].*//'`]
82238106Sdes                        if test -z "$required_minor" ; then
83238106Sdes                                [required_minor=0]
84238106Sdes                        fi
85238106Sdes                        [required=`echo $required | sed 's/[0-9]*[^0-9]//'`]
86238106Sdes                        [required_patch=`echo $required | sed 's/[^0-9].*//'`]
87238106Sdes                        if test -z "$required_patch" ; then
88238106Sdes                                [required_patch=0]
89238106Sdes                        fi
90238106Sdes                        # Calculate the available version number components
91238106Sdes                        [available=$swig_version]
92238106Sdes                        [available_major=`echo $available | sed 's/[^0-9].*//'`]
93238106Sdes                        if test -z "$available_major" ; then
94238106Sdes                                [available_major=0]
95238106Sdes                        fi
96238106Sdes                        [available=`echo $available | sed 's/[0-9]*[^0-9]//'`]
97238106Sdes                        [available_minor=`echo $available | sed 's/[^0-9].*//'`]
98238106Sdes                        if test -z "$available_minor" ; then
99238106Sdes                                [available_minor=0]
100238106Sdes                        fi
101238106Sdes                        [available=`echo $available | sed 's/[0-9]*[^0-9]//'`]
102238106Sdes                        [available_patch=`echo $available | sed 's/[^0-9].*//'`]
103238106Sdes                        if test -z "$available_patch" ; then
104238106Sdes                                [available_patch=0]
105238106Sdes                        fi
106238106Sdes                        if test $available_major -ne $required_major \
107238106Sdes                                -o $available_minor -ne $required_minor \
108238106Sdes                                -o $available_patch -lt $required_patch ; then
109238106Sdes                                AC_MSG_WARN([SWIG version >= $1 is required.  You have $swig_version.  You should look at http://www.swig.org])
110238106Sdes                                SWIG='echo "Error: SWIG version >= $1 is required.  You have '"$swig_version"'.  You should look at http://www.swig.org" ; false'
111238106Sdes                        else
112238106Sdes                                AC_MSG_NOTICE([SWIG executable is '$SWIG'])
113238106Sdes                                SWIG_LIB=`$SWIG -swiglib`
114238106Sdes                                AC_MSG_NOTICE([SWIG library directory is '$SWIG_LIB'])
115238106Sdes                        fi
116238106Sdes                else
117238106Sdes                        AC_MSG_WARN([cannot determine SWIG version])
118238106Sdes                        SWIG='echo "Error: Cannot determine SWIG version.  You should look at http://www.swig.org" ; false'
119238106Sdes                fi
120238106Sdes        fi
121238106Sdes        AC_SUBST([SWIG_LIB])
122238106Sdes])
123