10 def checkCHeaders(autoconf
, hdrs
):
11 p
= re
.compile('[^A-Z0-9]')
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]')
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]')
33 if autoconf
.CheckType(type, '#include <sys/types.h>'):
34 autoconf
.env
.Append(CPPFLAGS
= [ '-DHAVE_' + p
.sub('_', type.upper()) ])
36 def checkGmtOffInStructTm(context
):
45 context
.Message('Checking for tm_gmtoff in struct tm...')
46 result
= context
.TryLink(source
, '.c')
47 context
.Result(result
)
51 def checkIPv6(context
):
53 #include <sys/types.h>
54 #include <sys/socket.h>
55 #include <netinet/in.h>
58 struct sockaddr_in6 s; struct in6_addr t=in6addr_any; int i=AF_INET6; s; t.s6_addr[0] = 0;
62 context
.Message('Checking for IPv6 support...')
63 result
= context
.TryLink(source
, '.c')
64 context
.Result(result
)
68 def checkWeakSymbols(context
):
70 __attribute__((weak)) void __dummy(void *x) { }
76 context
.Message('Checking for weak symbol support...')
77 result
= context
.TryLink(source
, '.c')
78 context
.Result(result
)
82 def checkProgram(env
, withname
, progname
):
83 withname
= 'with_' + withname
86 if env
[withname
] != 1:
87 binpath
= env
[withname
]
89 prog
= env
.Detect(progname
)
91 binpath
= env
.WhereIs(prog
)
94 mode
= os
.stat(binpath
)[ST_MODE
]
96 print >> sys
.stderr
, "* error: path `%s' is a directory" % (binpath
)
99 print >> sys
.stderr
, "* error: path `%s' is not a file or not exists" % (binpath
)
103 print >> sys
.stderr
, "* error: can't find program `%s'" % (progname
)
108 VariantDir('sconsbuild/build', 'src', duplicate
= 0)
109 VariantDir('sconsbuild/tests', 'tests', duplicate
= 0)
111 vars = Variables() #('config.py')
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')
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
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'])
174 autoconf
.env
.Append(APPEND_LIBS
= '')
176 autoconf
.headerfile
= "foo.h"
177 checkCHeaders(autoconf
, string
.split("""
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
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 pipe2 \
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
= '')
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')
242 env
['LIBS'] += ['crypt']
243 checkFuncs(autoconf
, ['crypt', 'crypt_r']);
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' ])
259 if autoconf
.CheckLibWithHeader('z', 'zlib.h', 'C'):
260 autoconf
.env
.Append(CPPFLAGS
= [ '-DHAVE_ZLIB_H', '-DHAVE_LIBZ' ], LIBZ
= 'z')
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')
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')
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')
295 if autoconf
.CheckLibWithHeader('fcgi', 'fastcgi.h', 'C'):
296 autoconf
.env
.Append(LIBFCGI
= 'fcgi')
300 if autoconf
.CheckLibWithHeader('dl', 'dlfcn.h', 'C'):
301 autoconf
.env
.Append(LIBDL
= 'dl')
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
):
323 oldlibs
= env
['LIBS']
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' ])
332 env
['LIBS'] = oldlibs
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
):
342 raise RuntimeError("Couldn't find any lua implementation")
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')
350 xml2_config
= checkProgram(env
, 'xml', 'xml2-config')
353 env
.ParseConfig(xml2_config
+ ' --cflags --libs')
354 env
.Append(CPPFLAGS
= [ '-DHAVE_LIBXML_H', '-DHAVE_LIBXML2' ], LIBXML2
= env
['LIBS'])
357 if env
['with_mysql']:
358 mysql_config
= checkProgram(env
, 'mysql', 'mysql_config')
361 env
.ParseConfig(mysql_config
+ ' --cflags --libs')
362 env
.Append(CPPFLAGS
= [ '-DHAVE_MYSQL_H', '-DHAVE_LIBMYSQL' ], LIBMYSQL
= 'mysqlclient')
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')
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')