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