xref: /lighttpd1.4/SConstruct (revision 96abd9cf)
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.56'
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 Exception as e:
144			print(e.message, file=sys.stderr)
145			return False
146
147	def CheckParseConfigForLib(self, lib, *args, **kw):
148		with self.restoreEnvLibs():
149			self.env['LIBS'] = []
150			if not self.CheckParseConfig(*args, **kw):
151				return False
152			self.env.Append(**{lib: self.env['LIBS']})
153			return True
154
155	@staticmethod
156	def __checkGmtOffInStructTm(context):
157		source = """
158#include <time.h>
159int main() {
160	struct tm a;
161	a.tm_gmtoff = 0;
162	return 0;
163}
164"""
165		context.Message('Checking for tm_gmtoff in struct tm...')
166		result = context.TryLink(source, '.c')
167		context.Result(result)
168
169		return result
170
171	@staticmethod
172	def __checkIPv6(context):
173		source = """
174#include <sys/types.h>
175#include <sys/socket.h>
176#include <netinet/in.h>
177
178int 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		context.Message('Checking for IPv6 support...')
184		result = context.TryLink(source, '.c')
185		context.Result(result)
186
187		return result
188
189	@staticmethod
190	def __checkWeakSymbols(context):
191		source = """
192__attribute__((weak)) void __dummy(void *x) { }
193int main() {
194	void *x;
195	__dummy(x);
196}
197"""
198		context.Message('Checking for weak symbol support...')
199		result = context.TryLink(source, '.c')
200		context.Result(result)
201
202		return result
203
204	def checkProgram(self, withname, progname):
205		withname = 'with_' + withname
206		binpath = None
207
208		if self.env[withname] != 1:
209			binpath = self.env[withname]
210		else:
211			prog = self.env.Detect(progname)
212			if prog:
213				binpath = self.env.WhereIs(prog)
214
215		if binpath:
216			mode = os.stat(binpath)[ST_MODE]
217			if S_ISDIR(mode):
218				fail("* error: path `%s' is a directory" % (binpath))
219			if not S_ISREG(mode):
220				fail("* error: path `%s' is not a file or not exists" % (binpath))
221
222		if not binpath:
223			fail("* error: can't find program `%s'" % (progname))
224
225		return binpath
226
227VariantDir('sconsbuild/build', 'src', duplicate = 0)
228VariantDir('sconsbuild/tests', 'tests', duplicate = 0)
229
230vars = Variables()
231vars.AddVariables(
232	('prefix', 'prefix', '/usr/local'),
233	('bindir', 'binary directory', '${prefix}/bin'),
234	('sbindir', 'binary directory', '${prefix}/sbin'),
235	('libdir', 'library directory', '${prefix}/lib'),
236	PathVariable('CC', 'path to the c-compiler', None),
237	BoolVariable('build_dynamic', 'enable dynamic build', 'yes'),
238	BoolVariable('build_static', 'enable static build', 'no'),
239	BoolVariable('build_fullstatic', 'enable fullstatic build', 'no'),
240
241	BoolVariable('with_bzip2', 'enable bzip2 compression', 'no'),
242	BoolVariable('with_brotli', 'enable brotli compression', 'no'),
243	PackageVariable('with_dbi', 'enable dbi support', 'no'),
244	BoolVariable('with_fam', 'enable FAM/gamin support', 'no'),
245	BoolVariable('with_gdbm', 'enable gdbm support', 'no'),
246	BoolVariable('with_geoip', 'enable GeoIP support', 'no'),
247	BoolVariable('with_maxminddb', 'enable MaxMind GeoIP2 support', 'no'),
248	BoolVariable('with_krb5', 'enable krb5 auth support', 'no'),
249	BoolVariable('with_ldap', 'enable ldap auth support', 'no'),
250	# with_libev not supported
251	# with_libunwind not supported
252	BoolVariable('with_lua', 'enable lua support for mod_cml', 'no'),
253	BoolVariable('with_memcached', 'enable memcached support', 'no'),
254	PackageVariable('with_mysql', 'enable mysql support', 'no'),
255	BoolVariable('with_openssl', 'enable openssl support', 'no'),
256	PackageVariable('with_gnutls', 'enable GnuTLS support', 'no'),
257	PackageVariable('with_mbedtls', 'enable mbedTLS support', 'no'),
258	PackageVariable('with_nss', 'enable NSS crypto support', 'no'),
259	PackageVariable('with_wolfssl', 'enable wolfSSL support', 'no'),
260	BoolVariable('with_nettle', 'enable Nettle support', 'no'),
261	BoolVariable('with_pam', 'enable PAM auth support', 'no'),
262	PackageVariable('with_pcre', 'enable pcre support', 'yes'),
263	PackageVariable('with_pgsql', 'enable pgsql support', 'no'),
264	PackageVariable('with_sasl', 'enable SASL support', 'no'),
265	BoolVariable('with_sqlite3', 'enable sqlite3 support (required for webdav props)', 'no'),
266	BoolVariable('with_uuid', 'enable uuid support (required for webdav locks)', 'no'),
267	# with_valgrind not supported
268	# with_xattr not supported
269	PackageVariable('with_xml', 'enable xml support (required for webdav props)', 'no'),
270	BoolVariable('with_zlib', 'enable deflate/gzip compression', 'no'),
271
272	BoolVariable('with_all', 'enable all with_* features', 'no'),
273)
274
275env = Environment(
276	ENV = dict(os.environ),  # make sure we have a dict here so .Clone() works properly
277	variables = vars,
278	CPPPATH = Split('#sconsbuild/build')
279)
280
281env.Help(vars.GenerateHelpText(env))
282
283if env.subst('${CC}') != '':
284	env['CC'] = env.subst('${CC}')
285
286env['package'] = package
287env['version'] = version
288if env['CC'] == 'gcc':
289	## we need x-open 6 and bsd 4.3 features
290	env.Append(CCFLAGS = Split('-Wall -O2 -g -W -pedantic -Wunused -Wshadow -std=gnu99'))
291
292env.Append(CPPFLAGS = [
293	'-D_FILE_OFFSET_BITS=64',
294	'-D_LARGEFILE_SOURCE',
295	'-D_LARGE_FILES',
296	'-D_GNU_SOURCE',
297])
298
299if env['with_all']:
300	for feature in vars.keys():
301		# only enable 'with_*' flags
302		if not feature.startswith('with_'): continue
303		# don't overwrite manual arguments
304		if feature in vars.args: continue
305		# now activate
306		env[feature] = True
307
308# cache configure checks
309if 1:
310	autoconf = Autoconf(env)
311
312	if 'CFLAGS' in os.environ:
313		autoconf.env.Append(CCFLAGS = os.environ['CFLAGS'])
314		print(">> Appending custom build flags : " + os.environ['CFLAGS'])
315
316	if 'LDFLAGS' in os.environ:
317		autoconf.env.Append(LINKFLAGS = os.environ['LDFLAGS'])
318		print(">> Appending custom link flags : " + os.environ['LDFLAGS'])
319
320	if 'LIBS' in os.environ:
321		autoconf.env.Append(APPEND_LIBS = os.environ['LIBS'])
322		print(">> Appending custom libraries : " + os.environ['LIBS'])
323	else:
324		autoconf.env.Append(APPEND_LIBS = '')
325
326	autoconf.env.Append(
327		LIBBROTLI = '',
328		LIBBZ2 = '',
329		LIBCRYPT = '',
330		LIBCRYPTO = '',
331		LIBDBI = '',
332		LIBDL = '',
333		LIBFCGI = '',
334		LIBGDBM = '',
335		LIBGNUTLS = '',
336		LIBGSSAPI_KRB5 = '',
337		LIBKRB5 = '',
338		LIBLBER = '',
339		LIBLDAP = '',
340		LIBLUA = '',
341		LIBMEMCACHED = '',
342		LIBMYSQL = '',
343		LIBNSS = '',
344		LIBPAM = '',
345		LIBPCRE = '',
346		LIBPGSQL = '',
347		LIBSASL = '',
348		LIBSQLITE3 = '',
349		LIBSSL = '',
350		LIBUUID = '',
351		LIBX509 = '',
352		LIBXML2 = '',
353		LIBZ = '',
354	)
355
356	autoconf.haveCHeaders([
357		'arpa/inet.h',
358		'crypt.h',
359		'fcntl.h',
360		'getopt.h',
361		'inttypes.h',
362		'linux/random.h',
363		'poll.h',
364		'pwd.h',
365		'stdint.h',
366		'stdlib.h',
367		'string.h',
368		'strings.h',
369		'sys/devpoll.h',
370		'sys/epoll.h',
371		'sys/filio.h',
372		'sys/loadavg.h',
373		'sys/poll.h',
374		'sys/port.h',
375		'sys/prctl.h',
376		'sys/sendfile.h',
377		'sys/time.h',
378		'sys/wait.h',
379		'syslog.h',
380		'unistd.h',
381		'winsock2.h',
382
383		# "have" the last header if we include others before?
384		['sys/types.h', 'sys/time.h', 'sys/resource.h'],
385		['sys/types.h', 'netinet/in.h'],
386		['sys/types.h', 'sys/event.h'],
387		['sys/types.h', 'sys/mman.h'],
388		['sys/types.h', 'sys/select.h'],
389		['sys/types.h', 'sys/socket.h'],
390		['sys/types.h', 'sys/uio.h'],
391		['sys/types.h', 'sys/un.h'],
392	])
393
394	autoconf.haveFuncs([
395		'arc4random_buf',
396		'chroot',
397		'clock_gettime',
398		'copy_file_range',
399		'dup2',
400		'epoll_ctl',
401		'explicit_bzero',
402		'explicit_memset',
403		'fork',
404		'getcwd',
405		'gethostbyname',
406		'getloadavg',
407		'getopt',
408		'getrlimit',
409		'getuid',
410		'inet_ntoa',
411		'inet_ntop',
412		'inet_pton',
413		'issetugid',
414		'jrand48',
415		'kqueue',
416		'localtime_r',
417		'lstat',
418		'madvise',
419		'memset_s',
420		'memset',
421		'mmap',
422		'munmap',
423		'pathconf',
424		'pipe2',
425		'poll',
426		'port_create',
427		'posix_fadvise',
428		'prctl',
429		'select',
430		'send_file',
431		'sendfile',
432		'sendfile64',
433		'sigaction',
434		'signal',
435		'socket',
436		'srandom',
437		'stat',
438		'strchr',
439		'strdup',
440		'strerror',
441		'strftime',
442		'strstr',
443		'strtol',
444		'writev',
445	])
446	autoconf.haveFunc('getentropy', 'sys/random.h')
447	autoconf.haveFunc('getrandom', 'linux/random.h')
448
449	autoconf.haveTypes(Split('pid_t size_t off_t'))
450
451	# have crypt_r/crypt, and is -lcrypt needed?
452	if autoconf.CheckLib('crypt'):
453		autoconf.env.Append(
454			CPPFLAGS = [ '-DHAVE_LIBCRYPT' ],
455			LIBCRYPT = 'crypt',
456		)
457		with autoconf.restoreEnvLibs():
458			autoconf.env['LIBS'] = ['crypt']
459			autoconf.haveFuncs(['crypt', 'crypt_r'])
460	else:
461		autoconf.haveFuncs(['crypt', 'crypt_r'])
462
463	if autoconf.CheckType('socklen_t', '#include <unistd.h>\n#include <sys/socket.h>\n#include <sys/types.h>'):
464		autoconf.env.Append(CPPFLAGS = [ '-DHAVE_SOCKLEN_T' ])
465
466	if autoconf.CheckType('struct sockaddr_storage', '#include <sys/socket.h>\n'):
467		autoconf.env.Append(CPPFLAGS = [ '-DHAVE_STRUCT_SOCKADDR_STORAGE' ])
468
469	if autoconf.CheckLibWithHeader('elftc', 'libelftc.h', 'c', 'elftc_copyfile(0, 1);'):
470		autoconf.env.Append(
471			CPPFLAGS = [ '-DHAVE_ELFTC_COPYFILE' ],
472			LIBS = [ 'elftc' ],
473		)
474
475	if autoconf.CheckLibWithHeader('rt', 'time.h', 'c', 'clock_gettime(CLOCK_MONOTONIC, (struct timespec*)0);'):
476		autoconf.env.Append(
477			CPPFLAGS = [ '-DHAVE_CLOCK_GETTIME' ],
478			LIBS = [ 'rt' ],
479		)
480
481	if autoconf.CheckIPv6():
482		autoconf.env.Append(CPPFLAGS = [ '-DHAVE_IPV6' ])
483
484	if autoconf.CheckWeakSymbols():
485		autoconf.env.Append(CPPFLAGS = [ '-DHAVE_WEAK_SYMBOLS' ])
486
487	if autoconf.CheckGmtOffInStructTm():
488		autoconf.env.Append(CPPFLAGS = [ '-DHAVE_STRUCT_TM_GMTOFF' ])
489
490	if autoconf.CheckLibWithHeader('dl', 'dlfcn.h', 'C'):
491		autoconf.env.Append(LIBDL = 'dl')
492
493	# used in tests if present
494	if autoconf.CheckLibWithHeader('fcgi', 'fastcgi.h', 'C'):
495		autoconf.env.Append(LIBFCGI = 'fcgi')
496
497	if env['with_bzip2']:
498		if not autoconf.CheckLibWithHeader('bz2', 'bzlib.h', 'C'):
499			fail("Couldn't find bz2")
500		autoconf.env.Append(
501			CPPFLAGS = [ '-DHAVE_BZLIB_H', '-DHAVE_LIBBZ2' ],
502			LIBBZ2 = 'bz2',
503		)
504
505	if env['with_brotli']:
506		if not autoconf.CheckParseConfigForLib('LIBBROTLI', 'pkg-config --static --cflags --libs libbrotlienc'):
507			fail("Couldn't find libbrotlienc")
508		autoconf.env.Append(
509			CPPFLAGS = [ '-DHAVE_BROTLI_ENCODE_H', '-DHAVE_BROTLI' ],
510		)
511
512	if env['with_dbi']:
513		if not autoconf.CheckLibWithHeader('dbi', 'dbi/dbi.h', 'C'):
514			fail("Couldn't find dbi")
515		autoconf.env.Append(
516			CPPFLAGS = [ '-DHAVE_DBI_H', '-DHAVE_LIBDBI' ],
517			LIBDBI = 'dbi',
518		)
519
520	if env['with_fam']:
521		if not autoconf.CheckLibWithHeader('fam', 'fam.h', 'C'):
522			fail("Couldn't find fam")
523		autoconf.env.Append(
524			CPPFLAGS = [ '-DHAVE_FAM_H', '-DHAVE_LIBFAM' ],
525			LIBS = [ 'fam' ],
526		)
527		autoconf.haveFunc('FAMNoExists')
528
529	if env['with_gdbm']:
530		if not autoconf.CheckLibWithHeader('gdbm', 'gdbm.h', 'C'):
531			fail("Couldn't find gdbm")
532		autoconf.env.Append(
533			CPPFLAGS = [ '-DHAVE_GDBM_H', '-DHAVE_GDBM' ],
534			LIBGDBM = 'gdbm',
535		)
536
537	if env['with_geoip']:
538		if not autoconf.CheckLibWithHeader('GeoIP', 'GeoIP.h', 'C'):
539			fail("Couldn't find geoip")
540		autoconf.env.Append(
541			CPPFLAGS = [ '-DHAVE_GEOIP' ],
542			LIBGEOIP = 'GeoIP',
543		)
544
545	if env['with_maxminddb']:
546		if not autoconf.CheckLibWithHeader('maxminddb', 'maxminddb.h', 'C'):
547			fail("Couldn't find maxminddb")
548		autoconf.env.Append(
549			CPPFLAGS = [ '-DHAVE_MAXMINDDB' ],
550			LIBMAXMINDDB = 'maxminddb',
551		)
552
553	if env['with_krb5']:
554		if not autoconf.CheckLibWithHeader('krb5', 'krb5.h', 'C'):
555			fail("Couldn't find krb5")
556		if not autoconf.CheckLibWithHeader('gssapi_krb5', 'gssapi/gssapi_krb5.h', 'C'):
557			fail("Couldn't find gssapi_krb5")
558		autoconf.env.Append(
559			CPPFLAGS = [ '-DHAVE_KRB5' ],
560			LIBKRB5 = 'krb5',
561			LIBGSSAPI_KRB5 = 'gssapi_krb5',
562		)
563
564	if env['with_ldap']:
565		if not autoconf.CheckLibWithHeader('ldap', 'ldap.h', 'C'):
566			fail("Couldn't find ldap")
567		if not autoconf.CheckLibWithHeader('lber', 'lber.h', 'C'):
568			fail("Couldn't find lber")
569		autoconf.env.Append(
570			CPPFLAGS = [
571				'-DHAVE_LDAP_H', '-DHAVE_LIBLDAP',
572				'-DHAVE_LBER_H', '-DHAVE_LIBLBER',
573			],
574			LIBLDAP = 'ldap',
575			LIBLBER = 'lber',
576		)
577
578	if env['with_lua']:
579		found_lua = False
580		for lua_name in ['lua5.3', 'lua-5.3', 'lua5.2', 'lua-5.2', 'lua5.1', 'lua-5.1', 'lua']:
581			print("Searching for lua: " + lua_name + " >= 5.0")
582			if autoconf.CheckParseConfigForLib('LIBLUA', "pkg-config '" + lua_name + " >= 5.0' --cflags --libs"):
583				autoconf.env.Append(CPPFLAGS = [ '-DHAVE_LUA_H' ])
584				found_lua = True
585				break
586		if not found_lua:
587			fail("Couldn't find any lua implementation")
588
589	if env['with_memcached']:
590		if not autoconf.CheckLibWithHeader('memcached', 'libmemcached/memcached.h', 'C'):
591			fail("Couldn't find memcached")
592		autoconf.env.Append(
593			CPPFLAGS = [ '-DUSE_MEMCACHED' ],
594			LIBMEMCACHED = 'memcached',
595		)
596
597	if env['with_mysql']:
598		mysql_config = autoconf.checkProgram('mysql', 'mysql_config')
599		if not autoconf.CheckParseConfigForLib('LIBMYSQL', mysql_config + ' --cflags --libs'):
600			fail("Couldn't find mysql")
601		autoconf.env.Append(CPPFLAGS = [ '-DHAVE_MYSQL_H', '-DHAVE_LIBMYSQL' ])
602
603	if env['with_nss']:
604		nss_config = autoconf.checkProgram('nss', 'nss-config')
605		if not autoconf.CheckParseConfigForLib('LIBNSS', nss_config + ' --cflags --libs'):
606			fail("Couldn't find NSS")
607		autoconf.env.Append(CPPFLAGS = [ '-DHAVE_NSS3_NSS_H' ])
608
609	if env['with_openssl']:
610		if not autoconf.CheckLibWithHeader('ssl', 'openssl/ssl.h', 'C'):
611			fail("Couldn't find openssl")
612		autoconf.env.Append(
613			CPPFLAGS = [ '-DHAVE_OPENSSL_SSL_H', '-DHAVE_LIBSSL'],
614			LIBSSL = 'ssl',
615			LIBCRYPTO = 'crypto',
616		)
617
618	if env['with_wolfssl']:
619		if type(env['with_wolfssl']) is str:
620			autoconf.env.AppendUnique(
621				CPPPATH = [ env['with_wolfssl'] + '/include',
622					    env['with_wolfssl'] + '/include/wolfssl' ],
623				LIBPATH = [ env['with_wolfssl'] + '/lib' ],
624			)
625		if not autoconf.CheckLibWithHeader('wolfssl', 'wolfssl/ssl.h', 'C'):
626			fail("Couldn't find wolfssl")
627		autoconf.env.Append(
628			CPPFLAGS = [ '-DHAVE_WOLFSSL_SSL_H' ],
629			LIBSSL = '',
630			LIBCRYPTO = 'wolfssl',
631		)
632
633	if env['with_mbedtls']:
634		if not autoconf.CheckLibWithHeader('mbedtls', 'mbedtls/ssl.h', 'C'):
635			fail("Couldn't find mbedtls")
636		autoconf.env.Append(
637			CPPFLAGS = [ '-DHAVE_LIBMBEDCRYPTO' ],
638			LIBSSL = 'mbedtls',
639			LIBX509 = 'mbedx509',
640			LIBCRYPTO = 'mbedcrypto',
641		)
642
643	if env['with_nettle']:
644		if not autoconf.CheckLibWithHeader('nettle', 'nettle/nettle-types.h', 'C'):
645			fail("Couldn't find Nettle")
646		autoconf.env.Append(
647			CPPFLAGS = [ '-DHAVE_NETTLE_NETTLE_TYPES_H' ],
648			LIBCRYPTO = 'nettle',
649		)
650
651	if env['with_gnutls']:
652		if not autoconf.CheckLibWithHeader('gnutls', 'gnutls/crypto.h', 'C'):
653			fail("Couldn't find gnutls")
654		autoconf.env.Append(
655			CPPFLAGS = [ '-DHAVE_GNUTLS_CRYPTO_H' ],
656			LIBGNUTLS = 'gnutls',
657		)
658		if not autoconf.env.exists('LIBCRYPTO'):
659			autoconf.env.Append(
660				LIBCRYPTO = 'gnutls',
661			)
662
663	if env['with_pam']:
664		if not autoconf.CheckLibWithHeader('pam', 'security/pam_appl.h', 'C'):
665			fail("Couldn't find pam")
666		autoconf.env.Append(
667			CPPFLAGS = [ '-DHAVE_PAM' ],
668			LIBPAM = 'pam',
669		)
670
671	if env['with_pcre']:
672		pcre_config = autoconf.checkProgram('pcre', 'pcre-config')
673		if not autoconf.CheckParseConfigForLib('LIBPCRE', pcre_config + ' --cflags --libs'):
674			fail("Couldn't find pcre")
675		autoconf.env.Append(CPPFLAGS = [ '-DHAVE_PCRE_H', '-DHAVE_LIBPCRE' ])
676
677	if env['with_pgsql']:
678		if not autoconf.CheckParseConfigForLib('LIBPGSQL', 'pkg-config libpq --cflags --libs'):
679			fail("Couldn't find libpq")
680		autoconf.env.Append(CPPFLAGS = [ '-DHAVE_PGSQL_H', '-DHAVE_LIBPGSQL' ])
681
682	if env['with_sasl']:
683		if not autoconf.CheckLibWithHeader('sasl2', 'sasl/sasl.h', 'C'):
684			fail("Couldn't find libsasl2")
685		autoconf.env.Append(
686			CPPFLAGS = [ '-DHAVE_SASL' ],
687			LIBSASL = 'sasl2',
688		)
689
690	if env['with_sqlite3']:
691		if not autoconf.CheckLibWithHeader('sqlite3', 'sqlite3.h', 'C'):
692			fail("Couldn't find sqlite3")
693		autoconf.env.Append(
694			CPPFLAGS = [ '-DHAVE_SQLITE3_H', '-DHAVE_LIBSQLITE3' ],
695			LIBSQLITE3 = 'sqlite3',
696		)
697
698	if env['with_uuid']:
699		if not autoconf.CheckLibWithHeader('uuid', 'uuid/uuid.h', 'C'):
700			fail("Couldn't find uuid")
701		autoconf.env.Append(
702			CPPFLAGS = [ '-DHAVE_UUID_UUID_H', '-DHAVE_LIBUUID' ],
703			LIBUUID = 'uuid',
704		)
705
706	if env['with_xml']:
707		xml2_config = autoconf.checkProgram('xml', 'xml2-config')
708		if not autoconf.CheckParseConfigForLib('LIBXML2', xml2_config + ' --cflags --libs'):
709			fail("Couldn't find xml2")
710		autoconf.env.Append(CPPFLAGS = [ '-DHAVE_LIBXML_H', '-DHAVE_LIBXML2' ])
711
712	if env['with_zlib']:
713		if not autoconf.CheckLibWithHeader('z', 'zlib.h', 'C'):
714			fail("Couldn't find zlib")
715		autoconf.env.Append(
716			CPPFLAGS = [ '-DHAVE_ZLIB_H', '-DHAVE_LIBZ' ],
717			LIBZ = 'z',
718		)
719
720	env = autoconf.Finish()
721
722if re.compile("cygwin|mingw|midipix").search(env['PLATFORM']):
723	env.Append(COMMON_LIB = 'bin')
724elif re.compile("darwin|aix").search(env['PLATFORM']):
725	env.Append(COMMON_LIB = 'lib')
726else:
727	env.Append(COMMON_LIB = False)
728
729versions = version.split('.')
730version_id = int(versions[0]) << 16 | int(versions[1]) << 8 | int(versions[2])
731env.Append(CPPFLAGS = [
732		'-DLIGHTTPD_VERSION_ID=' + hex(version_id),
733		'-DPACKAGE_NAME=\\"' + package + '\\"',
734		'-DPACKAGE_VERSION=\\"' + version + '\\"',
735		'-DLIBRARY_DIR="\\"${libdir}\\""',
736		] )
737
738SConscript('src/SConscript', exports = 'env', variant_dir = 'sconsbuild/build', duplicate = 0)
739SConscript('tests/SConscript', exports = 'env', variant_dir = 'sconsbuild/tests')
740