[core] consolidate backend network write handlers
[lighttpd.git] / src / meson.build
blob8f696aa91a9180de62cb7977d8ef23368d346acc
1 sbinddir = join_paths(get_option('prefix'), get_option('sbindir'))
2 moduledir = join_paths(get_option('prefix'), get_option('moduledir'))
4 include_base_paths = [
5         '/usr/include',
6         '/usr/local/include',
7 #       '/opt/local/include',
10 defs = [
11         '-D_FILE_OFFSET_BITS=64',
12         '-D_LARGEFILE_SOURCE',
13         '-D_LARGE_FILES',
14         '-D_GNU_SOURCE',
17 libws2_32 = []
18 if target_machine.system() == 'windows'
19         libws2_32 = [ compiler.find_library('ws2_32') ]
20         defs += [
21                 '-DNVALGRIND',
22         ]
23 endif
26 compiler = meson.get_compiler('c')
27 conf_data = configuration_data()
29 conf_data.set('HAVE_SYS_DEVPOLL_H', compiler.has_header('sys/devpoll.h'))
30 conf_data.set('HAVE_SYS_EPOLL_H', compiler.has_header('sys/epoll.h'))
31 conf_data.set('HAVE_SYS_EVENT_H', compiler.has_header('sys/event.h'))
32 conf_data.set('HAVE_SYS_MMAN_H', compiler.has_header('sys/mman.h'))
33 conf_data.set('HAVE_SYS_POLL_H', compiler.has_header('sys/poll.h'))
34 conf_data.set('HAVE_SYS_PORT_H', compiler.has_header('sys/port.h'))
35 conf_data.set('HAVE_SYS_PRCTL_H', compiler.has_header('sys/prctl.h'))
36 conf_data.set('HAVE_SYS_RESOURCE_H', compiler.has_header('sys/resource.h'))
37 conf_data.set('HAVE_SYS_SENDFILE_H', compiler.has_header('sys/sendfile.h'))
38 conf_data.set('HAVE_SYS_SELECT_H', compiler.has_header('sys/select.h'))
39 conf_data.set('HAVE_SYS_TYPES_H', compiler.has_header('sys/types.h'))
40 conf_data.set('HAVE_SYS_UIO_H', compiler.has_header('sys/uio.h'))
41 conf_data.set('HAVE_SYS_UN_H', compiler.has_header('sys/un.h'))
42 conf_data.set('HAVE_SYS_WAIT_H', compiler.has_header('sys/wait.h'))
43 conf_data.set('HAVE_SYS_TIME_H', compiler.has_header('sys/time.h'))
44 conf_data.set('HAVE_UNISTD_H', compiler.has_header('unistd.h'))
45 conf_data.set('HAVE_PTHREAD_H', compiler.has_header('pthread.h'))
46 conf_data.set('HAVE_GETOPT_H', compiler.has_header('getopt.h'))
47 conf_data.set('HAVE_INTTYPES_H', compiler.has_header('inttypes.h'))
48 conf_data.set('HAVE_POLL_H', compiler.has_header('poll.h'))
49 conf_data.set('HAVE_PWD_H', compiler.has_header('pwd.h'))
50 conf_data.set('HAVE_STDDEF_H', compiler.has_header('stddef.h'))
51 conf_data.set('HAVE_STDINT_H', compiler.has_header('stdint.h'))
52 conf_data.set('HAVE_STRINGS_H', compiler.has_header('strings.h'))
53 conf_data.set('HAVE_SYSLOG_H', compiler.has_header('syslog.h'))
55 # check for fastcgi lib, for the tests only
56 conf_data.set('HAVE_FASTCGI_H', compiler.has_header('fastcgi.h'))
57 if not(conf_data.get('HAVE_FASTCGI_H'))
58         conf_data.set('HAVE_FASTCGI_FASTCGI_H', compiler.has_header('fastcgi/fastcgi.h'))
59 endif
61 # will be needed for auth
62 conf_data.set('HAVE_CRYPT_H', compiler.has_header('crypt.h'))
63 if conf_data.get('HAVE_CRYPT_H')
64         # check if we need libcrypt for crypt_r / crypt
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
83 endif
85 conf_data.set('HAVE_SYS_INOTIFY_H', compiler.has_header('sys/inotify.h'))
86 if conf_data.get('HAVE_SYS_INOTIFY_H')
87         conf_data.set('HAVE_INOTIFY_INIT', compiler.has_function('inotify_init', args: defs))
88 endif
90 conf_data.set('HAVE_SOCKLEN_T', compiler.has_type('socklen_t', args: defs, prefix: '#include <sys/socket.h>'))
92 conf_data.set('HAVE_SYS_RANDOM_H', compiler.has_header('sys/random.h'))
93 if 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         ))
99 endif
101 conf_data.set('HAVE_LINUX_RANDOM_H', compiler.has_header('linux/random.h'))
102 if 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         ))
108 endif
110 conf_data.set('SIZEOF_LONG', compiler.sizeof('long', args: defs))
111 conf_data.set('SIZEOF_OFF_T', compiler.sizeof('off_t', args: defs))
113 conf_data.set('HAVE_ARC4RANDOM_BUF', compiler.has_function('arc4random_buf', args: defs))
114 conf_data.set('HAVE_CHROOT', compiler.has_function('chroot', args: defs))
115 conf_data.set('HAVE_EPOLL_CTL', compiler.has_function('epoll_ctl', args: defs))
116 conf_data.set('HAVE_FORK', compiler.has_function('fork', args: defs))
117 conf_data.set('HAVE_GETLOADAVG', compiler.has_function('getloadavg', args: defs))
118 conf_data.set('HAVE_GETRLIMIT', compiler.has_function('getrlimit', args: defs))
119 conf_data.set('HAVE_GETUID', compiler.has_function('getuid', args: defs))
120 conf_data.set('HAVE_GMTIME_R', compiler.has_function('gmtime_r', args: defs))
121 conf_data.set('HAVE_INET_NTOP', compiler.has_function('inet_ntop', args: defs))
122 conf_data.set('HAVE_JRAND48', compiler.has_function('jrand48', args: defs))
123 conf_data.set('HAVE_KQUEUE', compiler.has_function('kqueue', args: defs))
124 conf_data.set('HAVE_LOCALTIME_R', compiler.has_function('localtime_r', args: defs))
125 conf_data.set('HAVE_LSTAT', compiler.has_function('lstat', args: defs))
126 conf_data.set('HAVE_MADVISE', compiler.has_function('madvise', args: defs))
127 conf_data.set('HAVE_MEMCPY', compiler.has_function('memcpy', args: defs))
128 conf_data.set('HAVE_MEMSET', compiler.has_function('memset', args: defs))
129 conf_data.set('HAVE_MMAP', compiler.has_function('mmap', args: defs))
130 conf_data.set('HAVE_PATHCONF', compiler.has_function('pathconf', args: defs))
131 conf_data.set('HAVE_PIPE2', compiler.has_function('pipe2', args: defs))
132 conf_data.set('HAVE_POLL', compiler.has_function('poll', args: defs))
133 conf_data.set('HAVE_PORT_CREATE', compiler.has_function('port_create', args: defs))
134 conf_data.set('HAVE_PRCTL', compiler.has_function('prctl', args: defs))
135 conf_data.set('HAVE_PREAD', compiler.has_function('pread', args: defs))
136 conf_data.set('HAVE_POSIX_FADVISE', compiler.has_function('posix_fadvise', args: defs))
137 conf_data.set('HAVE_SELECT', compiler.has_function('select', args: defs))
138 conf_data.set('HAVE_SENDFILE', compiler.has_function('sendfile', args: defs))
139 conf_data.set('HAVE_SEND_FILE', compiler.has_function('send_file', args: defs))
140 conf_data.set('HAVE_SENDFILE64', compiler.has_function('sendfile64', args: defs))
141 conf_data.set('HAVE_SENDFILEV', compiler.has_function('sendfilev', args: defs))
142 conf_data.set('HAVE_SIGACTION', compiler.has_function('sigaction', args: defs))
143 conf_data.set('HAVE_SIGNAL', compiler.has_function('signal', args: defs))
144 conf_data.set('HAVE_SIGTIMEDWAIT', compiler.has_function('sigtimedwait', args: defs))
145 conf_data.set('HAVE_SRANDOM', compiler.has_function('srandom', args: defs))
146 conf_data.set('HAVE_STRPTIME', compiler.has_function('strptime', args: defs))
147 conf_data.set('HAVE_SYSLOG', compiler.has_function('syslog', args: defs))
148 conf_data.set('HAVE_WRITEV', compiler.has_function('writev', args: defs))
149 conf_data.set('HAVE_INET_ATON', compiler.has_function('inet_aton', args: defs))
150 conf_data.set('HAVE_ISSETUGID', compiler.has_function('issetugid', args: defs))
151 conf_data.set('HAVE_INET_PTON', compiler.has_function('inet_pton', args: defs))
152 conf_data.set('HAVE_MEMSET_S', compiler.has_function('memset_s', args: defs))
153 conf_data.set('HAVE_EXPLICIT_BZERO', compiler.has_function('explicit_bzero', args: defs))
155 conf_data.set('HAVE_CLOCK_GETTIME', compiler.has_header_symbol('time.h', 'clock_gettime'))
156 clock_lib = []
157 if 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
162 endif
164 conf_data.set('HAVE_IPV6', compiler.compiles('''
165         #include <sys/types.h>
166         #include <sys/socket.h>
167         #include <netinet/in.h>
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
178 conf_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
189 conf_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
201 conf_data.set('LIGHTTPD_VERSION_ID', 10400)
202 conf_data.set_quoted('PACKAGE_NAME', meson.project_name())
203 conf_data.set_quoted('PACKAGE_VERSION', meson.project_version())
204 conf_data.set_quoted('LIBRARY_DIR', moduledir)
206 conf_data.set('LIGHTTPD_STATIC', get_option('build_static'))
207 libdl = []
208 if 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
215 endif
217 libbz2 = []
218 if 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
226 endif
228 if 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)
239 endif
241 libfam = []
242 if 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)
248 endif
250 libgeoip = []
251 if 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
261 endif
263 libgdbm = []
264 if 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)
271 endif
273 libkrb5 = []
274 libgssapi_krb5 = []
275 if 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
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
293         conf_data.set('HAVE_KRB5', true)
294 endif
296 libldap = []
297 liblber = []
298 if get_option('with_ldap')
299         libldap = [ compiler.find_library('ldap') ]
300         if not(compiler.has_function('ldap_bind',
301                 args: defs,
302                 dependencies: libldap,
303                 prefix: '''
304                         #define LDAP_DEPRECATED 1
305                         #include <ldap.h>
306                 '''
307         ))
308                 error('Couldn\'t find ldap.h or ldap_bind in lib libldap')
309         endif
310         conf_data.set('HAVE_LDAP_H', true)
311         conf_data.set('HAVE_LIBLDAP', true)
312         liblber = [ compiler.find_library('lber') ]
313         if not(compiler.has_function('ber_printf', args: defs, dependencies: liblber, prefix: '#include <lber.h>'))
314                 error('Couldn\'t find lber.h or ber_printf in lib liblber')
315         endif
316         conf_data.set('HAVE_LBER_H', true)
317         conf_data.set('HAVE_LIBLBER', true)
318         conf_data.set('LDAP_DEPRECATED', 1, comment: 'Using deprecated ldap api')
319 endif
321 libev = []
322 if get_option('with_libev')
323         libev = dependency('ev', required: false)
324         if libev.found()
325                 libev = [ libev ]
326         elif compiler.has_header('ev.h') and compiler.has_function('ev_time', args: defs + ['-lev'])
327                 libev = [ compiler.find_library('ev') ]
328         else
329                 error('Couldn\'t find libev header / library')
330         endif
331         conf_data.set('HAVE_LIBEV', true)
332 endif
334 libunwind = []
335 if get_option('with_libunwind')
336         libunwind = [ dependency('libunwind') ]
337 endif
339 liblua = []
340 if get_option('with_lua')
341         found_lua = false
342         foreach l: ['lua5.3', 'lua-5.3', 'lua5.2', 'lua-5.2', 'lua5.1', 'lua-5.1', 'lua']
343                 if not(found_lua)
344                         liblua = dependency(l, required: false)
345                         found_lua = liblua.found()
346                 endif
347         endforeach
348         if not(found_lua)
349                 error('Couldn\'t find any lua library')
350         endif
351         liblua = [ liblua ]
352         conf_data.set('HAVE_LUA_H', true)
353 endif
355 libmemcached = []
356 if get_option('with_memcached')
357         # manual search:
358         # header: libmemcached/memcached.h
359         # function: memcached (-lmemcached)
360         libmemcached = [ dependency('libmemcached') ]
361         conf_data.set('USE_MEMCACHED', true)
362 endif
364 libmysqlclient = []
365 if get_option('with_mysql')
366         # manual search: extend include path with 'mysql/'
367         # header: mysql.h
368         # function: mysql_real_connect (-lmysqlclient)
369         libmysqlclient = [ dependency('mysqlclient') ]
370         conf_data.set('HAVE_MYSQL', true)
371 endif
373 libssl = []
374 libcrypto = []
375 if get_option('with_openssl')
376         # manual search:
377         # header: openssl/ssl.h
378         # function: SSL_new (-lssl)
379         # function: BIO_f_base64 (-lcrypto)
380         libssl = [ dependency('libssl') ]
381         libcrypto = [ dependency('libcrypto') ]
382         conf_data.set('HAVE_OPENSSL_SSL_H', true)
383         conf_data.set('HAVE_LIBSSL', true)
384 endif
386 libpcre = []
387 if get_option('with_pcre')
388         # manual search:
389         # header: pcre.h
390         # function: pcre_exec (-lpcre)
391         libpcre = [ dependency('libpcre') ]
392         conf_data.set('HAVE_PCRE_H', true)
393         conf_data.set('HAVE_LIBPCRE', true)
394 endif
396 libpq = []
397 if get_option('with_pgsql')
398         # manual search:
399         # header: libpq-fe.h
400         # function: PQsetdbLogin (-lpq)
401         libpq = [ dependency('libpq') ]
402         conf_data.set('HAVE_PGSQL', true)
403 endif
405 #if get_option('with_valgrind')
406 #endif
408 libuuid = []
409 if get_option('with_webdav_locks')
410         libuuid = dependency('uuid', required: false)
411         if libuuid.found()
412                 libuuid = [ libuuid ]
413         elif compiler.has_function('uuid_generate', args: defs, prefix: '#include <uuid/uuid.h>')
414                 # uuid_generate in libc, everything is fine, no lib needed
415                 libuuid = []
416         else
417                 libuuid = compiler.find_library('uuid')
418                 if not(compiler.has_function('uuid_generate',
419                         args: defs,
420                         dependencies: libuuid,
421                         prefix: '#include <uuid/uuid.h>'
422                 ))
423                         error('Couldn\'t find uuid/uuid.h or uuid_generate in lib c and uuid')
424                 endif
425         endif
426         conf_data.set('HAVE_UUID', true)
427         conf_data.set('HAVE_UUID_UUID_H', true)
428 endif
430 libxml2 = []
431 libsqlite3 = []
432 if get_option('with_webdav_props')
433         libxml2 = dependency('libxml-2.0', required: false)
434         if libxml2.found()
435                 libxml2 = [ libxml2 ]
436         else
437                 libxml2_includes = []
438                 libxml2_includes_dep = []
439                 libxml2_found_header = compiler.has_header('libxml/tree.h')
440                 foreach i: include_base_paths
441                         if not(libxml2_found_header)
442                                 message('Searching in ' + join_paths(i, 'libxml2'))
443                                 i = include_directories(join_paths(i, 'libxml2'))
444                                 if compiler.has_header('libxml/tree.h', include_directories: i)
445                                         libxml2_found_header = true
446                                         libxml2_includes = [ i ]
447                                         libxml2_includes_dep = [ declare_dependency(include_directories: i) ]
448                                 endif
449                         endif
450                 endforeach
451                 if not(libxml2_found_header)
452                         error('Couldn\'t find libxml/tree.h')
453                 endif
454                 libxml2 = [ compiler.find_library('xml2') ]
455                 if not(compiler.has_function('xmlParseChunk',
456                         args: defs,
457                         dependencies: libxml2,
458                         include_directories: libxml2_includes,
459                         prefix: '''
460                                 #include <libxml/tree.h>
461                         '''
462                 ))
463                         error('Couldn\'t find xmlParseChunk in lib xml2')
464                 endif
465                 # has_function doesn't like "internal dependencies"
466                 libxml2 += libxml2_includes_dep
467         endif
468         conf_data.set('HAVE_LIBXML_H', true)
470         libsqlite3 = dependency('sqlite31', required: false)
471         if libsqlite3.found()
472                 libsqlite3 = [ libsqlite3 ]
473         else
474                 libsqlite3 = [ compiler.find_library('sqlite3') ]
475                 if not(compiler.has_function('sqlite3_reset',
476                         args: defs,
477                         dependencies: libsqlite3,
478                         prefix: '''
479                                 #include <sqlite3.h>
480                         '''
481                 ))
482                         error('Couldn\'t find sqlite3.h or sqlite3_reset in lib sqlite3')
483                 endif
484         endif
485         conf_data.set('HAVE_SQLITE3_H', true)
486 endif
488 libattr = []
489 if get_option('with_xattr')
490         libattr = [ compiler.find_library('attr') ]
491         if not(compiler.has_function('attr_get',
492                 args: defs,
493                 dependencies: libattr,
494                 prefix: '''
495                         #include <sys/types.h>
496                         #include <attr/attributes.h>
497                 '''
498         ))
499                 error('Couldn\'t find attr/attributes.h or attr_get in lib attr')
500         endif
501         conf_data.set('HAVE_ATTR_ATTRIBUTES_H', true)
502         conf_data.set('HAVE_XATTR', true)
503 endif
505 libz = []
506 if get_option('with_zlib')
507         libz = dependency('zlib', required: false)
508         if libz.found()
509                 libz = [ libz ]
510         else
511                 # windows alternative names? 'zlib', 'zdll'
512                 libz = [ compiler.find_library('z') ]
513                 if not(compiler.has_function('deflate', args: defs, dependencies: libz, prefix: '#include <zlib.h>'))
514                         error('Couldn\'t find z header / library')
515                 endif
516         endif
517         conf_data.set('HAVE_ZLIB_H', true)
518         conf_data.set('HAVE_LIBZ', true)
519 endif
521 configure_file(
522         output : 'config.h',
523         configuration : conf_data,
526 common_src = [
527         'algo_sha1.c',
528         'array.c',
529         'base64.c',
530         'buffer.c',
531         'chunk.c',
532         'configfile-glue.c',
533         'connections-glue.c',
534         'crc32.c',
535         'data_array.c',
536         'data_config.c',
537         'data_integer.c',
538         'data_string.c',
539         'etag.c',
540         'fdevent_freebsd_kqueue.c',
541         'fdevent_libev.c',
542         'fdevent_linux_sysepoll.c',
543         'fdevent_poll.c',
544         'fdevent_select.c',
545         'fdevent_solaris_devpoll.c',
546         'fdevent_solaris_port.c',
547         'fdevent.c',
548         'gw_backend.c',
549         'http_auth.c',
550         'http_chunk.c',
551         'http_vhostdb.c',
552         'http-header-glue.c',
553         'joblist.c',
554         'keyvalue.c',
555         'log.c',
556         'md5.c',
557         'plugin.c',
558         'rand.c',
559         'safe_memclear.c',
560         'sock_addr.c',
561         'splaytree.c',
562         'stat_cache.c',
563         'status_counter.c',
564         'stream.c',
565         'vector.c',
567 if target_machine.system() == 'windows'
568         common_src += [ 'xgetopt.c' ]
569 endif
570 main_src = [
571         'configfile.c',
572         'connections.c',
573         'inet_ntop_cache.c',
574         'network_write.c',
575         'network.c',
576         'proc_open.c',
577         'request.c',
578         'response.c',
579         'server.c',
582 lemon = executable('lemon',
583         sources: 'lemon.c',
584         native: true,
586 # generator doesn't handle additional "input dependencies" like lempar.c
587 # => use custom_target
588 configparser = custom_target('configparser',
589         input:  ['configparser.y', 'lempar.c'],
590         output: ['configparser.c', 'configparser.h'],
591         command: [lemon, '-q', 'o=@OUTDIR@', '@INPUT0@', '@INPUT1@'],
593 ssi_exprparser = custom_target('mod_ssi_exprparser',
594         input:  ['mod_ssi_exprparser.y', 'lempar.c'],
595         output: ['mod_ssi_exprparser.c', 'mod_ssi_exprparser.h'],
596         command: [lemon, '-q', 'o=@OUTDIR@', '@INPUT0@', '@INPUT1@'],
599 common_cflags = defs + [
600         '-DHAVE_CONFIG_H',
603 if compiler.get_id() == 'gcc' or compiler.get_id() == 'clang'
604         common_cflags += [
605                 '-Wall',
606                 '-g',
607                 '-Wshadow',
608                 '-W',
609                 '-pedantic',
610         ]
611         if get_option('build_extra_warnings')
612                 common_cflags += get_option('warn_cflags').split()
613         endif
614 endif
616 common_flags = [ declare_dependency(
617         compile_args: common_cflags,
618         # tests also use common_flags, and need this
619         include_directories: include_directories('.'),
620 ) ]
622 lighttpd_flags = []
623 lighttpd_angel_flags = []
624 if target_machine.system() == 'windows'
625         lighttpd_flags += [ declare_dependency(
626                 compile_args: [
627                         '-DLI_DECLARE_EXPORTS',
628                 ],
629         ) ]
630         if compiler.get_id() == 'gcc'
631                 libmsvcr70 = [ compiler.find_library('msvcr70') ]
632                 lighttpd_flags += libmsvcr70 + [ declare_dependency(
633                         link_args: [
634                                 '-Wl,-subsystem,console',
635                         ],
636                 ) ]
637                 lighttpd_angel_flags += libmsvcr70 + [ declare_dependency(
638                         link_args: [
639                                 '-Wl,-subsystem,console',
640                         ],
641                 ) ]
642         endif
643 endif
645 if compiler.get_id() == 'gcc' or target_machine.system() != 'darwin'
646         lighttpd_flags += [ declare_dependency(
647                 link_args: [
648                         '-Wl,-export-dynamic',
649                 ],
650         ) ]
651 endif
653 executable('lighttpd-angel',
654         sources: 'lighttpd-angel.c',
655         dependencies: common_flags + lighttpd_angel_flags,
656         c_args: ['-DSBIN_DIR="' + sbinddir + '"'],
657         install: true,
658         install_dir: sbinddir,
661 executable('lighttpd', configparser,
662         sources: common_src + main_src,
663         # libssl needed?
664         dependencies: common_flags + lighttpd_flags
665                 + libattr
666                 + libcrypto
667                 + libdl
668                 + libev
669                 + libfam
670                 + libpcre
671                 + libunwind
672                 + libws2_32
673         ,
674         install: true,
675         install_dir: sbinddir,
678 test('test_buffer', executable('test_buffer',
679         sources: ['test_buffer.c', 'buffer.c'],
680         dependencies: common_flags + libunwind,
681         build_by_default: false,
684 test('test_base64', executable('test_base64',
685         sources: ['test_base64.c', 'buffer.c', 'base64.c'],
686         dependencies: common_flags + libunwind,
687         build_by_default: false,
690 test('test_configfile', executable('test_configfile',
691         sources: [
692                 'test_configfile.c',
693                 'buffer.c',
694                 'array.c',
695                 'data_string.c',
696                 'keyvalue.c',
697                 'vector.c',
698                 'log.c',
699         ],
700         dependencies: common_flags + libpcre + libunwind,
701         build_by_default: false,
704 modules = [
705         [ 'mod_access', [ 'mod_access.c' ] ],
706         [ 'mod_accesslog', [ 'mod_accesslog.c' ] ],
707         [ 'mod_alias', [ 'mod_alias.c' ] ],
708         [ 'mod_auth', [ 'mod_auth.c' ] ],
709         [ 'mod_authn_file', [ 'mod_authn_file.c' ], libcrypt + libcrypto ],
710         [ 'mod_compress', [ 'mod_compress.c' ], libbz2 + libz ],
711         [ 'mod_deflate', [ 'mod_deflate.c' ], libbz2 + libz ],
712         [ 'mod_dirlisting', [ 'mod_dirlisting.c' ], libpcre ],
713         [ 'mod_evasive', [ 'mod_evasive.c' ] ],
714         [ 'mod_evhost', [ 'mod_evhost.c' ] ],
715         [ 'mod_expire', [ 'mod_expire.c' ] ],
716         [ 'mod_extforward', [ 'mod_extforward.c' ] ],
717         [ 'mod_fastcgi', [ 'mod_fastcgi.c' ], libws2_32 ],
718         [ 'mod_flv_streaming', [ 'mod_flv_streaming.c' ] ],
719         [ 'mod_indexfile', [ 'mod_indexfile.c' ] ],
720         [ 'mod_proxy', [ 'mod_proxy.c' ], libws2_32 ],
721         [ 'mod_redirect', [ 'mod_redirect.c' ], libpcre ],
722         [ 'mod_rewrite', [ 'mod_rewrite.c' ], libpcre ],
723         [ 'mod_rrdtool', [ 'mod_rrdtool.c' ] ],
724         [ 'mod_scgi', [ 'mod_scgi.c' ], libws2_32 ],
725         [ 'mod_secdownload', [ 'mod_secdownload.c' ], libcrypto ],
726         [ 'mod_setenv', [ 'mod_setenv.c' ] ],
727         [ 'mod_simple_vhost', [ 'mod_simple_vhost.c' ] ],
728         [ 'mod_ssi', [ ssi_exprparser, 'mod_ssi_expr.c', 'mod_ssi.c' ], libws2_32 ],
729         [ 'mod_staticfile', [ 'mod_staticfile.c' ] ],
730         [ 'mod_status', [ 'mod_status.c' ] ],
731         [ 'mod_uploadprogress', [ 'mod_uploadprogress.c' ] ],
732         [ 'mod_userdir', [ 'mod_userdir.c' ] ],
733         [ 'mod_usertrack', [ 'mod_usertrack.c' ] ],
734         [ 'mod_vhostdb', [ 'mod_vhostdb.c' ] ],
735         [ 'mod_webdav', [ 'mod_webdav.c' ], libsqlite3 + libuuid + libxml2 ],
736         [ 'mod_wstunnel', [ 'mod_wstunnel.c' ], libcrypto ],
739 if target_machine.system() != 'windows'
740         modules += [
741                 [ 'mod_cgi', [ 'mod_cgi.c' ] ],
742         ]
743 endif
745 if get_option('with_pcre') and (get_option('with_memcached') or get_option('with_gdbm'))
746         modules += [
747                 [ 'mod_trigger_b4_dl', [ 'mod_trigger_b4_dl.c' ], libpcre + libmemcached + libgdbm ],
748         ]
749 endif
751 if get_option('with_lua')
752         modules += [
753                 [ 'mod_cml', [ 'mod_cml.c', 'mod_cml_lua.c', 'mod_cml_funcs.c' ], liblua + libmemcached ],
754                 [ 'mod_magnet', [ 'mod_magnet.c', 'mod_magnet_cache.c' ], liblua ],
755         ]
756 endif
758 if get_option('with_geoip')
759         modules += [
760                 [ 'mod_geoip', [ 'mod_geoip.c' ], libgeoip ],
761         ]
762 endif
764 if get_option('with_mysql')
765         modules += [
766                 [ 'mod_authn_mysql', [ 'mod_authn_mysql.c' ], libcrypt + libmysqlclient ],
767                 [ 'mod_mysql_vhost', [ 'mod_mysql_vhost.c' ], libmysqlclient ],
768                 [ 'mod_vhostdb_mysql', [ 'mod_vhostdb_mysql.c' ], libmysqlclient ],
769         ]
770 endif
772 if get_option('with_pgsql')
773         modules += [
774                 [ 'mod_vhostdb_pgsql', [ 'mod_vhostdb_pgsql.c' ], libpq ],
775         ]
776 endif
778 if get_option('with_dbi')
779         modules += [
780                 [ 'mod_vhostdb_dbi', [ 'mod_vhostdb_dbi.c' ], libdbi ],
781         ]
782 endif
784 if get_option('with_krb5')
785         modules += [
786                 [ 'mod_authn_gssapi', [ 'mod_authn_gssapi.c' ], libkrb5 + libgssapi_krb5 ],
787         ]
788 endif
790 if get_option('with_ldap')
791         modules += [
792                 [ 'mod_authn_ldap', [ 'mod_authn_ldap.c' ], libldap + liblber ],
793                 [ 'mod_vhostdb_ldap', [ 'mod_vhostdb_ldap.c' ], libldap + liblber ],
794         ]
795 endif
797 if get_option('with_openssl')
798         modules += [
799                 [ 'mod_openssl', [ 'mod_openssl.c' ], libssl + libcrypto ],
800         ]
801 endif
803 foreach mod: modules
804         mod_name = mod.get(0)
805         mod_sources = mod.get(1)
806         mod_deps = mod.length() > 2 ? mod.get(2) : []
807         shared_module(mod_name,
808                 sources: mod_sources,
809                 dependencies: common_flags + mod_deps,
810                 name_prefix: '',
811                 install: true,
812                 install_dir: moduledir,
813         )
814 endforeach