[core] inline chunkqueue_is_empty()
[lighttpd.git] / SConstruct
blobabd55667db661291db8b83ff712f4fd65860b6af
1 import os
2 import sys
3 import re
4 import string
5 from stat import *
7 package = 'lighttpd'
8 version = '1.4.46'
10 def checkCHeaders(autoconf, hdrs):
11 p = re.compile('[^A-Z0-9]')
12 for hdr in hdrs:
13 if not hdr:
14 continue
15 _hdr = Split(hdr)
16 if autoconf.CheckCHeader(_hdr):
17 autoconf.env.Append(CPPFLAGS = [ '-DHAVE_' + p.sub('_', _hdr[-1].upper()) ])
19 def checkFunc(autoconf, func, header):
20 p = re.compile('[^A-Z0-9]')
21 if autoconf.CheckFunc(func, header):
22 autoconf.env.Append(CPPFLAGS = [ '-DHAVE_' + p.sub('_', func.upper()) ])
24 def checkFuncs(autoconf, funcs):
25 p = re.compile('[^A-Z0-9]')
26 for func in funcs:
27 if autoconf.CheckFunc(func):
28 autoconf.env.Append(CPPFLAGS = [ '-DHAVE_' + p.sub('_', func.upper()) ])
30 def checkTypes(autoconf, types):
31 p = re.compile('[^A-Z0-9]')
32 for type in types:
33 if autoconf.CheckType(type, '#include <sys/types.h>'):
34 autoconf.env.Append(CPPFLAGS = [ '-DHAVE_' + p.sub('_', type.upper()) ])
36 def checkGmtOffInStructTm(context):
37 source = """
38 #include <time.h>
39 int main() {
40 struct tm a;
41 a.tm_gmtoff = 0;
42 return 0;
44 """
45 context.Message('Checking for tm_gmtoff in struct tm...')
46 result = context.TryLink(source, '.c')
47 context.Result(result)
49 return result
51 def checkIPv6(context):
52 source = """
53 #include <sys/types.h>
54 #include <sys/socket.h>
55 #include <netinet/in.h>
57 int main() {
58 struct sockaddr_in6 s; struct in6_addr t=in6addr_any; int i=AF_INET6; s; t.s6_addr[0] = 0;
59 return 0;
61 """
62 context.Message('Checking for IPv6 support...')
63 result = context.TryLink(source, '.c')
64 context.Result(result)
66 return result
68 def checkWeakSymbols(context):
69 source = """
70 __attribute__((weak)) void __dummy(void *x) { }
71 int main() {
72 void *x;
73 __dummy(x);
75 """
76 context.Message('Checking for weak symbol support...')
77 result = context.TryLink(source, '.c')
78 context.Result(result)
80 return result
82 def checkProgram(env, withname, progname):
83 withname = 'with_' + withname
84 binpath = None
86 if env[withname] != 1:
87 binpath = env[withname]
88 else:
89 prog = env.Detect(progname)
90 if prog:
91 binpath = env.WhereIs(prog)
93 if binpath:
94 mode = os.stat(binpath)[ST_MODE]
95 if S_ISDIR(mode):
96 print >> sys.stderr, "* error: path `%s' is a directory" % (binpath)
97 env.Exit(-1)
98 if not S_ISREG(mode):
99 print >> sys.stderr, "* error: path `%s' is not a file or not exists" % (binpath)
100 env.Exit(-1)
102 if not binpath:
103 print >> sys.stderr, "* error: can't find program `%s'" % (progname)
104 env.Exit(-1)
106 return binpath
108 VariantDir('sconsbuild/build', 'src', duplicate = 0)
109 VariantDir('sconsbuild/tests', 'tests', duplicate = 0)
111 vars = Variables() #('config.py')
112 vars.AddVariables(
113 ('prefix', 'prefix', '/usr/local'),
114 ('bindir', 'binary directory', '${prefix}/bin'),
115 ('sbindir', 'binary directory', '${prefix}/sbin'),
116 ('libdir', 'library directory', '${prefix}/lib'),
117 PackageVariable('with_mysql', 'enable mysql support', 'no'),
118 PackageVariable('with_pgsql', 'enable pgsql support', 'no'),
119 PackageVariable('with_dbi', 'enable dbi support', 'no'),
120 PackageVariable('with_xml', 'enable xml support', 'no'),
121 PackageVariable('with_pcre', 'enable pcre support', 'yes'),
122 PathVariable('CC', 'path to the c-compiler', None),
123 BoolVariable('build_dynamic', 'enable dynamic build', 'yes'),
124 BoolVariable('build_static', 'enable static build', 'no'),
125 BoolVariable('build_fullstatic', 'enable fullstatic build', 'no'),
126 BoolVariable('with_sqlite3', 'enable sqlite3 support', 'no'),
127 BoolVariable('with_memcached', 'enable memcached support', 'no'),
128 BoolVariable('with_gdbm', 'enable gdbm support', 'no'),
129 BoolVariable('with_fam', 'enable FAM/gamin support', 'no'),
130 BoolVariable('with_openssl', 'enable openssl support', 'no'),
131 BoolVariable('with_gzip', 'enable gzip compression', 'no'),
132 BoolVariable('with_bzip2', 'enable bzip2 compression', 'no'),
133 BoolVariable('with_lua', 'enable lua support for mod_cml', 'no'),
134 BoolVariable('with_ldap', 'enable ldap auth support', 'no'),
135 BoolVariable('with_krb5', 'enable krb5 auth support', 'no'),
136 BoolVariable('with_geoip', 'enable GeoIP support', 'no')
139 env = Environment(
140 ENV = os.environ,
141 variables = vars,
142 CPPPATH = Split('#sconsbuild/build')
145 env.Help(vars.GenerateHelpText(env))
147 if env.subst('${CC}') is not '':
148 env['CC'] = env.subst('${CC}')
150 env['package'] = package
151 env['version'] = version
152 if env['CC'] == 'gcc':
153 ## we need x-open 6 and bsd 4.3 features
154 env.Append(CCFLAGS = Split('-Wall -O2 -g -W -pedantic -Wunused -Wshadow -std=gnu99'))
156 # cache configure checks
157 if 1:
158 autoconf = Configure(env, custom_tests = {
159 'CheckGmtOffInStructTm': checkGmtOffInStructTm,
160 'CheckIPv6': checkIPv6,
161 'CheckWeakSymbols': checkWeakSymbols,
164 if 'CFLAGS' in os.environ:
165 autoconf.env.Append(CCFLAGS = os.environ['CFLAGS'])
166 print(">> Appending custom build flags : " + os.environ['CFLAGS'])
168 if 'LDFLAGS' in os.environ:
169 autoconf.env.Append(LINKFLAGS = os.environ['LDFLAGS'])
170 print(">> Appending custom link flags : " + os.environ['LDFLAGS'])
172 if 'LIBS' in os.environ:
173 autoconf.env.Append(APPEND_LIBS = os.environ['LIBS'])
174 print(">> Appending custom libraries : " + os.environ['LIBS'])
175 else:
176 autoconf.env.Append(APPEND_LIBS = '')
178 autoconf.headerfile = "foo.h"
179 checkCHeaders(autoconf, string.split("""
180 arpa/inet.h
181 crypt.h
182 fcntl.h
183 getopt.h
184 inttypes.h
185 linux/random.h
186 netinet/in.h
187 poll.h
188 pwd.h
189 stdint.h
190 stdlib.h
191 string.h
192 strings.h
193 sys/devpoll.h
194 sys/epoll.h
195 sys/event.h
196 sys/filio.h
197 sys/mman.h
198 sys/poll.h
199 sys/port.h
200 sys/prctl.h
201 sys/resource.h
202 sys/select.h
203 sys/sendfile.h
204 sys/socket.h
205 sys/time.h
206 sys/time.h sys/types.h sys/resource.h
207 sys/types.h netinet/in.h
208 sys/types.h sys/event.h
209 sys/types.h sys/mman.h
210 sys/types.h sys/select.h
211 sys/types.h sys/socket.h
212 sys/types.h sys/uio.h
213 sys/types.h sys/un.h
214 sys/uio.h
215 sys/un.h
216 sys/wait.h
217 syslog.h
218 unistd.h
219 winsock2.h""", "\n"))
221 checkFuncs(autoconf, Split('fork stat lstat strftime dup2 getcwd inet_ntoa inet_ntop memset mmap munmap strchr \
222 strdup strerror strstr strtol sendfile getopt socket \
223 gethostbyname poll epoll_ctl getrlimit chroot \
224 getuid select signal pathconf madvise prctl\
225 writev sigaction sendfile64 send_file kqueue port_create localtime_r posix_fadvise issetugid inet_pton \
226 memset_s explicit_bzero clock_gettime pipe2 \
227 arc4random_buf jrand48 srandom getloadavg'))
228 checkFunc(autoconf, 'getentropy', 'sys/random.h')
229 checkFunc(autoconf, 'getrandom', 'linux/random.h')
231 checkTypes(autoconf, Split('pid_t size_t off_t'))
233 autoconf.env.Append( LIBSQLITE3 = '', LIBXML2 = '', LIBMYSQL = '', LIBZ = '',
234 LIBPGSQL = '', LIBDBI = '',
235 LIBBZ2 = '', LIBCRYPT = '', LIBMEMCACHED = '', LIBFCGI = '', LIBPCRE = '',
236 LIBLDAP = '', LIBLBER = '', LIBLUA = '', LIBDL = '', LIBUUID = '',
237 LIBKRB5 = '', LIBGSSAPI_KRB5 = '', LIBGDBM = '', LIBSSL = '', LIBCRYPTO = '')
239 if env['with_fam']:
240 if autoconf.CheckLibWithHeader('fam', 'fam.h', 'C'):
241 autoconf.env.Append(CPPFLAGS = [ '-DHAVE_FAM_H', '-DHAVE_LIBFAM' ], LIBS = 'fam')
242 checkFuncs(autoconf, ['FAMNoExists']);
244 if autoconf.CheckLib('crypt'):
245 autoconf.env.Append(CPPFLAGS = [ '-DHAVE_LIBCRYPT' ], LIBCRYPT = 'crypt')
246 oldlib = env['LIBS']
247 env['LIBS'] += ['crypt']
248 checkFuncs(autoconf, ['crypt', 'crypt_r']);
249 env['LIBS'] = oldlib
250 else:
251 checkFuncs(autoconf, ['crypt', 'crypt_r']);
253 if autoconf.CheckLibWithHeader('rt', 'time.h', 'c', 'clock_gettime(CLOCK_MONOTONIC, (struct timespec*)0);'):
254 autoconf.env.Append(CPPFLAGS = [ '-DHAVE_CLOCK_GETTIME' ], LIBS = [ 'rt' ])
256 if autoconf.CheckLibWithHeader('uuid', 'uuid/uuid.h', 'C'):
257 autoconf.env.Append(CPPFLAGS = [ '-DHAVE_UUID_UUID_H', '-DHAVE_LIBUUID' ], LIBUUID = 'uuid')
259 if env['with_openssl']:
260 if autoconf.CheckLibWithHeader('ssl', 'openssl/ssl.h', 'C'):
261 autoconf.env.Append(CPPFLAGS = [ '-DHAVE_OPENSSL_SSL_H', '-DHAVE_LIBSSL'] , LIBSSL = 'ssl', LIBCRYPTO = 'crypto', LIBS = [ 'crypto' ])
263 if env['with_gzip']:
264 if autoconf.CheckLibWithHeader('z', 'zlib.h', 'C'):
265 autoconf.env.Append(CPPFLAGS = [ '-DHAVE_ZLIB_H', '-DHAVE_LIBZ' ], LIBZ = 'z')
267 if env['with_krb5']:
268 if autoconf.CheckLibWithHeader('krb5', 'krb5.h', 'C'):
269 autoconf.env.Append(CPPFLAGS = [ '-DHAVE_KRB5' ], LIBKRB5 = 'krb5')
270 if autoconf.CheckLibWithHeader('gssapi_krb5', 'gssapi/gssapi_krb5.h', 'C'):
271 autoconf.env.Append(LIBGSSAPI_KRB5 = 'gssapi_krb5')
273 if env['with_ldap']:
274 if autoconf.CheckLibWithHeader('ldap', 'ldap.h', 'C'):
275 autoconf.env.Append(CPPFLAGS = [ '-DHAVE_LDAP_H', '-DHAVE_LIBLDAP' ], LIBLDAP = 'ldap')
276 if autoconf.CheckLibWithHeader('lber', 'lber.h', 'C'):
277 autoconf.env.Append(CPPFLAGS = [ '-DHAVE_LBER_H', '-DHAVE_LIBLBER' ], LIBLBER = 'lber')
279 if env['with_bzip2']:
280 if autoconf.CheckLibWithHeader('bz2', 'bzlib.h', 'C'):
281 autoconf.env.Append(CPPFLAGS = [ '-DHAVE_BZLIB_H', '-DHAVE_LIBBZ2' ], LIBBZ2 = 'bz2')
283 if env['with_memcached']:
284 if autoconf.CheckLibWithHeader('memcached', 'libmemcached/memcached.h', 'C'):
285 autoconf.env.Append(CPPFLAGS = [ '-DUSE_MEMCACHED' ], LIBMEMCACHED = 'memcached')
287 if env['with_gdbm']:
288 if autoconf.CheckLibWithHeader('gdbm', 'gdbm.h', 'C'):
289 autoconf.env.Append(CPPFLAGS = [ '-DHAVE_GDBM_H', '-DHAVE_GDBM' ], LIBGDBM = 'gdbm')
291 if env['with_sqlite3']:
292 if autoconf.CheckLibWithHeader('sqlite3', 'sqlite3.h', 'C'):
293 autoconf.env.Append(CPPFLAGS = [ '-DHAVE_SQLITE3_H', '-DHAVE_LIBSQLITE3' ], LIBSQLITE3 = 'sqlite3')
295 if env['with_geoip']:
296 if autoconf.CheckLibWithHeader('GeoIP', 'GeoIP.h', 'C'):
297 autoconf.env.Append(CPPFLAGS = [ '-DHAVE_GEOIP' ], LIBGEOIP = 'GeoIP')
299 ol = env['LIBS']
300 if autoconf.CheckLibWithHeader('fcgi', 'fastcgi.h', 'C'):
301 autoconf.env.Append(LIBFCGI = 'fcgi')
302 env['LIBS'] = ol
304 ol = env['LIBS']
305 if autoconf.CheckLibWithHeader('dl', 'dlfcn.h', 'C'):
306 autoconf.env.Append(LIBDL = 'dl')
307 env['LIBS'] = ol
309 if autoconf.CheckType('socklen_t', '#include <unistd.h>\n#include <sys/socket.h>\n#include <sys/types.h>'):
310 autoconf.env.Append(CPPFLAGS = [ '-DHAVE_SOCKLEN_T' ])
312 if autoconf.CheckType('struct sockaddr_storage', '#include <sys/socket.h>\n'):
313 autoconf.env.Append(CPPFLAGS = [ '-DHAVE_STRUCT_SOCKADDR_STORAGE' ])
315 if autoconf.CheckGmtOffInStructTm():
316 autoconf.env.Append(CPPFLAGS = [ '-DHAVE_STRUCT_TM_GMTOFF' ])
318 if autoconf.CheckIPv6():
319 autoconf.env.Append(CPPFLAGS = [ '-DHAVE_IPV6' ])
321 if autoconf.CheckWeakSymbols():
322 autoconf.env.Append(CPPFLAGS = [ '-DHAVE_WEAK_SYMBOLS' ])
324 env = autoconf.Finish()
326 def TryLua(env, name):
327 result = False
328 oldlibs = env['LIBS']
329 try:
330 print("Searching for lua: " + name + " >= 5.0")
331 env.ParseConfig("pkg-config '" + name + " >= 5.0' --cflags --libs")
332 env.Append(LIBLUA = env['LIBS'][len(oldlibs):])
333 env.Append(CPPFLAGS = [ '-DHAVE_LUA_H' ])
334 result = True
335 except:
336 pass
337 env['LIBS'] = oldlibs
338 return result
340 if env['with_lua']:
341 found_lua = False
342 for lua_name in ['lua5.3', 'lua-5.3', 'lua5.2', 'lua-5.2', 'lua5.1', 'lua-5.1', 'lua']:
343 if TryLua(env, lua_name):
344 found_lua = True
345 break
346 if not found_lua:
347 raise RuntimeError("Couldn't find any lua implementation")
349 if env['with_pcre']:
350 pcre_config = checkProgram(env, 'pcre', 'pcre-config')
351 env.ParseConfig(pcre_config + ' --cflags --libs')
352 env.Append(CPPFLAGS = [ '-DHAVE_PCRE_H', '-DHAVE_LIBPCRE' ], LIBPCRE = 'pcre')
354 if env['with_xml']:
355 xml2_config = checkProgram(env, 'xml', 'xml2-config')
356 oldlib = env['LIBS']
357 env['LIBS'] = []
358 env.ParseConfig(xml2_config + ' --cflags --libs')
359 env.Append(CPPFLAGS = [ '-DHAVE_LIBXML_H', '-DHAVE_LIBXML2' ], LIBXML2 = env['LIBS'])
360 env['LIBS'] = oldlib
362 if env['with_mysql']:
363 mysql_config = checkProgram(env, 'mysql', 'mysql_config')
364 oldlib = env['LIBS']
365 env['LIBS'] = []
366 env.ParseConfig(mysql_config + ' --cflags --libs')
367 env.Append(CPPFLAGS = [ '-DHAVE_MYSQL_H', '-DHAVE_LIBMYSQL' ], LIBMYSQL = 'mysqlclient')
368 env['LIBS'] = oldlib
370 if env['with_pgsql']:
371 pg_config = checkProgram(env, 'pgsql', 'pg_config')
372 oldlib = env['LIBS']
373 env['LIBS'] = []
374 env.ParseConfig(pg_config + ' --includedir --libdir')
375 env.Append(CPPFLAGS = [ '-DHAVE_PGSQL_H', '-DHAVE_LIBPGSQL' ], LIBPGSQL = 'pq')
376 env['LIBS'] = oldlib
377 #if autoconf.CheckLibWithHeader('pq', 'libpq-fe.h', 'C'):
378 # env.Append(CPPFLAGS = [ '-DHAVE_PGSQL_H', '-DHAVE_LIBPGSQL' ], LIBPGSQL = 'pq')
380 if env['with_dbi']:
381 if autoconf.CheckLibWithHeader('dbi', 'dbi/dbi.h', 'C'):
382 env.Append(CPPFLAGS = [ '-DHAVE_DBI_H', '-DHAVE_LIBDBI' ], LIBDBI = 'dbi')
384 if re.compile("cygwin|mingw|midipix").search(env['PLATFORM']):
385 env.Append(COMMON_LIB = 'bin')
386 elif re.compile("darwin|aix").search(env['PLATFORM']):
387 env.Append(COMMON_LIB = 'lib')
388 else:
389 env.Append(COMMON_LIB = False)
391 versions = string.split(version, '.')
392 version_id = int(versions[0]) << 16 | int(versions[1]) << 8 | int(versions[2])
393 env.Append(CPPFLAGS = [
394 '-DLIGHTTPD_VERSION_ID=' + hex(version_id),
395 '-DPACKAGE_NAME=\\"' + package + '\\"',
396 '-DPACKAGE_VERSION=\\"' + version + '\\"',
397 '-DLIBRARY_DIR="\\"${libdir}\\""',
398 '-D_FILE_OFFSET_BITS=64', '-D_LARGEFILE_SOURCE', '-D_LARGE_FILES'
401 SConscript('src/SConscript', exports = 'env', variant_dir = 'sconsbuild/build', duplicate = 0)
402 SConscript('tests/SConscript', exports = 'env', variant_dir = 'sconsbuild/tests')