Annotation of embedaddon/lighttpd/src/SConscript, revision 1.1.1.2

1.1       misho       1: import os
                      2: import re
                      3: import types
1.1.1.2 ! misho       4: import itertools
        !             5: from collections import OrderedDict
        !             6: 
        !             7: # search any file, not just executables
        !             8: def WhereIsFile(file, paths):
        !             9:        for d in paths:
        !            10:                f = os.path.join(d, file)
        !            11:                if os.path.isfile(f):
        !            12:                        try:
        !            13:                                st = os.stat(f)
        !            14:                        except OSError:
        !            15:                                # os.stat() raises OSError, not IOError if the file
        !            16:                                # doesn't exist, so in this case we let IOError get
        !            17:                                # raised so as to not mask possibly serious disk or
        !            18:                                # network issues.
        !            19:                                continue
        !            20:                        return os.path.normpath(f)
        !            21:        return None
        !            22: 
        !            23: def FlattenLibs(libs):
        !            24:        if isinstance(libs, basestring):
        !            25:                return [libs]
        !            26:        else:
        !            27:                return [item for sublibs in libs for item in FlattenLibs(sublibs)]
        !            28: 
        !            29: # removes all but the *LAST* occurance of a lib in the list
        !            30: def RemoveDuplicateLibs(libs):
        !            31:        libs = FlattenLibs(libs)
        !            32:        # remove empty strings from list
        !            33:        libs = list(filter(lambda x: x != '', libs))
        !            34:        return list(reversed(OrderedDict.fromkeys(reversed(libs))))
1.1       misho      35: 
                     36: Import('env')
                     37: 
1.1.1.2 ! misho      38: def GatherLibs(env, *libs):
        !            39:        return RemoveDuplicateLibs(env['LIBS'] + list(libs) + [env['APPEND_LIBS']])
        !            40: 
        !            41: common_src = Split("base64.c buffer.c log.c \
        !            42:        keyvalue.c chunk.c  \
        !            43:        http_chunk.c stream.c fdevent.c \
        !            44:        stat_cache.c plugin.c joblist.c etag.c array.c \
        !            45:        data_string.c data_count.c data_array.c \
        !            46:        data_integer.c md5.c data_fastcgi.c \
        !            47:        vector.c \
        !            48:        fdevent_select.c fdevent_libev.c \
        !            49:        fdevent_poll.c fdevent_linux_sysepoll.c \
        !            50:        fdevent_solaris_devpoll.c fdevent_solaris_port.c \
        !            51:        fdevent_freebsd_kqueue.c \
        !            52:        data_config.c \
        !            53:        inet_ntop_cache.c crc32.c \
        !            54:        connections-glue.c \
        !            55:        configfile-glue.c \
        !            56:        http-header-glue.c \
        !            57:        splaytree.c network_writev.c \
        !            58:        network_write_mmap.c network_write_no_mmap.c \
        !            59:        network_write.c network_linux_sendfile.c \
        !            60:        network_freebsd_sendfile.c  \
        !            61:        network_solaris_sendfilev.c network_openssl.c \
        !            62:        status_counter.c safe_memclear.c network_darwin_sendfile.c \
1.1       misho      63: ")
                     64: 
                     65: src = Split("server.c response.c connections.c network.c \
1.1.1.2 ! misho      66:        configfile.c configparser.c request.c proc_open.c")
1.1       misho      67: 
1.1.1.2 ! misho      68: lemon = env.Program('lemon', 'lemon.c', LIBS = GatherLibs(env))
1.1       misho      69: 
1.1.1.2 ! misho      70: def Lemon(env, input):
        !            71:        parser = env.Command([input.replace('.y', '.c'),input.replace('.y', '.h')], input, '(cd sconsbuild/build; ../../' + lemon[0].path + ' -q ../../$SOURCE ../../src/lempar.c)')
        !            72:        env.Depends(parser, lemon)
1.1       misho      73: 
1.1.1.2 ! misho      74: configparser = Lemon(env, 'configparser.y')
        !            75: mod_ssi_exprparser = Lemon(env, 'mod_ssi_exprparser.y')
