xref: /lighttpd1.4/src/meson.build (revision 5ec59999)
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
259libmaxminddb = []
260if get_option('with_maxminddb')
261	libmaxminddb = [ compiler.find_library('maxminddb') ]
262	if not(compiler.has_function('MMDB_open', args: defs, dependencies: libmaxminddb, prefix: '#include <maxminddb.h>'))
263		error('Couldn\'t find maxminddb.h or MMDB_open in lib maxminddb')
264	endif
265endif
266
267libgeoip = []
268if get_option('with_geoip')
269	libgeoip = dependency('geoip', required: false)
270	if libgeoip.found()
271		libgeoip = [ libgeoip ]
272	else
273		libgeoip = [ compiler.find_library('GeoIP') ]
274		if not(compiler.has_function('GeoIP_country_name_by_addr', args: defs, dependencies: libgeoip))
275			error('Couldn\'t find GeoIP_country_name_by_addr in lib GeoIP')
276		endif
277	endif
278endif
279
280libgdbm = []
281if get_option('with_gdbm')
282	libgdbm = [ compiler.find_library('gdbm') ]
283	if not(compiler.has_function('gdbm_open', args: defs, dependencies: libgdbm, prefix: '#include <gdbm.h>'))
284		error('Couldn\'t find gdbm.h or gdbm_open in lib gdbm')
285	endif
286	conf_data.set('HAVE_GDBM_H', true)
287	conf_data.set('HAVE_GDBM', true)
288endif
289
290libkrb5 = []
291libgssapi_krb5 = []
292if get_option('with_krb5')
293	libkrb5 = dependency('krb5', required: false)
294	if libkrb5.found()
295		libkrb5 = [ libkrb5 ]
296	else
297		libkrb5 = [ compiler.find_library('krb5') ]
298		if not(compiler.has_function('krb5_init_context', args: defs, dependencies: libkrb5))
299			error('Couldn\'t find krb5_init_context in lib krb5')
300		endif
301	endif
302
303	libgssapi_krb5 = dependency('krb5-gssapi', required: false)
304	if libgssapi_krb5.found()
305		libgssapi_krb5 = [ libgssapi_krb5 ]
306	else
307		libgssapi_krb5 = [ compiler.find_library('gssapi_krb5') ]
308	endif
309
310	conf_data.set('HAVE_KRB5', true)
311endif
312
313libldap = []
314liblber = []
315if get_option('with_ldap')
316	libldap = [ compiler.find_library('ldap') ]
317	if not(compiler.has_function('ldap_sasl_bind_s',
318		args: defs,
319		dependencies: libldap,
320		prefix: '''
321			#include <ldap.h>
322		'''
323	))
324		error('Couldn\'t find ldap.h or ldap_bind in lib libldap')
325	endif
326	conf_data.set('HAVE_LDAP_H', true)
327	conf_data.set('HAVE_LIBLDAP', true)
328	liblber = [ compiler.find_library('lber') ]
329	if not(compiler.has_function('ber_printf', args: defs, dependencies: liblber, prefix: '#include <lber.h>'))
330		error('Couldn\'t find lber.h or ber_printf in lib liblber')
331	endif
332	conf_data.set('HAVE_LBER_H', true)
333	conf_data.set('HAVE_LIBLBER', true)
334endif
335
336libpam = []
337if get_option('with_pam')
338	libpam = [ compiler.find_library('pam') ]
339	if not(compiler.has_function('pam_start',
340		args: defs,
341		dependencies: libpam,
342		prefix: '''
343			#include <security/pam_appl.h>
344		'''
345	))
346		error('Couldn\'t find security/pam_appl.h or pam_start in lib libpam')
347	endif
348	conf_data.set('HAVE_PAM', true)
349endif
350
351libev = []
352if get_option('with_libev')
353	libev = dependency('ev', required: false)
354	if libev.found()
355		libev = [ libev ]
356	elif compiler.has_header('ev.h') and compiler.has_function('ev_time', args: defs + ['-lev'])
357		libev = [ compiler.find_library('ev') ]
358	else
359		error('Couldn\'t find libev header / library')
360	endif
361	conf_data.set('HAVE_LIBEV', true)
362endif
363
364libunwind = []
365if get_option('with_libunwind')
366	libunwind = [ dependency('libunwind') ]
367endif
368
369liblua = []
370if get_option('with_lua')
371	found_lua = false
372	foreach l: ['lua5.3', 'lua-5.3', 'lua5.2', 'lua-5.2', 'lua5.1', 'lua-5.1', 'lua']
373		if not(found_lua)
374			liblua = dependency(l, required: false)
375			found_lua = liblua.found()
376		endif
377	endforeach
378	if not(found_lua)
379		error('Couldn\'t find any lua library')
380	endif
381	liblua = [ liblua ]
382	conf_data.set('HAVE_LUA_H', true)
383endif
384
385libmemcached = []
386if get_option('with_memcached')
387	# manual search:
388	# header: libmemcached/memcached.h
389	# function: memcached (-lmemcached)
390	libmemcached = [ dependency('libmemcached') ]
391	conf_data.set('USE_MEMCACHED', true)
392endif
393
394libmysqlclient = []
395if get_option('with_mysql')
396	# manual search: extend include path with 'mysql/'
397	# header: mysql.h
398	# function: mysql_real_connect (-lmariadb)
399	libmysqlclient = [ dependency('libmariadb') ]
400	#-# function: mysql_real_connect (-lmysqlclient)
401	#-libmysqlclient = [ dependency('mysqlclient') ]
402	conf_data.set('HAVE_MYSQL', true)
403endif
404
405libssl = []
406libx509 = []
407libcrypto = []
408libgnutls = []
409if get_option('with_openssl')
410	# manual search:
411	# header: openssl/ssl.h
412	# function: SSL_new (-lssl)
413	# function: BIO_f_base64 (-lcrypto)
414	libssl = [ dependency('libssl') ]
415	libcrypto = [ dependency('libcrypto') ]
416	conf_data.set('HAVE_OPENSSL_SSL_H', true)
417	conf_data.set('HAVE_LIBSSL', true)
418endif
419if get_option('with_wolfssl') != 'false'
420	# manual search:
421	# header: wolfssl/ssl.h
422	# function: wolfSSL_Init (-lwolfssl)
423	p = get_option('with_wolfssl')
424	if p == 'true'
425		p = '/usr/local'
426	endif
427	i = include_directories(p+'/include', p+'/include/wolfssl')
428	libwolfssl_includes_dep = [ declare_dependency(include_directories: i) ]
429	libcrypto = [ compiler.find_library('libwolfssl', dirs: [ p+'/lib', p+'/lib64' ]) ]
430	libcrypto += libwolfssl_includes_dep
431	conf_data.set('HAVE_WOLFSSL_SSL_H', true)
432endif
433if get_option('with_mbedtls') != 'false'
434	# manual search:
435	# header: mbedtls/ssl.h
436	# function: mbedtls_cipher_info_from_type (-lmbedtls)
437	# function: mbedtls_x509_get_name (-lmbedx509)
438	# function: mbedtls_base64_encode (-lmbedcrypto)
439	libssl = [ dependency('libmbedtls') ]
440	libx509 = [ dependency('libmbedx509') ]
441	libcrypto = [ dependency('libmbedcrypto') ]
442	conf_data.set('HAVE_LIBMBEDCRYPTO', true)
443endif
444if get_option('with_nettle')
445	# manual search:
446	# header: nettle/nettle-types.h
447	# function: nettle_md5_init (-lnettle)
448	libcrypto = [ dependency('libnettle') ]
449	conf_data.set('HAVE_NETTLE_NETTLE_TYPES_H', true)
450endif
451if get_option('with_gnutls') != 'false'
452	# manual search:
453	# header: gnutls/gnutls.h
454	# function: gnutls_check_version (-lgnutls)
455	libgnutls = [ dependency('libgnutls') ]
456	conf_data.set('HAVE_GNUTLS_CRYPTO_H', true)
457	if not(get_option('with_openssl')) and not(get_option('with_wolfssl')) and not(get_option('with_mbedtls')) and not(getoption('with_nettle'))
458	  libcrypto = [ dependency('libgnutls') ]
459	endif
460endif
461if get_option('with_nss') != 'false'
462	# manual search:
463	# header: nss3/nss.h
464	# function: NSSSSL_GetVersion (-lssl3)
465	# function: NSSSMIME_GetVersion (-lsmime3)
466	# function: NSS_GetVersion (-lnss3)
467	# function: NSSUTIL_GetVersion (-lnssutil3)
468	libssl3 = [ dependency('libssl3') ]
469	libsmime3 = [ dependency('libsmime3') ]
470	libnss3 = [ dependency('libnss3') ]
471	libnssutil3 = [ dependency('libnssutil3') ]
472	conf_data.set('HAVE_NSS3_NSS_H', true)
473endif
474
475libpcre = []
476if get_option('with_pcre')
477	# manual search:
478	# header: pcre.h
479	# function: pcre_exec (-lpcre)
480	libpcre = [ dependency('libpcre') ]
481	conf_data.set('HAVE_PCRE_H', true)
482	conf_data.set('HAVE_LIBPCRE', true)
483endif
484
485libpq = []
486if get_option('with_pgsql')
487	# manual search:
488	# header: libpq-fe.h
489	# function: PQsetdbLogin (-lpq)
490	libpq = [ dependency('libpq') ]
491	conf_data.set('HAVE_PGSQL', true)
492endif
493
494if get_option('with_sasl')
495	libsasl = dependency('sasl2', required: false)
496	if libsasl.found()
497		libsasl = [ libsasl2 ]
498	else
499		libsasl = [ compiler.find_library('sasl2') ]
500		if not(compiler.has_function('sasl_server_init', args: defs, dependencies: libsasl, prefix: '#include <sasl/sasl.h>'))
501			error('Couldn\'t find sasl/sasl.h or sasl_server_init in libsasl2')
502		endif
503	endif
504	conf_data.set('HAVE_SASL', true)
505endif
506
507#if get_option('with_valgrind')
508#endif
509
510libuuid = []
511if get_option('with_webdav_locks')
512	libuuid = dependency('uuid', required: false)
513	if libuuid.found()
514		libuuid = [ libuuid ]
515	elif compiler.has_function('uuid_generate', args: defs, prefix: '#include <uuid/uuid.h>')
516		# uuid_generate in libc, everything is fine, no lib needed
517		libuuid = []
518	else
519		libuuid = compiler.find_library('uuid')
520		if not(compiler.has_function('uuid_generate',
521			args: defs,
522			dependencies: libuuid,
523			prefix: '#include <uuid/uuid.h>'
524		))
525			error('Couldn\'t find uuid/uuid.h or uuid_generate in lib c and uuid')
526		endif
527	endif
528	conf_data.set('HAVE_LIBUUID', true)
529	conf_data.set('HAVE_UUID_UUID_H', true)
530endif
531
532libxml2 = []
533libsqlite3 = []
534if get_option('with_webdav_props')
535	libxml2 = dependency('libxml-2.0', required: false)
536	if libxml2.found()
537		libxml2 = [ libxml2 ]
538	else
539		libxml2_includes = []
540		libxml2_includes_dep = []
541		libxml2_found_header = compiler.has_header('libxml/tree.h')
542		foreach i: include_base_paths
543			if not(libxml2_found_header)
544				message('Searching in ' + join_paths(i, 'libxml2'))
545				i = include_directories(join_paths(i, 'libxml2'))
546				if compiler.has_header('libxml/tree.h', include_directories: i)
547					libxml2_found_header = true
548					libxml2_includes = [ i ]
549					libxml2_includes_dep = [ declare_dependency(include_directories: i) ]
550				endif
551			endif
552		endforeach
553		if not(libxml2_found_header)
554			error('Couldn\'t find libxml/tree.h')
555		endif
556		libxml2 = [ compiler.find_library('xml2') ]
557		if not(compiler.has_function('xmlParseChunk',
558			args: defs,
559			dependencies: libxml2,
560			include_directories: libxml2_includes,
561			prefix: '''
562				#include <libxml/tree.h>
563			'''
564		))
565			error('Couldn\'t find xmlParseChunk in lib xml2')
566		endif
567		# has_function doesn't like "internal dependencies"
568		libxml2 += libxml2_includes_dep
569	endif
570	conf_data.set('HAVE_LIBXML_H', true)
571
572	libsqlite3 = dependency('sqlite31', required: false)
573	if libsqlite3.found()
574		libsqlite3 = [ libsqlite3 ]
575	else
576		libsqlite3 = [ compiler.find_library('sqlite3') ]
577		if not(compiler.has_function('sqlite3_reset',
578			args: defs,
579			dependencies: libsqlite3,
580			prefix: '''
581				#include <sqlite3.h>
582			'''
583		))
584			error('Couldn\'t find sqlite3.h or sqlite3_reset in lib sqlite3')
585		endif
586	endif
587	conf_data.set('HAVE_SQLITE3_H', true)
588endif
589
590libattr = []
591if get_option('with_xattr')
592    if compiler.has_function('getxattr',
593		args: defs,
594		prefix: '''
595			#include <sys/types.h>
596			#include <sys/xattr.h>
597		'''
598    )
599	conf_data.set('HAVE_SYS_XATTR_H', true)
600	conf_data.set('HAVE_XATTR', true)
601    else
602	libattr = [ compiler.find_library('attr') ]
603	if not(compiler.has_function('attr_get',
604		args: defs,
605		dependencies: libattr,
606		prefix: '''
607			#include <sys/types.h>
608			#include <attr/attributes.h>
609		'''
610	))
611		error('Couldn\'t find attr/attributes.h or attr_get in lib attr')
612	endif
613	conf_data.set('HAVE_ATTR_ATTRIBUTES_H', true)
614	conf_data.set('HAVE_XATTR', true)
615    endif
616endif
617
618libz = []
619if get_option('with_zlib')
620	libz = dependency('zlib', required: false)
621	if libz.found()
622		libz = [ libz ]
623	else
624		# windows alternative names? 'zlib', 'zdll'
625		libz = [ compiler.find_library('z') ]
626		if not(compiler.has_function('deflate', args: defs, dependencies: libz, prefix: '#include <zlib.h>'))
627			error('Couldn\'t find z header / library')
628		endif
629	endif
630	conf_data.set('HAVE_ZLIB_H', true)
631	conf_data.set('HAVE_LIBZ', true)
632endif
633
634configure_file(
635	output : 'config.h',
636	configuration : conf_data,
637)
638
639common_src = [
640	'algo_md5.c',
641	'algo_sha1.c',
642	'algo_splaytree.c',
643	'array.c',
644	'base64.c',
645	'buffer.c',
646	'burl.c',
647	'chunk.c',
648	'configfile-glue.c',
649	'connections-glue.c',
650	'data_array.c',
651	'data_integer.c',
652	'data_string.c',
653	'etag.c',
654	'fdevent_freebsd_kqueue.c',
655	'fdevent_libev.c',
656	'fdevent_linux_sysepoll.c',
657	'fdevent_poll.c',
658	'fdevent_select.c',
659	'fdevent_solaris_devpoll.c',
660	'fdevent_solaris_port.c',
661	'fdevent.c',
662	'gw_backend.c',
663	'http_auth.c',
664	'http_chunk.c',
665	'http_header.c',
666	'http_kv.c',
667	'http_vhostdb.c',
668	'http-header-glue.c',
669	'keyvalue.c',
670	'log.c',
671	'plugin.c',
672	'rand.c',
673	'request.c',
674	'safe_memclear.c',
675	'sock_addr.c',
676	'stat_cache.c',
677	'stream.c',
678	'vector.c',
679]
680if target_machine.system() == 'windows'
681	common_src += [ 'xgetopt.c' ]
682endif
683main_src = [
684	'configfile.c',
685	'connections.c',
686	'data_config.c',
687	'h2.c',
688	'inet_ntop_cache.c',
689	'ls-hpack/lshpack.c',
690	'algo_xxhash.c',
691	'network_write.c',
692	'network.c',
693	'reqpool.c',
694	'response.c',
695	'server.c',
696]
697
698lemon = executable('lemon',
699	sources: 'lemon.c',
700	native: true,
701)
702# generator doesn't handle additional "input dependencies" like lempar.c
703# => use custom_target
704configparser = custom_target('configparser',
705	input:  ['configparser.y', 'lempar.c'],
706	output: ['configparser.c', 'configparser.h'],
707	command: [lemon, '-q', 'o=@OUTDIR@', '@INPUT0@', '@INPUT1@'],
708)
709ssi_exprparser = custom_target('mod_ssi_exprparser',
710	input:  ['mod_ssi_exprparser.y', 'lempar.c'],
711	output: ['mod_ssi_exprparser.c', 'mod_ssi_exprparser.h'],
712	command: [lemon, '-q', 'o=@OUTDIR@', '@INPUT0@', '@INPUT1@'],
713)
714
715common_cflags = defs + [
716	'-DHAVE_CONFIG_H',
717]
718
719if compiler.get_id() == 'gcc' or compiler.get_id() == 'clang'
720	common_cflags += [
721		'-Wall',
722		'-g',
723		'-Wshadow',
724		'-W',
725		'-pedantic',
726	]
727	if get_option('build_extra_warnings')
728		common_cflags += get_option('warn_cflags').split()
729	endif
730endif
731
732common_flags = [ declare_dependency(
733	compile_args: common_cflags,
734	# tests also use common_flags, and need this
735	include_directories: include_directories('.'),
736) ]
737
738lighttpd_flags = []
739lighttpd_angel_flags = []
740if target_machine.system() == 'windows'
741	lighttpd_flags += [ declare_dependency(
742		compile_args: [
743			'-DLI_DECLARE_EXPORTS',
744		],
745	) ]
746	if compiler.get_id() == 'gcc'
747		libmsvcr70 = [ compiler.find_library('msvcr70') ]
748		lighttpd_flags += libmsvcr70 + [ declare_dependency(
749			link_args: [
750				'-Wl,-subsystem,console',
751			],
752		) ]
753		lighttpd_angel_flags += libmsvcr70 + [ declare_dependency(
754			link_args: [
755				'-Wl,-subsystem,console',
756			],
757		) ]
758	endif
759endif
760
761if compiler.get_id() == 'gcc' or target_machine.system() != 'darwin'
762	lighttpd_flags += [ declare_dependency(
763		link_args: [
764			'-Wl,-export-dynamic',
765		],
766	) ]
767endif
768
769executable('lighttpd-angel',
770	sources: 'lighttpd-angel.c',
771	dependencies: common_flags + lighttpd_angel_flags,
772	c_args: ['-DSBIN_DIR="' + sbinddir + '"'],
773	install: true,
774	install_dir: sbinddir,
775)
776
777executable('lighttpd', configparser,
778	sources: common_src + main_src,
779	# libssl needed?
780	dependencies: [ common_flags, lighttpd_flags
781		, libattr
782		, libcrypto
783		, libdl
784		, libev
785		, libfam
786		, libpcre
787		, libunwind
788		, libws2_32
789	],
790	install: true,
791	install_dir: sbinddir,
792)
793
794test('test_array', executable('test_array',
795	sources: ['t/test_array.c', 'array.c', 'data_array.c', 'data_integer.c', 'data_string.c', 'buffer.c'],
796	dependencies: common_flags + libunwind,
797	build_by_default: false,
798))
799
800test('test_buffer', executable('test_buffer',
801	sources: ['t/test_buffer.c', 'buffer.c'],
802	dependencies: common_flags + libunwind,
803	build_by_default: false,
804))
805
806test('test_burl', executable('test_burl',
807	sources: ['t/test_burl.c', 'burl.c', 'buffer.c', 'base64.c'],
808	dependencies: common_flags + libunwind,
809	build_by_default: false,
810))
811
812test('test_base64', executable('test_base64',
813	sources: ['t/test_base64.c', 'buffer.c', 'base64.c'],
814	dependencies: common_flags + libunwind,
815	build_by_default: false,
816))
817
818test('test_configfile', executable('test_configfile',
819	sources: [
820		't/test_configfile.c',
821		'buffer.c',
822		'array.c',
823		'data_config.c',
824		'data_integer.c',
825		'data_string.c',
826		'http_header.c',
827		'http_kv.c',
828		'vector.c',
829		'log.c',
830		'sock_addr.c',
831	],
832	dependencies: common_flags + libpcre + libunwind,
833	build_by_default: false,
834))
835
836test('test_keyvalue', executable('test_keyvalue',
837	sources: [
838		't/test_keyvalue.c',
839		'burl.c',
840		'buffer.c',
841		'base64.c',
842		'array.c',
843		'data_integer.c',
844		'data_string.c',
845		'log.c',
846	],
847	dependencies: common_flags + libpcre + libunwind,
848	build_by_default: false,
849))
850
851test('test_mod_access', executable('test_mod_access',
852	sources: [
853		't/test_mod_access.c',
854		'buffer.c',
855		'array.c',
856		'data_integer.c',
857		'data_string.c',
858		'log.c',
859	],
860	dependencies: common_flags + libunwind,
861	build_by_default: false,
862))
863
864test('test_mod_evhost', executable('test_mod_evhost',
865	sources: [
866		't/test_mod_evhost.c',
867		'buffer.c',
868		'array.c',
869		'data_integer.c',
870		'data_string.c',
871		'log.c',
872	],
873	dependencies: common_flags + libunwind,
874	build_by_default: false,
875))
876
877test('test_mod_simple_vhost', executable('test_mod_simple_vhost',
878	sources: [
879		't/test_mod_simple_vhost.c',
880		'buffer.c',
881		'array.c',
882		'data_integer.c',
883		'data_string.c',
884		'log.c',
885	],
886	dependencies: common_flags + libunwind,
887	build_by_default: false,
888))
889
890test('test_mod_userdir', executable('test_mod_userdir',
891	sources: [
892		't/test_mod_userdir.c',
893		'buffer.c',
894		'array.c',
895		'data_integer.c',
896		'data_string.c',
897		'log.c',
898	],
899	dependencies: common_flags + libunwind,
900	build_by_default: false,
901))
902
903test('test_request', executable('test_request',
904	sources: [
905		't/test_request.c',
906		'base64.c',
907		'buffer.c',
908		'burl.c',
909		'array.c',
910		'data_integer.c',
911		'data_string.c',
912		'http_header.c',
913		'http_kv.c',
914		'log.c',
915		'sock_addr.c',
916	],
917	dependencies: common_flags + libunwind,
918	build_by_default: false,
919))
920
921modules = [
922	[ 'mod_access', [ 'mod_access.c' ] ],
923	[ 'mod_accesslog', [ 'mod_accesslog.c' ] ],
924	[ 'mod_alias', [ 'mod_alias.c' ] ],
925	[ 'mod_auth', [ 'mod_auth.c' ], [ libcrypto ] ],
926	[ 'mod_authn_file', [ 'mod_authn_file.c' ], [ libcrypt, libcrypto ] ],
927	[ 'mod_deflate', [ 'mod_deflate.c' ], libbz2 + libz ],
928	[ 'mod_dirlisting', [ 'mod_dirlisting.c' ], libpcre ],
929	[ 'mod_evasive', [ 'mod_evasive.c' ] ],
930	[ 'mod_evhost', [ 'mod_evhost.c' ] ],
931	[ 'mod_expire', [ 'mod_expire.c' ] ],
932	[ 'mod_extforward', [ 'mod_extforward.c' ] ],
933	[ 'mod_fastcgi', [ 'mod_fastcgi.c' ], libws2_32 ],
934	[ 'mod_flv_streaming', [ 'mod_flv_streaming.c' ] ],
935	[ 'mod_indexfile', [ 'mod_indexfile.c' ] ],
936	[ 'mod_proxy', [ 'mod_proxy.c' ], libws2_32 ],
937	[ 'mod_redirect', [ 'mod_redirect.c' ], libpcre ],
938	[ 'mod_rewrite', [ 'mod_rewrite.c' ], libpcre ],
939	[ 'mod_rrdtool', [ 'mod_rrdtool.c' ] ],
940	[ 'mod_scgi', [ 'mod_scgi.c' ], libws2_32 ],
941	[ 'mod_secdownload', [ 'mod_secdownload.c' ], libcrypto ],
942	[ 'mod_setenv', [ 'mod_setenv.c' ] ],
943	[ 'mod_simple_vhost', [ 'mod_simple_vhost.c' ] ],
944	[ 'mod_sockproxy', [ 'mod_sockproxy.c' ] ],
945	[ 'mod_ssi', [ ssi_exprparser, 'mod_ssi_expr.c', 'mod_ssi.c' ], libws2_32 ],
946	[ 'mod_staticfile', [ 'mod_staticfile.c' ] ],
947	[ 'mod_status', [ 'mod_status.c' ] ],
948	[ 'mod_uploadprogress', [ 'mod_uploadprogress.c' ] ],
949	[ 'mod_userdir', [ 'mod_userdir.c' ] ],
950	[ 'mod_usertrack', [ 'mod_usertrack.c' ] ],
951	[ 'mod_vhostdb', [ 'mod_vhostdb.c' ] ],
952	[ 'mod_webdav', [ 'mod_webdav.c' ], libsqlite3 + libuuid + libxml2 + libelftc ],
953	[ 'mod_wstunnel', [ 'mod_wstunnel.c' ], libcrypto ],
954]
955
956if target_machine.system() != 'windows'
957	modules += [
958		[ 'mod_cgi', [ 'mod_cgi.c' ] ],
959	]
960endif
961
962if get_option('with_pcre') and (get_option('with_memcached') or get_option('with_gdbm'))
963	modules += [
964		[ 'mod_trigger_b4_dl', [ 'mod_trigger_b4_dl.c' ], libpcre + libmemcached + libgdbm ],
965	]
966endif
967
968if get_option('with_lua')
969	modules += [
970		[ 'mod_cml', [ 'mod_cml.c', 'mod_cml_lua.c', 'mod_cml_funcs.c' ], liblua + libmemcached ],
971		[ 'mod_magnet', [ 'mod_magnet.c', 'mod_magnet_cache.c' ], liblua ],
972	]
973endif
974
975if get_option('with_maxminddb')
976	modules += [
977		[ 'mod_maxminddb', [ 'mod_maxminddb.c' ], libmaxminddb ],
978	]
979endif
980
981if get_option('with_geoip')
982	modules += [
983		[ 'mod_geoip', [ 'mod_geoip.c' ], libgeoip ],
984	]
985endif
986
987if get_option('with_mysql')
988	modules += [
989		[ 'mod_authn_mysql', [ 'mod_authn_mysql.c' ], libcrypt + libmysqlclient ],
990		[ 'mod_mysql_vhost', [ 'mod_mysql_vhost.c' ], libmysqlclient ],
991		[ 'mod_vhostdb_mysql', [ 'mod_vhostdb_mysql.c' ], libmysqlclient ],
992	]
993endif
994
995if get_option('with_pgsql')
996	modules += [
997		[ 'mod_vhostdb_pgsql', [ 'mod_vhostdb_pgsql.c' ], libpq ],
998	]
999endif
1000
1001if get_option('with_dbi')
1002	modules += [
1003		[ 'mod_authn_dbi', [ 'mod_authn_dbi.c' ], libcrypt + libdbi ],
1004		[ 'mod_vhostdb_dbi', [ 'mod_vhostdb_dbi.c' ], libdbi ],
1005	]
1006endif
1007
1008if get_option('with_krb5')
1009	modules += [
1010		[ 'mod_authn_gssapi', [ 'mod_authn_gssapi.c' ], libkrb5 + libgssapi_krb5 ],
1011	]
1012endif
1013
1014if get_option('with_ldap')
1015	modules += [
1016		[ 'mod_authn_ldap', [ 'mod_authn_ldap.c' ], libldap + liblber ],
1017		[ 'mod_vhostdb_ldap', [ 'mod_vhostdb_ldap.c' ], libldap + liblber ],
1018	]
1019endif
1020
1021if get_option('with_openssl')
1022	modules += [
1023		[ 'mod_openssl', [ 'mod_openssl.c' ], libssl + libcrypto ],
1024	]
1025endif
1026
1027if get_option('with_wolfssl') != 'false'
1028	modules += [
1029		[ 'mod_openssl', [ 'mod_openssl.c' ], libcrypto ],
1030	]
1031endif
1032
1033if get_option('with_mbedtls') != 'false'
1034	modules += [
1035		[ 'mod_mbedtls', [ 'mod_mbedtls.c' ], libssl + libx509 + libcrypto ],
1036	]
1037endif
1038
1039if get_option('with_nss') != 'false'
1040	modules += [
1041		[ 'mod_nss', [ 'mod_nss.c' ], libssl3 + libsmime3 + libnss3 + libnssutil3 ],
1042	]
1043endif
1044
1045if get_option('with_gnutls') != 'false'
1046	modules += [
1047		[ 'mod_gnutls', [ 'mod_gnutls.c' ], libgnutls ],
1048	]
1049endif
1050
1051if get_option('with_pam')
1052	modules += [
1053		[ 'mod_authn_pam', [ 'mod_authn_pam.c' ], libpam ],
1054	]
1055endif
1056
1057if get_option('with_sasl')
1058	modules += [
1059		[ 'mod_authn_sasl', [ 'mod_authn_sasl.c' ], libsasl ],
1060	]
1061endif
1062
1063foreach mod: modules
1064	mod_name = mod.get(0)
1065	mod_sources = mod.get(1)
1066	mod_deps = mod.length() > 2 ? mod.get(2) : []
1067	shared_module(mod_name,
1068		sources: mod_sources,
1069		dependencies: [ common_flags, mod_deps ],
1070		name_prefix: '',
1071		install: true,
1072		install_dir: moduledir,
1073	)
1074endforeach
1075