xref: /lighttpd1.4/SConstruct (revision 92cdf849)
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.61'
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_pcre', 'enable pcre support', 'yes'),
265	PackageVariable('with_pgsql', 'enable pgsql support', 'no'),
266	PackageVariable('with_sasl', 'enable SASL support', 'no'),
267	BoolVariable('with_sqlite3', 'enable sqlite3 support (required for webdav props)', 'no'),
268	BoolVariable('with_uuid', 'enable uuid support (required for webdav locks)', 'no'),
269	# with_valgrind not supported
270	# with_xattr not supported
271	PackageVariable('with_xml', 'enable xml support (required for webdav props)', 'no'),
272	BoolVariable('with_xxhash', 'build with system-provided xxhash', 'no'),
273	BoolVariable('with_zlib', 'enable deflate/gzip compression', 'no'),
274	BoolVariable('with_zstd', 'enable zstd compression', 'no'),
275
276	BoolVariable('with_all', 'enable all with_* features', 'no'),
277)
278
279env = Environment(
280	ENV = dict(os.environ),  # make sure we have a dict here so .Clone() works properly
281	variables = vars,
282	CPPPATH = Split('#sconsbuild/build')
283)
284
285env.Help(vars.GenerateHelpText(env))
286
287if env.subst('${CC}') != '':
288	env['CC'] = env.subst('${CC}')
289
290env['package'] = package
291env['version'] = version
292if env['CC'] == 'gcc':
293	## we need x-open 6 and bsd 4.3 features
294	env.Append(CCFLAGS = Split('-pipe -Wall -O2 -g -W -pedantic -Wunused -Wshadow -std=gnu99'))
295
296env.Append(CPPFLAGS = [
297	'-D_TIME_BITS=64',
298	'-D_FILE_OFFSET_BITS=64',
299	'-D_LARGEFILE_SOURCE',
300	'-D_LARGE_FILES',
301	'-D_GNU_SOURCE',
302])
303
304if env['with_all']:
305	for feature in vars.keys():
306		# only enable 'with_*' flags
307		if not feature.startswith('with_'): continue
308		# don't overwrite manual arguments
309		if feature in vars.args: continue
310		# now activate
311		env[feature] = True
312
313# cache configure checks
314if 1:
315	autoconf = Autoconf(env)
316
317	if 'CFLAGS' in os.environ:
318		autoconf.env.Append(CCFLAGS = os.environ['CFLAGS'])
319		print(">> Appending custom build flags : " + os.environ['CFLAGS'])
320
321	if 'LDFLAGS' in os.environ:
322		autoconf.env.Append(LINKFLAGS = os.environ['LDFLAGS'])
323		print(">> Appending custom link flags : " + os.environ['LDFLAGS'])
324
325	if 'LIBS' in os.environ:
326		autoconf.env.Append(APPEND_LIBS = os.environ['LIBS'])
327		print(">> Appending custom libraries : " + os.environ['LIBS'])
328	else:
329		autoconf.env.Append(APPEND_LIBS = '')
330
331	autoconf.env.Append(
332		LIBBROTLI = '',
333		LIBBZ2 = '',
334		LIBCRYPT = '',
335		LIBCRYPTO = '',
336		LIBDBI = '',
337		LIBDL = '',
338		LIBGDBM = '',
339		LIBGNUTLS = '',
340		LIBGSSAPI_KRB5 = '',
341		LIBKRB5 = '',
342		LIBLBER = '',
343		LIBLDAP = '',
344		LIBLUA = '',
345		LIBMBEDTLS = '',
346		LIBMBEDX509 = '',
347		LIBMBEDCRYPTO = '',
348		LIBMEMCACHED = '',
349		LIBMYSQL = '',
350		LIBNSS = '',
351		LIBPAM = '',
352		LIBPCRE = '',
353		LIBPGSQL = '',
354		LIBSASL = '',
355		LIBSQLITE3 = '',
356		LIBSSL = '',
357		LIBSSLCRYPTO = '',
358		LIBUUID = '',
359		LIBWOLFSSL = '',
360		LIBX509 = '',
361		LIBXML2 = '',
362		LIBXXHASH = '',
363		LIBZ = '',
364		LIBZSTD = '',
365	)
366
367	autoconf.haveCHeaders([
368		'arpa/inet.h',
369		'crypt.h',
370		'dlfcn.h',
371		'fcntl.h',
372		'getopt.h',
373		'inttypes.h',
374		'linux/random.h',
375		'malloc.h',
376		'poll.h',
377		'port.h',
378		'pwd.h',
379		'stdint.h',
380		'stdlib.h',
381		'string.h',
382		'strings.h',
383		'sys/devpoll.h',
384		'sys/epoll.h',
385		'sys/filio.h',
386		'sys/inotify.h',
387		'sys/loadavg.h',
388		'sys/poll.h',
389		'sys/prctl.h',
390		'sys/sendfile.h',
391		'sys/time.h',
392		'sys/wait.h',
393		'syslog.h',
394		'unistd.h',
395		'winsock2.h',
396
397		# "have" the last header if we include others before?
398		['sys/types.h', 'sys/time.h', 'sys/resource.h'],
399		['sys/types.h', 'netinet/in.h'],
400		['sys/types.h', 'sys/event.h'],
401		['sys/types.h', 'sys/mman.h'],
402		['sys/types.h', 'sys/select.h'],
403		['sys/types.h', 'sys/socket.h'],
404		['sys/types.h', 'sys/uio.h'],
405		['sys/types.h', 'sys/un.h'],
406	])
407
408	autoconf.haveFuncs([
409		'arc4random_buf',
410		'chroot',
411		'clock_gettime',
412		'copy_file_range',
413		'dup2',
414		'epoll_ctl',
415		'explicit_bzero',
416		'explicit_memset',
417		'fork',
418		'getcwd',
419		'gethostbyname',
420		'getloadavg',
421		'getopt',
422		'getrlimit',
423		'getuid',
424		'inet_aton',
425		'inet_ntop',
426		'inet_pton',
427		'issetugid',
428		'jrand48',
429		'kqueue',
430		'localtime_r',
431		'lstat',
432		'madvise',
433		'malloc_trim',
434		'mallopt',
435		'memcpy',
436		'mempcpy',
437		'memset_s',
438		'memset',
439		'mkostemp',
440		'mmap',
441		'munmap',
442		'pathconf',
443		'pipe2',
444		'poll',
445		'port_create',
446		'posix_fadvise',
447		'prctl',
448		'pread',
449		'preadv',
450		'pwrite',
451		'pwritev',
452		'select',
453		'send_file',
454		'sendfile',
455		'sendfile64',
456		'sigaction',
457		'signal',
458		'splice',
459		'srandom',
460		'stat',
461		'strchr',
462		'strdup',
463		'strerror',
464		'strerror_r',
465		'strftime',
466		'strstr',
467		'strtol',
468		'timegm',
469		'writev',
470	])
471	autoconf.haveFunc('getentropy', 'sys/random.h')
472	autoconf.haveFunc('getrandom', 'linux/random.h')
473
474	autoconf.haveTypes(Split('pid_t size_t off_t'))
475
476	# have crypt_r/crypt, and is -lcrypt needed?
477	if autoconf.CheckLib('crypt'):
478		autoconf.env.Append(
479			CPPFLAGS = [ '-DHAVE_LIBCRYPT' ],
480			LIBCRYPT = 'crypt',
481		)
482		with autoconf.restoreEnvLibs():
483			autoconf.env['LIBS'] = ['crypt']
484			autoconf.haveFuncs(['crypt', 'crypt_r'])
485	else:
486		autoconf.haveFuncs(['crypt', 'crypt_r'])
487
488	if autoconf.CheckType('socklen_t', '#include <unistd.h>\n#include <sys/socket.h>\n#include <sys/types.h>'):
489		autoconf.env.Append(CPPFLAGS = [ '-DHAVE_SOCKLEN_T' ])
490
491	if autoconf.CheckType('struct sockaddr_storage', '#include <sys/socket.h>\n'):
492		autoconf.env.Append(CPPFLAGS = [ '-DHAVE_STRUCT_SOCKADDR_STORAGE' ])
493
494	if autoconf.CheckLibWithHeader('elftc', 'libelftc.h', 'c', 'elftc_copyfile(0, 1);'):
495		autoconf.env.Append(
496			CPPFLAGS = [ '-DHAVE_ELFTC_COPYFILE' ],
497			LIBS = [ 'elftc' ],
498		)
499
500	if autoconf.CheckLibWithHeader('rt', 'time.h', 'c', 'clock_gettime(CLOCK_MONOTONIC, (struct timespec*)0);'):
501		autoconf.env.Append(
502			CPPFLAGS = [ '-DHAVE_CLOCK_GETTIME' ],
503			LIBS = [ 'rt' ],
504		)
505
506	if autoconf.CheckIPv6():
507		autoconf.env.Append(CPPFLAGS = [ '-DHAVE_IPV6' ])
508
509	if autoconf.CheckWeakSymbols():
510		autoconf.env.Append(CPPFLAGS = [ '-DHAVE_WEAK_SYMBOLS' ])
511
512	if autoconf.CheckGmtOffInStructTm():
513		autoconf.env.Append(CPPFLAGS = [ '-DHAVE_STRUCT_TM_GMTOFF' ])
514
515	if autoconf.CheckLibWithHeader('dl', 'dlfcn.h', 'C'):
516		autoconf.env.Append(LIBDL = 'dl')
517
518	if env['with_bzip2']:
519		if not autoconf.CheckLibWithHeader('bz2', 'bzlib.h', 'C'):
520			fail("Couldn't find bz2")
521		autoconf.env.Append(
522			CPPFLAGS = [ '-DHAVE_BZLIB_H', '-DHAVE_LIBBZ2' ],
523			LIBBZ2 = 'bz2',
524		)
525
526	if env['with_brotli']:
527		if not autoconf.CheckParseConfigForLib('LIBBROTLI', 'pkg-config --static --cflags --libs libbrotlienc'):
528			fail("Couldn't find libbrotlienc")
529		autoconf.env.Append(
530			CPPFLAGS = [ '-DHAVE_BROTLI_ENCODE_H', '-DHAVE_BROTLI' ],
531		)
532
533	if env['with_dbi']:
534		if not autoconf.CheckLibWithHeader('dbi', 'dbi/dbi.h', 'C'):
535			fail("Couldn't find dbi")
536		autoconf.env.Append(
537			CPPFLAGS = [ '-DHAVE_DBI_H', '-DHAVE_LIBDBI' ],
538			LIBDBI = 'dbi',
539		)
540
541	if env['with_fam'] and not autoconf.CheckCHeader('sys/inotify.h'):
542		if not autoconf.CheckLibWithHeader('fam', 'fam.h', 'C'):
543			fail("Couldn't find fam")
544		autoconf.env.Append(
545			CPPFLAGS = [ '-DHAVE_FAM_H', '-DHAVE_LIBFAM' ],
546			LIBS = [ 'fam' ],
547		)
548		autoconf.haveFunc('FAMNoExists')
549
550	if env['with_gdbm']:
551		if not autoconf.CheckLibWithHeader('gdbm', 'gdbm.h', 'C'):
552			fail("Couldn't find gdbm")
553		autoconf.env.Append(
554			CPPFLAGS = [ '-DHAVE_GDBM_H', '-DHAVE_GDBM' ],
555			LIBGDBM = 'gdbm',
556		)
557
558	if env['with_geoip']:
559		if not autoconf.CheckLibWithHeader('GeoIP', 'GeoIP.h', 'C'):
560			fail("Couldn't find geoip")
561		autoconf.env.Append(
562			CPPFLAGS = [ '-DHAVE_GEOIP' ],
563			LIBGEOIP = 'GeoIP',
564		)
565
566	if env['with_maxminddb']:
567		if not autoconf.CheckLibWithHeader('maxminddb', 'maxminddb.h', 'C'):
568			fail("Couldn't find maxminddb")
569		autoconf.env.Append(
570			CPPFLAGS = [ '-DHAVE_MAXMINDDB' ],
571			LIBMAXMINDDB = 'maxminddb',
572		)
573
574	if env['with_krb5']:
575		if not autoconf.CheckLibWithHeader('krb5', 'krb5.h', 'C'):
576			fail("Couldn't find krb5")
577		if not autoconf.CheckLibWithHeader('gssapi_krb5', 'gssapi/gssapi_krb5.h', 'C'):
578			fail("Couldn't find gssapi_krb5")
579		autoconf.env.Append(
580			CPPFLAGS = [ '-DHAVE_KRB5' ],
581			LIBKRB5 = 'krb5',
582			LIBGSSAPI_KRB5 = 'gssapi_krb5',
583		)
584
585	if env['with_ldap']:
586		if not autoconf.CheckLibWithHeader('ldap', 'ldap.h', 'C'):
587			fail("Couldn't find ldap")
588		if not autoconf.CheckLibWithHeader('lber', 'lber.h', 'C'):
589			fail("Couldn't find lber")
590		autoconf.env.Append(
591			CPPFLAGS = [
592				'-DHAVE_LDAP_H', '-DHAVE_LIBLDAP',
593				'-DHAVE_LBER_H', '-DHAVE_LIBLBER',
594			],
595			LIBLDAP = 'ldap',
596			LIBLBER = 'lber',
597		)
598
599	if env['with_lua']:
600		found_lua = False
601		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']:
602			print("Searching for lua: " + lua_name + " >= 5.0")
603			if autoconf.CheckParseConfigForLib('LIBLUA', "pkg-config '" + lua_name + " >= 5.0' --cflags --libs"):
604				autoconf.env.Append(CPPFLAGS = [ '-DHAVE_LUA_H' ])
605				found_lua = True
606				break
607		if not found_lua:
608			fail("Couldn't find any lua implementation")
609
610	if env['with_memcached']:
611		if not autoconf.CheckLibWithHeader('memcached', 'libmemcached/memcached.h', 'C'):
612			fail("Couldn't find memcached")
613		autoconf.env.Append(
614			CPPFLAGS = [ '-DUSE_MEMCACHED' ],
615			LIBMEMCACHED = 'memcached',
616		)
617
618	if env['with_mysql']:
619		mysql_config = autoconf.checkProgram('mysql', 'mysql_config')
620		if not autoconf.CheckParseConfigForLib('LIBMYSQL', mysql_config + ' --cflags --libs'):
621			fail("Couldn't find mysql")
622		autoconf.env.Append(CPPFLAGS = [ '-DHAVE_MYSQL_H', '-DHAVE_LIBMYSQL' ])
623
624	if env['with_nss']:
625		nss_config = autoconf.checkProgram('nss', 'nss-config')
626		if not autoconf.CheckParseConfigForLib('LIBNSS', nss_config + ' --cflags --libs'):
627			fail("Couldn't find NSS")
628		autoconf.env.Append(CPPFLAGS = [ '-DHAVE_NSS3_NSS_H' ])
629
630	if env['with_openssl']:
631		if not autoconf.CheckLibWithHeader('ssl', 'openssl/ssl.h', 'C'):
632			fail("Couldn't find openssl")
633		autoconf.env.Append(
634			CPPFLAGS = [ '-DHAVE_OPENSSL_SSL_H', '-DHAVE_LIBSSL'],
635			LIBSSL = 'ssl',
636			LIBSSLCRYPTO = 'crypto',
637			LIBCRYPTO = 'crypto',
638		)
639
640	if env['with_wolfssl']:
641		if type(env['with_wolfssl']) is str:
642			autoconf.env.AppendUnique(
643				CPPPATH = [ env['with_wolfssl'] + '/include',
644					    env['with_wolfssl'] + '/include/wolfssl' ],
645				LIBPATH = [ env['with_wolfssl'] + '/lib' ],
646			)
647		if not autoconf.CheckLibWithHeader('wolfssl', 'wolfssl/ssl.h', 'C'):
648			fail("Couldn't find wolfssl")
649		autoconf.env.Append(
650			CPPFLAGS = [ '-DHAVE_WOLFSSL_SSL_H' ],
651			LIBWOLFSSL= 'wolfssl',
652			LIBCRYPTO = 'wolfssl',
653		)
654
655	if env['with_mbedtls']:
656		if not autoconf.CheckLibWithHeader('mbedtls', 'mbedtls/ssl.h', 'C'):
657			fail("Couldn't find mbedtls")
658		autoconf.env.Append(
659			CPPFLAGS = [ '-DHAVE_LIBMBEDCRYPTO' ],
660			LIBMBEDTLS = 'mbedtls',
661			LIBMBEDX509 = 'mbedx509',
662			LIBMBEDCRYPTO = 'mbedcrypto',
663			LIBCRYPTO = 'mbedcrypto',
664		)
665
666	if env['with_nettle']:
667		if not autoconf.CheckLibWithHeader('nettle', 'nettle/nettle-types.h', 'C'):
668			fail("Couldn't find Nettle")
669		autoconf.env.Append(
670			CPPFLAGS = [ '-DHAVE_NETTLE_NETTLE_TYPES_H' ],
671			LIBCRYPTO = 'nettle',
672		)
673
674	if env['with_gnutls']:
675		if not autoconf.CheckLibWithHeader('gnutls', 'gnutls/crypto.h', 'C'):
676			fail("Couldn't find gnutls")
677		autoconf.env.Append(
678			CPPFLAGS = [ '-DHAVE_GNUTLS_CRYPTO_H' ],
679			LIBGNUTLS = 'gnutls',
680		)
681		if not autoconf.env.exists('LIBCRYPTO'):
682			autoconf.env.Append(
683				LIBCRYPTO = 'gnutls',
684			)
685
686	if env['with_pam']:
687		if not autoconf.CheckLibWithHeader('pam', 'security/pam_appl.h', 'C'):
688			fail("Couldn't find pam")
689		autoconf.env.Append(
690			CPPFLAGS = [ '-DHAVE_PAM' ],
691			LIBPAM = 'pam',
692		)
693
694	if env['with_pcre']:
695		pcre_config = autoconf.checkProgram('pcre', 'pcre-config')
696		if not autoconf.CheckParseConfigForLib('LIBPCRE', pcre_config + ' --cflags --libs'):
697			fail("Couldn't find pcre")
698		autoconf.env.Append(CPPFLAGS = [ '-DHAVE_PCRE_H', '-DHAVE_LIBPCRE' ])
699
700	if env['with_pgsql']:
701		if not autoconf.CheckParseConfigForLib('LIBPGSQL', 'pkg-config libpq --cflags --libs'):
702			fail("Couldn't find libpq")
703		autoconf.env.Append(CPPFLAGS = [ '-DHAVE_PGSQL_H', '-DHAVE_LIBPGSQL' ])
704
705	if env['with_sasl']:
706		if not autoconf.CheckLibWithHeader('sasl2', 'sasl/sasl.h', 'C'):
707			fail("Couldn't find libsasl2")
708		autoconf.env.Append(
709			CPPFLAGS = [ '-DHAVE_SASL' ],
710			LIBSASL = 'sasl2',
711		)
712
713	if env['with_sqlite3']:
714		if not autoconf.CheckLibWithHeader('sqlite3', 'sqlite3.h', 'C'):
715			fail("Couldn't find sqlite3")
716		autoconf.env.Append(
717			CPPFLAGS = [ '-DHAVE_SQLITE3_H', '-DHAVE_LIBSQLITE3' ],
718			LIBSQLITE3 = 'sqlite3',
719		)
720
721	if env['with_uuid']:
722		if not autoconf.CheckLibWithHeader('uuid', 'uuid/uuid.h', 'C'):
723			fail("Couldn't find uuid")
724		autoconf.env.Append(
725			CPPFLAGS = [ '-DHAVE_UUID_UUID_H', '-DHAVE_LIBUUID' ],
726			LIBUUID = 'uuid',
727		)
728
729	if env['with_xml']:
730		xml2_config = autoconf.checkProgram('xml', 'xml2-config')
731		if not autoconf.CheckParseConfigForLib('LIBXML2', xml2_config + ' --cflags --libs'):
732			fail("Couldn't find xml2")
733		autoconf.env.Append(CPPFLAGS = [ '-DHAVE_LIBXML_H', '-DHAVE_LIBXML2' ])
734
735	if env['with_xxhash']:
736		if not autoconf.CheckLibWithHeader('xxhash', 'xxhash.h', 'C'):
737			fail("Couldn't find xxhash")
738		autoconf.env.Append(
739			CPPFLAGS = [ '-DHAVE_XXHASH_H' ],
740			LIBXXHASH = 'xxhash',
741		)
742
743	if env['with_zlib']:
744		if not autoconf.CheckLibWithHeader('z', 'zlib.h', 'C'):
745			fail("Couldn't find zlib")
746		autoconf.env.Append(
747			CPPFLAGS = [ '-DHAVE_ZLIB_H', '-DHAVE_LIBZ' ],
748			LIBZ = 'z',
749		)
750
751	if env['with_zstd']:
752		if not autoconf.CheckLibWithHeader('zstd', 'zstd.h', 'C'):
753			fail("Couldn't find zstd")
754		autoconf.env.Append(
755			CPPFLAGS = [ '-DHAVE_ZSTD_H', '-DHAVE_ZSTD' ],
756			LIBZSTD = 'zstd',
757		)
758
759	env = autoconf.Finish()
760
761if re.compile("cygwin|mingw|midipix").search(env['PLATFORM']):
762	env.Append(COMMON_LIB = 'bin')
763elif re.compile("darwin|aix").search(env['PLATFORM']):
764	env.Append(COMMON_LIB = 'lib')
765else:
766	env.Append(COMMON_LIB = False)
767
768versions = version.split('.')
769version_id = int(versions[0]) << 16 | int(versions[1]) << 8 | int(versions[2])
770env.Append(CPPFLAGS = [
771		'-DLIGHTTPD_VERSION_ID=' + hex(version_id),
772		'-DPACKAGE_NAME=\\"' + package + '\\"',
773		'-DPACKAGE_VERSION=\\"' + version + '\\"',
774		'-DLIBRARY_DIR="\\"${libdir}\\""',
775		] )
776
777SConscript('src/SConscript', exports = 'env', variant_dir = 'sconsbuild/build', duplicate = 0)
778SConscript('tests/SConscript', exports = 'env', variant_dir = 'sconsbuild/tests')
779