1.1       misho      76: 
                     77: ## the modules and how they are built
                     78: modules = {
                     79:        'mod_access' : { 'src' : [ 'mod_access.c' ] },
                     80:        'mod_alias' : { 'src' : [ 'mod_alias.c' ] },
                     81:        'mod_cgi' : { 'src' : [ 'mod_cgi.c' ] },
                     82:        'mod_fastcgi' : { 'src' : [ 'mod_fastcgi.c' ] },
                     83:        'mod_scgi' : { 'src' : [ 'mod_scgi.c' ] },
                     84:        'mod_extforward' : { 'src' : [ 'mod_extforward.c' ] },
                     85:        'mod_staticfile' : { 'src' : [ 'mod_staticfile.c' ] },
                     86:        'mod_dirlisting' : { 'src' : [ 'mod_dirlisting.c' ], 'lib' : [ env['LIBPCRE'] ] },
                     87:        'mod_indexfile' : { 'src' : [ 'mod_indexfile.c' ] },
                     88:        'mod_setenv' : { 'src' : [ 'mod_setenv.c' ] },
                     89:        'mod_rrdtool' : { 'src' : [ 'mod_rrdtool.c' ] },
                     90:        'mod_usertrack' : { 'src' : [ 'mod_usertrack.c' ] },
                     91:        'mod_proxy' : { 'src' : [ 'mod_proxy.c' ] },
                     92:        'mod_userdir' : { 'src' : [ 'mod_userdir.c' ] },
1.1.1.2 ! misho      93:        'mod_secdownload' : { 'src' : [ 'mod_secdownload.c' ] },
1.1       misho      94:        'mod_accesslog' : { 'src' : [ 'mod_accesslog.c' ] },
                     95:        'mod_simple_vhost' : { 'src' : [ 'mod_simple_vhost.c' ] },
                     96:        'mod_evhost' : { 'src' : [ 'mod_evhost.c' ] },
                     97:        'mod_expire' : { 'src' : [ 'mod_expire.c' ] },
                     98:        'mod_status' : { 'src' : [ 'mod_status.c' ] },
                     99:        'mod_compress' : { 'src' : [ 'mod_compress.c' ], 'lib' : [ env['LIBZ'], env['LIBBZ2'] ] },
                    100:        'mod_redirect' : { 'src' : [ 'mod_redirect.c' ], 'lib' : [ env['LIBPCRE'] ] },
                    101:        'mod_rewrite' : { 'src' : [ 'mod_rewrite.c' ], 'lib' : [ env['LIBPCRE'] ] },
                    102:        'mod_auth' : {
                    103:                'src' : [ 'mod_auth.c', 'http_auth.c' ],
                    104:                'lib' : [ env['LIBCRYPT'], env['LIBLDAP'], env['LIBLBER'] ] },
                    105:        'mod_webdav' : { 'src' : [ 'mod_webdav.c' ], 'lib' : [ env['LIBXML2'], env['LIBSQLITE3'], env['LIBUUID'] ] },
                    106:        'mod_mysql_vhost' : { 'src' : [ 'mod_mysql_vhost.c' ], 'lib' : [ env['LIBMYSQL'] ] },
                    107: #      'mod_uploadprogress' : { 'src' : [ 'mod_uploadprogress.c' ] },
                    108:        'mod_evasive' : { 'src' : [ 'mod_evasive.c' ] },
1.1.1.2 ! misho     109:        'mod_ssi' : { 'src' : [ 'mod_ssi_exprparser.c', 'mod_ssi_expr.c', 'mod_ssi.c' ] },
1.1       misho     110:        'mod_flv_streaming' : { 'src' : [ 'mod_flv_streaming.c' ] },
1.1.1.2 ! misho     111:        'mod_cml': {
        !           112:                'src' : [ 'mod_cml_lua.c', 'mod_cml.c', 'mod_cml_funcs.c' ],
        !           113:                'lib' : [ env['LIBPCRE'], env['LIBMEMCACHED'], env['LIBLUA'] ]
        !           114:        },
1.1       misho     115: }
                    116: 
