configure.ac 5.54 KB
Newer Older
Baptiste Daroussin's avatar
Baptiste Daroussin committed
1
m4_define([maj_ver], [0])
2
m4_define([med_ver], [7])
3
4
m4_define([min_ver], [3])
m4_define([so_version], [5:0:2])
Baptiste Daroussin's avatar
Baptiste Daroussin committed
5
6
7
8
m4_define([ucl_version], [maj_ver.med_ver.min_ver])

AC_INIT([libucl],[ucl_version],[https://github.com/vstakhov/libucl],[libucl])
AC_CONFIG_SRCDIR([configure.ac])
9
10
AM_INIT_AUTOMAKE([1.11 foreign -Wall -Wportability no-dist-gzip dist-xz])
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
Baptiste Daroussin's avatar
Baptiste Daroussin committed
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

UCL_VERSION=ucl_version
SO_VERSION=so_version

AC_SUBST(UCL_VERSION)
AC_SUBST(SO_VERSION)

AC_PROG_CC_C99
AM_PROG_CC_C_O
AM_PROG_AR
LT_INIT
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_HEADERS([config.h])

AC_C_CONST
AC_TYPE_SIZE_T

AC_CHECK_HEADERS_ONCE([fcntl.h unistd.h])
AC_TYPE_OFF_T
AC_FUNC_MMAP
AC_CHECK_HEADERS_ONCE([fcntl.h])
AC_CHECK_HEADERS_ONCE([sys/types.h])
AC_CHECK_HEADERS_ONCE([sys/stat.h])
AC_CHECK_HEADERS_ONCE([sys/param.h])
AC_CHECK_HEADERS_ONCE([sys/mman.h])
AC_CHECK_HEADERS_ONCE([stdlib.h])
AC_CHECK_HEADERS_ONCE([stddef.h])
AC_CHECK_HEADERS_ONCE([stdarg.h])
AC_CHECK_HEADERS_ONCE([stdbool.h])
AC_CHECK_HEADERS_ONCE([stdint.h])
AC_CHECK_HEADERS_ONCE([string.h])
AC_CHECK_HEADERS_ONCE([unistd.h])
AC_CHECK_HEADERS_ONCE([ctype.h])
AC_CHECK_HEADERS_ONCE([errno.h])
AC_CHECK_HEADERS_ONCE([limits.h])
AC_CHECK_HEADERS_ONCE([libgen.h])
AC_CHECK_HEADERS_ONCE([stdio.h])
AC_CHECK_HEADERS_ONCE([float.h])
AC_CHECK_HEADERS_ONCE([math.h])
50
AC_CHECK_HEADERS_ONCE([endian.h sys/endian.h machine/endian.h])
Baptiste Daroussin's avatar
Baptiste Daroussin committed
51
52

dnl Example of default-disabled feature
Baptiste Daroussin's avatar
Baptiste Daroussin committed
53
54
55
56
57
58
AC_ARG_ENABLE([urls], AS_HELP_STRING([--enable-urls], 
	[Enable URLs fetch (requires libfetch or libcurl) @<:@default=no@:>@]), [],
	[enable_urls=no])
AC_ARG_ENABLE([regex], AS_HELP_STRING([--enable-regex], 
	[Enable regex checking for schema @<:@default=yes@:>@]), [],
	[enable_regex=yes])
Baptiste Daroussin's avatar
Baptiste Daroussin committed
59
AC_ARG_ENABLE([signatures], AS_HELP_STRING([--enable-signatures],
Baptiste Daroussin's avatar
Baptiste Daroussin committed
60
61
	[Enable signatures check (requires openssl) @<:@default=no@:>@]), [],
	[enable_signatures=no])
62
63
64
AC_ARG_ENABLE([lua], AS_HELP_STRING([--enable-lua],
	[Enable lua API build (requires lua libraries and headers) @<:@default=no@:>@]), [],
	[enable_lua=no])
Baptiste Daroussin's avatar
Baptiste Daroussin committed
65
AC_ARG_ENABLE([utils],
Baptiste Daroussin's avatar
Baptiste Daroussin committed
66
	AS_HELP_STRING([--enable-utils], [Build and install utils @<:@default=no@:>@]),
Baptiste Daroussin's avatar
Baptiste Daroussin committed
67
68
69
70
71
72
73
74
75
76
	[case "${enableval}" in
  		yes) utils=true ;;
  		no)  utils=false ;;
  		*) AC_MSG_ERROR([bad value ${enableval} for --enable-utils]) ;;
	esac],[utils=false])
AM_CONDITIONAL([UTILS], [test x$utils = xtrue])

AS_IF([test "x$enable_signatures" = "xyes"], [
	AC_SEARCH_LIBS([EVP_MD_CTX_create], [crypto], [
		AC_DEFINE(HAVE_OPENSSL, 1, [Define to 1 if you have the 'crypto' library (-lcrypto).])
Baptiste Daroussin's avatar
Baptiste Daroussin committed
77
		LIBCRYPTO_LIB="-lcrypto"
Baptiste Daroussin's avatar
Baptiste Daroussin committed
78
79
80
		LIBS_EXTRA="${LIBS_EXTRA} -lcrypto"
		], [AC_MSG_ERROR([unable to find the EVP_MD_CTX_create() function])])
])
Baptiste Daroussin's avatar
Baptiste Daroussin committed
81
AC_SUBST(LIBCRYPTO_LIB)
Baptiste Daroussin's avatar
Baptiste Daroussin committed
82
83
84
85
86
87
88
89
90
AC_PATH_PROG(PANDOC, pandoc, [/non/existent])

