5 from collections import OrderedDict
7 # search any file, not just executables
8 def WhereIsFile(file, paths):
10 f = os.path.join(d, file)
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
20 return os.path.normpath(f)
23 def FlattenLibs(libs):
24 if isinstance(libs, basestring):
27 return [item for sublibs in libs for item in FlattenLibs(sublibs)]
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))))
38 def WorkaroundFreeBSDLibOrder(libs):
39 # lib(re)ssl includes (weak) arc4random functions
40 # which "on purpose" might conflict with those in libc
41 # => link libc first solves this
42 # (required for FreeBSD11 fullstatic build)
44 if ('c' in libs) and (platform.system() == 'FreeBSD'):
48 def GatherLibs(env, *libs):
49 libs = RemoveDuplicateLibs(env['LIBS'] + list(libs) + [env['APPEND_LIBS']])
50 return WorkaroundFreeBSDLibOrder(libs)
52 common_src = Split("base64.c buffer.c log.c \
54 http_chunk.c stream.c fdevent.c \
55 stat_cache.c plugin.c joblist.c etag.c array.c \
56 data_string.c data_array.c \
57 data_integer.c md5.c data_fastcgi.c \
59 fdevent_select.c fdevent_libev.c \
60 fdevent_poll.c fdevent_linux_sysepoll.c \
61 fdevent_solaris_devpoll.c fdevent_solaris_port.c \
62 fdevent_freebsd_kqueue.c \
64 inet_ntop_cache.c crc32.c \
71 status_counter.c safe_memclear.c \
74 src = Split("server.c response.c connections.c network.c \
76 network_write_mmap.c network_write_no_mmap.c \
77 network_write.c network_linux_sendfile.c \
78 network_freebsd_sendfile.c \
79 network_solaris_sendfilev.c network_openssl.c \
80 network_darwin_sendfile.c \
81 configfile.c configparser.c request.c proc_open.c")
83 lemon = env.Program('lemon', 'lemon.c', LIBS = GatherLibs(env))
85 def Lemon(env, input):
86 parser = env.Command([input.replace('.y', '.c'),input.replace('.y', '.h')], input, '(cd sconsbuild/build; ../../' + lemon[0].path + ' -q ../../$SOURCE ../../src/lempar.c)')
87 env.Depends(parser, lemon)
89 configparser = Lemon(env, 'configparser.y')
90 mod_ssi_exprparser = Lemon(env, 'mod_ssi_exprparser.y')
92 ## the modules and how they are built
94 'mod_access' : { 'src' : [ 'mod_access.c' ] },
95 'mod_alias' : { 'src' : [ 'mod_alias.c' ] },
96 'mod_cgi' : { 'src' : [ 'mod_cgi.c' ] },
97 'mod_fastcgi' : { 'src' : [ 'mod_fastcgi.c' ] },
98 'mod_scgi' : { 'src' : [ 'mod_scgi.c' ] },
99 'mod_extforward' : { 'src' : [ 'mod_extforward.c' ] },
100 'mod_staticfile' : { 'src' : [ 'mod_staticfile.c' ] },
101 'mod_dirlisting' : { 'src' : [ 'mod_dirlisting.c' ], 'lib' : [ env['LIBPCRE'] ] },
102 'mod_indexfile' : { 'src' : [ 'mod_indexfile.c' ] },
103 'mod_setenv' : { 'src' : [ 'mod_setenv.c' ] },
104 'mod_rrdtool' : { 'src' : [ 'mod_rrdtool.c' ] },
105 'mod_usertrack' : { 'src' : [ 'mod_usertrack.c' ] },
106 'mod_proxy' : { 'src' : [ 'mod_proxy.c' ] },
107 'mod_userdir' : { 'src' : [ 'mod_userdir.c' ] },
108 'mod_secdownload' : { 'src' : [ 'mod_secdownload.c' ] },
109 'mod_accesslog' : { 'src' : [ 'mod_accesslog.c' ] },
110 'mod_simple_vhost' : { 'src' : [ 'mod_simple_vhost.c' ] },
111 'mod_evhost' : { 'src' : [ 'mod_evhost.c' ] },
112 'mod_expire' : { 'src' : [ 'mod_expire.c' ] },
113 'mod_status' : { 'src' : [ 'mod_status.c' ] },
114 'mod_compress' : { 'src' : [ 'mod_compress.c' ], 'lib' : [ env['LIBZ'], env['LIBBZ2'] ] },
115 'mod_deflate' : { 'src' : [ 'mod_deflate.c' ], 'lib' : [ env['LIBZ'], env['LIBBZ2'] ] },
116 'mod_redirect' : { 'src' : [ 'mod_redirect.c' ], 'lib' : [ env['LIBPCRE'] ] },
117 'mod_rewrite' : { 'src' : [ 'mod_rewrite.c' ], 'lib' : [ env['LIBPCRE'] ] },
118 'mod_auth' : { 'src' : [ 'mod_auth.c' ] },
119 'mod_authn_file' : { 'src' : [ 'mod_authn_file.c' ], 'lib' : [ env['LIBCRYPT'] ] },
120 'mod_webdav' : { 'src' : [ 'mod_webdav.c' ], 'lib' : [ env['LIBXML2'], env['LIBSQLITE3'], env['LIBUUID'] ] },
121 'mod_uploadprogress' : { 'src' : [ 'mod_uploadprogress.c' ] },
122 'mod_evasive' : { 'src' : [ 'mod_evasive.c' ] },
123 'mod_ssi' : { 'src' : [ 'mod_ssi_exprparser.c', 'mod_ssi_expr.c', 'mod_ssi.c' ] },
124 'mod_flv_streaming' : { 'src' : [ 'mod_flv_streaming.c' ] },
127 if env['with_geoip']:
128 modules['mod_geoip'] = { 'src' : [ 'mod_geoip.c' ], 'lib' : [ env['LIBGEOIP'] ] }
131 modules['mod_authn_gssapi'] = { 'src' : [ 'mod_authn_gssapi.c' ], 'lib' : [ env['LIBKRB5'], env['LIBGSSAPI_KRB5'] ] }
134 modules['mod_authn_ldap'] = { 'src' : [ 'mod_authn_ldap.c' ], 'lib' : [ env['LIBLDAP'], env['LIBLBER'] ] }
137 modules['mod_magnet'] = { 'src' : [ 'mod_magnet.c', 'mod_magnet_cache.c' ], 'lib' : [ env['LIBLUA'] ] }
138 modules['mod_cml'] = {
139 'src' : [ 'mod_cml_lua.c', 'mod_cml.c', 'mod_cml_funcs.c' ],
140 'lib' : [ env['LIBPCRE'], env['LIBMEMCACHED'], env['LIBLUA'] ]
143 if env['with_pcre'] and (env['with_memcached'] or env['with_gdbm']):
144 modules['mod_trigger_b4_dl'] = { 'src' : [ 'mod_trigger_b4_dl.c' ], 'lib' : [ env['LIBPCRE'], env['LIBMEMCACHED'] ] }
146 if env['with_mysql']:
147 modules['mod_authn_mysql'] = { 'src' : [ 'mod_authn_mysql.c' ], 'lib' : [ env['LIBCRYPT'], env['LIBMYSQL'] ] }
148 modules['mod_mysql_vhost'] = { 'src' : [ 'mod_mysql_vhost.c' ], 'lib' : [ env['LIBMYSQL'] ] }
150 staticenv = env.Clone(CPPFLAGS=[ env['CPPFLAGS'], '-DLIGHTTPD_STATIC' ])
152 ## all the core-sources + the modules
153 staticsrc = src + common_src
155 staticlib = env['LIBS']
157 for module in modules.keys():
158 staticsrc += modules[module]['src']
159 staticinit += "PLUGIN_INIT(%s)\n"%module
160 if modules[module].has_key('lib'):
161 staticlib += modules[module]['lib']
163 def WriteStaticPluginHeader(target, source, env):
165 data = env['STATICINIT']
166 # only touch the file if content actually changes
168 with open(target[0].abspath, 'r') as f:
169 do_write = (data != f.read())
173 with open(target[0].abspath, 'w+') as f:
174 f.write(env['STATICINIT'])
176 env['STATICINIT'] = staticinit
177 staticheader = env.AlwaysBuild(env.Command('plugin-static.h', [], WriteStaticPluginHeader))
179 ## turn all src-files into objects
181 static_plugin_obj = None
182 for cfile in staticsrc:
183 if cfile == 'plugin.c':
184 static_plugin_obj = [ staticenv.Object('static-' + cfile.replace('.c', ''), cfile) ]
185 staticobj += static_plugin_obj
187 staticobj += [ staticenv.Object('static-' + cfile.replace('.c', ''), cfile) ]
188 env.Depends(static_plugin_obj, 'plugin-static.h')
190 ## includes all modules, but links dynamically against other libs
191 staticbin = staticenv.Program('../static/build/lighttpd',
193 LIBS = GatherLibs(env, staticlib)
196 ## you might have to adjust the list of libs and the order for your setup
197 ## this is tricky, be warned
200 ## try to calculate the libs for fullstatic with ldd
203 ## 3. add them to the libs
204 #searchlibs = os.pathsep.join([ '/lib/', '/usr/lib/', '/usr/local/lib/' ])
206 searchpathre = re.compile(r'\bSEARCH_DIR\("=([^"]+)"\)')
207 f = os.popen('ld --verbose | grep SEARCH_DIR', 'r')
208 for aword in searchpathre.findall(f.read()):
209 searchlibs += [ aword]
212 lddre = re.compile(r'^\s+lib([^=-]+)(?:-[\.0-9]+)?\.so\.[0-9]+ =>', re.MULTILINE)
213 for libs in staticlib:
214 if type(libs) is types.StringType: libs = [ libs ]
216 fullstaticlib += [ lib ]
217 solibpath = WhereIsFile('lib' + lib + '.so', paths = searchlibs)
218 if solibpath is None:
221 f = os.popen('ldd ' + solibpath, 'r')
222 for aword in lddre.findall(f.read()):
223 fullstaticlib += [ aword ]
226 ## includes all modules, linked statically
227 fullstaticbin = staticenv.Program('../fullstatic/build/lighttpd',
229 LIBS = GatherLibs(env, fullstaticlib),
230 LINKFLAGS= [staticenv['LINKFLAGS'], '-static']
233 Alias('static', staticbin)
234 Alias('fullstatic', fullstaticbin)
236 implib = 'lighttpd.exe.a'
237 bin_targets = ['lighttpd']
238 bin_linkflags = [ env['LINKFLAGS'] ]
239 if env['COMMON_LIB'] == 'lib':
240 common_lib = env.SharedLibrary('liblighttpd', common_src, LINKFLAGS = [ env['LINKFLAGS'], '-Wl,--export-dynamic' ])
244 if env['COMMON_LIB'] == 'bin':
245 bin_linkflags += [ '-Wl,--export-all-symbols', '-Wl,--out-implib=build/' + implib ]
246 bin_targets += [ implib ]
248 bin_linkflags += [ '-Wl,--export-dynamic' ]
250 instbin = env.Program(bin_targets, src, LINKFLAGS = bin_linkflags, LIBS = GatherLibs(env, env['LIBS'], common_lib, env['LIBDL']))
251 env.Depends(instbin, configparser)
253 if env['COMMON_LIB'] == 'bin':
254 common_lib = instbin[1]
256 env['SHLIBPREFIX'] = ''
258 for module in modules.keys():
259 libs = [ common_lib ]
260 if modules[module].has_key('lib'):
261 libs += modules[module]['lib']
262 instlib += env.SharedLibrary(module, modules[module]['src'], LIBS= GatherLibs(env, libs))
263 env.Alias('modules', instlib)
267 if env['build_dynamic']:
268 Default(instbin[0], instlib)
269 inst += env.Install('${sbindir}', instbin[0])
270 inst += env.Install('${libdir}', instlib)
271 if env['COMMON_LIB'] == 'lib':
273 inst += env.Install('${bindir}', common_lib)
275 if env['build_static']:
277 inst += env.Install('${sbindir}', staticbin)
279 if env['build_fullstatic']:
280 Default(fullstaticbin)
281 inst += env.Install('${sbindir}', fullstaticbin)
283 env.Alias('dynamic', instbin)
284 # default all to be installed
285 env.Alias('install', inst)
288 tarname = env['package'] + '-' + env['version']