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