1.1.1.2 ! misho     117: if env['with_memcached']:
        !           118:        modules['mod_trigger_b4_dl'] = { 'src' : [ 'mod_trigger_b4_dl.c' ], 'lib' : [ env['LIBPCRE'], env['LIBMEMCACHED'] ] }
        !           119: 
        !           120: if env['with_lua']:
        !           121:        modules['mod_magnet'] = { 'src' : [ 'mod_magnet.c', 'mod_magnet_cache.c' ], 'lib' : [ env['LIBLUA'] ] }
        !           122: 
        !           123: staticenv = env.Clone(CPPFLAGS=[ env['CPPFLAGS'], '-DLIGHTTPD_STATIC' ])
1.1       misho     124: 
                    125: ## all the core-sources + the modules
                    126: staticsrc = src + common_src
                    127: 
                    128: staticlib = env['LIBS']
                    129: staticinit = ''
                    130: for module in modules.keys():
                    131:        staticsrc += modules[module]['src']
                    132:        staticinit += "PLUGIN_INIT(%s)\n"%module
                    133:        if modules[module].has_key('lib'):
                    134:                staticlib += modules[module]['lib']
                    135: 
1.1.1.2 ! misho     136: def WriteStaticPluginHeader(target, source, env):
        !           137:        do_write = True
        !           138:        data = env['STATICINIT']
        !           139:        # only touch the file if content actually changes
        !           140:        try:
        !           141:                with open(target[0].abspath, 'r') as f:
        !           142:                        do_write = (data != f.read())
        !           143:        except IOError:
        !           144:                pass
        !           145:        if do_write:
        !           146:                with open(target[0].abspath, 'w+') as f:
        !           147:                        f.write(env['STATICINIT'])
        !           148: 
        !           149: env['STATICINIT'] = staticinit
        !           150: staticheader = env.AlwaysBuild(env.Command('plugin-static.h', [], WriteStaticPluginHeader))
1.1       misho     151: 
                    152: ## turn all src-files into objects
                    153: staticobj = []
1.1.1.2 ! misho     154: static_plugin_obj = None
1.1       misho     155: for cfile in staticsrc:
1.1.1.2 ! misho     156:        if cfile == 'plugin.c':
        !           157:                static_plugin_obj = [ staticenv.Object('static-' + cfile.replace('.c', ''), cfile) ]
        !           158:                staticobj += static_plugin_obj
        !           159:        else:
        !           160:                staticobj += [ staticenv.Object('static-' + cfile.replace('.c', ''), cfile) ]
        !           161: env.Depends(static_plugin_obj, 'plugin-static.h')
1.1       misho     162: 
1.1.1.2 ! misho     163: ## includes all modules, but links dynamically against other libs
        !           164: staticbin = staticenv.Program('../static/build/lighttpd',
1.1       misho     165:        staticobj,
1.1.1.2 ! misho     166:        LIBS = GatherLibs(env, staticlib)
1.1       misho     167:        )
                    168: 
                    169: ## you might have to adjust the list of libs and the order for your setup
                    170: ## this is tricky, be warned
                    171: fullstaticlib = []
                    172: 
                    173: ## try to calculate the libs for fullstatic with ldd
                    174: ## 1. find the lib
                    175: ## 2. check the deps
                    176: ## 3. add them to the libs
1.1.1.2 ! misho     177: #searchlibs = os.pathsep.join([ '/lib/', '/usr/lib/', '/usr/local/lib/' ])
        !           178: searchlibs = []
        !           179: searchpathre = re.compile(r'\bSEARCH_DIR\("=([^"]+)"\)')
        !           180: f = os.popen('ld --verbose | grep SEARCH_DIR', 'r')
        !           181: for aword in searchpathre.findall(f.read()):
        !           182:        searchlibs += [ aword]
        !           183: f.close
        !           184: 
