1AC_INIT([libgadu], [1.12.2])
2AC_CONFIG_SRCDIR([src/libgadu.c])
3AM_INIT_AUTOMAKE()
4
5AC_PREREQ(2.50)
6AC_CANONICAL_HOST
7AC_CONFIG_HEADERS(config.h include/libgadu.h)
8AC_CONFIG_MACRO_DIR([m4])
9
10m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
11
12AC_PROG_CC
13AC_PROG_CPP
14AC_PROG_INSTALL
15AC_PROG_LN_S
16AC_C_CONST
17AC_PROG_LIBTOOL
18AC_SUBST(LIBTOOL_DEPS)
19
20AC_SUBST(AM_CPPFLAGS)
21dnl Zależności dla pkgconfig
22AC_SUBST(REQUIRES_PRIVATE)
23AC_SUBST(LIBS_PRIVATE)
24
25export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig"
26PKG_PROG_PKG_CONFIG
27
28if test "$GCC"; then
29dnl Other warnings that may be useful:
30dnl -Wdeclaration-after-statement -Wendif-labels
31dnl -Werror-implicit-function-declaration -Wformat-security -Winit-self
32dnl -Wmissing-declarations -Wmissing-noreturn -Wfloat-equal
33	CFLAGS="$CFLAGS -Wall -Wextra -Wmissing-prototypes \
34		-Wno-unused-parameter -Waggregate-return \
35		-Wdeclaration-after-statement -Wundef -Wcast-align \
36		-Wpointer-arith"
37fi
38
39dnl
40dnl  Egzotyczne systemy operacyjne
41dnl
42is_mingw="no"
43case "$host" in
44	*-*-mingw* | *-*-cygwin*)
45		MINGW_LDFLAGS="-no-undefined -lws2_32"
46		MINGW_LIBGEN="-Wl,--output-def,libgadu.def.in"
47		MINGW_LIBDATA="libgadu.def"
48		LDFLAGS_NO_INSTALL="-no-fast-install"
49		SRCDIR=`(cd $srcdir && pwd)`
50		AC_SUBST([AM_TESTS_ENVIRONMENT], [$SRCDIR/test/automatic/wine-wrapper.sh])
51		is_mingw="yes"
52		;;
53	*)
54		MINGW_LDFLAGS=""
55		MINGW_LIBDATA=""
56		LDFLAGS_NO_INSTALL="-no-install"
57		;;
58esac
59AM_CONDITIONAL([HAVE_MINGW], [test "x$is_mingw" = "xyes"])
60AC_SUBST([MINGW_LDFLAGS])
61AC_SUBST([MINGW_LIBGEN])
62AC_SUBST([MINGW_LIBDATA])
63AC_SUBST([LDFLAGS_NO_INSTALL])
64
65AC_CHECK_FUNCS([mkstemp])
66
67AC_C_BIGENDIAN
68
69if test "x$ac_cv_c_bigendian" = "xyes"; then
70	AC_DEFINE([GG_CONFIG_BIGENDIAN], [], [Defined if libgadu was compiled for bigendian machine.])
71fi
72
73AC_NEED_STDINT_H
74
75if test "x$STDINT_H" = "xstdint.h"; then
76	AC_DEFINE([GG_CONFIG_HAVE_STDINT_H], [], [Defined if uintX_t types are defined in <stdint.h>.])
77fi
78
79if test "x$STDINT_H" = "xinttypes.h"; then
80	AC_DEFINE([GG_CONFIG_HAVE_INTTYPES_H], [], [Defined if uintX_t types are defined in <inttypes.h>.])
81fi
82
83if test "x$STDINT_H" = "xsys/inttypes.h"; then
84	AC_DEFINE([GG_CONFIG_HAVE_SYS_INTTYPES_H], [], [Defined if uintX_t types are defined in <sys/inttypes.h>.])
85fi
86
87if test "x$STDINT_H" = "xsys/int_types.h"; then
88	AC_DEFINE([GG_CONFIG_HAVE_SYS_INT_TYPES_H], [], [Defined if uintX_t types are defined in <sys/int_types.h>.])
89fi
90
91if test "x$STDINT_H" = "xsys/types.h"; then
92	AC_DEFINE([GG_CONFIG_HAVE_SYS_TYPES_H], [], [Defined if uintX_t types are defined in <sys/types.h>.])
93fi
94
95AC_DEFINE_UNQUOTED([GG_LIBGADU_VERSION], ["${VERSION}"], [Library version])
96
97dnl
98dnl  Sprawdźmy, jaką wersję vsnprintf() dostajemy. Dodatkowa opcja jest
99dnl  dla kompilacji skrośnej, bo nie można wtedy korzystać z AC_TRY_RUN().
100dnl
101
102AC_ARG_WITH(c99-vsnprintf,
103	[  --with-c99-vsnprintf    target system has C99-compatible vsnprintf()])
104
105if test "x$with_c99_vsnprintf" = "xyes"; then
106	AC_DEFINE([GG_CONFIG_HAVE_C99_VSNPRINTF], [], [Defined if this machine has C99-compiliant vsnprintf().])
107fi
108
109if test "x$with_c99_vsnprintf" = "x"; then
110	AC_MSG_CHECKING([for C99-compatible vsnprintf()])
111	if test "x$cross_compiling" = "xyes"; then
112		AC_MSG_ERROR([cannot determine vsnprintf() behaviour when cross-compiling. You need to provide --with-c99-vsnprintf or --without-c99-vsnprintf option instead. It is safe to assume that the former is valid on most modern operating systems.])
113	fi
114	AC_TRY_RUN(
115	[
116		#include <stdio.h>
117		int main()
118		{
119			char tmp;
120			return (snprintf(&tmp, sizeof(tmp), "test") != 4);
121		}
122	], [
123		AC_MSG_RESULT([yes])
124		AC_DEFINE([GG_CONFIG_HAVE_C99_VSNPRINTF], [], [Defined if this machine has C99-compiliant vsnprintf().])
125	], [
126		AC_MSG_RESULT([no])
127	])
128fi
129
130dnl
131dnl  Sprawdzamy dostępność specyficznego dla Win32 _vscprintf(), które
132dnl  pozwala oszczędzić użycie alokatora na MSVC, które nie posiada
133dnl  vsnprintf() zgodnego z C99.
134dnl
135
136AC_CHECK_FUNCS([_vscprintf])
137
138dnl
139dnl  Sprawdzamy, czy jest system obsługuje zmienne 64-bitowe.
140dnl
141
142AC_MSG_CHECKING([for long long])
143
144AC_TRY_COMPILE([],
145[
146	long long a = 1LL;
147	unsigned long long b = 1LL;
148], [
149	AC_MSG_RESULT([yes])
150	AC_DEFINE([GG_CONFIG_HAVE_LONG_LONG], [], [Defined if this machine supports long long.])
151], [
152	AC_MSG_RESULT([no])
153	AC_MSG_ERROR([Your system does not support 64-bit variables.])
154])
155
156AC_CHECK_FUNCS([strtoull])
157AC_CHECK_FUNCS([_strtoui64])
158
159AC_MSG_CHECKING([if <$STDINT_H> has uint64_t])
160AC_TRY_COMPILE([#include <$STDINT_H>], [uint64_t foo],
161    AC_DEFINE([GG_CONFIG_HAVE_UINT64_T], [], [Defined if this machine has uint64_t.])
162    AC_MSG_RESULT([yes]),
163    AC_MSG_RESULT([no]))
164
165dnl
166dnl  SunOS
167dnl
168
169AC_CHECK_LIB(nsl, t_accept, LIBS_PRIVATE="$LIBS_PRIVATE -lnsl")
170AC_CHECK_LIB(socket, socket, LIBS_PRIVATE="$LIBS_PRIVATE -lsocket")
171
172dnl
173dnl  BeOS
174dnl
175
176AC_ARG_WITH(bind,
177	[  --without-bind          do not use libbind even if found])
178
179if test "x$with_bind" != "xno"; then
180	AC_CHECK_LIB(bind, __inet_addr, LIBS_PRIVATE="$LIBS_PRIVATE -lbind")
181fi
182
183dnl
184dnl  threadsafe
185dnl
186
187AC_CHECK_FUNCS([gethostbyname_r], [AC_DEFINE([GG_CONFIG_HAVE_GETHOSTBYNAME_R], [], [Defined if this machine has gethostbyname_r().])])
188
189AC_MSG_CHECKING([for va_copy])
190AC_TRY_LINK([#include <stdarg.h>], [va_list a, b; va_copy(a, b);],
191[
192	AC_MSG_RESULT([yes])
193	AC_DEFINE([GG_CONFIG_HAVE_VA_COPY], [], [Defined if this machine has va_copy().])
194], [
195	AC_MSG_RESULT([no])
196])
197
198AC_MSG_CHECKING([for __va_copy])
199AC_TRY_LINK([#include <stdarg.h>], [va_list a, b; __va_copy(a, b);],
200[
201	AC_MSG_RESULT([yes])
202	AC_DEFINE([GG_CONFIG_HAVE___VA_COPY], [], [Defined if this machine has __va_copy().])
203], [
204	AC_MSG_RESULT([no])
205])
206
207AC_CHECK_FUNCS([_exit])
208
209AC_CHECK_FUNCS([fork], [AC_DEFINE([GG_CONFIG_HAVE_FORK], [], [Defined if this machine has fork().])])
210
211AC_ARG_ENABLE(debug,
212	[  --disable-debug         compile without debugging support])
213
214if test "x$enable_debug" = "xno"; then
215	AC_MSG_WARN([--disable-debug is obsolete.])
216fi
217
218dnl
219dnl  Resolver libgadu oparty na pthread
220dnl
221
222AC_ARG_WITH(pthread,
223  [  --without-pthread       do not use pthread resolver even if found])
224
225have_pthread="no"
226if test "x$with_pthread" != "xno"; then
227	ACX_PTHREAD(
228	[
229		dnl workaround dla pkgconfiga
230		if test "x$PTHREAD_CFLAGS" = "x-pthread"; then
231			PTHREAD_LIBS="$PTHREAD_LIBS -pthread"
232			PTHREAD_CFLAGS=""
233		fi
234
235		LIBS_PRIVATE="$PTHREAD_LIBS $LIBS_PRIVATE"
236		CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
237		CC="$PTHREAD_CC"
238		have_pthread=yes
239
240		AC_DEFINE([GG_CONFIG_HAVE_PTHREAD], [], [Defined if libgadu was compiled and linked with pthread support.])
241	], [
242		if test "x$with_pthread" = "xyes"; then
243			AC_MSG_ERROR([Your system does not support pthreads])
244		fi
245	])
246fi
247
248dnl
249dnl  Sprawdzamy zlib
250dnl
251
252AC_CHECK_LIB(z, inflateEnd, [have_zlib=yes], [have_zlib=no])
253AC_CHECK_HEADER(zlib.h, [have_zlib_h=yes], [have_zlib_h=no])
254
255if test "x$have_zlib" = "xyes" -a "x$have_zlib_h" = "xyes"; then
256	LIBS_PRIVATE="$LIBS_PRIVATE -lz"
257	AC_DEFINE(HAVE_ZLIB, 1, [define if you have zlib])
258	AC_DEFINE([GG_CONFIG_HAVE_ZLIB], [], [Defined if libgadu was compiled and linked with zlib support.])
259fi
260
261dnl
262dnl  Sprawdzamy libprotobuf-c
263dnl
264
265AC_ARG_WITH(protobuf,
266  [  --without-protobuf      do not use libprotobuf-c even if found])
267
268if test "x$with_protobuf" != "xno"; then
269	PKG_CHECK_MODULES([PROTOBUF_C], [libprotobuf-c >= 1.0.0], [
270		protobufc_ver=`$PKG_CONFIG --modversion libprotobuf-c`
271		if test "x$protobufc_ver" = "x1.0.0-rc1"; then
272			echo "WARNING: libprotobuf-c $protobufc_ver found. It's not compatible with 1.0.0 API"
273			have_protobuf_c=no
274		else
275			LIBS_PRIVATE="$LIBS_PRIVATE $PROTOBUF_C_LIBS"
276			AC_DEFINE([GG_CONFIG_HAVE_PROTOBUF_C], [], [Defined if libgadu was compiled and linked with system provided libprotobuf-c.])
277			have_protobuf_c=yes
278		fi
279	], [have_protobuf_c=no])
280else
281	have_protobuf_c=no
282fi
283AM_CONDITIONAL([HAVE_PROTOBUF_C], [test "x$have_protobuf_c" = "xyes"])
284
285dnl
286dnl  Sprawdzamy GnuTLS
287dnl
288
289AC_ARG_WITH(gnutls,
290  [  --without-gnutls        do not use GnuTLS even if found])
291
292have_gnutls="no"
293
294if test "x$with_gnutls" != "xno"; then
295	PKG_CHECK_MODULES([GNUTLS], [gnutls >= 2.10.0], [
296		AC_DEFINE([HAVE_GNUTLS], [], [Defined if GnuTLS is available.])
297		AC_DEFINE([GG_CONFIG_HAVE_GNUTLS], [], [Defined if libgadu was compiled and linked with GnuTLS support.])
298		REQUIRES_PRIVATE="$REQUIRES_PRIVATE gnutls"
299		CFLAGS="$CFLAGS $GNUTLS_CFLAGS"
300		# Note: not adding to LIBS_PRIVATE, because
301		# "REQUIRES_PRIVATE" takes care of that for pkg-config.
302		LIBS="$LIBS $GNUTLS_LIBS"
303		have_gnutls="yes"
304	], [:])
305	PKG_CHECK_MODULES([GNUTLS_2_12], [gnutls >= 2.12.0], [
306		AC_DEFINE([HAVE_GNUTLS_2_12], [], [Defined if GnuTLS >= 2.12.0 is available.])
307	], [:])
308fi
309
310dnl
311dnl  Sprawdzamy czy mamy używać systemowych certyfikatów
312dnl
313
314AC_ARG_ENABLE(ssl-system-trust,
315       	[  --disable-ssl-system-trust  disable the use of system default trusted CAs])
316
317AC_ARG_WITH([gnutls-system-trust-store],
318	[  --with-gnutls-system-trust-store=FILE  provide alternative path of system default trust store for GnuTLS versions <= 3.x])
319
320if test "x$enable_ssl_system_trust" != "xno"; then
321	AC_DEFINE([GG_CONFIG_SSL_SYSTEM_TRUST], [], [Defined if libgadu uses system defalt trusted CAs])
322
323	if test "x$have_gnutls" = "xyes"; then
324		AC_CHECK_FUNCS([gnutls_certificate_set_x509_system_trust], [have_gnutls_certificate_set_x509_system_trust=yes], [have_gnutls_certificate_set_x509_system_trust=no])
325
326		if test "x$with_gnutls_system_trust_store" = "x"; then
327			# Lista certyfikatów skopiowana z GnuTLS (https://gitorious.org/gnutls/gnutls/blobs/c59329a089a9ed108692066de95f533f482b5422/configure.ac)
328			for i in /etc/ssl/ca-bundle.pem \
329				/etc/ssl/certs/ca-certificates.crt \
330				/etc/pki/tls/cert.pem \
331				/usr/local/share/certs/ca-root-nss.crt \
332				/etc/ssl/cert.pem
333				do
334				if test -e $i; then
335					with_gnutls_system_trust_store="$i"
336					break
337				fi
338			done
339		fi
340
341		if test "x$with_gnutls_system_trust_store" = "xno";then
342			with_gnutls_system_trust_store=""
343		fi
344
345		if test "x$with_gnutls_system_trust_store" != "x"; then
346			AC_DEFINE_UNQUOTED([GG_CONFIG_GNUTLS_SYSTEM_TRUST_STORE], ["$with_gnutls_system_trust_store"], [use the given file as GnuTLS default trust store])
347		fi
348	fi
349fi
350
351dnl
352dnl  Sprawdzamy OpenSSL, jeśli nie ma GnuTLS
353dnl
354
355if test "x$have_gnutls" != "xyes"; then
356	AC_CHECK_OPENSSL
357fi
358
359if test "x$have_openssl" = "xyes"; then
360	# Note: not adding to LIBS_PRIVATE, because "REQUIRES_PRIVATE" takes care
361	# of that for pkg-config.
362	LIBS="$LIBS $OPENSSL_LIBS"
363	CFLAGS="$CFLAGS $OPENSSL_CFLAGS"
364	REQUIRES_PRIVATE="$REQUIRES_PRIVATE openssl"
365	AC_DEFINE([GG_CONFIG_HAVE_OPENSSL], [], [Defined if libgadu was compiled and linked with OpenSSL support.])
366else
367	have_openssl="no"
368	AC_DEFINE([GG_CONFIG_IS_GPL_COMPLIANT], [], [Defined if libgadu is GPL compliant (was not linked with OpenSSL or any other non-GPL compliant library support).])
369fi
370
371AM_CONDITIONAL([IS_GPL_COMPLIANT], [test "x$have_openssl" != "xyes"])
372
373# We need separate lists of libs handled with and without pkgconfig help, for the pkgconfig file.
374# We concatenate them here so that libtool can pick the pkgconfig-less libs too.
375LIBS="$LIBS $LIBS_PRIVATE"
376
377dnl
378dnl  Testy
379dnl
380
381AC_ARG_ENABLE(tests,
382        [  --disable-tests         do not compile tests])
383
384AM_CONDITIONAL([ENABLE_TESTS], [test "x$enable_tests" != "xno"])
385
386if test "x$enable_tests" != "xno"; then
387	enable_tests="yes"
388
389	dnl
390	dnl  Sprawdź, czy można korzystać z __funkcji w libc.
391	dnl
392
393	AC_CHECK_LIB(c, __connect, [have_glibc="yes"], [have_glibc="no"])
394
395	dnl
396	dnl  curl i expat dla search
397	dnl
398
399	AC_CHECK_LIB(curl, curl_easy_init, [have_curl="yes"], [have_curl="no"])
400	if test "x$have_curl" = "xyes"; then
401		AC_CHECK_HEADERS(curl/curl.h, [], [have_curl="no"])
402	fi
403
404	AC_CHECK_LIB(expat, XML_ParserCreate, [have_expat="yes"], [have_expat="no"])
405	if test "x$have_expat" = "xyes"; then
406		AC_CHECK_HEADERS(expat.h, [], [have_expat="no"])
407	fi
408
409	dnl
410	dnl  Perl dla protocol
411	dnl
412
413	AC_CHECK_PROG([PERL], [perl], [perl], [:])
414	if test "x$PERL" != "x:"; then
415		have_perl="yes"
416	else
417		have_perl="no"
418	fi
419
420	dnl
421	dnl  Sprawdź, czy mamy libxml2 do testów automatycznych
422	dnl
423
424	PKG_CHECK_MODULES([LIBXML2], [libxml-2.0 >= 2.2.3], [
425		have_libxml2="yes"
426		AC_DEFINE([HAVE_LIBXML2], [], [Defined if libxml2 is available.])
427	], [
428		have_libxml2="no"
429	])
430fi
431
432AM_CONDITIONAL([HAVE_GLIBC], [test "x$have_glibc" = "xyes"])
433AM_CONDITIONAL([HAVE_CURL_AND_EXPAT], [test "x$have_curl" = "xyes" -a "x$have_expat" = "xyes"])
434AM_CONDITIONAL([HAVE_PERL], [test "x$have_perl" = "xyes"])
435
436AM_CONDITIONAL([BUILD_CONNECT_TEST], [test \( "x$have_glibc" = "xyes" -a \
437	"x$have_gnutls" = "xyes" -a "x$have_pthread" = "xyes" \) -o \
438	"x$is_mingw" = "xyes"])
439
440dnl
441dnl  Sprawdź, czy mamy czym generować dokumentację
442dnl
443
444AC_CHECK_PROG([DOXYGEN], [doxygen], [doxygen], [:])
445
446AC_SUBST([SUBDIRS_DOXYGEN])
447if test "x$DOXYGEN" = "xdoxygen"; then
448	SUBDIRS_DOXYGEN="docs"
449	AC_SUBST([DOXYFILE_HTML_DIR])
450	DOXYFILE_HTML_DIR="html"
451	have_doxygen="yes"
452else
453	SUBDIRS_DOXYGEN=""
454	have_doxygen="no"
455fi
456
457dnl
458dnl  Ostrzeżenia kompilatora
459dnl
460
461AC_ARG_ENABLE(werror,
462        [  --enable-werror         halt on warnings])
463
464if test "x$enable_werror" == "xyes"; then
465	CFLAGS="$CFLAGS -Werror"
466fi
467
468
469AC_CONFIG_FILES([Makefile src/Makefile include/Makefile pkgconfig/Makefile pkgconfig/libgadu.pc docs/Makefile docs/Doxyfile examples/Makefile])
470
471AM_COND_IF([ENABLE_TESTS],
472	[AC_CONFIG_FILES([
473		test/Makefile
474		test/automatic/Makefile
475		test/automatic/script/Makefile
476		test/manual/Makefile
477		test/manual/lib/Makefile
478	])]
479)
480
481AC_OUTPUT
482
483echo
484echo $PACKAGE $VERSION
485echo
486
487echo Build with gnutls.... : $have_gnutls
488echo Build with openssl... : $have_openssl
489echo Build with protobuf-c : $have_protobuf_c
490echo Build with pthread... : $have_pthread
491echo Build with zlib...... : $have_zlib
492echo Build with docs...... : $have_doxygen
493echo
494
495echo Enable tests......... : $enable_tests
496if test "x$enable_tests" = "xyes"; then
497	echo Build with glibc..... : $have_glibc
498	echo Build with libcurl... : $have_curl
499	echo Build with libexpat.. : $have_expat
500	echo Build with libxml2... : $have_libxml2
501	echo Build with perl...... : $have_perl
502fi
503
504echo
505echo configure complete, now type \'make\'
506echo
507