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