-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathmysql.m4
431 lines (359 loc) · 10.9 KB
/
mysql.m4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
dnl
dnl configure.in helper macros
dnl
dnl TODO: fix "mutual exclusive" stuff
dnl 3rd party macro for version number comparisons
m4_include([ax_compare_version.m4])
MYSQL_VERSION=none
dnl check for a --with-mysql configure option and set up
dnl MYSQL_CONFIG and MYSLQ_VERSION variables for further use
dnl this must always be called before any other macro from this file
dnl
dnl WITH_MYSQL()
dnl
AC_DEFUN([WITH_MYSQL], [
AC_MSG_CHECKING(for mysql_config executable)
# try to find the mysql_config script,
# --with-mysql will either accept its path directly
# or will treat it as the mysql install prefix and will
# search for the script in there
# if no path is given at all we look for the script in
# /usr/bin and /usr/local/mysql/bin
AC_ARG_WITH(mysql, [ --with-mysql=PATH path to mysql_config binary or mysql prefix dir], [
if test $withval = "no"
then
MYSQL_CONFIG="no"
else
if test -x $withval -a -f $withval
then
MYSQL_CONFIG=$withval
MYSQL_PREFIX=`dirname \`dirname $withval\``
elif test -x $withval/bin/mysql_config -a -f $withval/bin/mysql_config
then
MYSQL_CONFIG=$withval/bin/mysql_config
MYSQL_PREFIX=$withval
fi
fi
], [
# implicit "yes", check in $PATH and in known default prefix,
# but only if source not already configured
if test "x$MYSQL_SRCDIR" != "x"
then
MYSQL_CONFIG="no"
elif MYSQL_CONFIG=`which mysql_config`
then
MYSQL_PREFIX=`dirname \`dirname $MYSQL_CONFIG\``
elif test -x /usr/local/mysql/bin/mysql_config -a -f /usr/local/mysql/bin/mysql_config
then
MYSQL_CONFIG=/usr/local/mysql/bin/mysql_config
MYSQL_PREFIX=/usr/local/mysql
fi
])
if test "x$MYSQL_CONFIG" = "x"
then
AC_MSG_ERROR([not found])
elif test "$MYSQL_CONFIG" = "no"
then
MYSQL_CONFIG=""
MYSQL_PREFIX=""
AC_MSG_RESULT([no])
else
if test "x$MYSQL_SRCDIR" != "x"
then
AC_MSG_ERROR("--with-mysql can't be used together with --with-mysql-src")
else
# get installed version
MYSQL_VERSION=`$MYSQL_CONFIG --version`
MYSQL_CONFIG_INCLUDE=`$MYSQL_CONFIG --include`
MYSQL_CONFIG_LIBS_R=`$MYSQL_CONFIG --libs_r`
MYSQL_CLIENT=`dirname $MYSQL_CONFIG`/mysql
AC_MSG_RESULT($MYSQL_CONFIG)
fi
fi
])
dnl check for a --with-mysql-src configure option and set up
dnl MYSQL_CONFIG and MYSLQ_VERSION variables for further use
dnl this must always be called before any other macro from this file
dnl
dnl if you use this together with WITH_MYSQL you have to put this in front of it
dnl
dnl WITH_MYSQL_SRC()
dnl
AC_DEFUN([WITH_MYSQL_SRC], [
AC_MSG_CHECKING(for mysql source directory)
AC_ARG_WITH(mysql-src, [ --with-mysql-src=PATH path to mysql sourcecode], [
if test "x$MYSQL_CONFIG" != "x"
then
AC_MSG_ERROR([--with-mysql-src can't be used together with --with-mysql])
fi
if test -f $withval/include/mysql_version.h.in
then
if test -f $withval/include/mysql_version.h
then
AC_MSG_RESULT(ok)
MYSQL_SRCDIR=$withval
MYSQL_VERSION=`grep MYSQL_SERVER_VERSION $MYSQL_SRCDIR/include/mysql_version.h | sed -e's/"$//g' -e's/.*"//g'`
else
AC_MSG_ERROR([not configured yet])
fi
else
AC_MSG_ERROR([$withval doesn't look like a mysql source dir])
fi
], [
AC_MSG_RESULT(no)
])
if test "x$MYSQL_SRCDIR" != "x"
then
MYSQL_CONFIG_INCLUDE="-I$MYSQL_SRCDIR/include -I$MYSQL_SRCDIR -I$MYSQL_SRCDIR/sql "
MYSQL_CONFIG_LIBS_R="-L$MYSQL_SRCDIR/libmysql_r/.libs -lmysqlclient_r -lz -lm"
fi
])
dnl
dnl check for successfull mysql detection
dnl and register AC_SUBST variables
dnl
dnl MYSQL_SUBST()
dnl
AC_DEFUN([MYSQL_SUBST], [
if test "$MYSQL_VERSION" = "none"
then
AC_MSG_ERROR([MySQL required but not found])
fi
# register replacement vars, these will be filled
# with contant by the other macros
AC_SUBST([MYSQL_CFLAGS])
AC_SUBST([MYSQL_CXXFLAGS])
AC_SUBST([MYSQL_LDFLAGS])
AC_SUBST([MYSQL_LIBS])
AC_SUBST([MYSQL_VERSION])
])
dnl check if current MySQL version meets a version requirement
dnl and act accordingly
dnl
dnl MYSQL_CHECK_VERSION([requested_version],[yes_action],[no_action])
dnl
AC_DEFUN([MYSQL_CHECK_VERSION], [
AX_COMPARE_VERSION([$MYSQL_VERSION], [GE], [$1], [$2], [$3])
])
dnl check if current MySQL version meets a version requirement
dnl and bail out with an error message if not
dnl
dnl MYSQL_NEED_VERSION([need_version])
dnl
AC_DEFUN([MYSQL_NEED_VERSION], [
AC_MSG_CHECKING([mysql version >= $1])
MYSQL_CHECK_VERSION([$1],
[AC_MSG_RESULT([yes ($MYSQL_VERSION)])],
[AC_MSG_ERROR([no ($MYSQL_VERSION)])])
])
dnl check whether the installed server was compiled with libdbug
dnl
dnl TODO we also need to figure out whether we need to define
dnl SAFEMALLOC, maybe PEDANTIC_SAFEMALLOC and SAFE_MUTEX, too
dnl else we may run into errors like
dnl
dnl Can't open shared library '...'
dnl (errno: 22 undefined symbol: my_no_flags_free)
dnl
dnl on loading plugins
dnl
dnl MYSQL_DEBUG_SERVER()
dnl
AC_DEFUN([MYSQL_DEBUG_SERVER], [
AC_MSG_CHECKING(for mysqld debug version)
MYSQL_DBUG=unknown
OLD_CFLAGS=$CFLAGS
CFLAGS="$CFLAGS $MYSQL_CONFIG_INCLUDE"
OLD_CXXFLAGS=$CXXFLAGS
CXXFLAGS="$CXXFLAGS $MYSQL_CONFIG_INCLUDE"
# check for DBUG_ON/OFF being defined in my_config.h
AC_TRY_COMPILE(,[
#include "my_config.h"
#ifdef DBUG_ON
int ok;
#else
# ifdef DBUG_OFF
int ok;
# else
choke me
# endif
#endif
],AS_VAR_SET(MYSQL_DBUG, ["defined by header file"]),AS_VAR_SET(MYSQL_DBUG, unknown))
CFLAGS=$OLD_CFLAGS
CXXFLAGS=$OLD_CXXFLAGS
if test "$MYSQL_DBUG" = "unknown"
then
# fallback: need to check mysqld binary itself
# check $prefix/libexec, $prefix/sbin, $prefix/bin in that order
for dir in libexec sbin bin
do
MYSQLD=$MYSQL_PREFIX/$dir/mysqld
if test -f $MYSQLD -a -x $MYSQLD
then
if ($MYSQLD --help --verbose | grep -q -- "--debug")
then
AC_DEFINE([DBUG_ON], [1], [Use libdbug])
MYSQL_DBUG=yes
else
AC_DEFINE([DBUG_OFF], [1], [Don't use libdbug])
MYSQL_DBUG=no
fi
break;
fi
done
fi
if test "$MYSQL_DBUG" = "unknown"
then
# still unknown? make sure not to use it then
AC_DEFINE([DBUG_OFF], [1], [Don't use libdbug])
MYSQL_DBUG="unknown, assuming no"
fi
AC_MSG_RESULT($MYSQL_DBUG)
#
])
dnl set up variables for compilation of regular C API applications
dnl with optional embedded server
dnl
dnl MYSQL_USE_CLIENT_API()
dnl
AC_DEFUN([MYSQL_USE_CLIENT_API], [
# add regular MySQL C flags
ADDFLAGS=$MYSQL_CONFIG_INCLUDE
MYSQL_CFLAGS="$MYSQL_CFLAGS $ADDFLAGS"
MYSQL_CXXFLAGS="$MYSQL_CXXFLAGS $ADDFLAGS"
# add linker flags for client lib
AC_ARG_ENABLE([embedded-mysql], [ --enable-embedded-mysql enable the MySQL embedded server feature],
[MYSQL_EMBEDDED_LDFLAGS()],
[MYSQL_LDFLAGS="$MYSQL_LDFLAGS $MYSQL_CONFIG_LIBS_R"])
])
dnl set up variables for compilation of regular C API applications
dnl with mandatory embedded server
dnl
dnl MYSQL_USE_EMBEDDED_API()
dnl
AC_DEFUN([MYSQL_USE_EMBEDDED_API], [
# add regular MySQL C flags
ADDFLAGS=$MYSQL_CONFIG_INCLUDE
MYSQL_CFLAGS="$MYSQL_CFLAGS $ADDFLAGS"
MYSQL_CXXFLAGS="$MYSQL_CXXFLAGS $ADDFLAGS"
MYSQL_EMBEDDED_LDFLAGS()
])
dnl
AC_DEFUN([MYSQL_EMBEDDED_LDFLAGS], [
MYSQL_LDFLAGS="$MYSQL_LDFLAGS "`$MYSQL_CONFIG --libmysqld-libs`
AC_MSG_CHECKING([for missing libs])
OLD_CFLAGS=$CFLAGS
OLD_LIBS=$LIBS
CFLAGS="$CFLAGS $MYSQL_CFLAGS"
for MISSING_LIBS in " " "-lz" "-lssl" "-lz -lssl"
do
LIBS="$OLD_LIBS $MYSQL_LDFLAGS $MISSING_LIBS"
AC_TRY_LINK([
#include <stdio.h>
#include <mysql.h>
],[
mysql_server_init(0, NULL, NULL);
], [
LINK_OK=yes
], [
LINK_OK=no
])
if test $LINK_OK = "yes"
then
MYSQL_LDFLAGS="$MYSQL_LDFLAGS $MISSING_LIBS"
AC_MSG_RESULT([$MISSING_LIBS])
break;
fi
done
if test $LINK_OK = "no"
then
AC_MSG_ERROR([linking still fails])
fi
LIBS=$OLD_LIBS
CFLAGS=$OLD_CFLAGS
])
dnl set up variables for compilation of NDBAPI applications
dnl
dnl MYSQL_USE_NDB_API()
dnl
AC_DEFUN([MYSQL_USE_NDB_API], [
MYSQL_USE_CLIENT_API()
AC_PROG_CXX
MYSQL_CHECK_VERSION([5.0.0],[
# mysql_config results need some post processing for now
# the include pathes changed in 5.1.x due
# to the pluggable storage engine clenups,
# it also dependes on whether we build against
# mysql source or installed headers
if test "x$MYSQL_SRCDIR" = "x"
then
IBASE=$MYSQL_CONFIG_INCLUDE
else
IBASE=$MYSQL_SRCDIR
fi
MYSQL_CHECK_VERSION([5.1.0], [
IBASE="$IBASE/storage/ndb"
],[
IBASE="$IBASE/ndb"
])
if test "x$MYSQL_SRCDIR" != "x"
then
IBASE="$MYSQL_SRCDIR/include"
fi
# add the ndbapi specifc include dirs
ADDFLAGS="$ADDFLAGS $IBASE"
ADDFLAGS="$ADDFLAGS $IBASE/ndbapi"
ADDFLAGS="$ADDFLAGS $IBASE/mgmapi"
MYSQL_CFLAGS="$MYSQL_CFLAGS $ADDFLAGS"
MYSQL_CXXFLAGS="$MYSQL_CXXFLAGS $ADDFLAGS"
# check for ndbapi header file NdbApi.hpp
AC_LANG_PUSH(C++)
OLD_CXXFLAGS=$CXXFLAGS
CXXFLAGS="$CXXFLAGS $MYSQL_CXXFLAGS"
AC_CHECK_HEADER([NdbApi.hpp],,[AC_ERROR(["Can't find NdbApi header files"])])
CXXFLAGS=$OLD_CXXFLAGS
AC_LANG_POP()
# check for the ndbapi client library
AC_LANG_PUSH(C++)
OLD_LIBS=$LIBS
LIBS="$LIBS $MYSQL_LIBS -lmysys -lmystrings"
OLD_LDFLAGS=$LDFLAGS
LDFLAGS="$LDFLAGS $MYSQL_LDFLAGS"
AC_CHECK_LIB([ndbclient],[ndb_init],,[AC_ERROR(["Can't find NdbApi client lib"])])
LIBS=$OLD_LIBS
LDFLAGS=$OLD_LDFLAGS
AC_LANG_POP()
# add the ndbapi specific static libs
MYSQL_LIBS="$MYSQL_LIBS -lndbclient -lmysys -lmystrings "
],[
AC_ERROR(["NdbApi needs at lest MySQL 5.0"])
])
])
dnl set up variables for compilation of UDF extensions
dnl
dnl MYSQL_USE_UDF_API()
dnl
AC_DEFUN([MYSQL_USE_UDF_API], [
# add regular MySQL C flags
ADDFLAGS=$MYSQL_CONFIG_INCLUDE
MYSQL_CFLAGS="$MYSQL_CFLAGS $ADDFLAGS"
MYSQL_CXXFLAGS="$MYSQL_CXXFLAGS $ADDFLAGS"
MYSQL_DEBUG_SERVER()
])
dnl set up variables for compilation of plugins
dnl
dnl MYSQL_USE_PLUGIN_API()
dnl
AC_DEFUN([MYSQL_USE_PLUGIN_API], [
# plugin interface is only availabe starting with MySQL 5.1
MYSQL_NEED_VERSION([5.1.0])
# for plugins the recommended way to include plugin.h
# is <mysql/plugin.h>, not <plugin.h>, so we have to
# strip thetrailing /mysql from the include paht
# reported by mysql_config
ADDFLAGS=`echo $MYSQL_CONFIG_INCLUDE | sed -e"s/\/mysql\$//g"`
MYSQL_CFLAGS="$ADDFLAGS $MYSQL_CONFIG_INCLUDE $MYSQL_CFLAGS -DMYSQL_DYNAMIC_PLUGIN"
MYSQL_CXXFLAGS="$ADDFLAGS $MYSQL_CONFIG_INCLUDE $MYSQL_CXXFLAGS -DMYSQL_DYNAMIC_PLUGIN"
MYSQL_CXXFLAGS="$MYSQL_CXXFLAGS -fno-implicit-templates -fno-exceptions -fno-rtti"
MYSQL_DEBUG_SERVER()
])