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