1m4_define([libpreludedb_major_version], [1])
2m4_define([libpreludedb_minor_version], [2])
3m4_define([libpreludedb_micro_version], [6])
4m4_define([libpreludedb_level_version], [LIBPRELUDEDB_RELEASE_LEVEL_FINAL])
5m4_define([libpreludedb_serial_version], [0])
6
7m4_define([serial_string], ifelse(libpreludedb_level_version, LIBPRELUDEDB_RELEASE_LEVEL_ALPHA, alpha,
8                                  ifelse(libpreludedb_level_version, LIBPRELUDEDB_RELEASE_LEVEL_BETA, beta,
9                                  ifelse(libpreludedb_level_version, LIBPRELUDEDB_RELEASE_LEVEL_RC, rc))))
10
11m4_define([version_error], ifelse(serial_string, [], ,
12                                  ifelse(libpreludedb_serial_version, 0, error)))
13ifelse(version_error, [], , [m4_fatal(Release level 'serial_string' and serial 'libpreludedb_serial_version' are incompatible)])
14
15m4_append([serial_string], ifelse(serial_string, [],
16                                  ifelse(libpreludedb_serial_version, 0, , .libpreludedb_serial_version),
17                                  libpreludedb_serial_version))
18
19AC_INIT(libpreludedb, m4_join([.], [libpreludedb_major_version],
20                                   [libpreludedb_minor_version],
21                                   m4_join([], libpreludedb_micro_version, serial_string)))
22
23LIBPRELUDEDB_MAJOR_VERSION=libpreludedb_major_version
24LIBPRELUDEDB_MINOR_VERSION=libpreludedb_minor_version
25LIBPRELUDEDB_MICRO_VERSION=libpreludedb_micro_version
26LIBPRELUDEDB_LEVEL_VERSION=libpreludedb_level_version
27LIBPRELUDEDB_SERIAL_VERSION=libpreludedb_serial_version
28
29dnl **********************************************************
30dnl * Library soname (http://sources.redhat.com/autobook/autobook/autobook_91.html#SEC91)
31dnl **********************************************************
32libpreludedb_current=7
33libpreludedb_revision=0
34libpreludedb_age=0
35LIBPRELUDEDB_SONAME=$libpreludedb_current:$libpreludedb_revision:$libpreludedb_age
36
37libpreludedbcpp_current=2
38libpreludedbcpp_revision=0
39libpreludedbcpp_age=0
40LIBPRELUDEDBCPP_SONAME=$libpreludedbcpp_current:$libpreludedbcpp_revision:$libpreludedbcpp_age
41
42AC_PREREQ(2.59)
43AC_CANONICAL_HOST
44AC_CANONICAL_TARGET
45
46AC_CONFIG_SRCDIR([src])
47AM_INIT_AUTOMAKE([-Wall tar-pax 1.9])
48
49AC_CONFIG_HEADER(config.h)
50AM_MAINTAINER_MODE
51
52
53dnl **********************************************************
54dnl * Check required program.
55dnl **********************************************************
56AC_PROG_INSTALL
57AC_PROG_MAKE_SET
58AC_PROG_CC
59AC_PROG_CXX
60
61BINDINGS_CC="$CC"
62
63
64dnl **********************************************************
65dnl * Setup GnuLib, libtool and libltdl.
66dnl **********************************************************
67
68dnl Provide replacement for system missing this GnuLib required macro.
69m4_ifndef([AS_VAR_COPY], [m4_define([AS_VAR_COPY],
70       [AS_LITERAL_IF([$1[]$2], [$1=$$2], [eval $1=\$$2])])])
71
72gl_EARLY
73AC_CONFIG_MACRO_DIR([m4])
74m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
75
76AC_LIBTOOL_DLOPEN
77AC_LIBTOOL_WIN32_DLL
78AM_DISABLE_STATIC
79AC_PROG_LIBTOOL
80
81
82
83dnl **************************************************
84dnl * Setup custom compiler flags                    *
85dnl **************************************************
86
87AC_MSG_CHECKING(for cpu-specific compiler flags)
88if test "$host_cpu" == "x86_64" && test $enable_static = "yes"; then
89        AC_MSG_RESULT(x86_64/static: adding -fPIC)
90        AX_CHECK_COMPILE_FLAG(-fPIC, CPPFLAGS="$CPPFLAGS -fPIC")
91else
92        AC_MSG_RESULT(none needed)
93fi
94
95AC_MSG_CHECKING(for platform-specific compiler flags)
96case "$host_os" in
97 darwin*)
98        # It may be called "cc", but it's really a GCC derivative
99        # with a problematic special precompiler and precompiled
100        # headers; turn off the special precompiler, as some
101        # apparently-legal code won't compile with its precompiled
102        # headers.
103        AC_MSG_RESULT(Darwin: adding -no-cpp-precomp)
104        AX_CHECK_COMPILE_FLAG(-no-cpp-precomp, PCFLAGS="$PCFLAGS -no-cpp-precomp")
105        libext=dylib
106        ;;
107 *)
108        libext=so
109        AC_MSG_RESULT(none needed)
110        ;;
111esac
112
113AX_CHECK_LINK_FLAG([-z relro], LDFLAGS="$LDFLAGS -z relro")
114AX_CHECK_LINK_FLAG([-z now], LDFLAGS="$LDFLAGS -z now")
115
116
117for i in -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations \
118         -Wbad-function-cast -Wcast-qual -Wcast-align -Wnested-externs -Wunused \
119         -Wformat -Wformat-security; do
120        AX_CHECK_COMPILE_FLAG([$i], PCFLAGS="$PCFLAGS $i")
121done
122
123if test x$buggy_pthread_initializers = xyes; then
124   AX_CHECK_COMPILE_FLAG([-Wno-missing-braces], PCFLAGS="$PCFLAGS -Wno-missing-braces")
125fi
126
127
128dnl **************************************************
129dnl * Check for libprelude                           *
130dnl **************************************************
131
132AM_PATH_LIBPRELUDE(1.2.6, , AC_MSG_ERROR(Cannot find libprelude: Is libprelude-config in the path?), no)
133
134
135dnl ***************************************************
136dnl * Check for the MySQL library (MySQL plugin       *
137dnl ***************************************************
138AX_LIB_MYSQL()
139with_mysql="no"
140if test x$MYSQL_CONFIG != x; then
141        LIBS_bkp=$LIBS
142        LIBS="$MYSQL_LDFLAGS"
143        AC_CHECK_FUNC(mysql_real_escape_string, AC_DEFINE(HAVE_MYSQL_REAL_ESCAPE_STRING, , mysql_real_escape_string function present))
144        LIBS=$LIBS_bkp
145
146        CPPFLAGS_bkp=$CPPFLAGS
147        CPPFLAGS="$MYSQL_CFLAGS"
148        AC_CHECK_HEADER(mysql.h, with_mysql=yes, with_mysql=no)
149        CPPFLAGS=$CPPFLAGS_bkp;
150fi
151
152AM_CONDITIONAL(HAVE_MYSQL, test x$with_mysql = xyes)
153
154
155dnl ********************************************************
156dnl * Check for the PostgreSQL library (PostgreSQL plugin) *
157dnl ********************************************************
158AX_LIB_POSTGRESQL()
159
160with_pgsql="no"
161if test x$POSTGRESQL_VERSION != x; then
162        LIBS_bkp=$LIBS
163        LIBS="$POSTGRESQL_LDFLAGS"
164        AC_CHECK_FUNC(PQserverVersion, AC_DEFINE(HAVE_PQSERVERVERSION, , [Define if PQserverVersion function is available]))
165        AC_CHECK_FUNC(PQescapeStringConn, AC_DEFINE(HAVE_PQESCAPESTRINGCONN, , [Define if PQescapeStringConn function is available]))
166        AC_CHECK_FUNC(PQescapeByteaConn, AC_DEFINE(HAVE_PQESCAPEBYTEACONN, , [Define if PQescapeByteaConn function is available]))
167        LIBS=$LIBS_bkp;
168
169        CPPFLAGS_bkp=$CPPFLAGS
170        CPPFLAGS="$POSTGRESQL_CFLAGS"
171        AC_CHECK_HEADER(libpq-fe.h, with_pgsql=yes, with_pgsql=no)
172        CPPFLAGS=$CPPFLAGS_bkp;
173fi
174
175AM_CONDITIONAL(HAVE_PGSQL, test x$with_pgsql = xyes)
176
177dnl ********************************************************
178dnl * Check for the SQLite3 library (SQLite3 plugin)       *
179dnl ********************************************************
180AX_LIB_SQLITE3("3.0.0")
181
182with_sqlite3="no"
183if test x$SQLITE3_VERSION != x; then
184        CPPFLAGS_bkp=$CPPFLAGS
185        CPPFLAGS="$SQLITE3_CFLAGS"
186        AC_CHECK_HEADER(sqlite3.h, with_sqlite3=yes, with_sqlite3=no)
187        CPPFLAGS=$CPPFLAGS_bkp;
188fi
189
190AM_CONDITIONAL(HAVE_SQLITE3, test x$with_sqlite3 = xyes)
191
192
193
194dnl **************************************************
195dnl * Swig support                                   *
196dnl **************************************************
197
198AC_ARG_WITH(swig, AC_HELP_STRING(--with-swig@<:@=PATH@:>@, Re-generate python bindings sources @<:@default=auto@:>@),
199            [swig_required=true; if test x$withval = xyes; then with_swig="swig"; fi], with_swig="swig")
200
201if test x$with_swig != xno; then
202   AC_PATH_PROG(SWIG, `basename $with_swig`, no, `dirname $with_swig`:$PATH)
203
204   if test x$SWIG = xno; then
205      if test x$swig_required = xtrue; then
206         AC_MSG_ERROR([Could not find $with_swig binary])
207      fi
208   fi
209fi
210
211AM_CONDITIONAL(HAVE_SWIG, test x$SWIG != xno)
212
213
214
215dnl **************************************************
216dnl * Python support                                 *
217dnl **************************************************
218
219AC_ARG_WITH(python2, AC_HELP_STRING(--with-python2@<:@=PATH@:>@, Enable support for python2 binding @<:@default=auto@:>@),
220            [python2_required=true; if test x$withval = xyes; then with_python2="python2"; fi], with_python2="python2")
221
222if test x$with_python2 != xno; then
223   AC_PATH_PROGS(PYTHON2, $with_python2 "python2.7" "python2.6" "python2.5" "python2.4" "python2.3" "python2.2" "python2.1" "python2.0", no, `dirname $with_python2`:$PATH)
224   if test x$PYTHON2 = xno; then
225      if test x$python2_required = xtrue; then
226         AC_MSG_ERROR([Could not find $with_python2 binary])
227      fi
228
229      with_python2=no
230   else
231      old_CPPFLAGS="$CPPFLAGS"
232      CPPFLAGS="-I`$PYTHON2 -c 'from distutils.sysconfig import get_python_inc; print(get_python_inc())'`"
233
234      AC_CHECK_HEADER(Python.h, with_python2=yes, with_python2=no)
235      CPPFLAGS="$old_CPPFLAGS"
236      AX_RESET_HEADERS_CACHE([Python.h])
237   fi
238fi
239
240AM_CONDITIONAL(HAVE_PYTHON2, test x$with_python2 = xyes)
241
242
243AC_ARG_WITH(python3, AC_HELP_STRING(--with-python3@<:@=PATH@:>@, Enable support for python3 binding @<:@default=auto@:>@),
244            [python3_required=true; if test x$withval = xyes; then with_python3="python3"; fi], with_python3="python3")
245
246if test x$with_python3 != xno; then
247   AC_PATH_PROGS(PYTHON3, $with_python3 "python3.5" "python3.4" "python3.3" "python3.2" "python3.1" "python3.0", no, `dirname $with_python3`:$PATH)
248   if test x$PYTHON3 = xno; then
249      if test x$python3_required = xtrue; then
250         AC_MSG_ERROR([Could not find $with_python3 binary])
251      fi
252
253      with_python3=no
254   else
255      old_CPPFLAGS="$CPPFLAGS"
256      CPPFLAGS="-I`$PYTHON3 -c 'from distutils.sysconfig import get_python_inc; print(get_python_inc())'`"
257
258      AC_CHECK_HEADER(Python.h, with_python3=yes, with_python3=no)
259      CPPFLAGS="$old_CPPFLAGS"
260   fi
261fi
262
263AM_CONDITIONAL(HAVE_PYTHON3, test x$with_python3 = xyes)
264AM_CONDITIONAL(HAVE_PYTHON, test x$with_python2 = xyes -o x$with_python3 = xyes)
265
266
267
268dnl **************************************************
269dnl * Easy bindings support                          *
270dnl **************************************************
271
272AC_ARG_ENABLE(easy-bindings, AC_HELP_STRING(--enable-easy-bindings, Enable support for high level binding @<:@default=yes@:>@),
273                enable_easy_bindings=$enableval, enable_easy_bindings="yes")
274
275AM_CONDITIONAL(HAVE_EASY_BINDINGS, test x$enable_easy_bindings = xyes)
276
277if test x$enable_easy_bindings = xyes; then
278        AC_CHECK_PROG(HAVE_CXX, $CXX, yes, no)
279        if test x$HAVE_CXX != xyes; then
280                AC_MSG_ERROR([Easybindings require a C++ compiler, but none were found.])
281        fi
282fi
283
284
285dnl **************************************************
286dnl * Check for missing function replacement         *
287dnl **************************************************
288gl_SOURCE_BASE(libmissing)
289gl_M4_BASE(libmissing/m4)
290gl_INIT
291
292
293dnl **************************************************
294dnl * Check for GTK-DOC                              *
295dnl **************************************************
296
297GTK_DOC_CHECK(1.0)
298
299
300dnl **************************************************
301dnl * Typedefs, structures, compiler characteristics.*
302dnl **************************************************
303
304AC_C_CONST
305AC_C_INLINE
306AC_TYPE_SIZE_T
307AC_HEADER_TIME
308
309
310dnl **************************************************
311dnl * Setup build variable                           *
312dnl **************************************************
313
314AC_SUBST(PCFLAGS)
315AC_SUBST(BINDINGS_CC)
316AC_SUBST(LIBPRELUDEDB_SONAME)
317AC_SUBST(LIBPRELUDEDBCPP_SONAME)
318
319AS_AC_EXPAND(LIBDIR, $libdir)
320AS_AC_EXPAND(DATADIR, $datadir)
321AS_AC_EXPAND(SYSCONFDIR, $sysconfdir)
322
323
324db_plugin_dir=$LIBDIR/libpreludedb/plugins
325sql_plugin_dir=$db_plugin_dir/sql
326format_plugin_dir=$db_plugin_dir/formats
327format_schema_dir=$DATADIR/libpreludedb
328
329AC_SUBST(db_plugin_dir)
330AC_SUBST(sql_plugin_dir)
331AC_SUBST(format_plugin_dir)
332AC_SUBST(format_schema_dir)
333AC_SUBST(LIBPRELUDEDB_VERSION)
334AC_SUBST(LIBPRELUDEDB_MAJOR_VERSION)
335AC_SUBST(LIBPRELUDEDB_MINOR_VERSION)
336AC_SUBST(LIBPRELUDEDB_MICRO_VERSION)
337AC_SUBST(LIBPRELUDEDB_LEVEL_VERSION)
338AC_SUBST(LIBPRELUDEDB_SERIAL_VERSION)
339
340
341AC_CONFIG_FILES([
342libpreludedb-config
343
344Makefile
345m4/Makefile
346libmissing/Makefile
347libmissing/tests/Makefile
348
349src/Makefile
350src/include/Makefile
351src/include/preludedb-version.h
352
353plugins/Makefile
354
355plugins/sql/Makefile
356plugins/sql/mysql/Makefile
357plugins/sql/pgsql/Makefile
358plugins/sql/sqlite3/Makefile
359
360plugins/format/Makefile
361plugins/format/classic/Makefile
362plugins/format/classic/include/Makefile
363
364docs/Makefile
365docs/api/Makefile
366docs/manpages/Makefile
367
368bindings/Makefile
369bindings/c++/Makefile
370bindings/c++/include/Makefile
371bindings/python/Makefile
372bindings/python/setup.py
373])
374AC_CONFIG_COMMANDS([default],[[ chmod +x libpreludedb-config ]],[[]])
375AC_OUTPUT
376
377
378echo
379echo "*** Dumping configuration ***"
380echo "    - Generate documentation      : $enable_gtk_doc"
381echo "    - Enable MySQL plugin         : $with_mysql"
382echo "    - Enable PostgreSQL plugin    : $with_pgsql"
383echo "    - Enable SQLite3 plugin       : $with_sqlite3"
384echo "    - Python2.x binding           : $with_python2";
385echo "    - Python3.x binding           : $with_python3";
386echo "    - Easy bindings               : $enable_easy_bindings"
387