configure.ac revision 298166
150276Speterm4_define([maj_ver], [0])
276726Speterm4_define([med_ver], [8])
350276Speterm4_define([min_ver], [0])
450276Speterm4_define([so_version], [6:0:0])
550276Speterm4_define([ucl_version], [maj_ver.med_ver.min_ver])
650276Speter
750276SpeterAC_INIT([libucl],[ucl_version],[https://github.com/vstakhov/libucl],[libucl])
850276SpeterAC_CONFIG_SRCDIR([configure.ac])
950276SpeterAM_INIT_AUTOMAKE([1.11 foreign -Wall -Wportability no-dist-gzip dist-xz])
1050276Speterm4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
1150276Speter
1250276SpeterUCL_VERSION=ucl_version
1350276SpeterSO_VERSION=so_version
1450276Speter
1550276SpeterAC_SUBST(UCL_VERSION)
1650276SpeterAC_SUBST(SO_VERSION)
1750276Speter
1850276SpeterAC_PROG_CC_C99
1950276SpeterAM_PROG_CC_C_O
2050276SpeterAM_PROG_AR
2150276SpeterLT_INIT
2250276SpeterAC_CONFIG_MACRO_DIR([m4])
2350276SpeterAC_CONFIG_HEADERS([config.h])
2450276Speter
2550276SpeterAC_C_CONST
2650276SpeterAC_TYPE_SIZE_T
2750276Speter
2850276SpeterAC_CHECK_HEADERS_ONCE([fcntl.h unistd.h])
2950276SpeterAC_TYPE_OFF_T
3050276SpeterAC_FUNC_MMAP
3150276SpeterAC_CHECK_HEADERS_ONCE([fcntl.h])
3250276SpeterAC_CHECK_HEADERS_ONCE([sys/types.h])
3350276SpeterAC_CHECK_HEADERS_ONCE([sys/stat.h])
3450276SpeterAC_CHECK_HEADERS_ONCE([sys/param.h])
3550276SpeterAC_CHECK_HEADERS_ONCE([sys/mman.h])
3650276SpeterAC_CHECK_HEADERS_ONCE([stdlib.h])
3750276SpeterAC_CHECK_HEADERS_ONCE([stddef.h])
3850276SpeterAC_CHECK_HEADERS_ONCE([stdarg.h])
3976726SpeterAC_CHECK_HEADERS_ONCE([stdbool.h])
4050276SpeterAC_CHECK_HEADERS_ONCE([stdint.h])
4176726SpeterAC_CHECK_HEADERS_ONCE([string.h])
4250276SpeterAC_CHECK_HEADERS_ONCE([unistd.h])
4350276SpeterAC_CHECK_HEADERS_ONCE([ctype.h])
4476726SpeterAC_CHECK_HEADERS_ONCE([errno.h])
4576726SpeterAC_CHECK_HEADERS_ONCE([limits.h])
4676726SpeterAC_CHECK_HEADERS_ONCE([libgen.h])
4750276SpeterAC_CHECK_HEADERS_ONCE([stdio.h])
4876726SpeterAC_CHECK_HEADERS_ONCE([float.h])
4976726SpeterAC_CHECK_HEADERS_ONCE([math.h])
5076726SpeterAC_CHECK_HEADERS_ONCE([endian.h sys/endian.h machine/endian.h])
5176726Speter
5276726Speterdnl Example of default-disabled feature
5376726SpeterAC_ARG_ENABLE([urls], AS_HELP_STRING([--enable-urls], 
5450276Speter	[Enable URLs fetch (requires libfetch or libcurl) @<:@default=no@:>@]), [],
5576726Speter	[enable_urls=no])
5650276SpeterAC_ARG_ENABLE([regex], AS_HELP_STRING([--enable-regex], 
57	[Enable regex checking for schema @<:@default=yes@:>@]), [],
58	[enable_regex=yes])
59AC_ARG_ENABLE([signatures], AS_HELP_STRING([--enable-signatures],
60	[Enable signatures check (requires openssl) @<:@default=no@:>@]), [],
61	[enable_signatures=no])
62AC_ARG_ENABLE([lua], AS_HELP_STRING([--enable-lua],
63	[Enable lua API build (requires lua libraries and headers) @<:@default=no@:>@]), [],
64	[enable_lua=no])
65AC_ARG_ENABLE([utils],
66	AS_HELP_STRING([--enable-utils], [Build and install utils @<:@default=no@:>@]),
67	[case "${enableval}" in
68  		yes) utils=true ;;
69  		no)  utils=false ;;
70  		*) AC_MSG_ERROR([bad value ${enableval} for --enable-utils]) ;;
71	esac],[utils=false])
72AM_CONDITIONAL([UTILS], [test x$utils = xtrue])
73
74AS_IF([test "x$enable_signatures" = "xyes"], [
75	AC_SEARCH_LIBS([EVP_MD_CTX_create], [crypto], [
76		AC_DEFINE(HAVE_OPENSSL, 1, [Define to 1 if you have the 'crypto' library (-lcrypto).])
77		LIBCRYPTO_LIB="-lcrypto"
78		LIBS_EXTRA="${LIBS_EXTRA} -lcrypto"
79		], [AC_MSG_ERROR([unable to find the EVP_MD_CTX_create() function])])
80])
81AC_SUBST(LIBCRYPTO_LIB)
82AC_PATH_PROG(PANDOC, pandoc, [/non/existent])
83
84AC_SEARCH_LIBS([clock_gettime], [rt], [], [
85	AC_CHECK_HEADER([mach/mach_time.h], [
86		AC_DEFINE(HAVE_MACH_MACH_TIME_H, 1, [Define to 1 on Darwin])
87	], [AC_MSG_ERROR([unable to find clock_gettime or mach_absolute_time])])
88])
89AC_SEARCH_LIBS([remainder], [m], [], [AC_MSG_ERROR([unable to find remainder() function])])
90
91AS_IF([test "x$enable_regex" = "xyes"], [
92	AC_CHECK_HEADER([regex.h], [
93		AC_DEFINE(HAVE_REGEX_H, 1, [Define to 1 if you have the <regex.h> header file.])
94		AC_SEARCH_LIBS([regexec], [regex], [
95			AS_IF([test "x$ac_cv_search_regexec" = "x-lregex"], [
96				LIBREGEX_LIB="-lregex"
97				LIBS_EXTRA="${LIBS_EXTRA} -lregex"
98				]
99			)], 
100			[AC_MSG_ERROR([unable to find the regexec() function])])],
101			[AC_MSG_ERROR([unable to find the regex.h header])
102		],
103		[#include <sys/types.h>])
104])
105AC_SUBST(LIBREGEX_LIB)
106
107AS_IF([test "x$enable_lua" = "xyes"], [
108	AX_PROG_LUA([5.1], [], [
109		AX_LUA_HEADERS([
110			AX_LUA_LIBS([
111				AC_DEFINE(HAVE_LUA, 1, [Define to 1 for lua support.])
112				with_lua="yes"
113			], [AC_MSG_ERROR([unable to find the lua libraries])
114			])
115		], [AC_MSG_ERROR([unable to find the lua header files])
116		])
117	], [AC_MSG_ERROR([unable to find the lua interpreter])])
118], [with_lua="no"])
119
120AM_CONDITIONAL([LUA_SUB], [test "$with_lua" = "yes"])
121
122AS_IF([test "x$enable_urls" = "xyes"], [
123	AC_CHECK_HEADER([fetch.h], [
124		AC_DEFINE(HAVE_FETCH_H, 1, [Define to 1 if you have the <fetch.h> header file.])
125		AC_CHECK_LIB(fetch, fetchXGet, [
126			AC_DEFINE(HAVE_LIBFETCH, 1, [Define to 1 if you have the 'fetch' library (-lfetch).])
127			LIBFETCH_LIBS="-lfetch"
128			have_libfetch="yes"
129			LIBS_EXTRA="${LIBS_EXTRA} -lfetch"
130		])
131	], [],[
132	#include <stdio.h>
133	#ifdef HAVE_SYS_PARAM_H
134	#include <sys/param.h>
135	#endif
136	])
137	AC_SUBST(LIBFETCH_LIBS)
138
139	AS_IF([ test "x$have_libfetch" != "xyes"], [
140		dnl Fallback to libcurl
141		PKG_CHECK_MODULES([CURL], [libcurl], [
142			AC_DEFINE(CURL_FOUND, 1, [Use libcurl])
143			LIBS_EXTRA="${LIBS_EXTRA} -lcurl"],
144		[AC_MSG_ERROR([unable to find neither libfetch nor libcurl])])
145	])
146	AC_SUBST(CURL_FOUND)
147	AC_SUBST(CURL_LIBS)
148	AC_SUBST(CURL_CFLAGS)
149])
150
151AC_SUBST(LIBS_EXTRA)
152
153AC_MSG_CHECKING(for GCC atomic builtins)
154AC_LINK_IFELSE([
155	AC_LANG_SOURCE([[
156		int main() {
157			volatile unsigned long val = 1;
158			__sync_synchronize();
159			__sync_val_compare_and_swap(&val, 1, 0);
160			__sync_add_and_fetch(&val, 1);
161			__sync_sub_and_fetch(&val, 1);
162			return 0;
163		}
164	]])
165],
166[
167	AC_MSG_RESULT([yes])
168	AC_DEFINE([HAVE_ATOMIC_BUILTINS], [1], [Has gcc/MSVC atomic intrinsics])
169],
170[
171	AC_MSG_RESULT([no])
172	AC_DEFINE([HAVE_ATOMIC_BUILTINS], [0], [Has gcc/MSVC atomic intrinsics])
173	AC_MSG_WARN([Libucl references could be thread-unsafe because atomic builtins are missing])
174])
175
176AX_CODE_COVERAGE
177
178AC_CONFIG_FILES(Makefile \
179	src/Makefile \
180	lua/Makefile
181	tests/Makefile \
182	utils/Makefile \
183	doc/Makefile \
184	lua/libucl.rockspec \
185	libucl.pc)
186AC_CONFIG_FILES([stamp-h], [echo timestamp > stamp-h])
187AC_OUTPUT
188