[mod_auth] require digest uri= match original URI
[lighttpd.git] / src / SConscript
blobd181ce5a61494430429966fe2848ee480e7462d2
1 import itertools
2 import os
3 import re
4 from collections import OrderedDict
5 from copy import copy
7 try:
8         string_types = basestring
9 except NameError:
10         string_types = str
13 # search any file, not just executables
14 def WhereIsFile(file, paths):
15         for d in paths:
16                 f = os.path.join(d, file)
17                 if os.path.isfile(f):
18                         try:
19                                 st = os.stat(f)
20                         except OSError:
21                                 # os.stat() raises OSError, not IOError if the file
22                                 # doesn't exist, so in this case we let IOError get
23                                 # raised so as to not mask possibly serious disk or
24                                 # network issues.
25                                 continue
26                         return os.path.normpath(f)
27         return None
29 def FlattenLibs(libs):
30         if isinstance(libs, string_types):
31                 return [libs]
32         else:
33                 return [item for sublibs in libs for item in FlattenLibs(sublibs)]
35 # removes all but the *LAST* occurance of a lib in the list
36 def RemoveDuplicateLibs(libs):
37         libs = FlattenLibs(libs)
38         # remove empty strings from list
39         libs = list(filter(lambda x: x != '', libs))
40         return list(reversed(OrderedDict.fromkeys(reversed(libs))))
42 Import('env')
44 def WorkaroundFreeBSDLibOrder(libs):
45         # lib(re)ssl includes (weak) arc4random functions
46         # which "on purpose" might conflict with those in libc
47         # => link libc first solves this
48         # (required for FreeBSD11 fullstatic build)
49         import platform
50         if ('c' in libs) and (platform.system() == 'FreeBSD'):
51                 return ['c'] + libs
52         return libs
54 def GatherLibs(env, *libs):
55         libs = RemoveDuplicateLibs(env['LIBS'] + list(libs) + [env['APPEND_LIBS']])
56         return WorkaroundFreeBSDLibOrder(libs)
58 common_src = Split("base64.c buffer.c burl.c log.c \
59         http_header.c http_kv.c keyvalue.c chunk.c  \
60         http_chunk.c stream.c fdevent.c gw_backend.c \
61         stat_cache.c plugin.c joblist.c etag.c array.c \
62         data_string.c data_array.c \
63         data_integer.c algo_sha1.c md5.c \
64         vector.c \
65         fdevent_select.c fdevent_libev.c \
66         fdevent_poll.c fdevent_linux_sysepoll.c \
67         fdevent_solaris_devpoll.c fdevent_solaris_port.c \
68         fdevent_freebsd_kqueue.c \
69         data_config.c \
70         crc32.c \
71         connections-glue.c \
72         configfile-glue.c \
73         http-header-glue.c \
74         http_auth.c \
75         http_vhostdb.c \
76         request.c \
77         sock_addr.c \
78         splaytree.c \
79         rand.c \
80         safe_memclear.c \
83 src = Split("server.c response.c connections.c \
84         inet_ntop_cache.c \
85         network.c \
86         network_write.c \
87         configfile.c configparser.c")
89 lemon = env.Program('lemon', 'lemon.c', LIBS = GatherLibs(env))
91 def Lemon(env, input):
92         parser = env.Command([input.replace('.y', '.c'),input.replace('.y', '.h')], input, '(cd sconsbuild/build; ../../' + lemon[0].path + ' -q ../../$SOURCE ../../src/lempar.c)')
93         env.Depends(parser, lemon)
95 configparser = Lemon(env, 'configparser.y')
96 mod_ssi_exprparser = Lemon(env, 'mod_ssi_exprparser.y')
98 ## the modules and how they are built
99 modules = {
100         'mod_access' : { 'src' : [ 'mod_access.c' ] },
101         'mod_accesslog' : { 'src' : [ 'mod_accesslog.c' ] },
102         'mod_alias' : { 'src' : [ 'mod_alias.c' ] },
103         'mod_auth' : { 'src' : [ 'mod_auth.c' ], 'lib' : [ env['LIBCRYPTO'] ] },
104         'mod_authn_file' : { 'src' : [ 'mod_authn_file.c' ], 'lib' : [ env['LIBCRYPT'], env['LIBCRYPTO'] ] },
105         'mod_cgi' : { 'src' : [ 'mod_cgi.c' ] },
106         'mod_compress' : { 'src' : [ 'mod_compress.c' ], 'lib' : [ env['LIBZ'], env['LIBBZ2'] ] },
107         'mod_deflate' : { 'src' : [ 'mod_deflate.c' ], 'lib' : [ env['LIBZ'], env['LIBBZ2'] ] },
108         'mod_dirlisting' : { 'src' : [ 'mod_dirlisting.c' ], 'lib' : [ env['LIBPCRE'] ] },
109         'mod_evasive' : { 'src' : [ 'mod_evasive.c' ] },
110         'mod_evhost' : { 'src' : [ 'mod_evhost.c' ] },
111         'mod_expire' : { 'src' : [ 'mod_expire.c' ] },
112         'mod_extforward' : { 'src' : [ 'mod_extforward.c' ] },
113         'mod_fastcgi' : { 'src' : [ 'mod_fastcgi.c' ] },
114         'mod_flv_streaming' : { 'src' : [ 'mod_flv_streaming.c' ] },
115         'mod_indexfile' : { 'src' : [ 'mod_indexfile.c' ] },
116         'mod_proxy' : { 'src' : [ 'mod_proxy.c' ] },
117         'mod_redirect' : { 'src' : [ 'mod_redirect.c' ], 'lib' : [ env['LIBPCRE'] ] },
118         'mod_rewrite' : { 'src' : [ 'mod_rewrite.c' ], 'lib' : [ env['LIBPCRE'] ] },
119         'mod_rrdtool' : { 'src' : [ 'mod_rrdtool.c' ] },
120         'mod_scgi' : { 'src' : [ 'mod_scgi.c' ] },
121         'mod_secdownload' : { 'src' : [ 'mod_secdownload.c' ], 'lib' : [ env['LIBCRYPTO'] ] },
122         'mod_setenv' : { 'src' : [ 'mod_setenv.c' ] },
123         'mod_simple_vhost' : { 'src' : [ 'mod_simple_vhost.c' ] },
124         'mod_sockproxy' : { 'src' : [ 'mod_sockproxy.c' ] },
125         'mod_ssi' : { 'src' : [ 'mod_ssi_exprparser.c', 'mod_ssi_expr.c', 'mod_ssi.c' ] },
126         'mod_staticfile' : { 'src' : [ 'mod_staticfile.c' ] },
127         'mod_status' : { 'src' : [ 'mod_status.c' ] },
128         'mod_uploadprogress' : { 'src' : [ 'mod_uploadprogress.c' ] },
129         'mod_userdir' : { 'src' : [ 'mod_userdir.c' ] },
130         'mod_usertrack' : { 'src' : [ 'mod_usertrack.c' ] },
131         'mod_vhostdb' : { 'src' : [ 'mod_vhostdb.c' ] },
132         'mod_webdav' : { 'src' : [ 'mod_webdav.c' ], 'lib' : [ env['LIBXML2'], env['LIBSQLITE3'], env['LIBUUID'] ] },
133         'mod_wstunnel' : { 'src' : [ 'mod_wstunnel.c' ], 'lib' : [ env['LIBCRYPTO'] ] },
136 if env['with_geoip']:
137         modules['mod_geoip'] = { 'src' : [ 'mod_geoip.c' ], 'lib' : [ env['LIBGEOIP'] ] }
139 if env['with_maxminddb']:
140         modules['mod_maxminddb'] = { 'src' : [ 'mod_maxminddb.c' ], 'lib' : [ env['LIBMAXMINDDB'] ] }
142 if env['with_krb5']:
143         modules['mod_authn_gssapi'] = { 'src' : [ 'mod_authn_gssapi.c' ], 'lib' : [ env['LIBKRB5'], env['LIBGSSAPI_KRB5'] ] }
145 if env['with_ldap']:
146         modules['mod_authn_ldap'] = { 'src' : [ 'mod_authn_ldap.c' ], 'lib' : [ env['LIBLDAP'], env['LIBLBER'] ] }
147         modules['mod_vhostdb_ldap'] = { 'src' : [ 'mod_vhostdb_ldap.c' ], 'lib' : [ env['LIBLDAP'], env['LIBLBER'] ] }
149 if env['with_lua']:
150         modules['mod_magnet'] = { 'src' : [ 'mod_magnet.c', 'mod_magnet_cache.c' ], 'lib' : [ env['LIBLUA'] ] }
151         modules['mod_cml'] = {
152                 'src' : [ 'mod_cml_lua.c', 'mod_cml.c', 'mod_cml_funcs.c' ],
153                 'lib' : [ env['LIBMEMCACHED'], env['LIBLUA'] ]
154         }
156 if env['with_pam']:
157         modules['mod_authn_pam'] = { 'src' : [ 'mod_authn_pam.c' ], 'lib' : [ env['LIBPAM'] ] }
159 if env['with_pcre'] and (env['with_memcached'] or env['with_gdbm']):
160         modules['mod_trigger_b4_dl'] = { 'src' : [ 'mod_trigger_b4_dl.c' ], 'lib' : [ env['LIBPCRE'], env['LIBMEMCACHED'], env['LIBGDBM'] ] }
162 if env['with_mysql']:
163         modules['mod_authn_mysql'] = { 'src' : [ 'mod_authn_mysql.c' ], 'lib' : [ env['LIBCRYPT'], env['LIBMYSQL'] ] }
164         modules['mod_mysql_vhost'] = { 'src' : [ 'mod_mysql_vhost.c' ], 'lib' : [ env['LIBMYSQL'] ] }
165         modules['mod_vhostdb_mysql'] = { 'src' : [ 'mod_vhostdb_mysql.c' ], 'lib' : [ env['LIBMYSQL'] ] }
167 if env['with_pgsql']:
168         modules['mod_vhostdb_pgsql'] = { 'src' : [ 'mod_vhostdb_pgsql.c' ], 'lib' : [ env['LIBPGSQL'] ] }
170 if env['with_dbi']:
171         modules['mod_vhostdb_dbi'] = { 'src' : [ 'mod_vhostdb_dbi.c' ], 'lib' : [ env['LIBDBI'] ] }
173 if env['with_sasl']:
174         modules['mod_authn_sasl'] = { 'src' : [ 'mod_authn_sasl.c' ], 'lib' : [ env['LIBSASL'] ] }
176 if env['with_openssl']:
177         modules['mod_openssl'] = { 'src' : [ 'mod_openssl.c' ], 'lib' : [ env['LIBSSL'], env['LIBCRYPTO'] ] }
179 if env['with_wolfssl']:
180         modules['mod_openssl'] = { 'src' : [ 'mod_openssl.c' ], 'lib' : [ env['LIBCRYPTO'], 'm' ] }
182 staticenv = env.Clone(CPPFLAGS=[ env['CPPFLAGS'], '-DLIGHTTPD_STATIC' ])
184 ## all the core-sources + the modules
185 staticsrc = src + common_src
187 staticlib = copy(env['LIBS'])
188 staticinit = ''
189 for module in modules.keys():
190         staticsrc += modules[module]['src']
191         staticinit += "PLUGIN_INIT(%s)\n"%module
192         if 'lib' in modules[module]:
193                 staticlib += modules[module]['lib']
195 def WriteStaticPluginHeader(target, source, env):
196         do_write = True
197         data = env['STATICINIT']
198         # only touch the file if content actually changes
199         try:
200                 with open(target[0].abspath, 'r') as f:
201                         do_write = (data != f.read())
202         except IOError:
203                 pass
204         if do_write:
205                 with open(target[0].abspath, 'w+') as f:
206                         f.write(env['STATICINIT'])
208 env['STATICINIT'] = staticinit
209 staticheader = env.AlwaysBuild(env.Command('plugin-static.h', [], WriteStaticPluginHeader))
211 ## turn all src-files into objects
212 staticobj = []
213 static_plugin_obj = None
214 for cfile in staticsrc:
215         if cfile == 'plugin.c':
216                 static_plugin_obj = [ staticenv.Object('static-' + cfile.replace('.c', ''), cfile) ]
217                 staticobj += static_plugin_obj
218         else:
219                 staticobj += [ staticenv.Object('static-' + cfile.replace('.c', ''), cfile) ]
220 env.Depends(static_plugin_obj, 'plugin-static.h')
222 ## includes all modules, but links dynamically against other libs
223 staticbin = staticenv.Program('../static/build/lighttpd',
224         staticobj,
225         LIBS = GatherLibs(env, staticlib)
226         )
228 ## you might have to adjust the list of libs and the order for your setup
229 ## this is tricky, be warned
230 fullstaticlib = []
232 ## try to calculate the libs for fullstatic with ldd
233 ## 1. find the lib
234 ## 2. check the deps
235 ## 3. add them to the libs
236 #searchlibs = os.pathsep.join([ '/lib/', '/usr/lib/', '/usr/local/lib/' ])
237 searchlibs = []
238 searchpathre = re.compile(r'\bSEARCH_DIR\("=([^"]+)"\)')
239 f = os.popen('ld --verbose | grep SEARCH_DIR', 'r')
240 for aword in searchpathre.findall(f.read()):
241         searchlibs += [ aword]
242 f.close
244 lddre = re.compile(r'^\s+lib([^=-]+)(?:-[\.0-9]+)?\.so\.[0-9]+ =>', re.MULTILINE)
245 for libs in staticlib:
246         if isinstance(libs, string_types): libs = [ libs ]
247         for lib in libs:
248                 fullstaticlib += [ lib ]
249                 solibpath = WhereIsFile('lib' + lib + '.so', paths = searchlibs)
250                 if solibpath is None:
251                         continue
253                 f = os.popen('ldd ' + solibpath, 'r')
254                 for aword in lddre.findall(f.read()):
255                         fullstaticlib += [ aword ]
256                 f.close
258 ## glibc pthread needs to be linked completely (especially nptl-init.o)
259 ## or not at all, or else pthread structures may not be initialized correctly
260 import platform
261 fullstatic_libs = GatherLibs(env, fullstaticlib)
262 fullstatic_linkflags = [staticenv['LINKFLAGS'], '-static']
263 if (('pthread' in fullstatic_libs) or ('pcre' in fullstatic_libs)) and (platform.system() == 'Linux'):
264         fullstatic_linkflags += ['-Wl,--whole-archive','-lpthread','-Wl,--no-whole-archive']
265         if 'pthread' in fullstatic_libs:
266                 fullstatic_libs.remove('pthread')
267 if 'gcc_s' in fullstatic_libs:
268         fullstatic_linkflags += ['-static-libgcc']
269         fullstatic_libs.remove('gcc_s')
271 ## includes all modules, linked statically
272 fullstaticbin = staticenv.Program('../fullstatic/build/lighttpd',
273         staticobj,
274         LIBS = fullstatic_libs,
275         LINKFLAGS= fullstatic_linkflags
276         )
278 Alias('static', staticbin)
279 Alias('fullstatic', fullstaticbin)
281 implib = 'lighttpd.exe.a'
282 bin_targets = ['lighttpd']
283 bin_linkflags = [ env['LINKFLAGS'] ]
284 if env['COMMON_LIB'] == 'lib':
285         common_lib = env.SharedLibrary('liblighttpd', common_src, LINKFLAGS = [ env['LINKFLAGS'], '-Wl,--export-dynamic' ])
286 else:
287         src += common_src
288         common_lib = []
289         if env['COMMON_LIB'] == 'bin':
290                 bin_linkflags += [ '-Wl,--export-all-symbols', '-Wl,--out-implib=build/' + implib ]
291                 bin_targets += [ implib ]
292         else:
293                 bin_linkflags += [ '-Wl,--export-dynamic' ]
295 instbin = env.Program(bin_targets, src, LINKFLAGS = bin_linkflags,
296         LIBS = GatherLibs(
297                 env,
298                 common_lib,
299                 env['LIBCRYPTO'],
300                 env['LIBDL'],
301                 env['LIBPCRE'],
302         )
304 env.Depends(instbin, configparser)
306 if env['COMMON_LIB'] == 'bin':
307         common_lib = instbin[1]
309 env['SHLIBPREFIX'] = ''
310 instlib = []
311 for module in modules.keys():
312         libs = [ common_lib ]
313         if 'lib' in modules[module]:
314                 libs +=  modules[module]['lib']
315         instlib += env.SharedLibrary(module, modules[module]['src'], LIBS = GatherLibs(env, libs))
316 env.Alias('modules', instlib)
318 inst = []
320 if env['build_dynamic']:
321         Default(instbin[0], instlib)
322         inst += env.Install('${sbindir}', instbin[0])
323         inst += env.Install('${libdir}', instlib)
324         if env['COMMON_LIB'] == 'lib':
325                 Default(common_lib)
326                 inst += env.Install('${bindir}', common_lib)
328 if env['build_static']:
329         Default(staticbin)
330         inst += env.Install('${sbindir}', staticbin)
332 if env['build_fullstatic']:
333         Default(fullstaticbin)
334         inst += env.Install('${sbindir}', fullstaticbin)
336 env.Alias('dynamic', instbin)
337 # default all to be installed
338 env.Alias('install', inst)
340 pkgdir = '.'
341 tarname = env['package'] + '-' + env['version']