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