AC_SEARCH_LIBS([clock_gettime], [rt], [], [
	AC_CHECK_HEADER([mach/mach_time.h], [
		AC_DEFINE(HAVE_MACH_MACH_TIME_H, 1, [Define to 1 on Darwin])
	], [AC_MSG_ERROR([unable to find clock_gettime or mach_absolute_time])])
])
AC_SEARCH_LIBS([remainder], [m], [], [AC_MSG_ERROR([unable to find remainder() function])])

Baptiste Daroussin's avatar
Baptiste Daroussin committed
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
AS_IF([test "x$enable_regex" = "xyes"], [
	AC_CHECK_HEADER([regex.h], [
		AC_DEFINE(HAVE_REGEX_H, 1, [Define to 1 if you have the <regex.h> header file.])
		AC_SEARCH_LIBS([regexec], [regex], [
			AS_IF([test "x$ac_cv_search_regexec" = "x-lregex"], [
				LIBREGEX_LIB="-lregex"
				LIBS_EXTRA="${LIBS_EXTRA} -lregex"
				]
			)], 
			[AC_MSG_ERROR([unable to find the regexec() function])])],
			[AC_MSG_ERROR([unable to find the regex.h header])
		],
		[#include <sys/types.h>])
])
AC_SUBST(LIBREGEX_LIB)
Baptiste Daroussin's avatar
Baptiste Daroussin committed
106

107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
AS_IF([test "x$enable_lua" = "xyes"], [
	AX_PROG_LUA([5.1], [], [
		AX_LUA_HEADERS([
			AX_LUA_LIBS([
				AC_DEFINE(HAVE_LUA, 1, [Define to 1 for lua support.])
				with_lua="yes"
			], [AC_MSG_ERROR([unable to find the lua libraries])
			])
		], [AC_MSG_ERROR([unable to find the lua header files])
		])
	], [AC_MSG_ERROR([unable to find the lua interpreter])])
], [with_lua="no"])

AM_CONDITIONAL([LUA_SUB], [test "$with_lua" = "yes"])

Baptiste Daroussin's avatar
Baptiste Daroussin committed
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
AS_IF([test "x$enable_urls" = "xyes"], [
	AC_CHECK_HEADER([fetch.h], [
		AC_DEFINE(HAVE_FETCH_H, 1, [Define to 1 if you have the <fetch.h> header file.])
		AC_CHECK_LIB(fetch, fetchXGet, [
			AC_DEFINE(HAVE_LIBFETCH, 1, [Define to 1 if you have the 'fetch' library (-lfetch).])
			LIBFETCH_LIBS="-lfetch"
			have_libfetch="yes"
			LIBS_EXTRA="${LIBS_EXTRA} -lfetch"
		])
	], [],[
	#include <stdio.h>
	#ifdef HAVE_SYS_PARAM_H
	#include <sys/param.h>
	#endif
	])
	AC_SUBST(LIBFETCH_LIBS)

	AS_IF([ test "x$have_libfetch" != "xyes"], [
		dnl Fallback to libcurl
		PKG_CHECK_MODULES([CURL], [libcurl], [
			AC_DEFINE(CURL_FOUND, 1, [Use libcurl])
			LIBS_EXTRA="${LIBS_EXTRA} -lcurl"],
		[AC_MSG_ERROR([unable to find neither libfetch nor libcurl])])
	])
	AC_SUBST(CURL_FOUND)
	AC_SUBST(CURL_LIBS)
	AC_SUBST(CURL_CFLAGS)
])

AC_SUBST(LIBS_EXTRA)

Baptiste Daroussin's avatar
Baptiste Daroussin committed
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
AC_MSG_CHECKING(for GCC atomic builtins)
AC_LINK_IFELSE([
	AC_LANG_SOURCE([[
		int main() {
			volatile unsigned long val = 1;
			__sync_synchronize();
			__sync_val_compare_and_swap(&val, 1, 0);
			__sync_add_and_fetch(&val, 1);
			__sync_sub_and_fetch(&val, 1);
			return 0;
		}
	]])
],
[
	AC_MSG_RESULT([yes])
	AC_DEFINE([HAVE_ATOMIC_BUILTINS], [1], [Has gcc/MSVC atomic intrinsics])
],
[
	AC_MSG_RESULT([no])
	AC_DEFINE([HAVE_ATOMIC_BUILTINS], [0], [Has gcc/MSVC atomic intrinsics])
	AC_MSG_WARN([Libucl references could be thread-unsafe because atomic builtins are missing])
])

Baptiste Daroussin's avatar
Baptiste Daroussin committed
176
177
AC_CONFIG_FILES(Makefile \
	src/Makefile \
178
	lua/Makefile
Baptiste Daroussin's avatar
Baptiste Daroussin committed
179
180
181
	tests/Makefile \
	utils/Makefile \
	doc/Makefile \
182
	lua/libucl.rockspec \
Baptiste Daroussin's avatar
Baptiste Daroussin committed
183
184
185
	libucl.pc)
AC_CONFIG_FILES([stamp-h], [echo timestamp > stamp-h])
AC_OUTPUT