SConstruct 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. import os
  2. import sys
  3. import re
  4. import string
  5. from stat import *
  6. package = 'lighttpd'
  7. version = '1.4.33'
  8. def checkCHeaders(autoconf, hdrs):
  9. p = re.compile('[^A-Z0-9]')
  10. for hdr in hdrs:
  11. if not hdr:
  12. continue
  13. _hdr = Split(hdr)
  14. if autoconf.CheckCHeader(_hdr):
  15. autoconf.env.Append(CPPFLAGS = [ '-DHAVE_' + p.sub('_', _hdr[-1].upper()) ])
  16. def checkFuncs(autoconf, funcs):
  17. p = re.compile('[^A-Z0-9]')
  18. for func in funcs:
  19. if autoconf.CheckFunc(func):
  20. autoconf.env.Append(CPPFLAGS = [ '-DHAVE_' + p.sub('_', func.upper()) ])
  21. def checkTypes(autoconf, types):
  22. p = re.compile('[^A-Z0-9]')
  23. for type in types:
  24. if autoconf.CheckType(type, '#include <sys/types.h>'):
  25. autoconf.env.Append(CPPFLAGS = [ '-DHAVE_' + p.sub('_', type.upper()) ])
  26. def checkProgram(env, withname, progname):
  27. withname = 'with_' + withname
  28. binpath = None
  29. if env[withname] != 1:
  30. binpath = env[withname]
  31. else:
  32. prog = env.Detect(progname)
  33. if prog:
  34. binpath = env.WhereIs(prog)
  35. if binpath:
  36. mode = os.stat(binpath)[ST_MODE]
  37. if S_ISDIR(mode):
  38. print >> sys.stderr, "* error: path `%s' is a directory" % (binpath)
  39. env.Exit(-1)
  40. if not S_ISREG(mode):
  41. print >> sys.stderr, "* error: path `%s' is not a file or not exists" % (binpath)
  42. env.Exit(-1)
  43. if not binpath:
  44. print >> sys.stderr, "* error: can't find program `%s'" % (progname)
  45. env.Exit(-1)
  46. return binpath
  47. def checkStructMember(context):
  48. struct_member = """
  49. #include <time.h>
  50. int main() {
  51. struct tm a;
  52. a.tm_gmtoff = 0;
  53. return 0;
  54. }
  55. """
  56. context.Message('Checking for tm_gmtoff in struct tm...')
  57. result = context.TryLink(struct_member, '.c')
  58. context.Result(result)
  59. return result
  60. BuildDir('build', 'src', duplicate = 0)
  61. opts = Options('config.py')
  62. opts.AddOptions(
  63. ('prefix', 'prefix', '/usr/local'),
  64. ('bindir', 'binary directory', '${prefix}/bin'),
  65. ('sbindir', 'binary directory', '${prefix}/sbin'),
  66. ('libdir', 'library directory', '${prefix}/lib'),
  67. PackageOption('with_mysql', 'enable mysql support', 'no'),
  68. PackageOption('with_xml', 'enable xml support', 'no'),
  69. PackageOption('with_pcre', 'enable pcre support', 'yes'),
  70. PathOption('CC', 'path to the c-compiler', None),
  71. BoolOption('build_dynamic', 'enable dynamic build', 'yes'),
  72. BoolOption('build_static', 'enable static build', 'no'),
  73. BoolOption('build_fullstatic', 'enable fullstatic build', 'no'),
  74. BoolOption('with_sqlite3', 'enable sqlite3 support', 'no'),
  75. BoolOption('with_memcache', 'enable memcache support', 'no'),
  76. BoolOption('with_fam', 'enable FAM/gamin support', 'no'),
  77. BoolOption('with_openssl', 'enable memcache support', 'no'),
  78. BoolOption('with_gzip', 'enable gzip compression', 'no'),
  79. BoolOption('with_bzip2', 'enable bzip2 compression', 'no'),
  80. BoolOption('with_lua', 'enable lua support for mod_cml', 'no'),
  81. BoolOption('with_ldap', 'enable ldap auth support', 'no'))
  82. env = Environment(
  83. env = os.environ,
  84. options = opts,
  85. CPPPATH = Split('#build')
  86. )
  87. env.Help(opts.GenerateHelpText(env))
  88. if env.subst('${CC}') is not '':
  89. env['CC'] = env.subst('${CC}')
  90. env['package'] = package
  91. env['version'] = version
  92. if env['CC'] == 'gcc':
  93. ## we need x-open 6 and bsd 4.3 features
  94. env.Append(CCFLAGS = Split('-Wall -O2 -g -W -pedantic -Wunused -Wshadow -std=gnu99'))
  95. # cache configure checks
  96. if 1:
  97. autoconf = Configure(env, custom_tests = {'CheckStructMember': checkStructMember })
  98. autoconf.headerfile = "foo.h"
  99. checkCHeaders(autoconf, string.split("""
  100. arpa/inet.h
  101. fcntl.h
  102. netinet/in.h
  103. sys/types.h netinet/in.h
  104. stdlib.h
  105. string.h
  106. sys/socket.h
  107. sys/types.h sys/socket.h
  108. sys/time.h
  109. unistd.h
  110. sys/sendfile.h
  111. sys/uio.h
  112. sys/types.h sys/uio.h
  113. getopt.h
  114. sys/epoll.h
  115. sys/select.h
  116. sys/types.h sys/select.h
  117. poll.h
  118. sys/poll.h
  119. sys/devpoll.h
  120. sys/filio.h
  121. sys/mman.h
  122. sys/types.h sys/mman.h
  123. sys/event.h
  124. sys/types.h sys/event.h
  125. sys/port.h
  126. winsock2.h
  127. pwd.h
  128. sys/syslimits.h
  129. sys/resource.h
  130. sys/time.h sys/types.h sys/resource.h
  131. sys/un.h
  132. sys/types.h sys/un.h
  133. syslog.h
  134. stdint.h
  135. inttypes.h
  136. sys/prctl.h
  137. sys/wait.h""", "\n"))
  138. checkFuncs(autoconf, Split('fork stat lstat strftime dup2 getcwd inet_ntoa inet_ntop memset mmap munmap strchr \
  139. strdup strerror strstr strtol sendfile getopt socket \
  140. gethostbyname poll epoll_ctl getrlimit chroot \
  141. getuid select signal pathconf madvise prctl\
  142. writev sigaction sendfile64 send_file kqueue port_create localtime_r posix_fadvise issetugid inet_pton'))
  143. checkTypes(autoconf, Split('pid_t size_t off_t'))
  144. autoconf.env.Append( LIBSQLITE3 = '', LIBXML2 = '', LIBMYSQL = '', LIBZ = '',
  145. LIBBZ2 = '', LIBCRYPT = '', LIBMEMCACHE = '', LIBFCGI = '', LIBPCRE = '',
  146. LIBLDAP = '', LIBLBER = '', LIBLUA = '', LIBLUALIB = '', LIBDL = '')
  147. if env['with_fam']:
  148. if autoconf.CheckLibWithHeader('fam', 'fam.h', 'C'):
  149. autoconf.env.Append(CPPFLAGS = [ '-DHAVE_FAM_H', '-DHAVE_LIBFAM' ], LIBS = 'fam')
  150. checkFuncs(autoconf, ['FAMNoExists']);
  151. if autoconf.CheckLibWithHeader('crypt', 'crypt.h', 'C'):
  152. autoconf.env.Append(CPPFLAGS = [ '-DHAVE_CRYPT_H', '-DHAVE_LIBCRYPT' ], LIBCRYPT = 'crypt')
  153. if autoconf.CheckLibWithHeader('uuid', 'uuid/uuid.h', 'C'):
  154. autoconf.env.Append(CPPFLAGS = [ '-DHAVE_UUID_UUID_H', '-DHAVE_LIBUUID' ], LIBUUID = 'uuid')
  155. if env['with_openssl']:
  156. if autoconf.CheckLibWithHeader('ssl', 'openssl/ssl.h', 'C'):
  157. autoconf.env.Append(CPPFLAGS = [ '-DHAVE_OPENSSL_SSL_H', '-DHAVE_LIBSSL'] , LIBS = [ 'ssl', 'crypto' ])
  158. if env['with_gzip']:
  159. if autoconf.CheckLibWithHeader('z', 'zlib.h', 'C'):
  160. autoconf.env.Append(CPPFLAGS = [ '-DHAVE_ZLIB_H', '-DHAVE_LIBZ' ], LIBZ = 'z')
  161. if env['with_ldap']:
  162. if autoconf.CheckLibWithHeader('ldap', 'ldap.h', 'C'):
  163. autoconf.env.Append(CPPFLAGS = [ '-DHAVE_LDAP_H', '-DHAVE_LIBLDAP' ], LIBLDAP = 'ldap')
  164. if autoconf.CheckLibWithHeader('lber', 'lber.h', 'C'):
  165. autoconf.env.Append(CPPFLAGS = [ '-DHAVE_LBER_H', '-DHAVE_LIBLBER' ], LIBLBER = 'lber')
  166. if env['with_bzip2']:
  167. if autoconf.CheckLibWithHeader('bz2', 'bzlib.h', 'C'):
  168. autoconf.env.Append(CPPFLAGS = [ '-DHAVE_BZLIB_H', '-DHAVE_LIBBZ2' ], LIBBZ2 = 'bz2')
  169. if env['with_memcache']:
  170. if autoconf.CheckLibWithHeader('memcache', 'memcache.h', 'C'):
  171. autoconf.env.Append(CPPFLAGS = [ '-DHAVE_MEMCACHE_H', '-DHAVE_LIBMEMCACHE' ], LIBMEMCACHE = 'memcache')
  172. if env['with_sqlite3']:
  173. if autoconf.CheckLibWithHeader('sqlite3', 'sqlite3.h', 'C'):
  174. autoconf.env.Append(CPPFLAGS = [ '-DHAVE_SQLITE3_H', '-DHAVE_LIBSQLITE3' ], LIBSQLITE3 = 'sqlite3')
  175. ol = env['LIBS']
  176. if autoconf.CheckLibWithHeader('fcgi', 'fastcgi.h', 'C'):
  177. autoconf.env.Append(LIBFCGI = 'fcgi')
  178. env['LIBS'] = ol
  179. ol = env['LIBS']
  180. if autoconf.CheckLibWithHeader('dl', 'dlfcn.h', 'C'):
  181. autoconf.env.Append(LIBDL = 'dl')
  182. env['LIBS'] = ol
  183. if autoconf.CheckType('socklen_t', '#include <unistd.h>\n#include <sys/socket.h>\n#include <sys/types.h>'):
  184. autoconf.env.Append(CPPFLAGS = [ '-DHAVE_SOCKLEN_T' ])
  185. if autoconf.CheckType('struct sockaddr_storage', '#include <sys/socket.h>\n'):
  186. autoconf.env.Append(CPPFLAGS = [ '-DHAVE_STRUCT_SOCKADDR_STORAGE' ])
  187. if autoconf.CheckStructMember():
  188. autoconf.env.Append(CPPFLAGS = [ '-DHAVE_STRUCT_TM_GMTOFF' ])
  189. env = autoconf.Finish()
  190. if env['with_lua']:
  191. oldlibs = env['LIBS']
  192. env.ParseConfig("pkg-config 'lua >= 5.0' --cflags --libs")
  193. lualibs = env['LIBS'][len(oldlibs):]
  194. env.Append(LIBLUA = lualibs)
  195. env.Append(CPPFLAGS = [ '-DHAVE_LUA_H' ])
  196. env['LIBS'] = oldlibs
  197. if env['with_pcre']:
  198. pcre_config = checkProgram(env, 'pcre', 'pcre-config')
  199. env.ParseConfig(pcre_config + ' --cflags --libs')
  200. env.Append(CPPFLAGS = [ '-DHAVE_PCRE_H', '-DHAVE_LIBPCRE' ], LIBPCRE = 'pcre')
  201. if env['with_xml']:
  202. xml2_config = checkProgram(env, 'xml', 'xml2-config')
  203. oldlib = env['LIBS']
  204. env['LIBS'] = []
  205. env.ParseConfig(xml2_config + ' --cflags --libs')
  206. env.Append(CPPFLAGS = [ '-DHAVE_LIBXML_H', '-DHAVE_LIBXML2' ], LIBXML2 = env['LIBS'])
  207. env['LIBS'] = oldlib
  208. if env['with_mysql']:
  209. mysql_config = checkProgram(env, 'mysql', 'mysql_config')
  210. oldlib = env['LIBS']
  211. env['LIBS'] = []
  212. env.ParseConfig(mysql_config + ' --cflags --libs')
  213. env.Append(CPPFLAGS = [ '-DHAVE_MYSQL_H', '-DHAVE_LIBMYSQL' ], LIBMYSQL = 'mysqlclient')
  214. env['LIBS'] = oldlib
  215. if re.compile("cygwin|mingw").search(env['PLATFORM']):
  216. env.Append(COMMON_LIB = 'bin')
  217. elif re.compile("darwin|aix").search(env['PLATFORM']):
  218. env.Append(COMMON_LIB = 'lib')
  219. else:
  220. env.Append(COMMON_LIB = False)
  221. versions = string.split(version, '.')
  222. version_id = int(versions[0]) << 16 | int(versions[1]) << 8 | int(versions[2])
  223. env.Append(CPPFLAGS = [
  224. '-DLIGHTTPD_VERSION_ID=' + str(version_id),
  225. '-DPACKAGE_NAME=\\"' + package + '\\"',
  226. '-DPACKAGE_VERSION=\\"' + version + '\\"',
  227. '-DLIBRARY_DIR="\\"${libdir}\\""',
  228. '-D_FILE_OFFSET_BITS=64', '-D_LARGEFILE_SOURCE', '-D_LARGE_FILES'
  229. ] )
  230. SConscript( 'src/SConscript', 'env', build_dir = 'build', duplicate = 0)
  231. SConscript( 'tests/SConscript', 'env' )