xref: /lighttpd1.4/SConstruct (revision 6c857868)
1from __future__ import print_function
2import os
3import re
4import string
5import sys
6from copy import copy
7from stat import *
8
9try:
10	string_types = basestring
11except NameError:
12	string_types = str
13
14package = 'lighttpd'
15version = '1.4.64'
16
17underscorify_reg = re.compile('[^A-Z0-9]')
18def underscorify(id):
19	return underscorify_reg.sub('_', id.upper())
20
21def fail(*args, **kwargs):
22	print(*args, file=sys.stderr, **kwargs)
23	sys.exit(-1)
24
25class Autoconf:
26	class RestoreEnvLibs:
27		def __init__(self, env):
28			self.env = env
29			self.active = False
30
31		def __enter__(self):
32			if self.active:
33				raise Exception('entered twice')
34			self.active = True
35			if 'LIBS' in self.env:
36				#print("Backup LIBS: " + repr(self.env['LIBS']))
37				self.empty = False
38				self.backup_libs = copy(self.env['LIBS'])
39			else:
40				#print("No LIBS to backup")
41				self.empty = True
42
43		def __exit__(self, type, value, traceback):
44			if not self.active:
45				raise Exception('exited twice')
46			self.active = False
47			if self.empty:
48				if 'LIBS' in self.env:
49					del self.env['LIBS']
50			else:
51				#print("Restoring LIBS, now: " + repr(self.env['LIBS']))
52				self.env['LIBS'] = self.backup_libs
53				#print("Restoring LIBS, to: " + repr(self.env['LIBS']))
54
55	def __init__(self, env):
56		self.conf = Configure(env, custom_tests = {
57			'CheckGmtOffInStructTm': Autoconf.__checkGmtOffInStructTm,
58			'CheckIPv6': Autoconf.__checkIPv6,
59			'CheckWeakSymbols': Autoconf.__checkWeakSymbols,
60		})
61
62	def append(self, *args, **kw):
63		return self.conf.env.Append(*args, **kw)
64
65	def Finish(self):
66		return self.conf.Finish()
67
68	@property
69	def env(self):
70		return self.conf.env
71
72	def restoreEnvLibs(self):
73		return Autoconf.RestoreEnvLibs(self.conf.env)
74
75	def CheckType(self, *args, **kw):
76		return self.conf.CheckType(*args, **kw)
77
78	def CheckLib(self, *args, **kw):
79		return self.conf.CheckLib(*args, autoadd = 0, **kw)
80
81	def CheckLibWithHeader(self, *args, **kw):
82		return self.conf.CheckLibWithHeader(*args, autoadd = 0, **kw)
83
84	def CheckGmtOffInStructTm(self):
85		return self.conf.CheckGmtOffInStructTm()
86
87	def CheckIPv6(self):
88		return self.conf.CheckIPv6()
89
90	def CheckWeakSymbols(self):
91		return self.conf.CheckWeakSymbols()
92
93	def CheckCHeader(self, hdr):
94		return self.conf.CheckCHeader(hdr)
95
96	def haveCHeader(self, hdr):
97		if self.CheckCHeader(hdr):
98			# if we have a list of headers define HAVE_ only for last one
99			target = hdr
100			if not isinstance(target, string_types):
101				target = target[-1]
102			self.conf.env.Append(CPPFLAGS = [ '-DHAVE_' + underscorify(target) ])
103			return True
104		return False
105
106	def haveCHeaders(self, hdrs):
107		for hdr in hdrs:
108			self.haveCHeader(hdr)
109
110	def CheckFunc(self, func, header = None, libs = []):
111		with self.restoreEnvLibs():
112			self.env.Append(LIBS = libs)
113			return self.conf.CheckFunc(func, header = header)
114
115	def CheckFuncInLib(self, func, lib):
116		return self.CheckFunc(func, libs = [lib])
117
118	def haveFuncInLib(self, func, lib):
119		if self.CheckFuncInLib(func, lib):
120			self.conf.env.Append(CPPFLAGS = [ '-DHAVE_' + underscorify(func) ])
121			return True
122		return False
123
124	def haveFunc(self, func, header = None, libs = []):
125		if self.CheckFunc(func, header = header, libs = libs):
126			self.conf.env.Append(CPPFLAGS = [ '-DHAVE_' + underscorify(func) ])
127			return True
128		return False
129
130	def haveFuncs(self, funcs):
131		for func in funcs:
132			self.haveFunc(func)
133
134	def haveTypes(self, types):
135		for type in types:
136			if self.conf.CheckType(type, '#include <sys/types.h>'):
137				self.conf.env.Append(CPPFLAGS = [ '-DHAVE_' + underscorify(type) ])
138
139	def CheckParseConfig(self, *args, **kw):
140		try:
141			self.conf.env.ParseConfig(*args, **kw)
142			return True
143		except OSError:
144			return False
145		except Exception as e:
146			print(e.message, file=sys.stderr)
147			return False
148
149	def CheckParseConfigForLib(self, lib, *args, **kw):
150		with self.restoreEnvLibs():
151			self.env['LIBS'] = []
152			if not self.CheckParseConfig(*args, **kw):
153				return False
154			self.env.Append(**{lib: self.env['LIBS']})
155			return True
156
157	@staticmethod
158	def __checkGmtOffInStructTm(context):
159		source = """
160#include <time.h>
161int main() {
162	struct tm a;
163	a.tm_gmtoff = 0;
164	return 0;
165}
166"""
167		context.Message('Checking for tm_gmtoff in struct tm...')
168		result = context.TryLink(source, '.c')
169		context.Result(result)
170
171		return result
172
173	@staticmethod
174	def __checkIPv6(context):
175		source = """
176#include <sys/types.h>
177#include <sys/socket.h>
178#include <netinet/in.h>
179
180int main() {
181	struct sockaddr_in6 s; struct in6_addr t=in6addr_any; int i=AF_INET6; s; t.s6_addr[0] = 0;
182	return 0;
183}
184"""
185		context.Message('Checking for IPv6 support...')
186		result = context.TryLink(source, '.c')
187		context.Result(result)
188
189		return result
190
191	@staticmethod
192	def __checkWeakSymbols(context):
193		source = """
194__attribute__((weak)) void __dummy(void *x) { }
195int main() {
196	void *x;
197	__dummy(x);
198}
199"""
200		context.Message('Checking for weak symbol support...')
201		result = context.TryLink(source, '.c')
202		context.Result(result)
203
204		return result
205
206	def checkProgram(self, withname, progname):
207		withname = 'with_' + withname
208		binpath = None
209
210		if self.env[withname] != 1:
211			binpath = self.env[withname]
212		else:
213			prog = self.env.Detect(progname)
214			if prog:
215				binpath = self.env.WhereIs(prog)
216
217		if binpath:
218			mode = os.stat(binpath)[ST_MODE]
219			if S_ISDIR(mode):
220				fail("* error: path `%s' is a directory" % (binpath))
221			if not S_ISREG(mode):
222				fail("* error: path `%s' is not a file or not exists" % (binpath))
223
224		if not binpath:
225			fail("* error: can't find program `%s'" % (progname))
226
227		return binpath
228
229VariantDir('sconsbuild/build', 'src', duplicate = 0)
230VariantDir('sconsbuild/tests', 'tests', duplicate = 0)
231
232vars = Variables()
233vars.AddVariables(
234	('prefix', 'prefix', '/usr/local'),
235	('bindir', 'binary directory', '${prefix}/bin'),
236	('sbindir', 'binary directory', '${prefix}/sbin'),
237	('libdir', 'library directory', '${prefix}/lib'),
238	PathVariable('CC', 'path to the c-compiler', None),
239	BoolVariable('build_dynamic', 'enable dynamic build', 'yes'),
240	BoolVariable('build_static', 'enable static build', 'no'),
241	BoolVariable('build_fullstatic', 'enable fullstatic build', 'no'),
242
243	BoolVariable('with_bzip2', 'enable bzip2 compression', 'no'),
244	BoolVariable('with_brotli', 'enable brotli compression', 'no'),
245	PackageVariable('with_dbi', 'enable dbi support', 'no'),
246	BoolVariable('with_fam', 'enable FAM/gamin support', 'no'),
247	BoolVariable('with_gdbm', 'enable gdbm support', 'no'),
248	BoolVariable('with_geoip', 'enable GeoIP support', 'no'),
249	BoolVariable('with_maxminddb', 'enable MaxMind GeoIP2 support', 'no'),
250	BoolVariable('with_krb5', 'enable krb5 auth support', 'no'),
251	BoolVariable('with_ldap', 'enable ldap auth support', 'no'),
252	# with_libev not supported
253	# with_libunwind not supported
254	BoolVariable('with_lua', 'enable lua support for mod_cml', 'no'),
255	BoolVariable('with_memcached', 'enable memcached support', 'no'),
256	PackageVariable('with_mysql', 'enable mysql support', 'no'),
257	BoolVariable('with_openssl', 'enable openssl support', 'no'),
258	PackageVariable('with_gnutls', 'enable GnuTLS support', 'no'),
259	PackageVariable('with_mbedtls', 'enable mbedTLS support', 'no'),
260	PackageVariable('with_nss', 'enable NSS crypto support', 'no'),
261	PackageVariable('with_wolfssl', 'enable wolfSSL support', 'no'),
262	BoolVariable('with_nettle', 'enable Nettle support', 'no'),
263	BoolVariable('with_pam', 'enable PAM auth support', 'no'),
264	PackageVariable('with_pcre2', 'enable pcre2 support', 'no'),
265	PackageVariable('with_pcre', 'enable pcre support', 'yes'),
266	PackageVariable('with_pgsql', 'enable pgsql support', 'no'),
267	PackageVariable('with_sasl', 'enable SASL support', 'no'),
268	BoolVariable('with_sqlite3', 'enable sqlite3 support (required for webdav props)', 'no'),
269	BoolVariable('with_uuid', 'enable uuid support (required for webdav locks)', 'no'),
270	# with_valgrind not supported
271	# with_xattr not supported
272	PackageVariable('with_xml', 'enable xml support (required for webdav props)', 'no'),
273	BoolVariable('with_xxhash', 'build with system-provided xxhash', 'no'),
274	BoolVariable('with_zlib', 'enable deflate/gzip compression', 'no'),
275	BoolVariable('with_zstd', 'enable zstd compression', 'no'),
276
277	BoolVariable('with_all', 'enable all with_* features', 'no'),
278)
279
280env = Environment(
281	ENV = dict(os.environ),  # make sure we have a dict here so .Clone() works properly
282	variables = vars,
283	CPPPATH = Split('#sconsbuild/build')
284)
285
286env.Help(vars.GenerateHelpText(env))
287
288if env.subst('${CC}') != '':
289	env['CC'] = env.subst('${CC}')
290
291env['package'] = package
292env['version'] = version
293if env['CC'] == 'gcc':
294	## we need x-open 6 and bsd 4.3 features
295	env.Append(CCFLAGS = Split('-pipe -Wall -O2 -g -W -pedantic -Wunused -Wshadow -std=gnu99'))
296
297env.Append(CPPFLAGS = [
298	'-D_TIME_BITS=64',
299	'-D_FILE_OFFSET_BITS=64',
300	'-D_LARGEFILE_SOURCE',
301	'-D_LARGE_FILES',
302	'-D_GNU_SOURCE',
303])
304
305if env['with_all']:
306	for feature in vars.keys():
307		# only enable 'with_*' flags
308		if not feature.startswith('with_'): continue
309		# don't overwrite manual arguments
310		if feature in vars.args: continue
311		# now activate
312		env[feature] = True
313
314# cache configure checks
315if 1:
316	autoconf = Autoconf(env)
317
318	if 'CFLAGS' in os.environ:
319		autoconf.env.Append(CCFLAGS = os.environ['CFLAGS'])
320		print(">> Appending custom build flags : " + os.environ['CFLAGS'])
321
322	if 'LDFLAGS' in os.environ:
323		autoconf.env.Append(LINKFLAGS = os.environ['LDFLAGS'])
324		print(">> Appending custom link flags : " + os.environ['LDFLAGS'])
325
326	if 'LIBS' in os.environ:
327		autoconf.env.Append(APPEND_LIBS = os.environ['LIBS'])
328		print(">> Appending custom libraries : " + os.environ['LIBS'])
329	else:
330		autoconf.env.Append(APPEND_LIBS = '')
331
332	autoconf.env.Append(
333		LIBBROTLI = '',
334		LIBBZ2 = '',
335		LIBCRYPT = '',
336		LIBCRYPTO = '',
337		LIBDBI = '',
338		LIBDL = '',
339		LIBGDBM = '',
340		LIBGNUTLS = '',
341		LIBGSSAPI_KRB5 = '',
342		LIBKRB5 = '',
343		LIBLBER = '',
344		LIBLDAP = '',
345		LIBLUA = '',
346		LIBMBEDTLS = '',
347		LIBMBEDX509 = '',
348		LIBMBEDCRYPTO = '',
349		LIBMEMCACHED = '',
350		LIBMYSQL = '',
351		LIBNSS = '',
352		LIBPAM = '',
353		LIBPCRE = '',
354		LIBPGSQL = '',
355		LIBSASL = '',
356		LIBSQLITE3 = '',
357		LIBSSL = '',
358		LIBSSLCRYPTO = '',
359		LIBUUID = '',
360		LIBWOLFSSL = '',
361		LIBX509 = '',
362		LIBXML2 = '',
363		LIBXXHASH = '',
364		LIBZ = '',
365		LIBZSTD = '',
366	)
367
368	autoconf.haveCHeaders([
369		'arpa/inet.h',
370		'crypt.h',
371		'dlfcn.h',
372		'fcntl.h',
373		'getopt.h',
374		'inttypes.h',
375		'linux/random.h',
376		'malloc.h',
377		'poll.h',
378		'port.h',
379		'pwd.h',
380		'stdint.h',
381		'stdlib.h',
382		'string.h',
383		'strings.h',
384		'sys/devpoll.h',
385		'sys/epoll.h',
386		'sys/filio.h',
387		'sys/inotify.h',
388		'sys/loadavg.h',
389		'sys/poll.h',
390		'sys/prctl.h',
391		'sys/sendfile.h',
392		'sys/time.h',
393		'sys/wait.h',
394		'syslog.h',
395		'unistd.h',
396		'winsock2.h',
397
398		# "have" the last header if we include others before?
399		['sys/types.h', 'sys/time.h', 'sys/resource.h'],
400		['sys/types.h', 'netinet/in.h'],
401		['sys/types.h', 'sys/event.h'],
402		['sys/types.h', 'sys/mman.h'],
403		['sys/types.h', 'sys/select.h'],
404		['sys/types.h', 'sys/socket.h'],
405		['sys/types.h', 'sys/uio.h'],
406		['sys/types.h', 'sys/un.h'],
407	])
408
409	autoconf.haveFuncs([
410		'arc4random_buf',
411		'chroot',
412		'clock_gettime',
413		'copy_file_range',
414		'dup2',
415		'epoll_ctl',
416		'explicit_bzero',
417		'explicit_memset',
418		'fork',
419		'getcwd',
420		'gethostbyname',
421		'getloadavg',
422		'getopt',
423		'getrlimit',
424		'getuid',
425		'inet_aton',
426		'inet_ntop',
427		'inet_pton',
428		'issetugid',
429		'jrand48',
430		'kqueue',
431		'localtime_r',
432		'lstat',
433		'madvise',
434		'malloc_trim',
435		'mallopt',
436		'memcpy',
437		'mempcpy',
438		'memset_s',
439		'memset',
440		'mkostemp',
441		'mmap',
442		'munmap',
443		'pathconf',
444		'pipe2',
445		'poll',
446		'port_create',
447		'posix_fadvise',
448		'prctl',
449		'pread',
450		'preadv',
451		'pwrite',
452		'pwritev',
453		'select',
454		'send_file',
455		'sendfile',
456		'sendfile64',
457		'sigaction',
458		'signal',
459		'splice',
460		'srandom',
461		'stat',
462		'strchr',
463		'strdup',
464		'strerror',
465		'strerror_r',
466		'strftime',
467		'strstr',
468		'strtol',
469		'timegm',
470		'writev',
471	])
472	autoconf.haveFunc('getentropy', 'sys/random.h')
473	autoconf.haveFunc('getrandom', 'linux/random.h')
474
475	autoconf.haveTypes(Split('pid_t size_t off_t'))
476
477	# have crypt_r/crypt, and is -lcrypt needed?
478	if autoconf.CheckLib('crypt'):
479		autoconf.env.Append(
480			CPPFLAGS = [ '-DHAVE_LIBCRYPT' ],
481			LIBCRYPT = 'crypt',
482		)
483		with autoconf.restoreEnvLibs():
484			autoconf.env['LIBS'] = ['crypt']
485			autoconf.haveFuncs(['crypt', 'crypt_r'])
486	else:
487		autoconf.haveFuncs(['crypt', 'crypt_r'])
488
489	if autoconf.CheckType('socklen_t', '#include <unistd.h>\n#include <sys/socket.h>\n#include <sys/types.h>'):
490		autoconf.env.Append(CPPFLAGS = [ '-DHAVE_SOCKLEN_T' ])
491
492	if autoconf.CheckType('struct sockaddr_storage', '#include <sys/socket.h>\n'):
493		autoconf.env.Append(CPPFLAGS = [ '-DHAVE_STRUCT_SOCKADDR_STORAGE' ])
494
495	if autoconf.CheckLibWithHeader('elftc', 'libelftc.h', 'c', 'elftc_copyfile(0, 1);'):
496		autoconf.env.Append(
497			CPPFLAGS = [ '-DHAVE_ELFTC_COPYFILE' ],
498			LIBS = [ 'elftc' ],
499		)
500
501	if autoconf.CheckLibWithHeader('rt', 'time.h', 'c', 'clock_gettime(CLOCK_MONOTONIC, (struct timespec*)0);'):
502		autoconf.env.Append(
503			CPPFLAGS = [ '-DHAVE_CLOCK_GETTIME' ],
504			LIBS = [ 'rt' ],
505		)
506
507	if autoconf.CheckIPv6():
508		autoconf.env.Append(CPPFLAGS = [ '-DHAVE_IPV6' ])
509
510	if autoconf.CheckWeakSymbols():
511		autoconf.env.Append(CPPFLAGS = [ '-DHAVE_WEAK_SYMBOLS' ])
512
513	if autoconf.CheckGmtOffInStructTm():
514		autoconf.env.Append(CPPFLAGS = [ '-DHAVE_STRUCT_TM_GMTOFF' ])
515
516	if autoconf.CheckLibWithHeader('dl', 'dlfcn.h', 'C'):
517		autoconf.env.Append(LIBDL = 'dl')
518
519	if env['with_bzip2']:
520		if not autoconf.CheckLibWithHeader('bz2', 'bzlib.h', 'C'):
521			fail("Couldn't find bz2")
522		autoconf.env.Append(
523			CPPFLAGS = [ '-DHAVE_BZLIB_H', '-DHAVE_LIBBZ2' ],
524			LIBBZ2 = 'bz2',
525		)
526
527	if env['with_brotli']:
528		if not autoconf.CheckParseConfigForLib('LIBBROTLI', 'pkg-config --static --cflags --libs libbrotlienc'):
529			fail("Couldn't find libbrotlienc")
530		autoconf.env.Append(
531			CPPFLAGS = [ '-DHAVE_BROTLI_ENCODE_H', '-DHAVE_BROTLI' ],
532		)
533
534	if env['with_dbi']:
535		if not autoconf.CheckLibWithHeader('dbi', 'dbi/dbi.h', 'C'):
536			fail("Couldn't find dbi")
537		autoconf.env.Append(
538			CPPFLAGS = [ '-DHAVE_DBI_H', '-DHAVE_LIBDBI' ],
539			LIBDBI = 'dbi',
540		)
541
542	if env['with_fam'] and not autoconf.CheckCHeader('sys/inotify.h'):
543		if not autoconf.CheckLibWithHeader('fam', 'fam.h', 'C'):
544			fail("Couldn't find fam")
545		autoconf.env.Append(
546			CPPFLAGS = [ '-DHAVE_FAM_H', '-DHAVE_LIBFAM' ],
547			LIBS = [ 'fam' ],
548		)
549		autoconf.haveFunc('FAMNoExists')
550
551	if env['with_gdbm']:
552		if not autoconf.CheckLibWithHeader('gdbm', 'gdbm.h', 'C'):
553			fail("Couldn't find gdbm")
554		autoconf.env.Append(
555			CPPFLAGS = [ '-DHAVE_GDBM_H', '-DHAVE_GDBM' ],
556			LIBGDBM = 'gdbm',
557		)
558
559	if env['with_geoip']:
560		if not autoconf.CheckLibWithHeader('GeoIP', 'GeoIP.h', 'C'):
561			fail("Couldn't find geoip")
562		autoconf.env.Append(
563			CPPFLAGS = [ '-DHAVE_GEOIP' ],
564			LIBGEOIP = 'GeoIP',
565		)
566
567	if env['with_maxminddb']:
568		if not autoconf.CheckLibWithHeader('maxminddb', 'maxminddb.h', 'C'):
569			fail("Couldn't find maxminddb")
570		autoconf.env.Append(
571			CPPFLAGS = [ '-DHAVE_MAXMINDDB' ],
572			LIBMAXMINDDB = 'maxminddb',
573		)
574
575	if env['with_krb5']:
576		if not autoconf.CheckLibWithHeader('krb5', 'krb5.h', 'C'):
577			fail("Couldn't find krb5")
578		if not autoconf.CheckLibWithHeader('gssapi_krb5', 'gssapi/gssapi_krb5.h', 'C'):
579			fail("Couldn't find gssapi_krb5")
580		autoconf.env.Append(
581			CPPFLAGS = [ '-DHAVE_KRB5' ],
582			LIBKRB5 = 'krb5',
583			LIBGSSAPI_KRB5 = 'gssapi_krb5',
584		)
585
586	if env['with_ldap']:
587		if not autoconf.CheckLibWithHeader('ldap', 'ldap.h', 'C'):
588			fail("Couldn't find ldap")
589		if not autoconf.CheckLibWithHeader('lber', 'lber.h', 'C'):
590			fail("Couldn't find lber")
591		autoconf.env.Append(
592			CPPFLAGS = [
593				'-DHAVE_LDAP_H', '-DHAVE_LIBLDAP',
594				'-DHAVE_LBER_H', '-DHAVE_LIBLBER',
595			],
596			LIBLDAP = 'ldap',
597			LIBLBER = 'lber',
598		)
599
600	if env['with_lua']:
601		found_lua = False
602		for lua_name in ['lua5.4', 'lua-5.4', 'lua5.3', 'lua-5.3', 'lua5.2', 'lua-5.2', 'lua5.1', 'lua-5.1', 'lua']:
603			print("Searching for lua: " + lua_name + " >= 5.0")
604			if autoconf.CheckParseConfigForLib('LIBLUA', "pkg-config '" + lua_name + " >= 5.0' --cflags --libs"):
605				autoconf.env.Append(CPPFLAGS = [ '-DHAVE_LUA_H' ])
606				found_lua = True
607				break
608		if not found_lua:
609			fail("Couldn't find any lua implementation")
610
611	if env['with_memcached']:
612		if not autoconf.CheckLibWithHeader('memcached', 'libmemcached/memcached.h', 'C'):
613			fail("Couldn't find memcached")
614		autoconf.env.Append(
615			CPPFLAGS = [ '-DUSE_MEMCACHED' ],
616			LIBMEMCACHED = 'memcached',
617		)
618
619	if env['with_mysql']:
620		mysql_config = autoconf.checkProgram('mysql', 'mysql_config')
621		if not autoconf.CheckParseConfigForLib('LIBMYSQL', mysql_config + ' --cflags --libs'):
622			fail("Couldn't find mysql")
623		autoconf.env.Append(CPPFLAGS = [ '-DHAVE_MYSQL_H', '-DHAVE_LIBMYSQL' ])
624
625	if env['with_nss']:
626		nss_config = autoconf.checkProgram('nss', 'nss-config')
627		if not autoconf.CheckParseConfigForLib('LIBNSS', nss_config + ' --cflags --libs'):
628			fail("Couldn't find NSS")
629		autoconf.env.Append(CPPFLAGS = [ '-DHAVE_NSS3_NSS_H' ])
630
631	if env['with_openssl']:
632		if not autoconf.CheckLibWithHeader('ssl', 'openssl/ssl.h', 'C'):
633			fail("Couldn't find openssl")
634		autoconf.env.Append(
635			CPPFLAGS = [ '-DHAVE_OPENSSL_SSL_H', '-DHAVE_LIBSSL'],
636			LIBSSL = 'ssl',
637			LIBSSLCRYPTO = 'crypto',
638			LIBCRYPTO = 'crypto',
639		)
640
641	if env['with_wolfssl']:
642		if type(env['with_wolfssl']) is str:
643			autoconf.env.AppendUnique(
644				CPPPATH = [ env['with_wolfssl'] + '/include',
645					    env['with_wolfssl'] + '/include/wolfssl' ],
646				LIBPATH = [ env['with_wolfssl'] + '/lib' ],
647			)
648		if not autoconf.CheckLibWithHeader('wolfssl', 'wolfssl/ssl.h', 'C'):
649			fail("Couldn't find wolfssl")
650		autoconf.env.Append(
651			CPPFLAGS = [ '-DHAVE_WOLFSSL_SSL_H' ],
652			LIBWOLFSSL= 'wolfssl',
653			LIBCRYPTO = 'wolfssl',
654		)
655
656	if env['with_mbedtls']:
657		if not autoconf.CheckLibWithHeader('mbedtls', 'mbedtls/ssl.h', 'C'):
658			fail("Couldn't find mbedtls")
659		autoconf.env.Append(
660			CPPFLAGS = [ '-DHAVE_LIBMBEDCRYPTO' ],
661			LIBMBEDTLS = 'mbedtls',
662			LIBMBEDX509 = 'mbedx509',
663			LIBMBEDCRYPTO = 'mbedcrypto',
664			LIBCRYPTO = 'mbedcrypto',
665		)
666
667	if env['with_nettle']:
668		if not autoconf.CheckLibWithHeader('nettle', 'nettle/nettle-types.h', 'C'):
669			fail("Couldn't find Nettle")
670		autoconf.env.Append(
671			CPPFLAGS = [ '-DHAVE_NETTLE_NETTLE_TYPES_H' ],
672			LIBCRYPTO = 'nettle',
673		)
674
675	if env['with_gnutls']:
676		if not autoconf.CheckLibWithHeader('gnutls', 'gnutls/crypto.h', 'C'):
677			fail("Couldn't find gnutls")
678		autoconf.env.Append(
679			CPPFLAGS = [ '-DHAVE_GNUTLS_CRYPTO_H' ],
680			LIBGNUTLS = 'gnutls',
681		)
682		if not autoconf.env.exists('LIBCRYPTO'):
683			autoconf.env.Append(
684				LIBCRYPTO = 'gnutls',
685			)
686
687	if env['with_pam']:
688		if not autoconf.CheckLibWithHeader('pam', 'security/pam_appl.h', 'C'):
689			fail("Couldn't find pam")
690		autoconf.env.Append(
691			CPPFLAGS = [ '-DHAVE_PAM' ],
692			LIBPAM = 'pam',
693		)
694
695	if env['with_pcre2']:
696		pcre2_config = autoconf.checkProgram('pcre2', 'pcre2-config')
697		if not autoconf.CheckParseConfigForLib('LIBPCRE', pcre2_config + ' --cflags --libs8'):
698			fail("Couldn't find pcre2")
699		autoconf.env.Append(CPPFLAGS = [ '-DHAVE_PCRE2_H', '-DHAVE_PCRE' ])
700	elif env['with_pcre']:
701		pcre_config = autoconf.checkProgram('pcre', 'pcre-config')
702		if not autoconf.CheckParseConfigForLib('LIBPCRE', pcre_config + ' --cflags --libs'):
703			fail("Couldn't find pcre")
704		autoconf.env.Append(CPPFLAGS = [ '-DHAVE_PCRE_H', '-DHAVE_PCRE' ])
705
706	if env['with_pgsql']:
707		if not autoconf.CheckParseConfigForLib('LIBPGSQL', 'pkg-config libpq --cflags --libs'):
708			fail("Couldn't find libpq")
709		autoconf.env.Append(CPPFLAGS = [ '-DHAVE_PGSQL_H', '-DHAVE_LIBPGSQL' ])
710
711	if env['with_sasl']:
712		if not autoconf.CheckLibWithHeader('sasl2', 'sasl/sasl.h', 'C'):
713			fail("Couldn't find libsasl2")
714		autoconf.env.Append(
715			CPPFLAGS = [ '-DHAVE_SASL' ],
716			LIBSASL = 'sasl2',
717		)
718
719	if env['with_sqlite3']:
720		if not autoconf.CheckLibWithHeader('sqlite3', 'sqlite3.h', 'C'):
721			fail("Couldn't find sqlite3")
722		autoconf.env.Append(
723			CPPFLAGS = [ '-DHAVE_SQLITE3_H', '-DHAVE_LIBSQLITE3' ],
724			LIBSQLITE3 = 'sqlite3',
725		)
726
727	if env['with_uuid']:
728		if not autoconf.CheckLibWithHeader('uuid', 'uuid/uuid.h', 'C'):
729			fail("Couldn't find uuid")
730		autoconf.env.Append(
731			CPPFLAGS = [ '-DHAVE_UUID_UUID_H', '-DHAVE_LIBUUID' ],
732			LIBUUID = 'uuid',
733		)
734
735	if env['with_xml']:
736		xml2_config = autoconf.checkProgram('xml', 'xml2-config')
737		if not autoconf.CheckParseConfigForLib('LIBXML2', xml2_config + ' --cflags --libs'):
738			fail("Couldn't find xml2")
739		autoconf.env.Append(CPPFLAGS = [ '-DHAVE_LIBXML_H', '-DHAVE_LIBXML2' ])
740
741	if env['with_xxhash']:
742		if not autoconf.CheckLibWithHeader('xxhash', 'xxhash.h', 'C'):
743			fail("Couldn't find xxhash")
744		autoconf.env.Append(
745			CPPFLAGS = [ '-DHAVE_XXHASH_H' ],
746			LIBXXHASH = 'xxhash',
747		)
748
749	if env['with_zlib']:
750		if not autoconf.CheckLibWithHeader('z', 'zlib.h', 'C'):
751			fail("Couldn't find zlib")
752		autoconf.env.Append(
753			CPPFLAGS = [ '-DHAVE_ZLIB_H', '-DHAVE_LIBZ' ],
754			LIBZ = 'z',
755		)
756
757	if env['with_zstd']:
758		if not autoconf.CheckLibWithHeader('zstd', 'zstd.h', 'C'):
759			fail("Couldn't find zstd")
760		autoconf.env.Append(
761			CPPFLAGS = [ '-DHAVE_ZSTD_H', '-DHAVE_ZSTD' ],
762			LIBZSTD = 'zstd',
763		)
764
765	env = autoconf.Finish()
766
767if re.compile("cygwin|mingw|midipix").search(env['PLATFORM']):
768	env.Append(COMMON_LIB = 'bin')
769elif re.compile("darwin|aix").search(env['PLATFORM']):
770	env.Append(COMMON_LIB = 'lib')
771else:
772	env.Append(COMMON_LIB = False)
773
774versions = version.split('.')
775version_id = int(versions[0]) << 16 | int(versions[1]) << 8 | int(versions[2])
776env.Append(CPPFLAGS = [
777		'-DLIGHTTPD_VERSION_ID=' + hex(version_id),
778		'-DPACKAGE_NAME=\\"' + package + '\\"',
779		'-DPACKAGE_VERSION=\\"' + version + '\\"',
780		'-DLIBRARY_DIR="\\"${libdir}\\""',
781		] )
782
783SConscript('src/SConscript', exports = 'env', variant_dir = 'sconsbuild/build', duplicate = 0)
784SConscript('tests/SConscript', exports = 'env', variant_dir = 'sconsbuild/tests')
785