Issue 7: Support for the TMote Sky and MicaZ platforms
[remote/remote-mci.git] / acinclude.m4
blob9d7f383849c75af8139cc594df208968b4f605e9
1 # The boost library autoconf macros were taken from
3 #  http://autoconf-archive.cryp.to/ax_boost_program_options.html
5 # and the mysql client library autoconf macro was taken from:
7 #  http://autoconf-archive.cryp.to/ax_lib_mysql.html
9 # Both have the following license:
11 #  Copyright (c) 2007 Thomas Porschberg <thomas@randspringer.de>
12 #  Copyright (c) 2006 Mateusz Loskot <mateusz@loskot.net>
14 #  Copying and distribution of this file, with or without modification,
15 #  are permitted in any medium without royalty provided the copyright
16 #  notice and this notice are preserved.
18 # {{{ Boost program options
20 AC_DEFUN([AX_BOOST_PROGRAM_OPTIONS],
22 AC_ARG_WITH([boost-program-options],
23         AS_HELP_STRING([--with-boost-program-options@<:@=special-lib@:>@],
24                 [use the program options library from boost - it is possible to specify a certain library for the linker
25                 e.g. --with-boost-program-options=boost_program_options-gcc-mt-1_33_1 ]),
26         [
27                 if test "$withval" = "no"; then
28                         want_boost="no"
29                 elif test "$withval" = "yes"; then
30                         want_boost="yes"
31                         ax_boost_user_program_options_lib=""
32                 else
33                         want_boost="yes"
34                         ax_boost_user_program_options_lib="$withval"
35                 fi
36         ],
37         [want_boost="yes"]
40 CONFIG_BOOST_PROGRAM_OPTIONS=no
42 if test "x$want_boost" = "xyes"; then
43         AC_REQUIRE([AC_PROG_CC])
44         export want_boost
45         CPPFLAGS_SAVED="$CPPFLAGS"
46         CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
47         export CPPFLAGS
48         LDFLAGS_SAVED="$LDFLAGS"
49         LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
50         export LDFLAGS
52         AC_CACHE_CHECK([whether the Boost::Program_Options library is available],
53                 ax_cv_boost_program_options,
54                 [AC_LANG_PUSH(C++)
55                 AC_COMPILE_IFELSE(AC_LANG_PROGRAM([[@%:@include <boost/program_options.hpp>
56                                                   ]],
57                                                   [[boost::program_options::options_description generic("Generic options")]]),
58                                   ax_cv_boost_program_options=yes,
59                                   ax_cv_boost_program_options=no)
60                 AC_LANG_POP([C++])
61         ])
62         if test "$ax_cv_boost_program_options" = yes; then
63                 AC_DEFINE(HAVE_BOOST_PROGRAM_OPTIONS,[1],[Define if the Boost::PROGRAM_OPTIONS library is available])
64                 BN=boost_program_options
65                 AC_LANG_PUSH(C++)
66                 if test "x$ax_boost_user_program_options_lib" = "x"; then
67                         for ax_lib in $BN $BN-$CC $BN-$CC-mt $BN-$CC-mt-s $BN-$CC-s \
68                                 lib$BN lib$BN-$CC lib$BN-$CC-mt lib$BN-$CC-mt-s lib$BN-$CC-s \
69                                         $BN-mgw $BN-mgw $BN-mgw-mt $BN-mgw-mt-s $BN-mgw-s ; do
70                                 AC_CHECK_LIB($ax_lib, main,
71                                         [BOOST_PROGRAM_OPTIONS_LIB="-l$ax_lib"; AC_SUBST(BOOST_PROGRAM_OPTIONS_LIB) CONFIG_BOOST_PROGRAM_OPTIONS="yes"; break],
72                                         [CONFIG_BOOST_PROGRAM_OPTIONS="no"])
73                         done
74                 else
75                         for ax_lib in $ax_boost_user_program_options_lib $BN-$ax_boost_user_program_options_lib; do
76                                 AC_CHECK_LIB($ax_lib, main,
77                                         [BOOST_PROGRAM_OPTIONS_LIB="-l$ax_lib"; AC_SUBST(BOOST_PROGRAM_OPTIONS_LIB) CONFIG_BOOST_PROGRAM_OPTIONS="yes"; break],
78                                         [CONFIG_BOOST_PROGRAM_OPTIONS="no"])
79                         done
80                 fi
81                 AC_LANG_POP([C++])
82                 if test "x$CONFIG_BOOST_PROGRAM_OPTIONS" = "xno"; then
83                         AC_MSG_ERROR([Could not link against [$ax_lib] !])
84                 fi
85         fi
86         CPPFLAGS="$CPPFLAGS_SAVED"
87         LDFLAGS="$LDFLAGS_SAVED"
91 # }}}
92 # {{{ MySQL
94 AC_DEFUN([AX_LIB_MYSQL],
96 AC_ARG_WITH([mysql],
97         AC_HELP_STRING([--with-mysql=@<:@ARG@:>@],
98                 [use MySQL client library @<:@default=yes@:>@, optionally specify path to mysql_config]
99         ),
100         [
101         if test "$withval" = "no"; then
102                 want_mysql="no"
103         elif test "$withval" = "yes"; then
104                 want_mysql="yes"
105         else
106                 want_mysql="yes"
107                 MYSQL_CONFIG="$withval"
108         fi
109         ],
110         [want_mysql="yes"]
113 MYSQL_CFLAGS=""
114 MYSQL_LDFLAGS=""
115 MYSQL_VERSION=""
116 CONFIG_MYSQL=no
119 dnl Check MySQL libraries (libpq)
122 if test "$want_mysql" = "yes"; then
124         if test -z "$MYSQL_CONFIG" -o test; then
125                 AC_PATH_PROG([MYSQL_CONFIG], [mysql_config], [no])
126         fi
128         if test "$MYSQL_CONFIG" != "no"; then
129                 AC_MSG_CHECKING([for MySQL libraries])
131                 MYSQL_CFLAGS="`$MYSQL_CONFIG --cflags`"
132                 MYSQL_LDFLAGS="`$MYSQL_CONFIG --libs`"
133                 MYSQL_VERSION=`$MYSQL_CONFIG --version`
135                 AC_DEFINE([HAVE_MYSQL], [1],
136                           [Define to 1 if MySQL libraries are available])
138                 CONFIG_MYSQL="yes"
139                 AC_MSG_RESULT([yes])
140         fi
144 dnl Check if required version of MySQL is available
148 mysql_version_req=ifelse([$1], [], [], [$1])
150 if test "$CONFIG_MYSQL" = "yes" -a -n "$mysql_version_req"; then
152         AC_MSG_CHECKING([if MySQL version is >= $mysql_version_req])
154         dnl Decompose required version string of MySQL
155         dnl and calculate its number representation
156         mysql_version_req_major=`expr $mysql_version_req : '\([[0-9]]*\)'`
157         mysql_version_req_minor=`expr $mysql_version_req : '[[0-9]]*\.\([[0-9]]*\)'`
158         mysql_version_req_micro=`expr $mysql_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
159         if test "x$mysql_version_req_micro" = "x"; then
160                 mysql_version_req_micro="0"
161         fi
163         mysql_version_req_number=`expr $mysql_version_req_major \* 1000000 \
164                                    \+ $mysql_version_req_minor \* 1000 \
165                                    \+ $mysql_version_req_micro`
167         dnl Decompose version string of installed MySQL
168         dnl and calculate its number representation
169         mysql_version_major=`expr $MYSQL_VERSION : '\([[0-9]]*\)'`
170         mysql_version_minor=`expr $MYSQL_VERSION : '[[0-9]]*\.\([[0-9]]*\)'`
171         mysql_version_micro=`expr $MYSQL_VERSION : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
172         if test "x$mysql_version_micro" = "x"; then
173                 mysql_version_micro="0"
174         fi
176         mysql_version_number=`expr $mysql_version_major \* 1000000 \
177                                    \+ $mysql_version_minor \* 1000 \
178                                    \+ $mysql_version_micro`
180         mysql_version_check=`expr $mysql_version_number \>\= $mysql_version_req_number`
181         if test "$mysql_version_check" = "1"; then
182                 AC_MSG_RESULT([yes])
183         else
184                 AC_MSG_RESULT([no])
185                 CONFIG_MYSQL=no
186         fi
189 AC_SUBST([MYSQL_VERSION])
190 AC_SUBST([MYSQL_CFLAGS])
191 AC_SUBST([MYSQL_LDFLAGS])
194 # }}}
195 # {{{ MySQL++
197 AC_DEFUN([AX_LIB_MYSQLPP],
199 AC_ARG_WITH([mysqlpp],
200         AC_HELP_STRING([--with-mysqlpp=@<:@ARG@:>@],
201                 [use MySQL client C++ library @<:@default=yes@:>@, optionally specify path to the library]),
202         [
203                 if test "$withval" = "no"; then
204                         want_mysqlpp="no"
205                 elif test "$withval" = "yes"; then
206                         want_mysqlpp="yes"
207                         ax_mysqlpp_path=""
208                 else
209                         want_mysqlpp="yes"
210                         ax_mysqlpp_path="$withval"
211                 fi
212         ],
213         [want_mysqlpp="yes"]
216 CONFIG_MYSQLPP=no
217 MYSQLPP_CXXFLAGS=""
218 test -z "$ax_mysqlpp_path" || MYSQLPP_CXXFLAGS="-I$ax_myslpp_path"
220 if test "x$want_mysqlpp" = "xyes"; then
221         AC_REQUIRE([AC_PROG_CC])
222         CPPFLAGS_SAVED="$CPPFLAGS"
223         CPPFLAGS="$CPPFLAGS $MYSQLPP_CPPFLAGS"
224         export CPPFLAGS
226         CXXFLAGS_SAVED="$CXXFLAGS"
227         CXXFLAGS="$CPPFLAGS $MYSQL_CFLAGS $MYSQL_CXXFLAGS"
228         export CXXFLAGS
230         LDFLAGS_SAVED="$LDFLAGS"
231         LDFLAGS="$LDFLAGS $MYSQL_LDFLAGS $MYSQLPP_LDFLAGS"
232         export LDFLAGS
234         AC_CACHE_CHECK(whether the MySQL++ library is available,
235                 ax_cv_mysqlpp,
236                 [AC_LANG_PUSH([C++])
237                 AC_COMPILE_IFELSE(AC_LANG_PROGRAM([[@%:@include <mysql++/mysql++.h>
238                                                   ]],
239                                                   [[mysqlpp::Connection con(false)]]),
240                                   ax_cv_mysqlpp=yes,
241                                   ax_cv_mysqlpp=no)
242                 AC_LANG_POP([C++])
243                 ])
245         if test "x$ax_cv_mysqlpp" = "xyes"; then
246                 AC_DEFINE(HAVE_MYSQLPP,[1],[Define if the MySQL++ library is available])
247                 AC_LANG_PUSH([C++])
248                 AC_CHECK_LIB(mysqlpp, main,CONFIG_MYSQLPP=yes,CONFIG_MYSQLPP=no)
249                 AC_LANG_POP([C++])
251                 if test "x$CONFIG_MYSQLPP" = "xno"; then
252                         AC_MSG_ERROR(Could not link against mysqlpp !)
253                 fi
254         fi
256         CPPFLAGS="$CPPFLAGS_SAVED"
257         CXXFLAGS="$CXXFLAGS_SAVED"
258         LDFLAGS="$LDFLAGS_SAVED"
261 AC_SUBST([MYSQLPP_CPPFLAGS])
262 AC_SUBST([MYSQLPP_CXXFLAGS])
265 # }}}