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