1.1       misho     185: lddre = re.compile(r'^\s+lib([^=-]+)(?:-[\.0-9]+)?\.so\.[0-9]+ =>', re.MULTILINE)
                    186: for libs in staticlib:
                    187:        if type(libs) is types.StringType: libs = [ libs ]
                    188:        for lib in libs:
                    189:                fullstaticlib += [ lib ]
1.1.1.2 ! misho     190:                solibpath = WhereIsFile('lib' + lib + '.so', paths = searchlibs)
1.1       misho     191:                if solibpath is None:
                    192:                        continue
                    193: 
                    194:                f = os.popen('ldd ' + solibpath, 'r')
                    195:                for aword in lddre.findall(f.read()):
                    196:                        fullstaticlib += [ aword ]
                    197:                f.close
                    198: 
1.1.1.2 ! misho     199: ## includes all modules, linked statically
        !           200: fullstaticbin = staticenv.Program('../fullstatic/build/lighttpd',
1.1       misho     201:        staticobj,
1.1.1.2 ! misho     202:        LIBS = GatherLibs(env, fullstaticlib),
        !           203:        LINKFLAGS= [staticenv['LINKFLAGS'], '-static']
1.1       misho     204:        )
                    205: 
                    206: Alias('static', staticbin)
                    207: Alias('fullstatic', fullstaticbin)
                    208: 
                    209: implib = 'lighttpd.exe.a'
                    210: bin_targets = ['lighttpd']
                    211: bin_linkflags = [ env['LINKFLAGS'] ]
                    212: if env['COMMON_LIB'] == 'lib':
                    213:        common_lib = env.SharedLibrary('liblighttpd', common_src, LINKFLAGS = [ env['LINKFLAGS'], '-Wl,--export-dynamic' ])
                    214: else:
                    215:        src += common_src
                    216:        common_lib = []
                    217:        if env['COMMON_LIB'] == 'bin':
                    218:                bin_linkflags += [ '-Wl,--export-all-symbols', '-Wl,--out-implib=build/' + implib ]
                    219:                bin_targets += [ implib ]
                    220:        else:
                    221:                bin_linkflags += [ '-Wl,--export-dynamic' ]
                    222: 
1.1.1.2 ! misho     223: instbin = env.Program(bin_targets, src, LINKFLAGS = bin_linkflags, LIBS = GatherLibs(env, env['LIBS'], common_lib, env['LIBDL']))
1.1       misho     224: env.Depends(instbin, configparser)
                    225: 
                    226: if env['COMMON_LIB'] == 'bin':
                    227:        common_lib = instbin[1]
                    228: 
                    229: env['SHLIBPREFIX'] = ''
                    230: instlib = []
                    231: for module in modules.keys():
                    232:        libs = [ common_lib ]
                    233:        if modules[module].has_key('lib'):
                    234:                libs +=  modules[module]['lib']
1.1.1.2 ! misho     235:        instlib += env.SharedLibrary(module, modules[module]['src'], LIBS= GatherLibs(env, libs))
        !           236: env.Alias('modules', instlib)
1.1       misho     237: 
                    238: inst = []
                    239: 
                    240: if env['build_dynamic']:
                    241:        Default(instbin[0], instlib)
                    242:        inst += env.Install('${sbindir}', instbin[0])
                    243:        inst += env.Install('${libdir}', instlib)
                    244:        if env['COMMON_LIB'] == 'lib':
                    245:                Default(common_lib)
                    246:                inst += env.Install('${bindir}', common_lib)
                    247: 
                    248: if env['build_static']:
                    249:        Default(staticbin)
                    250:        inst += env.Install('${sbindir}', staticbin)
                    251: 
                    252: if env['build_fullstatic']:
                    253:        Default(fullstaticbin)
                    254:        inst += env.Install('${sbindir}', fullstaticbin)
                    255: 
                    256: env.Alias('dynamic', instbin)
                    257: # default all to be installed
                    258: env.Alias('install', inst)
                    259: 
                    260: pkgdir = '.'
                    261: tarname = env['package'] + '-' + env['version']

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>