1 from __future__
import print_function
10 string_types
= basestring
17 underscorify_reg
= re
.compile('[^A-Z0-9]')
19 return underscorify_reg
.sub('_', id.upper())
21 def fail(*args
, **kwargs
):
22 print(*args
, file=sys
.stderr
, **kwargs
)
27 def __init__(self
, env
):
33 raise Exception('entered twice')
35 if 'LIBS' in self
.env
:
36 #print("Backup LIBS: " + repr(self.env['LIBS']))
38 self
.backup_libs
= copy(self
.env
['LIBS'])
40 #print("No LIBS to backup")
43 def __exit__(self
, type, value
, traceback
):
45 raise Exception('exited twice')
48 if 'LIBS' in self
.env
:
51 #print("Restoring LIBS, now: " + repr(self.env['LIBS']))
52 self
.env
['LIBS'] = self
.backup_libs
53 #print("Restoring LIBS, to: " + repr(self.env['LIBS']))
55 def __init__(self
, env
):
56 self
.conf
= Configure(env
, custom_tests
= {
57 'CheckGmtOffInStructTm': Autoconf
.__checkGmtOffInStructTm
,
58 'CheckIPv6': Autoconf
.__checkIPv
6,
59 'CheckWeakSymbols': Autoconf
.__checkWeakSymbols
,
62 def append(self
, *args
, **kw
):
63 return self
.conf
.env
.Append(*args
, **kw
)
66 return self
.conf
.Finish()
72 def restoreEnvLibs(self
):
73 return Autoconf
.RestoreEnvLibs(self
.conf
.env
)
75 def CheckType(self
, *args
, **kw
):
76 return self
.conf
.CheckType(*args
, **kw
)
78 def CheckLib(self
, *args
, **kw
):
79 return self
.conf
.CheckLib(*args
, autoadd
= 0, **kw
)
81 def CheckLibWithHeader(self
, *args
, **kw
):
82 return self
.conf
.CheckLibWithHeader(*args
, autoadd
= 0, **kw
)
84 def CheckGmtOffInStructTm(self
):
85 return self
.conf
.CheckGmtOffInStructTm()
88 return self
.conf
.CheckIPv6()
90 def CheckWeakSymbols(self
):
91 return self
.conf
.CheckWeakSymbols()
93 def CheckCHeader(self
, hdr
):
94 return self
.conf
.CheckCHeader(hdr
)
96 def haveCHeader(self
, hdr
):
97 if self
.CheckCHeader(hdr
):
98 # if we have a list of headers define HAVE_ only for last one
100 if not isinstance(target
, string_types
):
102 self
.conf
.env
.Append(CPPFLAGS
= [ '-DHAVE_' + underscorify(target
) ])
106 def haveCHeaders(self
, hdrs
):
108 self
.haveCHeader(hdr
)
110 def CheckFunc(self
, func
, header
= None, libs
= []):
111 with self
.restoreEnvLibs():
112 self
.env
.Append(LIBS
= libs
)
113 return self
.conf
.CheckFunc(func
, header
= header
)
115 def CheckFuncInLib(self
, func
, lib
):
116 return self
.CheckFunc(func
, libs
= [lib
])
118 def haveFuncInLib(self
, func
, lib
):
119 if self
.CheckFuncInLib(func
, lib
):
120 self
.conf
.env
.Append(CPPFLAGS
= [ '-DHAVE_' + underscorify(func
) ])
124 def haveFunc(self
, func
, header
= None, libs
= []):
125 if self
.CheckFunc(func
, header
= header
, libs
= libs
):
126 self
.conf
.env
.Append(CPPFLAGS
= [ '-DHAVE_' + underscorify(func
) ])
130 def haveFuncs(self
, funcs
):
134 def haveTypes(self
, types
):
136 if self
.conf
.CheckType(type, '#include <sys/types.h>'):
137 self
.conf
.env
.Append(CPPFLAGS
= [ '-DHAVE_' + underscorify(type) ])
139 def CheckParseConfig(self
, *args
, **kw
):
141 self
.conf
.env
.ParseConfig(*args
, **kw
)
143 except Exception as e
:
144 print(e
.message
, file=sys
.stderr
)
147 def CheckParseConfigForLib(self
, lib
, *args
, **kw
):
148 with self
.restoreEnvLibs():
149 self
.env
['LIBS'] = []
150 if not self
.CheckParseConfig(*args
, **kw
):
152 self
.env
.Append(**{lib
: self
.env
['LIBS']})
156 def __checkGmtOffInStructTm(context
):
165 context
.Message('Checking for tm_gmtoff in struct tm...')
166 result
= context
.TryLink(source
, '.c')
167 context
.Result(result
)
172 def __checkIPv6(context
):
174 #include <sys/types.h>
175 #include <sys/socket.h>
176 #include <netinet/in.h>
179 struct sockaddr_in6 s; struct in6_addr t=in6addr_any; int i=AF_INET6; s; t.s6_addr[0] = 0;
183 context
.Message('Checking for IPv6 support...')
184 result
= context
.TryLink(source
, '.c')
185 context
.Result(result
)
190 def __checkWeakSymbols(context
):
192 __attribute__((weak)) void __dummy(void *x) { }
198 context
.Message('Checking for weak symbol support...')
199 result
= context
.TryLink(source
, '.c')
200 context
.Result(result
)
204 def checkProgram(self
, withname
, progname
):
205 withname
= 'with_' + withname
208 if self
.env
[withname
] != 1:
209 binpath
= self
.env
[withname
]
211 prog
= self
.env
.Detect(progname
)
213 binpath
= self
.env
.WhereIs(prog
)
216 mode
= os
.stat(binpath
)[ST_MODE
]
218 fail("* error: path `%s' is a directory" % (binpath
))
219 if not S_ISREG(mode
):
220 fail("* error: path `%s' is not a file or not exists" % (binpath
))
223 fail("* error: can't find program `%s'" % (progname
))
227 VariantDir('sconsbuild/build', 'src', duplicate
= 0)
228 VariantDir('sconsbuild/tests', 'tests', duplicate
= 0)
232 ('prefix', 'prefix', '/usr/local'),
233 ('bindir', 'binary directory', '${prefix}/bin'),
234 ('sbindir', 'binary directory', '${prefix}/sbin'),
235 ('libdir', 'library directory', '${prefix}/lib'),
236 PathVariable('CC', 'path to the c-compiler', None),
237 BoolVariable('build_dynamic', 'enable dynamic build', 'yes'),
238 BoolVariable('build_static', 'enable static build', 'no'),
239 BoolVariable('build_fullstatic', 'enable fullstatic build', 'no'),
241 BoolVariable('with_bzip2', 'enable bzip2 compression', 'no'),
242 PackageVariable('with_dbi', 'enable dbi support', 'no'),
243 BoolVariable('with_fam', 'enable FAM/gamin support', 'no'),
244 BoolVariable('with_gdbm', 'enable gdbm support', 'no'),
245 BoolVariable('with_geoip', 'enable GeoIP support', 'no'),
246 BoolVariable('with_maxminddb', 'enable MaxMind GeoIP2 support', 'no'),
247 BoolVariable('with_krb5', 'enable krb5 auth support', 'no'),
248 BoolVariable('with_ldap', 'enable ldap auth support', 'no'),
249 # with_libev not supported
250 # with_libunwind not supported
251 BoolVariable('with_lua', 'enable lua support for mod_cml', 'no'),
252 BoolVariable('with_memcached', 'enable memcached support', 'no'),
253 PackageVariable('with_mysql', 'enable mysql support', 'no'),
254 BoolVariable('with_openssl', 'enable openssl support', 'no'),
255 PackageVariable('with_wolfssl', 'enable wolfSSL support', 'no'),
256 BoolVariable('with_pam', 'enable PAM auth support', 'no'),
257 PackageVariable('with_pcre', 'enable pcre support', 'yes'),
258 PackageVariable('with_pgsql', 'enable pgsql support', 'no'),
259 PackageVariable('with_sasl', 'enable SASL support', 'no'),
260 BoolVariable('with_sqlite3', 'enable sqlite3 support (required for webdav props)', 'no'),
261 BoolVariable('with_uuid', 'enable uuid support (required for webdav locks)', 'no'),
262 # with_valgrind not supported
263 # with_xattr not supported
264 PackageVariable('with_xml', 'enable xml support (required for webdav props)', 'no'),
265 BoolVariable('with_zlib', 'enable deflate/gzip compression', 'no'),
267 BoolVariable('with_all', 'enable all with_* features', 'no'),
273 CPPPATH
= Split('#sconsbuild/build')
276 env
.Help(vars.GenerateHelpText(env
))
278 if env
.subst('${CC}') is not '':
279 env
['CC'] = env
.subst('${CC}')
281 env
['package'] = package
282 env
['version'] = version
283 if env
['CC'] == 'gcc':
284 ## we need x-open 6 and bsd 4.3 features
285 env
.Append(CCFLAGS
= Split('-Wall -O2 -g -W -pedantic -Wunused -Wshadow -std=gnu99'))
287 env
.Append(CPPFLAGS
= [
288 '-D_FILE_OFFSET_BITS=64',
289 '-D_LARGEFILE_SOURCE',
295 for feature
in vars.keys():
296 # only enable 'with_*' flags
297 if not feature
.startswith('with_'): continue
298 # don't overwrite manual arguments
299 if feature
in vars.args
: continue
303 # cache configure checks
305 autoconf
= Autoconf(env
)
307 if 'CFLAGS' in os
.environ
:
308 autoconf
.env
.Append(CCFLAGS
= os
.environ
['CFLAGS'])
309 print(">> Appending custom build flags : " + os
.environ
['CFLAGS'])
311 if 'LDFLAGS' in os
.environ
:
312 autoconf
.env
.Append(LINKFLAGS
= os
.environ
['LDFLAGS'])
313 print(">> Appending custom link flags : " + os
.environ
['LDFLAGS'])
315 if 'LIBS' in os
.environ
:
316 autoconf
.env
.Append(APPEND_LIBS
= os
.environ
['LIBS'])
317 print(">> Appending custom libraries : " + os
.environ
['LIBS'])
319 autoconf
.env
.Append(APPEND_LIBS
= '')
347 autoconf
.haveCHeaders([
373 # "have" the last header if we include others before?
374 ['sys/types.h', 'sys/time.h', 'sys/resource.h'],
375 ['sys/types.h', 'netinet/in.h'],
376 ['sys/types.h', 'sys/event.h'],
377 ['sys/types.h', 'sys/mman.h'],
378 ['sys/types.h', 'sys/select.h'],
379 ['sys/types.h', 'sys/socket.h'],
380 ['sys/types.h', 'sys/uio.h'],
381 ['sys/types.h', 'sys/un.h'],
435 autoconf
.haveFunc('getentropy', 'sys/random.h')
436 autoconf
.haveFunc('getrandom', 'linux/random.h')
438 autoconf
.haveTypes(Split('pid_t size_t off_t'))
440 # have crypt_r/crypt, and is -lcrypt needed?
441 if autoconf
.CheckLib('crypt'):
443 CPPFLAGS
= [ '-DHAVE_LIBCRYPT' ],
446 with autoconf
.restoreEnvLibs():
447 autoconf
.env
['LIBS'] = ['crypt']
448 autoconf
.haveFuncs(['crypt', 'crypt_r'])
450 autoconf
.haveFuncs(['crypt', 'crypt_r'])
452 if autoconf
.CheckType('socklen_t', '#include <unistd.h>\n#include <sys/socket.h>\n#include <sys/types.h>'):
453 autoconf
.env
.Append(CPPFLAGS
= [ '-DHAVE_SOCKLEN_T' ])
455 if autoconf
.CheckType('struct sockaddr_storage', '#include <sys/socket.h>\n'):
456 autoconf
.env
.Append(CPPFLAGS
= [ '-DHAVE_STRUCT_SOCKADDR_STORAGE' ])
458 if autoconf
.CheckLibWithHeader('elftc', 'libelftc.h', 'c', 'elftc_copyfile(0, 1);'):
460 CPPFLAGS
= [ '-DHAVE_ELFTC_COPYFILE' ],
464 if autoconf
.CheckLibWithHeader('rt', 'time.h', 'c', 'clock_gettime(CLOCK_MONOTONIC, (struct timespec*)0);'):
466 CPPFLAGS
= [ '-DHAVE_CLOCK_GETTIME' ],
470 if autoconf
.CheckIPv6():
471 autoconf
.env
.Append(CPPFLAGS
= [ '-DHAVE_IPV6' ])
473 if autoconf
.CheckWeakSymbols():
474 autoconf
.env
.Append(CPPFLAGS
= [ '-DHAVE_WEAK_SYMBOLS' ])
476 if autoconf
.CheckGmtOffInStructTm():
477 autoconf
.env
.Append(CPPFLAGS
= [ '-DHAVE_STRUCT_TM_GMTOFF' ])
479 if autoconf
.CheckLibWithHeader('dl', 'dlfcn.h', 'C'):
480 autoconf
.env
.Append(LIBDL
= 'dl')
482 # used in tests if present
483 if autoconf
.CheckLibWithHeader('fcgi', 'fastcgi.h', 'C'):
484 autoconf
.env
.Append(LIBFCGI
= 'fcgi')
486 if env
['with_bzip2']:
487 if not autoconf
.CheckLibWithHeader('bz2', 'bzlib.h', 'C'):
488 fail("Couldn't find bz2")
490 CPPFLAGS
= [ '-DHAVE_BZLIB_H', '-DHAVE_LIBBZ2' ],
495 if not autoconf
.CheckLibWithHeader('dbi', 'dbi/dbi.h', 'C'):
496 fail("Couldn't find dbi")
498 CPPFLAGS
= [ '-DHAVE_DBI_H', '-DHAVE_LIBDBI' ],
503 if not autoconf
.CheckLibWithHeader('fam', 'fam.h', 'C'):
504 fail("Couldn't find fam")
506 CPPFLAGS
= [ '-DHAVE_FAM_H', '-DHAVE_LIBFAM' ],
509 autoconf
.haveFunc('FAMNoExists')
512 if not autoconf
.CheckLibWithHeader('gdbm', 'gdbm.h', 'C'):
513 fail("Couldn't find gdbm")
515 CPPFLAGS
= [ '-DHAVE_GDBM_H', '-DHAVE_GDBM' ],
519 if env
['with_geoip']:
520 if not autoconf
.CheckLibWithHeader('GeoIP', 'GeoIP.h', 'C'):
521 fail("Couldn't find geoip")
523 CPPFLAGS
= [ '-DHAVE_GEOIP' ],
527 if env
['with_maxminddb']:
528 if not autoconf
.CheckLibWithHeader('maxminddb', 'maxminddb.h', 'C'):
529 fail("Couldn't find maxminddb")
531 CPPFLAGS
= [ '-DHAVE_MAXMINDDB' ],
532 LIBMAXMINDDB
= 'maxminddb',
536 if not autoconf
.CheckLibWithHeader('krb5', 'krb5.h', 'C'):
537 fail("Couldn't find krb5")
538 if not autoconf
.CheckLibWithHeader('gssapi_krb5', 'gssapi/gssapi_krb5.h', 'C'):
539 fail("Couldn't find gssapi_krb5")
541 CPPFLAGS
= [ '-DHAVE_KRB5' ],
543 LIBGSSAPI_KRB5
= 'gssapi_krb5',
547 if not autoconf
.CheckLibWithHeader('ldap', 'ldap.h', 'C'):
548 fail("Couldn't find ldap")
549 if not autoconf
.CheckLibWithHeader('lber', 'lber.h', 'C'):
550 fail("Couldn't find lber")
553 '-DHAVE_LDAP_H', '-DHAVE_LIBLDAP',
554 '-DHAVE_LBER_H', '-DHAVE_LIBLBER',
562 for lua_name
in ['lua5.3', 'lua-5.3', 'lua5.2', 'lua-5.2', 'lua5.1', 'lua-5.1', 'lua']:
563 print("Searching for lua: " + lua_name
+ " >= 5.0")
564 if autoconf
.CheckParseConfigForLib('LIBLUA', "pkg-config '" + lua_name
+ " >= 5.0' --cflags --libs"):
565 autoconf
.env
.Append(CPPFLAGS
= [ '-DHAVE_LUA_H' ])
569 fail("Couldn't find any lua implementation")
571 if env
['with_memcached']:
572 if not autoconf
.CheckLibWithHeader('memcached', 'libmemcached/memcached.h', 'C'):
573 fail("Couldn't find memcached")
575 CPPFLAGS
= [ '-DUSE_MEMCACHED' ],
576 LIBMEMCACHED
= 'memcached',
579 if env
['with_mysql']:
580 mysql_config
= autoconf
.checkProgram('mysql', 'mysql_config')
581 if not autoconf
.CheckParseConfigForLib('LIBMYSQL', mysql_config
+ ' --cflags --libs'):
582 fail("Couldn't find mysql")
583 autoconf
.env
.Append(CPPFLAGS
= [ '-DHAVE_MYSQL_H', '-DHAVE_LIBMYSQL' ])
585 if env
['with_openssl']:
586 if not autoconf
.CheckLibWithHeader('ssl', 'openssl/ssl.h', 'C'):
587 fail("Couldn't find openssl")
589 CPPFLAGS
= [ '-DHAVE_OPENSSL_SSL_H', '-DHAVE_LIBSSL'],
591 LIBCRYPTO
= 'crypto',
594 if env
['with_wolfssl']:
595 if type(env
['with_wolfssl']) is str:
596 autoconf
.env
.AppendUnique(
597 CPPPATH
= [ env
['with_wolfssl'] + '/include',
598 env
['with_wolfssl'] + '/include/wolfssl' ],
599 LIBPATH
= [ env
['with_wolfssl'] + '/lib' ],
601 if not autoconf
.CheckLibWithHeader('wolfssl', 'wolfssl/ssl.h', 'C'):
602 fail("Couldn't find wolfssl")
604 CPPFLAGS
= [ '-DHAVE_WOLFSSL_SSL_H' ],
606 LIBCRYPTO
= 'wolfssl',
610 if not autoconf
.CheckLibWithHeader('pam', 'security/pam_appl.h', 'C'):
611 fail("Couldn't find pam")
613 CPPFLAGS
= [ '-DHAVE_PAM' ],
618 pcre_config
= autoconf
.checkProgram('pcre', 'pcre-config')
619 if not autoconf
.CheckParseConfigForLib('LIBPCRE', pcre_config
+ ' --cflags --libs'):
620 fail("Couldn't find pcre")
621 autoconf
.env
.Append(CPPFLAGS
= [ '-DHAVE_PCRE_H', '-DHAVE_LIBPCRE' ])
623 if env
['with_pgsql']:
624 if not autoconf
.CheckParseConfigForLib('LIBPGSQL', 'pkg-config libpq --cflags --libs'):
625 fail("Couldn't find libpq")
626 autoconf
.env
.Append(CPPFLAGS
= [ '-DHAVE_PGSQL_H', '-DHAVE_LIBPGSQL' ])
629 if not autoconf
.CheckLibWithHeader('sasl2', 'sasl/sasl.h', 'C'):
630 fail("Couldn't find libsasl2")
632 CPPFLAGS
= [ '-DHAVE_SASL' ],
636 if env
['with_sqlite3']:
637 if not autoconf
.CheckLibWithHeader('sqlite3', 'sqlite3.h', 'C'):
638 fail("Couldn't find sqlite3")
640 CPPFLAGS
= [ '-DHAVE_SQLITE3_H', '-DHAVE_LIBSQLITE3' ],
641 LIBSQLITE3
= 'sqlite3',
645 if not autoconf
.CheckLibWithHeader('uuid', 'uuid/uuid.h', 'C'):
646 fail("Couldn't find uuid")
648 CPPFLAGS
= [ '-DHAVE_UUID_UUID_H', '-DHAVE_LIBUUID' ],
653 xml2_config
= autoconf
.checkProgram('xml', 'xml2-config')
654 if not autoconf
.CheckParseConfigForLib('LIBXML2', xml2_config
+ ' --cflags --libs'):
655 fail("Couldn't find xml2")
656 autoconf
.env
.Append(CPPFLAGS
= [ '-DHAVE_LIBXML_H', '-DHAVE_LIBXML2' ])
659 if not autoconf
.CheckLibWithHeader('z', 'zlib.h', 'C'):
660 fail("Couldn't find zlib")
662 CPPFLAGS
= [ '-DHAVE_ZLIB_H', '-DHAVE_LIBZ' ],
666 env
= autoconf
.Finish()
668 if re
.compile("cygwin|mingw|midipix").search(env
['PLATFORM']):
669 env
.Append(COMMON_LIB
= 'bin')
670 elif re
.compile("darwin|aix").search(env
['PLATFORM']):
671 env
.Append(COMMON_LIB
= 'lib')
673 env
.Append(COMMON_LIB
= False)
675 versions
= version
.split('.')
676 version_id
= int(versions
[0]) << 16 |
int(versions
[1]) << 8 |
int(versions
[2])
677 env
.Append(CPPFLAGS
= [
678 '-DLIGHTTPD_VERSION_ID=' + hex(version_id
),
679 '-DPACKAGE_NAME=\\"' + package
+ '\\"',
680 '-DPACKAGE_VERSION=\\"' + version
+ '\\"',
681 '-DLIBRARY_DIR="\\"${libdir}\\""',
684 SConscript('src/SConscript', exports
= 'env', variant_dir
= 'sconsbuild/build', duplicate
= 0)
685 SConscript('tests/SConscript', exports
= 'env', variant_dir
= 'sconsbuild/tests')