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