xref: /lighttpd1.4/src/meson.build (revision 9570cc2f)
1sbinddir = join_paths(get_option('prefix'), get_option('sbindir'))
2moduledir = join_paths(get_option('prefix'), get_option('moduledir'))
3
4include_base_paths = [
5	'/usr/include',
6	'/usr/local/include',
7#	'/opt/local/include',
8]
9
10defs = [
11	'-D_FILE_OFFSET_BITS=64',
12	'-D_LARGEFILE_SOURCE',
13	'-D_LARGE_FILES',
14	'-D_GNU_SOURCE',
15]
16
17libws2_32 = []
18if target_machine.system() == 'windows'
19	libws2_32 = [ compiler.find_library('ws2_32') ]
20	defs += [
21		'-DNVALGRIND',
22	]
23endif
24
25
26compiler = meson.get_compiler('c')
27conf_data = configuration_data()
28
29conf_data.set('HAVE_SYS_DEVPOLL_H', compiler.has_header('sys/devpoll.h'))
30conf_data.set('HAVE_SYS_EPOLL_H', compiler.has_header('sys/epoll.h'))
31conf_data.set('HAVE_SYS_EVENT_H', compiler.has_header('sys/event.h'))
32conf_data.set('HAVE_SYS_LOADAVG_H', compiler.has_header('sys/loadavg.h'))
33conf_data.set('HAVE_SYS_MMAN_H', compiler.has_header('sys/mman.h'))
34conf_data.set('HAVE_SYS_POLL_H', compiler.has_header('sys/poll.h'))
35conf_data.set('HAVE_SYS_PORT_H', compiler.has_header('sys/port.h'))
36conf_data.set('HAVE_SYS_PRCTL_H', compiler.has_header('sys/prctl.h'))
37conf_data.set('HAVE_SYS_RESOURCE_H', compiler.has_header('sys/resource.h'))
38conf_data.set('HAVE_SYS_SENDFILE_H', compiler.has_header('sys/sendfile.h'))
39conf_data.set('HAVE_SYS_SELECT_H', compiler.has_header('sys/select.h'))
40conf_data.set('HAVE_SYS_TYPES_H', compiler.has_header('sys/types.h'))
41conf_data.set('HAVE_SYS_UIO_H', compiler.has_header('sys/uio.h'))
42conf_data.set('HAVE_SYS_UN_H', compiler.has_header('sys/un.h'))
43conf_data.set('HAVE_SYS_WAIT_H', compiler.has_header('sys/wait.h'))
44conf_data.set('HAVE_SYS_TIME_H', compiler.has_header('sys/time.h'))
45conf_data.set('HAVE_UNISTD_H', compiler.has_header('unistd.h'))
46conf_data.set('HAVE_PTHREAD_H', compiler.has_header('pthread.h'))
47conf_data.set('HAVE_GETOPT_H', compiler.has_header('getopt.h'))
48conf_data.set('HAVE_INTTYPES_H', compiler.has_header('inttypes.h'))
49conf_data.set('HAVE_POLL_H', compiler.has_header('poll.h'))
50conf_data.set('HAVE_PWD_H', compiler.has_header('pwd.h'))
51conf_data.set('HAVE_STDDEF_H', compiler.has_header('stddef.h'))
52conf_data.set('HAVE_STDINT_H', compiler.has_header('stdint.h'))
53conf_data.set('HAVE_STRINGS_H', compiler.has_header('strings.h'))
54conf_data.set('HAVE_SYSLOG_H', compiler.has_header('syslog.h'))
55
56# check for fastcgi lib, for the tests only
57conf_data.set('HAVE_FASTCGI_H', compiler.has_header('fastcgi.h'))
58if not(conf_data.get('HAVE_FASTCGI_H'))
59	conf_data.set('HAVE_FASTCGI_FASTCGI_H', compiler.has_header('fastcgi/fastcgi.h'))
60endif
61
62# will be needed for auth
63conf_data.set('HAVE_CRYPT_H', compiler.has_header('crypt.h'))
64if conf_data.get('HAVE_CRYPT_H')
65	# check if we need libcrypt for crypt_r / crypt
66
67	# crypt_r in default libs?
68	if compiler.has_function('crypt_r', args: defs, prefix: '#include <crypt.h>')
69		libcrypt = []
70		conf_data.set('HAVE_CRYPT_R', 1)
71	# crypt_r in -lcrypt ?
72	elif compiler.has_function('crypt_r', args: defs + ['-lcrypt'], prefix: '#include <crypt.h>')
73		libcrypt = [ compiler.find_library('crypt') ]
74		conf_data.set('HAVE_CRYPT_R', 1)
75	# crypt in default libs?
76	elif compiler.has_function('crypt', args: defs, prefix: '#include <crypt.h>')
77		libcrypt = []
78		conf_data.set('HAVE_CRYPT', 1)
79	# crypt in -lcrypt ?
80	elif compiler.has_function('crypt', args: defs + ['-lcrypt'], prefix: '#include <crypt.h>')
81		libcrypt = [ compiler.find_library('crypt') ]
82		conf_data.set('HAVE_CRYPT', 1)
83	endif
84endif
85
86conf_data.set('HAVE_SYS_INOTIFY_H', compiler.has_header('sys/inotify.h'))
87if conf_data.get('HAVE_SYS_INOTIFY_H')
88	conf_data.set('HAVE_INOTIFY_INIT', compiler.has_function('inotify_init', args: defs))
89endif
90
91conf_data.set('HAVE_SOCKLEN_T', compiler.has_type('socklen_t', args: defs, prefix: '#include <sys/socket.h>'))
92
93conf_data.set('HAVE_SYS_RANDOM_H', compiler.has_header('sys/random.h'))
94if conf_data.get('HAVE_SYS_RANDOM_H')
95	conf_data.set('HAVE_GETENTROPY', compiler.has_function(
96		'getentropy',
97		args: defs,
98		prefix: '#include <sys/random.h>'
99	))
100endif
101
102conf_data.set('HAVE_LINUX_RANDOM_H', compiler.has_header('linux/random.h'))
103if conf_data.get('HAVE_LINUX_RANDOM_H')
104	conf_data.set('HAVE_GETRANDOM', compiler.has_function(
105		'getrandom',
106		args: defs,
107		prefix: '#include <linux/random.h>'
108	))
109endif
110
111conf_data.set('SIZEOF_LONG', compiler.sizeof('long', args: defs))
112conf_data.set('SIZEOF_OFF_T', compiler.sizeof('off_t', args: defs))
113
114conf_data.set('HAVE_ARC4RANDOM_BUF', compiler.has_function('arc4random_buf', args: defs))
115conf_data.set('HAVE_CHROOT', compiler.has_function('chroot', args: defs))
116conf_data.set('HAVE_COPY_FILE_RANGE', compiler.has_function('copy_file_range', args: defs))
117conf_data.set('HAVE_EPOLL_CTL', compiler.has_function('epoll_ctl', args: defs))
118conf_data.set('HAVE_FORK', compiler.has_function('fork', args: defs))
119conf_data.set('HAVE_GETLOADAVG', compiler.has_function('getloadavg', args: defs))
120conf_data.set('HAVE_GETRLIMIT', compiler.has_function('getrlimit', args: defs))
121conf_data.set('HAVE_GETUID', compiler.has_function('getuid', args: defs))
122conf_data.set('HAVE_GMTIME_R', compiler.has_function('gmtime_r', args: defs))
123conf_data.set('HAVE_INET_NTOP', compiler.has_function('inet_ntop', args: defs))
124conf_data.set('HAVE_JRAND48', compiler.has_function('jrand48', args: defs))
125conf_data.set('HAVE_KQUEUE', compiler.has_function('kqueue', args: defs))
126conf_data.set('HAVE_LOCALTIME_R', compiler.has_function('localtime_r', args: defs))
127conf_data.set('HAVE_LSTAT', compiler.has_function('lstat', args: defs))
128conf_data.set('HAVE_MADVISE', compiler.has_function('madvise', args: defs))
129conf_data.set('HAVE_MEMCPY', compiler.has_function('memcpy', args: defs))
130conf_data.set('HAVE_MEMSET', compiler.has_function('memset', args: defs))
131conf_data.set('HAVE_MMAP', compiler.has_function('mmap', args: defs))
132conf_data.set('HAVE_PATHCONF', compiler.has_function('pathconf', args: defs))
133conf_data.set('HAVE_PIPE2', compiler.has_function('pipe2', args: defs))
134conf_data.set('HAVE_POLL', compiler.has_function('poll', args: defs))
135conf_data.set('HAVE_PORT_CREATE', compiler.has_function('port_create', args: defs))
136conf_data.set('HAVE_PRCTL', compiler.has_function('prctl', args: defs))
137conf_data.set('HAVE_PREAD', compiler.has_function('pread', args: defs))
138conf_data.set('HAVE_POSIX_FADVISE', compiler.has_function('posix_fadvise', args: defs))
139conf_data.set('HAVE_SELECT', compiler.has_function('select', args: defs))
140conf_data.set('HAVE_SENDFILE', compiler.has_function('sendfile', args: defs))
141conf_data.set('HAVE_SEND_FILE', compiler.has_function('send_file', args: defs))
142conf_data.set('HAVE_SENDFILE64', compiler.has_function('sendfile64', args: defs))
143conf_data.set('HAVE_SENDFILEV', compiler.has_function('sendfilev', args: defs))
144conf_data.set('HAVE_SIGACTION', compiler.has_function('sigaction', args: defs))
145conf_data.set('HAVE_SIGNAL', compiler.has_function('signal', args: defs))
146conf_data.set('HAVE_SIGTIMEDWAIT', compiler.has_function('sigtimedwait', args: defs))
147conf_data.set('HAVE_SRANDOM', compiler.has_function('srandom', args: defs))
148conf_data.set('HAVE_STRPTIME', compiler.has_function('strptime', args: defs))
149conf_data.set('HAVE_SYSLOG', compiler.has_function('syslog', args: defs))
150conf_data.set('HAVE_WRITEV', compiler.has_function('writev', args: defs))
151conf_data.set('HAVE_INET_ATON', compiler.has_function('inet_aton', args: defs))
152conf_data.set('HAVE_ISSETUGID', compiler.has_function('issetugid', args: defs))
153conf_data.set('HAVE_INET_PTON', compiler.has_function('inet_pton', args: defs))
154conf_data.set('HAVE_MEMSET_S', compiler.has_function('memset_s', args: defs))
155conf_data.set('HAVE_EXPLICIT_BZERO', compiler.has_function('explicit_bzero', args: defs))
156conf_data.set('HAVE_EXPLICIT_MEMSET', compiler.has_function('explicit_memset', args: defs))
157
158conf_data.set('HAVE_CLOCK_GETTIME', compiler.has_header_symbol('time.h', 'clock_gettime'))
159clock_lib = []
160if not(conf_data.get('HAVE_CLOCK_GETTIME'))
161	if compiler.has_function('clock_gettime', args: defs + ['-lrt'], prefix: '#include <time.h>')
162		conf_data.set('HAVE_CLOCK_GETTIME', true)
163		clock_lib = [ compiler.find_library('rt') ]
164	endif
165endif
166
167libelftc = []
168if compiler.has_function('elftc_copyfile', args: defs + ['-lelftc'], prefix: '#include <libelftc.h>')
169	conf_data.set('HAVE_ELFTC_COPYFILE', true)
170	libelftc = [ compiler.find_library('elftc') ]
171endif
172
173conf_data.set('HAVE_IPV6', compiler.compiles('''
174	#include <sys/types.h>
175	#include <sys/socket.h>
176	#include <netinet/in.h>
177
178	int main() {
179		struct sockaddr_in6 s; struct in6_addr t=in6addr_any; int i=AF_INET6; s; t.s6_addr[0] = 0;
180		return 0;
181	}
182''',
183	name: 'IPv6 support',
184	args: defs
185))
186
187conf_data.set('HAVE_WEAK_SYMBOLS', compiler.compiles('''
188	__attribute__((weak)) void __dummy(void *x) { }
189	int main() {
190		void *x;
191		__dummy(x);
192	}
193''',
194	name: 'weak symbols',
195	args: defs
196))
197
198conf_data.set('HAVE_STRUCT_TM_GMTOFF', compiler.compiles('''
199	#include <time.h>
200	int main(void) {
201		struct tm t;
202		t.tm_gmtoff = 0;
203		return 0;
204	}
205''',
206	name: 'struct tm gmt offset',
207	args: defs
208))
209
210conf_data.set('LIGHTTPD_VERSION_ID', 10400)
211conf_data.set_quoted('PACKAGE_NAME', meson.project_name())
212conf_data.set_quoted('PACKAGE_VERSION', meson.project_version())
213conf_data.set_quoted('LIBRARY_DIR', moduledir)
214
215conf_data.set('LIGHTTPD_STATIC', get_option('build_static'))
216libdl = []
217if not(get_option('build_static'))
218	if target_machine.system() != 'windows'
219		libdl = [ compiler.find_library('dl') ]
220		if not(compiler.has_function('dlopen', args: defs, dependencies: libdl, prefix: '#include <dlfcn.h>'))
221			error('Couldn\'t find dlfcn.h or dlopen in lib dl')
222		endif
223	endif
224endif
225
226libbz2 = []
227if get_option('with_bzip')
228	libbz2 = [ compiler.find_library('bz2') ]
229	if compiler.has_function('BZ2_bzCompress', args: defs, dependencies: libbz2, prefix: '#include <bzlib.h>')
230		conf_data.set('HAVE_BZLIB_H', true)
231		conf_data.set('HAVE_LIBBZ2', true)
232	else
233		error('Couldn\'t find bz2 header / library')
234	endif
235endif
236
237if get_option('with_dbi')
238	libdbi = dependency('dbi', required: false)
239	if libdbi.found()
240		libdbi = [ libdbi ]
241	else
242		libdbi = [ compiler.find_library('dbi') ]
243		if not(compiler.has_function('dbi_conn_connect', args: defs, dependencies: libdbi, prefix: '#include <dbi/dbi.h>'))
244			error('Couldn\'t find dbi/dbi.h or dbi_conn_connect in lib dbi')
245		endif
246	endif
247	conf_data.set('HAVE_DBI', true)
248endif
249
250libfam = []
251if get_option('with_fam')
252	libfam = [ compiler.find_library('fam') ]
253	if not(compiler.has_function('FAMOpen2', args: defs, dependencies: libfam, prefix: '#include <fam.h>'))
254		error('Couldn\'t find fam.h or FAMOpen2 in lib fam')
255	endif
256	conf_data.set('HAVE_FAM_H', true)
257endif
258
259libgeoip = []
260if get_option('with_geoip')
261	libgeoip = dependency('geoip', required: false)
262	if libgeoip.found()
263		libgeoip = [ libgeoip ]
264	else
265		libgeoip = [ compiler.find_library('GeoIP') ]
266		if not(compiler.has_function('GeoIP_country_name_by_addr', args: defs, dependencies: libgeoip))
267			error('Couldn\'t find GeoIP_country_name_by_addr in lib GeoIP')
268		endif
269	endif
270endif
271
272libgdbm = []
273if get_option('with_gdbm')
274	libgdbm = [ compiler.find_library('gdbm') ]
275	if not(compiler.has_function('gdbm_open', args: defs, dependencies: libgdbm, prefix: '#include <gdbm.h>'))
276		error('Couldn\'t find gdbm.h or gdbm_open in lib gdbm')
277	endif
278	conf_data.set('HAVE_GDBM_H', true)
279	conf_data.set('HAVE_GDBM', true)
280endif
281
282libkrb5 = []
283libgssapi_krb5 = []
284if get_option('with_krb5')
285	libkrb5 = dependency('krb5', required: false)
286	if libkrb5.found()
287		libkrb5 = [ libkrb5 ]
288	else
289		libkrb5 = [ compiler.find_library('krb5') ]
290		if not(compiler.has_function('krb5_init_context', args: defs, dependencies: libkrb5))
291			error('Couldn\'t find krb5_init_context in lib krb5')
292		endif
293	endif
294
295	libgssapi_krb5 = dependency('krb5-gssapi', required: false)
296	if libgssapi_krb5.found()
297		libgssapi_krb5 = [ libgssapi_krb5 ]
298	else
299		libgssapi_krb5 = [ compiler.find_library('gssapi_krb5') ]
300	endif
301
302	conf_data.set('HAVE_KRB5', true)
303endif
304
305libldap = []
306liblber = []
307if get_option('with_ldap')
308	libldap = [ compiler.find_library('ldap') ]
309	if not(compiler.has_function('ldap_sasl_bind_s',
310		args: defs,
311		dependencies: libldap,
312		prefix: '''
313			#include <ldap.h>
314		'''
315	))
316		error('Couldn\'t find ldap.h or ldap_bind in lib libldap')
317	endif
318	conf_data.set('HAVE_LDAP_H', true)
319	conf_data.set('HAVE_LIBLDAP', true)
320	liblber = [ compiler.find_library('lber') ]
321	if not(compiler.has_function('ber_printf', args: defs, dependencies: liblber, prefix: '#include <lber.h>'))
322		error('Couldn\'t find lber.h or ber_printf in lib liblber')
323	endif
324	conf_data.set('HAVE_LBER_H', true)
325	conf_data.set('HAVE_LIBLBER', true)
326endif
327
328libpam = []
329if get_option('with_pam')
330	libpam = [ compiler.find_library('pam') ]
331	if not(compiler.has_function('pam_start',
332		args: defs,
333		dependencies: libpam,
334		prefix: '''
335			#include <security/pam_appl.h>
336		'''
337	))
338		error('Couldn\'t find security/pam_appl.h or pam_start in lib libpam')
339	endif
340	conf_data.set('HAVE_PAM', true)
341endif
342
343libev = []
344if get_option('with_libev')
345	libev = dependency('ev', required: false)
346	if libev.found()
347		libev = [ libev ]
348	elif compiler.has_header('ev.h') and compiler.has_function('ev_time', args: defs + ['-lev'])
349		libev = [ compiler.find_library('ev') ]
350	else
351		error('Couldn\'t find libev header / library')
352	endif
353	conf_data.set('HAVE_LIBEV', true)
354endif
355
356libunwind = []
357if get_option('with_libunwind')
358	libunwind = [ dependency('libunwind') ]
359endif
360
361liblua = []
362if get_option('with_lua')
363	found_lua = false
364	foreach l: ['lua5.3', 'lua-5.3', 'lua5.2', 'lua-5.2', 'lua5.1', 'lua-5.1', 'lua']
365		if not(found_lua)
366			liblua = dependency(l, required: false)
367			found_lua = liblua.found()
368		endif
369	endforeach
370	if not(found_lua)
371		error('Couldn\'t find any lua library')
372	endif
373	liblua = [ liblua ]
374	conf_data.set('HAVE_LUA_H', true)
375endif
376
377libmemcached = []
378if get_option('with_memcached')
379	# manual search:
380	# header: libmemcached/memcached.h
381	# function: memcached (-lmemcached)
382	libmemcached = [ dependency('libmemcached') ]
383	conf_data.set('USE_MEMCACHED', true)
384endif
385
386libmysqlclient = []
387if get_option('with_mysql')
388	# manual search: extend include path with 'mysql/'
389	# header: mysql.h
390	# function: mysql_real_connect (-lmariadb)
391	libmysqlclient = [ dependency('mariadb') ]
392	#-# function: mysql_real_connect (-lmysqlclient)
393	#-libmysqlclient = [ dependency('mysqlclient') ]
394	conf_data.set('HAVE_MYSQL', true)
395endif
396
397libssl = []
398libx509 = []
399libcrypto = []
400libgnutls = []
401if get_option('with_openssl')
402	# manual search:
403	# header: openssl/ssl.h
404	# function: SSL_new (-lssl)
405	# function: BIO_f_base64 (-lcrypto)
406	libssl = [ dependency('libssl') ]
407	libcrypto = [ dependency('libcrypto') ]
408	conf_data.set('HAVE_OPENSSL_SSL_H', true)
409	conf_data.set('HAVE_LIBSSL', true)
410endif
411if get_option('with_wolfssl') != 'false'
412	# manual search:
413	# header: wolfssl/ssl.h
414	# function: wolfSSL_Init (-lwolfssl)
415	p = get_option('with_wolfssl')
416	if p == 'true'
417		p = '/usr/local'
418	endif
419	i = include_directories(p+'/include', p+'/include/wolfssl')
420	libwolfssl_includes_dep = [ declare_dependency(include_directories: i) ]
421	libcrypto = [ compiler.find_library('libwolfssl', dirs: [ p+'/lib', p+'/lib64' ]) ]
422	libcrypto += libwolfssl_includes_dep
423	conf_data.set('HAVE_WOLFSSL_SSL_H', true)
424endif
425if get_option('with_mbedtls')
426	# manual search:
427	# header: mbedtls/ssl.h
428	# function: mbedtls_cipher_info_from_type (-lmbedtls)
429	# function: mbedtls_x509_get_name (-lmbedx509)
430	# function: mbedtls_base64_encode (-lmbedcrypto)
431	libssl = [ dependency('libmbedtls') ]
432	libx509 = [ dependency('libmbedx509') ]
433	libcrypto = [ dependency('libmbedcrypto') ]
434	conf_data.set('HAVE_LIBMBEDCRYPTO', true)
435endif
436if get_option('with_nettle') != 'false'
437	# manual search:
438	# header: nettle/nettle-types.h
439	# function: nettle_md5_init (-lnettle)
440	libcrypto = [ dependency('libnettle') ]
441	conf_data.set('HAVE_NETTLE_NETTLE_TYPES_H', true)
442endif
443if get_option('with_gnutls')
444	# manual search:
445	# header: gnutls/gnutls.h
446	# function: gnutls_check_version (-lgnutls)
447	libgnutls = [ dependency('libgnutls') ]
448	conf_data.set('HAVE_GNUTLS_CRYPTO_H', true)
449	if not(get_option('with_openssl')) and not(get_option('with_wolfssl')) and not(get_option('with_mbedtls')) and not(getoption('with_nettle'))
450	  libcrypto = [ dependency('libgnutls') ]
451	endif
452endif
453
454libpcre = []
455if get_option('with_pcre')
456	# manual search:
457	# header: pcre.h
458	# function: pcre_exec (-lpcre)
459	libpcre = [ dependency('libpcre') ]
460	conf_data.set('HAVE_PCRE_H', true)
461	conf_data.set('HAVE_LIBPCRE', true)
462endif
463
464libpq = []
465if get_option('with_pgsql')
466	# manual search:
467	# header: libpq-fe.h
468	# function: PQsetdbLogin (-lpq)
469	libpq = [ dependency('libpq') ]
470	conf_data.set('HAVE_PGSQL', true)
471endif
472
473if get_option('with_sasl')
474	libsasl = dependency('sasl2', required: false)
475	if libsasl.found()
476		libsasl = [ libsasl2 ]
477	else
478		libsasl = [ compiler.find_library('sasl2') ]
479		if not(compiler.has_function('sasl_server_init', args: defs, dependencies: libsasl, prefix: '#include <sasl/sasl.h>'))
480			error('Couldn\'t find sasl/sasl.h or sasl_server_init in libsasl2')
481		endif
482	endif
483	conf_data.set('HAVE_SASL', true)
484endif
485
486#if get_option('with_valgrind')
487#endif
488
489libuuid = []
490if get_option('with_webdav_locks')
491	libuuid = dependency('uuid', required: false)
492	if libuuid.found()
493		libuuid = [ libuuid ]
494	elif compiler.has_function('uuid_generate', args: defs, prefix: '#include <uuid/uuid.h>')
495		# uuid_generate in libc, everything is fine, no lib needed
496		libuuid = []
497	else
498		libuuid = compiler.find_library('uuid')
499		if not(compiler.has_function('uuid_generate',
500			args: defs,
501			dependencies: libuuid,
502			prefix: '#include <uuid/uuid.h>'
503		))
504			error('Couldn\'t find uuid/uuid.h or uuid_generate in lib c and uuid')
505		endif
506	endif
507	conf_data.set('HAVE_LIBUUID', true)
508	conf_data.set('HAVE_UUID_UUID_H', true)
509endif
510
511libxml2 = []
512libsqlite3 = []
513if get_option('with_webdav_props')
514	libxml2 = dependency('libxml-2.0', required: false)
515	if libxml2.found()
516		libxml2 = [ libxml2 ]
517	else
518		libxml2_includes = []
519		libxml2_includes_dep = []
520		libxml2_found_header = compiler.has_header('libxml/tree.h')
521		foreach i: include_base_paths
522			if not(libxml2_found_header)
523				message('Searching in ' + join_paths(i, 'libxml2'))
524				i = include_directories(join_paths(i, 'libxml2'))
525				if compiler.has_header('libxml/tree.h', include_directories: i)
526					libxml2_found_header = true
527					libxml2_includes = [ i ]
528					libxml2_includes_dep = [ declare_dependency(include_directories: i) ]
529				endif
530			endif
531		endforeach
532		if not(libxml2_found_header)
533			error('Couldn\'t find libxml/tree.h')
534		endif
535		libxml2 = [ compiler.find_library('xml2') ]
536		if not(compiler.has_function('xmlParseChunk',
537			args: defs,
538			dependencies: libxml2,
539			include_directories: libxml2_includes,
540			prefix: '''
541				#include <libxml/tree.h>
542			'''
543		))
544			error('Couldn\'t find xmlParseChunk in lib xml2')
545		endif
546		# has_function doesn't like "internal dependencies"
547		libxml2 += libxml2_includes_dep
548	endif
549	conf_data.set('HAVE_LIBXML_H', true)
550
551	libsqlite3 = dependency('sqlite31', required: false)
552	if libsqlite3.found()
553		libsqlite3 = [ libsqlite3 ]
554	else
555		libsqlite3 = [ compiler.find_library('sqlite3') ]
556		if not(compiler.has_function('sqlite3_reset',
557			args: defs,
558			dependencies: libsqlite3,
559			prefix: '''
560				#include <sqlite3.h>
561			'''
562		))
563			error('Couldn\'t find sqlite3.h or sqlite3_reset in lib sqlite3')
564		endif
565	endif
566	conf_data.set('HAVE_SQLITE3_H', true)
567endif
568
569libattr = []
570if get_option('with_xattr')
571    if compiler.has_function('getxattr',
572		args: defs,
573		prefix: '''
574			#include <sys/types.h>
575			#include <sys/xattr.h>
576		'''
577    )
578	conf_data.set('HAVE_SYS_XATTR_H', true)
579	conf_data.set('HAVE_XATTR', true)
580    else
581	libattr = [ compiler.find_library('attr') ]
582	if not(compiler.has_function('attr_get',
583		args: defs,
584		dependencies: libattr,
585		prefix: '''
586			#include <sys/types.h>
587			#include <attr/attributes.h>
588		'''
589	))
590		error('Couldn\'t find attr/attributes.h or attr_get in lib attr')
591	endif
592	conf_data.set('HAVE_ATTR_ATTRIBUTES_H', true)
593	conf_data.set('HAVE_XATTR', true)
594    endif
595endif
596
597libz = []
598if get_option('with_zlib')
599	libz = dependency('zlib', required: false)
600	if libz.found()
601		libz = [ libz ]
602	else
603		# windows alternative names? 'zlib', 'zdll'
604		libz = [ compiler.find_library('z') ]
605		if not(compiler.has_function('deflate', args: defs, dependencies: libz, prefix: '#include <zlib.h>'))
606			error('Couldn\'t find z header / library')
607		endif
608	endif
609	conf_data.set('HAVE_ZLIB_H', true)
610	conf_data.set('HAVE_LIBZ', true)
611endif
612
613configure_file(
614	output : 'config.h',
615	configuration : conf_data,
616)
617
618common_src = [
619	'algo_sha1.c',
620	'array.c',
621	'base64.c',
622	'buffer.c',
623	'burl.c',
624	'chunk.c',
625	'configfile-glue.c',
626	'connections-glue.c',
627	'crc32.c',
628	'data_array.c',
629	'data_integer.c',
630	'data_string.c',
631	'etag.c',
632	'fdevent_freebsd_kqueue.c',
633	'fdevent_libev.c',
634	'fdevent_linux_sysepoll.c',
635	'fdevent_poll.c',
636	'fdevent_select.c',
637	'fdevent_solaris_devpoll.c',
638	'fdevent_solaris_port.c',
639	'fdevent.c',
640	'gw_backend.c',
641	'http_auth.c',
642	'http_chunk.c',
643	'http_header.c',
644	'http_kv.c',
645	'http_vhostdb.c',
646	'http-header-glue.c',
647	'keyvalue.c',
648	'log.c',
649	'md5.c',
650	'plugin.c',
651	'rand.c',
652	'request.c',
653	'safe_memclear.c',
654	'sock_addr.c',
655	'splaytree.c',
656	'stat_cache.c',
657	'stream.c',
658	'vector.c',
659]
660if target_machine.system() == 'windows'
661	common_src += [ 'xgetopt.c' ]
662endif
663main_src = [
664	'configfile.c',
665	'connections.c',
666	'data_config.c',
667	'inet_ntop_cache.c',
668	'network_write.c',
669	'network.c',
670	'response.c',
671	'server.c',
672]
673
674lemon = executable('lemon',
675	sources: 'lemon.c',
676	native: true,
677)
678# generator doesn't handle additional "input dependencies" like lempar.c
679# => use custom_target
680configparser = custom_target('configparser',
681	input:  ['configparser.y', 'lempar.c'],
682	output: ['configparser.c', 'configparser.h'],
683	command: [lemon, '-q', 'o=@OUTDIR@', '@INPUT0@', '@INPUT1@'],
684)
685ssi_exprparser = custom_target('mod_ssi_exprparser',
686	input:  ['mod_ssi_exprparser.y', 'lempar.c'],
687	output: ['mod_ssi_exprparser.c', 'mod_ssi_exprparser.h'],
688	command: [lemon, '-q', 'o=@OUTDIR@', '@INPUT0@', '@INPUT1@'],
689)
690
691common_cflags = defs + [
692	'-DHAVE_CONFIG_H',
693]
694
695if compiler.get_id() == 'gcc' or compiler.get_id() == 'clang'
696	common_cflags += [
697		'-Wall',
698		'-g',
699		'-Wshadow',
700		'-W',
701		'-pedantic',
702	]
703	if get_option('build_extra_warnings')
704		common_cflags += get_option('warn_cflags').split()
705	endif
706endif
707
708common_flags = [ declare_dependency(
709	compile_args: common_cflags,
710	# tests also use common_flags, and need this
711	include_directories: include_directories('.'),
712) ]
713
714lighttpd_flags = []
715lighttpd_angel_flags = []
716if target_machine.system() == 'windows'
717	lighttpd_flags += [ declare_dependency(
718		compile_args: [
719			'-DLI_DECLARE_EXPORTS',
720		],
721	) ]
722	if compiler.get_id() == 'gcc'
723		libmsvcr70 = [ compiler.find_library('msvcr70') ]
724		lighttpd_flags += libmsvcr70 + [ declare_dependency(
725			link_args: [
726				'-Wl,-subsystem,console',
727			],
728		) ]
729		lighttpd_angel_flags += libmsvcr70 + [ declare_dependency(
730			link_args: [
731				'-Wl,-subsystem,console',
732			],
733		) ]
734	endif
735endif
736
737if compiler.get_id() == 'gcc' or target_machine.system() != 'darwin'
738	lighttpd_flags += [ declare_dependency(
739		link_args: [
740			'-Wl,-export-dynamic',
741		],
742	) ]
743endif
744
745executable('lighttpd-angel',
746	sources: 'lighttpd-angel.c',
747	dependencies: common_flags + lighttpd_angel_flags,
748	c_args: ['-DSBIN_DIR="' + sbinddir + '"'],
749	install: true,
750	install_dir: sbinddir,
751)
752
753executable('lighttpd', configparser,
754	sources: common_src + main_src,
755	# libssl needed?
756	dependencies: [ common_flags, lighttpd_flags
757		, libattr
758		, libcrypto
759		, libdl
760		, libev
761		, libfam
762		, libpcre
763		, libunwind
764		, libws2_32
765	],
766	install: true,
767	install_dir: sbinddir,
768)
769
770test('test_array', executable('test_array',
771	sources: ['t/test_array.c', 'array.c', 'data_array.c', 'data_integer.c', 'data_string.c', 'buffer.c'],
772	dependencies: common_flags + libunwind,
773	build_by_default: false,
774))
775
776test('test_buffer', executable('test_buffer',
777	sources: ['t/test_buffer.c', 'buffer.c'],
778	dependencies: common_flags + libunwind,
779	build_by_default: false,
780))
781
782test('test_burl', executable('test_burl',
783	sources: ['t/test_burl.c', 'burl.c', 'buffer.c', 'base64.c'],
784	dependencies: common_flags + libunwind,
785	build_by_default: false,
786))
787
788test('test_base64', executable('test_base64',
789	sources: ['t/test_base64.c', 'buffer.c', 'base64.c'],
790	dependencies: common_flags + libunwind,
791	build_by_default: false,
792))
793
794test('test_configfile', executable('test_configfile',
795	sources: [
796		't/test_configfile.c',
797		'buffer.c',
798		'array.c',
799		'data_config.c',
800		'data_integer.c',
801		'data_string.c',
802		'http_header.c',
803		'http_kv.c',
804		'vector.c',
805		'log.c',
806		'sock_addr.c',
807	],
808	dependencies: common_flags + libpcre + libunwind,
809	build_by_default: false,
810))
811
812test('test_keyvalue', executable('test_keyvalue',
813	sources: [
814		't/test_keyvalue.c',
815		'burl.c',
816		'buffer.c',
817		'base64.c',
818		'array.c',
819		'data_integer.c',
820		'data_string.c',
821		'log.c',
822	],
823	dependencies: common_flags + libpcre + libunwind,
824	build_by_default: false,
825))
826
827test('test_mod_access', executable('test_mod_access',
828	sources: [
829		't/test_mod_access.c',
830		'buffer.c',
831		'array.c',
832		'data_integer.c',
833		'data_string.c',
834		'log.c',
835	],
836	dependencies: common_flags + libunwind,
837	build_by_default: false,
838))
839
840test('test_mod_evhost', executable('test_mod_evhost',
841	sources: [
842		't/test_mod_evhost.c',
843		'buffer.c',
844		'array.c',
845		'data_integer.c',
846		'data_string.c',
847		'log.c',
848	],
849	dependencies: common_flags + libunwind,
850	build_by_default: false,
851))
852
853test('test_mod_simple_vhost', executable('test_mod_simple_vhost',
854	sources: [
855		't/test_mod_simple_vhost.c',
856		'buffer.c',
857		'array.c',
858		'data_integer.c',
859		'data_string.c',
860		'log.c',
861	],
862	dependencies: common_flags + libunwind,
863	build_by_default: false,
864))
865
866test('test_mod_userdir', executable('test_mod_userdir',
867	sources: [
868		't/test_mod_userdir.c',
869		'buffer.c',
870		'array.c',
871		'data_integer.c',
872		'data_string.c',
873		'log.c',
874	],
875	dependencies: common_flags + libunwind,
876	build_by_default: false,
877))
878
879test('test_request', executable('test_request',
880	sources: [
881		't/test_request.c',
882		'request.c',
883		'base64.c',
884		'buffer.c',
885		'burl.c',
886		'array.c',
887		'data_integer.c',
888		'data_string.c',
889		'http_header.c',
890		'http_kv.c',
891		'log.c',
892		'sock_addr.c',
893	],
894	dependencies: common_flags + libunwind,
895	build_by_default: false,
896))
897
898modules = [
899	[ 'mod_access', [ 'mod_access.c' ] ],
900	[ 'mod_accesslog', [ 'mod_accesslog.c' ] ],
901	[ 'mod_alias', [ 'mod_alias.c' ] ],
902	[ 'mod_auth', [ 'mod_auth.c' ], [ libcrypto ] ],
903	[ 'mod_authn_file', [ 'mod_authn_file.c' ], [ libcrypt, libcrypto ] ],
904	[ 'mod_compress', [ 'mod_compress.c' ], libbz2 + libz ],
905	[ 'mod_deflate', [ 'mod_deflate.c' ], libbz2 + libz ],
906	[ 'mod_dirlisting', [ 'mod_dirlisting.c' ], libpcre ],
907	[ 'mod_evasive', [ 'mod_evasive.c' ] ],
908	[ 'mod_evhost', [ 'mod_evhost.c' ] ],
909	[ 'mod_expire', [ 'mod_expire.c' ] ],
910	[ 'mod_extforward', [ 'mod_extforward.c' ] ],
911	[ 'mod_fastcgi', [ 'mod_fastcgi.c' ], libws2_32 ],
912	[ 'mod_flv_streaming', [ 'mod_flv_streaming.c' ] ],
913	[ 'mod_indexfile', [ 'mod_indexfile.c' ] ],
914	[ 'mod_proxy', [ 'mod_proxy.c' ], libws2_32 ],
915	[ 'mod_redirect', [ 'mod_redirect.c' ], libpcre ],
916	[ 'mod_rewrite', [ 'mod_rewrite.c' ], libpcre ],
917	[ 'mod_rrdtool', [ 'mod_rrdtool.c' ] ],
918	[ 'mod_scgi', [ 'mod_scgi.c' ], libws2_32 ],
919	[ 'mod_secdownload', [ 'mod_secdownload.c' ], libcrypto ],
920	[ 'mod_setenv', [ 'mod_setenv.c' ] ],
921	[ 'mod_simple_vhost', [ 'mod_simple_vhost.c' ] ],
922	[ 'mod_sockproxy', [ 'mod_sockproxy.c' ] ],
923	[ 'mod_ssi', [ ssi_exprparser, 'mod_ssi_expr.c', 'mod_ssi.c' ], libws2_32 ],
924	[ 'mod_staticfile', [ 'mod_staticfile.c' ] ],
925	[ 'mod_status', [ 'mod_status.c' ] ],
926	[ 'mod_uploadprogress', [ 'mod_uploadprogress.c' ] ],
927	[ 'mod_userdir', [ 'mod_userdir.c' ] ],
928	[ 'mod_usertrack', [ 'mod_usertrack.c' ] ],
929	[ 'mod_vhostdb', [ 'mod_vhostdb.c' ] ],
930	[ 'mod_webdav', [ 'mod_webdav.c' ], libsqlite3 + libuuid + libxml2 + libelftc ],
931	[ 'mod_wstunnel', [ 'mod_wstunnel.c' ], libcrypto ],
932]
933
934if target_machine.system() != 'windows'
935	modules += [
936		[ 'mod_cgi', [ 'mod_cgi.c' ] ],
937	]
938endif
939
940if get_option('with_pcre') and (get_option('with_memcached') or get_option('with_gdbm'))
941	modules += [
942		[ 'mod_trigger_b4_dl', [ 'mod_trigger_b4_dl.c' ], libpcre + libmemcached + libgdbm ],
943	]
944endif
945
946if get_option('with_lua')
947	modules += [
948		[ 'mod_cml', [ 'mod_cml.c', 'mod_cml_lua.c', 'mod_cml_funcs.c' ], liblua + libmemcached ],
949		[ 'mod_magnet', [ 'mod_magnet.c', 'mod_magnet_cache.c' ], liblua ],
950	]
951endif
952
953if get_option('with_maxminddb')
954	modules += [
955		[ 'mod_maxminddb', [ 'mod_maxminddb.c' ], libmaxminddb ],
956	]
957endif
958
959if get_option('with_geoip')
960	modules += [
961		[ 'mod_geoip', [ 'mod_geoip.c' ], libgeoip ],
962	]
963endif
964
965if get_option('with_mysql')
966	modules += [
967		[ 'mod_authn_mysql', [ 'mod_authn_mysql.c' ], libcrypt + libmysqlclient ],
968		[ 'mod_mysql_vhost', [ 'mod_mysql_vhost.c' ], libmysqlclient ],
969		[ 'mod_vhostdb_mysql', [ 'mod_vhostdb_mysql.c' ], libmysqlclient ],
970	]
971endif
972
973if get_option('with_pgsql')
974	modules += [
975		[ 'mod_vhostdb_pgsql', [ 'mod_vhostdb_pgsql.c' ], libpq ],
976	]
977endif
978
979if get_option('with_dbi')
980	modules += [
981		[ 'mod_vhostdb_dbi', [ 'mod_vhostdb_dbi.c' ], libdbi ],
982	]
983endif
984
985if get_option('with_krb5')
986	modules += [
987		[ 'mod_authn_gssapi', [ 'mod_authn_gssapi.c' ], libkrb5 + libgssapi_krb5 ],
988	]
989endif
990
991if get_option('with_ldap')
992	modules += [
993		[ 'mod_authn_ldap', [ 'mod_authn_ldap.c' ], libldap + liblber ],
994		[ 'mod_vhostdb_ldap', [ 'mod_vhostdb_ldap.c' ], libldap + liblber ],
995	]
996endif
997
998if get_option('with_openssl')
999	modules += [
1000		[ 'mod_openssl', [ 'mod_openssl.c' ], libssl + libcrypto ],
1001	]
1002endif
1003
1004if get_option('with_wolfssl') != 'false'
1005	modules += [
1006		[ 'mod_openssl', [ 'mod_openssl.c' ], libcrypto ],
1007	]
1008endif
1009
1010if get_option('with_mbedtls') != 'false'
1011	modules += [
1012		[ 'mod_mbedtls', [ 'mod_mbedtls.c' ], libssl + libx509 + libcrypto ],
1013	]
1014endif
1015
1016if get_option('with_gnutls') != 'false'
1017	modules += [
1018		[ 'mod_gnutls', [ 'mod_gnutls.c' ], libgnutls ],
1019	]
1020endif
1021
1022if get_option('with_pam')
1023	modules += [
1024		[ 'mod_authn_pam', [ 'mod_authn_pam.c' ], libpam ],
1025	]
1026endif
1027
1028if get_option('with_sasl')
1029	modules += [
1030		[ 'mod_authn_sasl', [ 'mod_authn_sasl.c' ], libsasl ],
1031	]
1032endif
1033
1034foreach mod: modules
1035	mod_name = mod.get(0)
1036	mod_sources = mod.get(1)
1037	mod_deps = mod.length() > 2 ? mod.get(2) : []
1038	shared_module(mod_name,
1039		sources: mod_sources,
1040		dependencies: [ common_flags, mod_deps ],
1041		name_prefix: '',
1042		install: true,
1043		install_dir: moduledir,
1044	)
1045endforeach
1046