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