[scons] rename with_gzip to with_zlib
[lighttpd.git] / SConstruct
blob4bb9e3808ece2f410aa2c3fda6b6d51666007429
1 import os
2 import sys
3 import re
4 import string
5 from stat import *
7 package = 'lighttpd'
8 version = '1.4.48'
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()
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 PathVariable('CC', 'path to the c-compiler', None),
118 BoolVariable('build_dynamic', 'enable dynamic build', 'yes'),
119 BoolVariable('build_static', 'enable static build', 'no'),
120 BoolVariable('build_fullstatic', 'enable fullstatic build', 'no'),
122 BoolVariable('with_bzip2', 'enable bzip2 compression', 'no'),
123 PackageVariable('with_dbi', 'enable dbi support', 'no'),
124 BoolVariable('with_fam', 'enable FAM/gamin support', 'no'),
125 BoolVariable('with_gdbm', 'enable gdbm support', 'no'),
126 BoolVariable('with_geoip', 'enable GeoIP support', 'no'),
127 BoolVariable('with_krb5', 'enable krb5 auth support', 'no'),
128 BoolVariable('with_ldap', 'enable ldap auth support', 'no'),
129 # with_libev not supported
130 # with_libunwind not supported
131 BoolVariable('with_lua', 'enable lua support for mod_cml', 'no'),
132 BoolVariable('with_memcached', 'enable memcached support', 'no'),
133 PackageVariable('with_mysql', 'enable mysql support', 'no'),
134 BoolVariable('with_openssl', 'enable openssl support', 'no'),
135 PackageVariable('with_pcre', 'enable pcre support', 'yes'),
136 PackageVariable('with_pgsql', 'enable pgsql support', 'no'),
137 BoolVariable('with_sqlite3', 'enable sqlite3 support', 'no'),
138 # with_uuid not supported
139 # with_valgrind not supported
140 # with_xattr not supported
141 PackageVariable('with_xml', 'enable xml support', 'no'),
142 BoolVariable('with_zlib', 'enable deflate/gzip compression', 'no'),
145 env = Environment(
146 ENV = os.environ,
147 variables = vars,
148 CPPPATH = Split('#sconsbuild/build')
151 env.Help(vars.GenerateHelpText(env))
153 if env.subst('${CC}') is not '':
154 env['CC'] = env.subst('${CC}')
156 env['package'] = package
157 env['version'] = version
158 if env['CC'] == 'gcc':
159 ## we need x-open 6 and bsd 4.3 features
160 env.Append(CCFLAGS = Split('-Wall -O2 -g -W -pedantic -Wunused -Wshadow -std=gnu99'))
162 # cache configure checks
163 if 1:
164 autoconf = Configure(env, custom_tests = {
165 'CheckGmtOffInStructTm': checkGmtOffInStructTm,
166 'CheckIPv6': checkIPv6,
167 'CheckWeakSymbols': checkWeakSymbols,
170 if 'CFLAGS' in os.environ:
171 autoconf.env.Append(CCFLAGS = os.environ['CFLAGS'])
172 print(">> Appending custom build flags : " + os.environ['CFLAGS'])
174 if 'LDFLAGS' in os.environ:
175 autoconf.env.Append(LINKFLAGS = os.environ['LDFLAGS'])
176 print(">> Appending custom link flags : " + os.environ['LDFLAGS'])
178 if 'LIBS' in os.environ:
179 autoconf.env.Append(APPEND_LIBS = os.environ['LIBS'])
180 print(">> Appending custom libraries : " + os.environ['LIBS'])
181 else:
182 autoconf.env.Append(APPEND_LIBS = '')
184 autoconf.headerfile = "foo.h"
185 checkCHeaders(autoconf, string.split("""
186 arpa/inet.h
187 crypt.h
188 fcntl.h
189 getopt.h
190 inttypes.h
191 linux/random.h
192 netinet/in.h
193 poll.h
194 pwd.h
195 stdint.h
196 stdlib.h
197 string.h
198 strings.h
199 sys/devpoll.h
200 sys/epoll.h
201 sys/event.h
202 sys/filio.h
203 sys/mman.h
204 sys/poll.h
205 sys/port.h
206 sys/prctl.h
207 sys/resource.h
208 sys/select.h
209 sys/sendfile.h
210 sys/socket.h
211 sys/time.h
212 sys/time.h sys/types.h sys/resource.h
213 sys/types.h netinet/in.h
214 sys/types.h sys/event.h
215 sys/types.h sys/mman.h
216 sys/types.h sys/select.h
217 sys/types.h sys/socket.h
218 sys/types.h sys/uio.h
219 sys/types.h sys/un.h
220 sys/uio.h
221 sys/un.h
222 sys/wait.h
223 syslog.h
224 unistd.h
225 winsock2.h""", "\n"))
227 checkFuncs(autoconf, Split('fork stat lstat strftime dup2 getcwd inet_ntoa inet_ntop memset mmap munmap strchr \
228 strdup strerror strstr strtol sendfile getopt socket \
229 gethostbyname poll epoll_ctl getrlimit chroot \
230 getuid select signal pathconf madvise prctl\
231 writev sigaction sendfile64 send_file kqueue port_create localtime_r posix_fadvise issetugid inet_pton \
232 memset_s explicit_bzero clock_gettime pipe2 \
233 arc4random_buf jrand48 srandom getloadavg'))
234 checkFunc(autoconf, 'getentropy', 'sys/random.h')
235 checkFunc(autoconf, 'getrandom', 'linux/random.h')
237 checkTypes(autoconf, Split('pid_t size_t off_t'))
239 autoconf.env.Append( LIBSQLITE3 = '', LIBXML2 = '', LIBMYSQL = '', LIBZ = '',
240 LIBPGSQL = '', LIBDBI = '',
241 LIBBZ2 = '', LIBCRYPT = '', LIBMEMCACHED = '', LIBFCGI = '', LIBPCRE = '',
242 LIBLDAP = '', LIBLBER = '', LIBLUA = '', LIBDL = '', LIBUUID = '',
243 LIBKRB5 = '', LIBGSSAPI_KRB5 = '', LIBGDBM = '', LIBSSL = '', LIBCRYPTO = '')
245 if env['with_fam']:
246 if autoconf.CheckLibWithHeader('fam', 'fam.h', 'C'):
247 autoconf.env.Append(CPPFLAGS = [ '-DHAVE_FAM_H', '-DHAVE_LIBFAM' ], LIBS = 'fam')
248 checkFuncs(autoconf, ['FAMNoExists']);
250 if autoconf.CheckLib('crypt'):
251 autoconf.env.Append(CPPFLAGS = [ '-DHAVE_LIBCRYPT' ], LIBCRYPT = 'crypt')
252 oldlib = env['LIBS']
253 env['LIBS'] += ['crypt']
254 checkFuncs(autoconf, ['crypt', 'crypt_r']);
255 env['LIBS'] = oldlib
256 else:
257 checkFuncs(autoconf, ['crypt', 'crypt_r']);
259 if autoconf.CheckLibWithHeader('rt', 'time.h', 'c', 'clock_gettime(CLOCK_MONOTONIC, (struct timespec*)0);'):
260 autoconf.env.Append(CPPFLAGS = [ '-DHAVE_CLOCK_GETTIME' ], LIBS = [ 'rt' ])
262 if autoconf.CheckLibWithHeader('uuid', 'uuid/uuid.h', 'C'):
263 autoconf.env.Append(CPPFLAGS = [ '-DHAVE_UUID_UUID_H', '-DHAVE_LIBUUID' ], LIBUUID = 'uuid')
265 if env['with_openssl']:
266 if autoconf.CheckLibWithHeader('ssl', 'openssl/ssl.h', 'C'):
267 autoconf.env.Append(CPPFLAGS = [ '-DHAVE_OPENSSL_SSL_H', '-DHAVE_LIBSSL'] , LIBSSL = 'ssl', LIBCRYPTO = 'crypto', LIBS = [ 'crypto' ])
269 if env['with_zlib']:
270 if autoconf.CheckLibWithHeader('z', 'zlib.h', 'C'):
271 autoconf.env.Append(CPPFLAGS = [ '-DHAVE_ZLIB_H', '-DHAVE_LIBZ' ], LIBZ = 'z')
273 if env['with_krb5']:
274 if autoconf.CheckLibWithHeader('krb5', 'krb5.h', 'C'):
275 autoconf.env.Append(CPPFLAGS = [ '-DHAVE_KRB5' ], LIBKRB5 = 'krb5')
276 if autoconf.CheckLibWithHeader('gssapi_krb5', 'gssapi/gssapi_krb5.h', 'C'):
277 autoconf.env.Append(LIBGSSAPI_KRB5 = 'gssapi_krb5')
279 if env['with_ldap']:
280 if autoconf.CheckLibWithHeader('ldap', 'ldap.h', 'C'):
281 autoconf.env.Append(CPPFLAGS = [ '-DHAVE_LDAP_H', '-DHAVE_LIBLDAP' ], LIBLDAP = 'ldap')
282 if autoconf.CheckLibWithHeader('lber', 'lber.h', 'C'):
283 autoconf.env.Append(CPPFLAGS = [ '-DHAVE_LBER_H', '-DHAVE_LIBLBER' ], LIBLBER = 'lber')
285 if env['with_bzip2']:
286 if autoconf.CheckLibWithHeader('bz2', 'bzlib.h', 'C'):
287 autoconf.env.Append(CPPFLAGS = [ '-DHAVE_BZLIB_H', '-DHAVE_LIBBZ2' ], LIBBZ2 = 'bz2')
289 if env['with_memcached']:
290 if autoconf.CheckLibWithHeader('memcached', 'libmemcached/memcached.h', 'C'):
291 autoconf.env.Append(CPPFLAGS = [ '-DUSE_MEMCACHED' ], LIBMEMCACHED = 'memcached')
293 if env['with_gdbm']:
294 if autoconf.CheckLibWithHeader('gdbm', 'gdbm.h', 'C'):
295 autoconf.env.Append(CPPFLAGS = [ '-DHAVE_GDBM_H', '-DHAVE_GDBM' ], LIBGDBM = 'gdbm')
297 if env['with_sqlite3']:
298 if autoconf.CheckLibWithHeader('sqlite3', 'sqlite3.h', 'C'):
299 autoconf.env.Append(CPPFLAGS = [ '-DHAVE_SQLITE3_H', '-DHAVE_LIBSQLITE3' ], LIBSQLITE3 = 'sqlite3')
301 if env['with_geoip']:
302 if autoconf.CheckLibWithHeader('GeoIP', 'GeoIP.h', 'C'):
303 autoconf.env.Append(CPPFLAGS = [ '-DHAVE_GEOIP' ], LIBGEOIP = 'GeoIP')
305 ol = env['LIBS']
306 if autoconf.CheckLibWithHeader('fcgi', 'fastcgi.h', 'C'):
307 autoconf.env.Append(LIBFCGI = 'fcgi')
308 env['LIBS'] = ol
310 ol = env['LIBS']
311 if autoconf.CheckLibWithHeader('dl', 'dlfcn.h', 'C'):
312 autoconf.env.Append(LIBDL = 'dl')
313 env['LIBS'] = ol
315 if autoconf.CheckType('socklen_t', '#include <unistd.h>\n#include <sys/socket.h>\n#include <sys/types.h>'):
316 autoconf.env.Append(CPPFLAGS = [ '-DHAVE_SOCKLEN_T' ])
318 if autoconf.CheckType('struct sockaddr_storage', '#include <sys/socket.h>\n'):
319 autoconf.env.Append(CPPFLAGS = [ '-DHAVE_STRUCT_SOCKADDR_STORAGE' ])
321 if autoconf.CheckGmtOffInStructTm():
322 autoconf.env.Append(CPPFLAGS = [ '-DHAVE_STRUCT_TM_GMTOFF' ])
324 if autoconf.CheckIPv6():
325 autoconf.env.Append(CPPFLAGS = [ '-DHAVE_IPV6' ])
327 if autoconf.CheckWeakSymbols():
328 autoconf.env.Append(CPPFLAGS = [ '-DHAVE_WEAK_SYMBOLS' ])
330 env = autoconf.Finish()
332 def TryLua(env, name):
333 result = False
334 oldlibs = env['LIBS']
335 try:
336 print("Searching for lua: " + name + " >= 5.0")
337 env.ParseConfig("pkg-config '" + name + " >= 5.0' --cflags --libs")
338 env.Append(LIBLUA = env['LIBS'][len(oldlibs):])
339 env.Append(CPPFLAGS = [ '-DHAVE_LUA_H' ])
340 result = True
341 except:
342 pass
343 env['LIBS'] = oldlibs
344 return result
346 if env['with_lua']:
347 found_lua = False
348 for lua_name in ['lua5.3', 'lua-5.3', 'lua5.2', 'lua-5.2', 'lua5.1', 'lua-5.1', 'lua']:
349 if TryLua(env, lua_name):
350 found_lua = True
351 break
352 if not found_lua:
353 raise RuntimeError("Couldn't find any lua implementation")
355 if env['with_pcre']:
356 pcre_config = checkProgram(env, 'pcre', 'pcre-config')
357 env.ParseConfig(pcre_config + ' --cflags --libs')
358 env.Append(CPPFLAGS = [ '-DHAVE_PCRE_H', '-DHAVE_LIBPCRE' ], LIBPCRE = 'pcre')
360 if env['with_xml']:
361 xml2_config = checkProgram(env, 'xml', 'xml2-config')
362 oldlib = env['LIBS']
363 env['LIBS'] = []
364 env.ParseConfig(xml2_config + ' --cflags --libs')
365 env.Append(CPPFLAGS = [ '-DHAVE_LIBXML_H', '-DHAVE_LIBXML2' ], LIBXML2 = env['LIBS'])
366 env['LIBS'] = oldlib
368 if env['with_mysql']:
369 mysql_config = checkProgram(env, 'mysql', 'mysql_config')
370 oldlib = env['LIBS']
371 env['LIBS'] = []
372 env.ParseConfig(mysql_config + ' --cflags --libs')
373 env.Append(CPPFLAGS = [ '-DHAVE_MYSQL_H', '-DHAVE_LIBMYSQL' ], LIBMYSQL = 'mysqlclient')
374 env['LIBS'] = oldlib
376 if env['with_pgsql']:
377 pg_config = checkProgram(env, 'pgsql', 'pg_config')
378 oldlib = env['LIBS']
379 env['LIBS'] = []
380 env.ParseConfig(pg_config + ' --includedir --libdir')
381 env.Append(CPPFLAGS = [ '-DHAVE_PGSQL_H', '-DHAVE_LIBPGSQL' ], LIBPGSQL = 'pq')
382 env['LIBS'] = oldlib
383 #if autoconf.CheckLibWithHeader('pq', 'libpq-fe.h', 'C'):
384 # env.Append(CPPFLAGS = [ '-DHAVE_PGSQL_H', '-DHAVE_LIBPGSQL' ], LIBPGSQL = 'pq')
386 if env['with_dbi']:
387 if autoconf.CheckLibWithHeader('dbi', 'dbi/dbi.h', 'C'):
388 env.Append(CPPFLAGS = [ '-DHAVE_DBI_H', '-DHAVE_LIBDBI' ], LIBDBI = 'dbi')
390 if re.compile("cygwin|mingw|midipix").search(env['PLATFORM']):
391 env.Append(COMMON_LIB = 'bin')
392 elif re.compile("darwin|aix").search(env['PLATFORM']):
393 env.Append(COMMON_LIB = 'lib')
394 else:
395 env.Append(COMMON_LIB = False)
397 versions = string.split(version, '.')
398 version_id = int(versions[0]) << 16 | int(versions[1]) << 8 | int(versions[2])
399 env.Append(CPPFLAGS = [
400 '-DLIGHTTPD_VERSION_ID=' + hex(version_id),
401 '-DPACKAGE_NAME=\\"' + package + '\\"',
402 '-DPACKAGE_VERSION=\\"' + version + '\\"',
403 '-DLIBRARY_DIR="\\"${libdir}\\""',
404 '-D_FILE_OFFSET_BITS=64', '-D_LARGEFILE_SOURCE', '-D_LARGE_FILES'
407 SConscript('src/SConscript', exports = 'env', variant_dir = 'sconsbuild/build', duplicate = 0)
408 SConscript('tests/SConscript', exports = 'env', variant_dir = 'sconsbuild/tests')