Skip to content

Commit aee68dd

Browse files
author
q-posev
committed
add Autoconf macro for SWIG
1 parent 5d5025a commit aee68dd

File tree

2 files changed

+143
-0
lines changed

2 files changed

+143
-0
lines changed

configure.ac

+4
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ if test "x${TREXIO_DEVEL}" != "x"; then
126126
AC_PROG_AWK
127127
AM_PATH_PYTHON([3.0])
128128

129+
AX_PKG_SWIG(4.0.0, [], AC_MSG_WARN([SWIG is required to build Python API.]) )
130+
# The macro below performs Python benchmarks, but overlapping with AM_PATH_PYTHON
131+
#AX_SWIG_PYTHON
132+
129133
AC_CHECK_PROGS([EMACS],[emacs26 emacs],[no])
130134
if test x${EMACS} == xno ; then
131135
AC_MSG_ERROR([

m4/ax_pkg_swig.m4

+139
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
# ===========================================================================
2+
# https://www.gnu.org/software/autoconf-archive/ax_pkg_swig.html
3+
# ===========================================================================
4+
#
5+
# SYNOPSIS
6+
#
7+
# AX_PKG_SWIG([major.minor.micro], [action-if-found], [action-if-not-found])
8+
#
9+
# DESCRIPTION
10+
#
11+
# This macro searches for a SWIG installation on your system. If found,
12+
# then SWIG is AC_SUBST'd; if not found, then $SWIG is empty. If SWIG is
13+
# found, then SWIG_LIB is set to the SWIG library path, and AC_SUBST'd.
14+
#
15+
# You can use the optional first argument to check if the version of the
16+
# available SWIG is greater than or equal to the value of the argument. It
17+
# should have the format: N[.N[.N]] (N is a number between 0 and 999. Only
18+
# the first N is mandatory.) If the version argument is given (e.g.
19+
# 1.3.17), AX_PKG_SWIG checks that the swig package is this version number
20+
# or higher.
21+
#
22+
# As usual, action-if-found is executed if SWIG is found, otherwise
23+
# action-if-not-found is executed.
24+
#
25+
# In configure.in, use as:
26+
#
27+
# AX_PKG_SWIG(1.3.17, [], [ AC_MSG_ERROR([SWIG is required to build..]) ])
28+
# AX_SWIG_ENABLE_CXX
29+
# AX_SWIG_MULTI_MODULE_SUPPORT
30+
# AX_SWIG_PYTHON
31+
#
32+
# LICENSE
33+
#
34+
# Copyright (c) 2008 Sebastian Huber <[email protected]>
35+
# Copyright (c) 2008 Alan W. Irwin
36+
# Copyright (c) 2008 Rafael Laboissiere <[email protected]>
37+
# Copyright (c) 2008 Andrew Collier
38+
# Copyright (c) 2011 Murray Cumming <[email protected]>
39+
# Copyright (c) 2021 Vincent Danjean <[email protected]>
40+
#
41+
# This program is free software; you can redistribute it and/or modify it
42+
# under the terms of the GNU General Public License as published by the
43+
# Free Software Foundation; either version 2 of the License, or (at your
44+
# option) any later version.
45+
#
46+
# This program is distributed in the hope that it will be useful, but
47+
# WITHOUT ANY WARRANTY; without even the implied warranty of
48+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
49+
# Public License for more details.
50+
#
51+
# You should have received a copy of the GNU General Public License along
52+
# with this program. If not, see <https://www.gnu.org/licenses/>.
53+
#
54+
# As a special exception, the respective Autoconf Macro's copyright owner
55+
# gives unlimited permission to copy, distribute and modify the configure
56+
# scripts that are the output of Autoconf when processing the Macro. You
57+
# need not follow the terms of the GNU General Public License when using
58+
# or distributing such scripts, even though portions of the text of the
59+
# Macro appear in them. The GNU General Public License (GPL) does govern
60+
# all other use of the material that constitutes the Autoconf Macro.
61+
#
62+
# This special exception to the GPL applies to versions of the Autoconf
63+
# Macro released by the Autoconf Archive. When you make and distribute a
64+
# modified version of the Autoconf Macro, you may extend this special
65+
# exception to the GPL to apply to your modified version as well.
66+
67+
#serial 14
68+
69+
AC_DEFUN([AX_PKG_SWIG],[
70+
# Find path to the "swig" executable.
71+
AC_PATH_PROGS([SWIG],[swig swig3.0 swig2.0])
72+
if test -z "$SWIG" ; then
73+
m4_ifval([$3],[$3],[:])
74+
elif test -z "$1" ; then
75+
m4_ifval([$2],[$2],[:])
76+
else
77+
AC_MSG_CHECKING([SWIG version])
78+
[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'`]
79+
AC_MSG_RESULT([$swig_version])
80+
if test -n "$swig_version" ; then
81+
# Calculate the required version number components
82+
[required=$1]
83+
[required_major=`echo $required | sed 's/[^0-9].*//'`]
84+
if test -z "$required_major" ; then
85+
[required_major=0]
86+
fi
87+
[required=`echo $required. | sed 's/[0-9]*[^0-9]//'`]
88+
[required_minor=`echo $required | sed 's/[^0-9].*//'`]
89+
if test -z "$required_minor" ; then
90+
[required_minor=0]
91+
fi
92+
[required=`echo $required. | sed 's/[0-9]*[^0-9]//'`]
93+
[required_patch=`echo $required | sed 's/[^0-9].*//'`]
94+
if test -z "$required_patch" ; then
95+
[required_patch=0]
96+
fi
97+
# Calculate the available version number components
98+
[available=$swig_version]
99+
[available_major=`echo $available | sed 's/[^0-9].*//'`]
100+
if test -z "$available_major" ; then
101+
[available_major=0]
102+
fi
103+
[available=`echo $available | sed 's/[0-9]*[^0-9]//'`]
104+
[available_minor=`echo $available | sed 's/[^0-9].*//'`]
105+
if test -z "$available_minor" ; then
106+
[available_minor=0]
107+
fi
108+
[available=`echo $available | sed 's/[0-9]*[^0-9]//'`]
109+
[available_patch=`echo $available | sed 's/[^0-9].*//'`]
110+
if test -z "$available_patch" ; then
111+
[available_patch=0]
112+
fi
113+
# Convert the version tuple into a single number for easier comparison.
114+
# Using base 100 should be safe since SWIG internally uses BCD values
115+
# to encode its version number.
116+
required_swig_vernum=`expr $required_major \* 10000 \
117+
\+ $required_minor \* 100 \+ $required_patch`
118+
available_swig_vernum=`expr $available_major \* 10000 \
119+
\+ $available_minor \* 100 \+ $available_patch`
120+
121+
if test $available_swig_vernum -lt $required_swig_vernum; then
122+
AC_MSG_WARN([SWIG version >= $1 is required. You have $swig_version.])
123+
SWIG=''
124+
m4_ifval([$3],[$3],[])
125+
else
126+
AC_MSG_CHECKING([for SWIG library])
127+
SWIG_LIB=`$SWIG -swiglib`
128+
AC_MSG_RESULT([$SWIG_LIB])
129+
m4_ifval([$2],[$2],[])
130+
fi
131+
else
132+
AC_MSG_WARN([cannot determine SWIG version])
133+
SWIG=''
134+
m4_ifval([$3],[$3],[])
135+
fi
136+
fi
137+
AC_SUBST([SWIG_LIB])
138+
])
139+

0 commit comments

Comments
 (0)