forked from hholzgra/mysql-m4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmysql.m4
568 lines (485 loc) · 15 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
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
# ========================================
# https://github.com/hholzgra/mysql-m4
# ========================================
#
# SYNOPSIS
#
# See README.md
#
# LICENSE
#
# Copyright (c) 2006-2014 Hartmut Holzgraefe <[email protected]>
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation, either version 3 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
# As a special exception, the respective Autoconf Macro's copyright owner
# gives unlimited permission to copy, distribute and modify the configure
# scripts that are the output of Autoconf when processing the Macro. You
# need not follow the terms of the GNU General Public License when using
# or distributing such scripts, even though portions of the text of the
# Macro appear in them. The GNU General Public License (GPL) does govern
# all other use of the material that constitutes the Autoconf Macro.
#
# This special exception to the GPL applies to versions of the Autoconf
# Macro released by the Autoconf Archive. When you make and distribute a
# modified version of the Autoconf Macro, you may extend this special
# exception to the GPL to apply to your modified version as well.
MYSQL_VERSION=none
MYSQL_CONFIG_ALTERNATIVES="mysql_config mariadb_config"
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 with the exception of WITH_MYSQL_SRC()
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\``
else
for _MC in $MYSQL_CONFIG_ALTERNATIVES
do
if test -x $withval/bin/$_MC -a -f $withval/bin/$_MC
then
MYSQL_CONFIG=$withval/bin/$_MC
MYSQL_PREFIX=$withval
break
fi
done
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\``
else
for _MC in $MYSQL_CONFIG_ALTERNATIVES
do
if test -x $withval/bin/$_MC -a -f $withval/bin/$_MC
then
MYSQL_CONFIG=$withval/bin/$_MC
MYSQL_PREFIX=$withval
break
fi
done
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`
AC_MSG_RESULT($MYSQL_CONFIG)
fi
fi
if test -x "$MYSQL_CONFIG"
then
MYSQL_FORK=mysql
include_dir=`$MYSQL_CONFIG --variable=pkgincludedir`
if grep -q ndb "$include_dir"/mysql_version.h
then
MYSQL_FORK=mysql_cluster
elif grep -q MariaDB "$include_dir"/mysql_version.h
then
MYSQL_FORK=mariadb
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)
mysql_src_default=$1;
if test "x$mysql_src_default" = "x"
then
mysql_src_default="no"
fi
AC_DEFUN([help_string],[path to mysql sourcecode @<:@default=$1@:>@])
AC_ARG_WITH(mysql-src, [AS_HELP_STRING([--with-mysql-src@<:@=PATH@:>@],help_string)],
[ if test "x$MYSQL_CONFIG" != "x"
then
AC_MSG_ERROR([--with-mysql-src can't be used together with --with-mysql])
fi
],[
with_mysql_src=$mysql_src_default
])
AC_MSG_RESULT($with_mysql_src)
if test "$with_mysql_src" != "no" && test "x$with_mysql_src" != "x"
then
if test -f $with_mysql_src/include/mysql_version.h.in
then
if test -f $with_mysql_src/include/mysql_version.h
then
MYSQL_SRCDIR=`readlink -f $with_mysql_src`
MYSQL_VERSION=`grep MYSQL_SERVER_VERSION $MYSQL_SRCDIR/include/mysql_version.h | sed -e's/"$//g' -e's/.*"//g'`
MYSQL_FORK=mysql
if grep -q ndb $MYSQL_SRCDIR/include/mysql_version.h
then
MYSQL_FORK=mysql_cluster
elif grep -q MariaDB $MYSQL_SRCDIR/include/mysql_version.h
then
MYSQL_FORK=mariadb
fi
else
AC_MSG_ERROR([$MYSQL_SRCDIR/not configured yet])
fi
else
AC_MSG_ERROR([$with_mysql_src doesn't look like a mysql source dir])
fi
dnl else
dnl AC_MSG_ERROR([no source dir given $withval , $with_mysql_src, $mysql_src_default])
fi
if test "x$MYSQL_SRCDIR" != "x"
then
MYSQL_CONFIG_INCLUDE="-I$MYSQL_SRCDIR/include -I$MYSQL_SRCDIR -I$MYSQL_SRCDIR/sql -I$MYSQL_SRCDIR/regex -I$MYSQL_SRCDIR/libmysqld"
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_PLUGIN_DIR])
AC_SUBST([MYSQL_VERSION])
AC_SUBST([MYSQL_FORK])
AC_SUBST([MYSQL_SRCDIR])
])
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], [
if test "x$MYSQL_FORK" = "x"
then
forkname=mysql
else
forkname=$MYSQL_FORK
fi
AC_MSG_CHECKING([$forkname version >= $1])
MYSQL_CHECK_VERSION([$1],
[AC_MSG_RESULT([yes ($MYSQL_VERSION)])],
[AC_MSG_ERROR([no ($MYSQL_VERSION)])])
])
dnl check for embedded server library
dnl
dnl MYSQL_NEED_EMBEDDED()
dnl
AC_DEFUN([MYSQL_NEED_EMBEDDED], [
AC_MSG_CHECKING([for libmysqld embedded server library])
if test "x$MYSQL_SRCDIR" = "x"
then
true # TODO check install prefix libdir
else
if test -f $MYSQL_SRCDIR/libmysqld/libmysqld.a
then
AC_MSG_RESULT([yes])
else
AC_MSG_ERROR([not found in $MYSQL_SRCDIR/libmysqld])
fi
fi
])
dnl check for a specific fork/product
dnl and bail out with an error message if not
dnl
dnl MYSQL_NEED_FORK([need_fork])
dnl
AC_DEFUN([MYSQL_NEED_FORK], [
AC_MSG_CHECKING([if mysql variant is $1])
if test "$MYSQL_FORK" = "$1"
then
AC_MSG_RESULT([yes])
else
AC_MSG_ERROR([no, it's $MYSQL_FORK])
fi
])
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], [
MYSQL_NEED_EMBEDDED()
# add regular MySQL C flags
ADDFLAGS="$MYSQL_CONFIG_INCLUDE"
if test "x$MYSQL_CONFIG" != "x"
then
ADDFLAGS="$ADDFLAGS -I"`$MYSQL_CONFIG --variable=pkgincludedir`"/private"
fi
MYSQL_CFLAGS="$MYSQL_CFLAGS $ADDFLAGS"
MYSQL_CXXFLAGS="$MYSQL_CXXFLAGS $ADDFLAGS"
MYSQL_EMBEDDED_LDFLAGS()
])
dnl
AC_DEFUN([MYSQL_EMBEDDED_LDFLAGS], [
if test "x$MYSQL_CONFIG" != "x"
then
MYSQL_LDFLAGS="$MYSQL_LDFLAGS -Wl,-rpath="`$MYSQL_CONFIG --variable=pkglibdir`" "`$MYSQL_CONFIG --libmysqld-libs`
else
MYSQL_LDFLAGS="-L$MYSQL_SRCDIR/libmysqld -lmysqld"
fi
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 the trailing /mysql from the include path
# 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()
])