Update to 2.0.0 tree from current Fremantle build
[opencv] / autotools / aclocal / swig_complete.m4
1 # original version contributed by   Sebastian Huber
2
3 # this version by                   Mark Asbach
4 #                                   Institute of Communications Engineering
5 #                                   RWTH Aachen University
6
7
8 # SWIG_PROG([required-version = N[.N[.N]]])
9 #
10 # Checks for the SWIG program.  If found you can (and should) call
11 # SWIG via $(SWIG).  You can use the optional first argument to check
12 # if the version of the available SWIG is greater than or equal to the
13 # value of the argument.  It should have the format: N[.N[.N]] (N is a
14 # number between 0 and 999.  Only the first N is mandatory.)
15 #
16 AC_DEFUN([SWIG_PROG],[
17   AC_DIAGNOSE([obsolete],[Please replace calls to SWIG_PROG by AC_PATH_SWIG])
18   AC_PATH_SWIG($1)
19 ])
20
21
22 # AC_PATH_SWIG([required-version = N[.N[.N]]])
23 #
24 # Checks for the SWIG program.  If found you can (and should) call
25 # SWIG via $(SWIG).  You can use the optional first argument to check
26 # if the version of the available SWIG is greater than or equal to the
27 # value of the argument.  It should have the format: N[.N[.N]] (N is a
28 # number between 0 and 999.  Only the first N is mandatory.)
29 #
30 AC_DEFUN([AC_PATH_SWIG],[
31   #
32   # define SWIG as precious variable
33   AC_ARG_VAR([SWIG],[Simplified Wrapper and Interface Generator, used for Python bindings])
34   #
35   # check where to find the swig executable
36   AC_PATH_PROG([SWIG],[swig])
37   if test -n "$SWIG"; then
38     #
39     # inquire version number
40     if test -n "$SWIG"; then
41       AC_MSG_CHECKING([for SWIG version])
42       dnl command is m4 quoted, otherwise, the sed command line breaks on some platforms
43       [SWIG_VERSION=`$SWIG -version 2>&1 | grep 'SWIG Version' | sed -e 's/^[^0-9]*//g' -e 's/ .*//g'`]
44       AC_MSG_RESULT([$SWIG_VERSION])
45     else
46       SWIG_VERSION=""
47     fi
48     #
49     # if a user requested a given number, check for that now
50     if test -n "$1"; then
51       if test -n "$SWIG_VERSION"; then
52         # 
53         # compare version strings
54         AC_VERSION_AT_LEAST([$SWIG_VERSION],[$1])
55         if test x"$ac_version_at_least" = "xyes"; then
56           # everything is perfect
57           :
58         else
59           # version requirement not fulfilled
60           # we could stop with an error, but instead we just pretend 
61           # that there is no swig installed
62           AC_MSG_WARN([SWIG version $1 is required, you have $SWIG_VERSION])
63           SWIG=""
64         fi
65       else
66         # there was no version number available from swig
67         # and because the user has given requirements, we take
68         # this for a version mismatch
69         AC_MSG_WARN([SWIG version $1 is required, you have $SWIG_VERSION])
70         SWIG=""
71       fi
72     else
73       # there was no version number available from swig
74       # but because no requirement was given, just warn and go on
75       AC_MSG_WARN([cannot determine SWIG version])
76     fi
77   fi
78   #
79   # just in case someone wants to link swig libraries,
80   # we try to determine their path
81   if test -n "$SWIG" ; then
82     SWIG_RUNTIME_LIBS_DIR="${SWIG%/bin*}/lib"
83     AC_MSG_NOTICE([SWIG runtime library directory is '$SWIG_RUNTIME_LIBS_DIR'])
84   fi
85   #
86 # AC_SUBST([SWIG])  -- already done by AC_PATH_PROG([SWIG],[swig])
87   AC_SUBST([SWIG_VERSION])
88   AC_SUBST([SWIG_RUNTIME_LIBS_DIR])
89 ])
90
91
92 # SWIG_ENABLE_CXX()
93 #
94 # Enable SWIG C++ support.  This effects all invocations of $(SWIG).
95 AC_DEFUN([SWIG_ENABLE_CXX],[
96   AC_REQUIRE([AC_PATH_SWIG])
97   AC_REQUIRE([AC_PROG_CXX])
98   if test -z "$SWIG" ; then
99     AC_MSG_ERROR([swig not found])
100   fi
101   SWIG="$SWIG -c++"
102 ]) # SWIG_ENABLE_CXX
103
104
105 # SWIG_MULTI_MODULE_SUPPORT()
106 #
107 # Enable support for multiple modules.  This effects all invocations
108 # of $(SWIG).  You have to link all generated modules against the
109 # appropriate SWIG runtime library.  If you want to build Python
110 # modules for example, use the SWIG_PYTHON() macro and link the
111 # modules against $(SWIG_PYTHON_LIBS).
112 AC_DEFUN([SWIG_MULTI_MODULE_SUPPORT],[
113   AC_REQUIRE([AC_PATH_SWIG])
114   AC_MSG_CHECKING([for swig multi module support])
115   #
116   if test -n "$SWIG_VERSION"; then
117     #
118     AC_VERSION_AT_LEAST([$SWIG_VERSION],[1.3.24])
119     if test x"$ac_version_at_least" = "xyes"; then
120       # perfect!
121       AC_MSG_RESULT([[always working (SWIG >= 1.3.24)]])
122     else
123       #
124       # there were some older versions that need special treatment
125       # in form of additional command line flags and/or library
126       # dependencies
127       AC_VERSION_AT_LEAST([$SWIG_VERSION],[1.3.20])
128       if test x"$ac_version_at_least" = "xyes"; then
129         SWIG="$SWIG -noruntime"
130         AC_MSG_RESULT([[interim syntax (SWIG >= 1.3.20 < 1.3.24)]])
131       else
132         SWIG="$SWIG -c"
133         AC_MSG_RESULT([[old syntax (SWIG < 1.3.20)]])
134       fi
135     fi
136   else
137     AC_MSG_ERROR([SWIG version number unknown - cannot set flags for multi module support])
138   fi
139 # AC_SUBST([SWIG]) -- already done by AC_PATH_SWIG()
140 ])
141
142
143 # SWIG_PYTHON([use-shadow-classes = {no, yes}])
144 #
145 # Checks for Python and provides the $(SWIG_PYTHON_CPPFLAGS),
146 # $(SWIG_PYTHON_LIBS) and $(SWIG_PYTHON_OPT) output variables.
147 # $(SWIG_PYTHON_OPT) contains all necessary SWIG options to generate
148 # code for Python.  Shadow classes are enabled unless the value of the
149 # optional first argument is exactly 'no'.  If you need multi module
150 # support (provided by the SWIG_MULTI_MODULE_SUPPORT() macro) use
151 # $(SWIG_PYTHON_LIBS) to link against the appropriate library.  It
152 # contains the SWIG Python runtime library that is needed by the type
153 # check system for example.
154 #
155 AC_DEFUN([SWIG_PYTHON],[
156   AC_REQUIRE([AC_PATH_SWIG])
157   AC_REQUIRE([AM_PATH_PYTHON])
158   #
159   test "x$1" != "xno" || swig_shadow=" -noproxy"
160   #
161   if test -n "$SWIG_VERSION"; then
162     AC_VERSION_AT_LEAST([$SWIG_VERSION],[1.3.24])
163     if test x"$ac_version_at_least" = "xyes"; then
164       SWIG_PYTHON_LIBS=""
165     else
166       SWIG_PYTHON_LIBS="-L$SWIG_RUNTIME_LIBS_DIR -lswigpy"
167     fi
168   else
169     AC_MSG_ERROR([SWIG version number unknown - cannot set python libs])
170   fi
171   #
172   AC_SUBST([SWIG_PYTHON_OPT], "-python$swig_shadow")
173   AC_SUBST([SWIG_PYTHON_LIBS])
174 ])
175
176 # PYTHON_DEVEL()
177 #
178 # Checks for Python and tries to get the include path to 'Python.h'.
179 # It provides the $(PYTHON_CPPFLAGS) and $(PYTHON_LDFLAGS) output variable.
180 AC_DEFUN([PYTHON_DEVEL],[
181         AC_REQUIRE([AM_PATH_PYTHON])[]dnl
182
183         # Check for Python include path
184         AC_MSG_CHECKING([for Python include path])
185         python_path=${PYTHON%/bin*}
186         for i in "$python_path/include/python$PYTHON_VERSION/" "$python_path/include/python/" "$python_path/" ; do
187                 python_path=`find $i -type f -name Python.h -print`
188                 if test -n "$python_path" ; then
189                         break
190                 fi
191         done
192         for i in $python_path ; do
193                 python_path=${python_path%/Python.h}
194                 break
195         done
196         AC_MSG_RESULT([$python_path])
197         if test -z "$python_path" ; then
198                 AC_MSG_ERROR([cannot find Python include path])
199         fi
200         AC_SUBST([PYTHON_CPPFLAGS],[-I$python_path])
201
202         # Check for Python library path
203         AC_MSG_CHECKING([for Python library path])
204         python_path=${PYTHON%/bin*}
205         for i in "$python_path/lib/python$PYTHON_VERSION/config/" "$python_path/lib/python$PYTHON_VERSION/" "$python_path/lib/python/config/" "$python_path/lib/python/" "$python_path/" ; do
206                 python_path=`find $i -type f -name libpython$PYTHON_VERSION.* -print`
207                 if test -n "$python_path" ; then
208                         break
209                 fi
210         done
211         for i in $python_path ; do
212                 python_path=${python_path%/libpython*}
213                 break
214         done
215         AC_MSG_RESULT([$python_path])
216         if test -z "$python_path" ; then
217                 AC_MSG_ERROR([cannot find Python library path])
218         fi
219         AC_SUBST([PYTHON_LDFLAGS],["-L$python_path -lpython$PYTHON_VERSION"])
220 ])