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