summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Bühler <stbuehler@web.de>2015-12-19 08:28:42 +0000
committerStefan Bühler <stbuehler@web.de>2015-12-19 08:28:42 +0000
commitc27e27a51bca703da6ff289d629956ae20699b0f (patch)
treebc7e5ce1980e66c680fc9283e428a5d9d2734edd
parent6ef3b709dbf4cf8b9fcc99c2c02aadce43d9f589 (diff)
downloadlighttpd-git-c27e27a51bca703da6ff289d629956ae20699b0f.tar.gz
[scons] fix fullstatic buildlighttpd-1.4.39
- scons searches the dynamic libs to find all dependencies to link against in the static link: - now use the system search path (ld --verbose) instead of some hardcoded list - remove duplicates from the list (all but the last) to avoid linker errors - use custom WhereIsFile function instead of env.WhereIs to find not-executable files too - only write 'plugin-static.h' if it actually changes From: Stefan Bühler <stbuehler@web.de> git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@3066 152afb58-edef-0310-8abb-c4023f1b3aa9
-rw-r--r--src/SConscript58
1 files changed, 52 insertions, 6 deletions
diff --git a/src/SConscript b/src/SConscript
index b29f4c07..a03e101f 100644
--- a/src/SConscript
+++ b/src/SConscript
@@ -2,11 +2,41 @@ import os
import re
import types
import itertools
+from collections import OrderedDict
+
+# search any file, not just executables
+def WhereIsFile(file, paths):
+ for d in paths:
+ f = os.path.join(d, file)
+ if os.path.isfile(f):
+ try:
+ st = os.stat(f)
+ except OSError:
+ # os.stat() raises OSError, not IOError if the file
+ # doesn't exist, so in this case we let IOError get
+ # raised so as to not mask possibly serious disk or
+ # network issues.
+ continue
+ return os.path.normpath(f)
+ return None
+
+def FlattenLibs(libs):
+ if isinstance(libs, basestring):
+ return [libs]
+ else:
+ return [item for sublibs in libs for item in FlattenLibs(sublibs)]
+
+# removes all but the *LAST* occurance of a lib in the list
+def RemoveDuplicateLibs(libs):
+ libs = FlattenLibs(libs)
+ # remove empty strings from list
+ libs = list(filter(lambda x: x != '', libs))
+ return list(reversed(OrderedDict.fromkeys(reversed(libs))))
Import('env')
def GatherLibs(env, *libs):
- return env['LIBS'] + [libs] + [env['APPEND_LIBS']]
+ return RemoveDuplicateLibs(env['LIBS'] + list(libs) + [env['APPEND_LIBS']])
common_src = Split("base64.c buffer.c log.c \
keyvalue.c chunk.c \
@@ -103,7 +133,18 @@ for module in modules.keys():
staticlib += modules[module]['lib']
def WriteStaticPluginHeader(target, source, env):
- open(target[0].abspath, 'w+').write(env['STATICINIT'])
+ do_write = True
+ data = env['STATICINIT']
+ # only touch the file if content actually changes
+ try:
+ with open(target[0].abspath, 'r') as f:
+ do_write = (data != f.read())
+ except IOError:
+ pass
+ if do_write:
+ with open(target[0].abspath, 'w+') as f:
+ f.write(env['STATICINIT'])
+
env['STATICINIT'] = staticinit
staticheader = env.AlwaysBuild(env.Command('plugin-static.h', [], WriteStaticPluginHeader))
@@ -117,7 +158,6 @@ for cfile in staticsrc:
else:
staticobj += [ staticenv.Object('static-' + cfile.replace('.c', ''), cfile) ]
env.Depends(static_plugin_obj, 'plugin-static.h')
-print(str(static_plugin_obj))
## includes all modules, but links dynamically against other libs
staticbin = staticenv.Program('../static/build/lighttpd',
@@ -133,14 +173,20 @@ fullstaticlib = []
## 1. find the lib
## 2. check the deps
## 3. add them to the libs
-searchlibs = os.pathsep.join([ '/lib/', '/usr/lib/', '/usr/local/lib/' ])
+#searchlibs = os.pathsep.join([ '/lib/', '/usr/lib/', '/usr/local/lib/' ])
+searchlibs = []
+searchpathre = re.compile(r'\bSEARCH_DIR\("=([^"]+)"\)')
+f = os.popen('ld --verbose | grep SEARCH_DIR', 'r')
+for aword in searchpathre.findall(f.read()):
+ searchlibs += [ aword]
+f.close
+
lddre = re.compile(r'^\s+lib([^=-]+)(?:-[\.0-9]+)?\.so\.[0-9]+ =>', re.MULTILINE)
for libs in staticlib:
if type(libs) is types.StringType: libs = [ libs ]
for lib in libs:
fullstaticlib += [ lib ]
- solibpath = env.WhereIs('lib' + lib + '.so', searchlibs)
- fullstaticlib += [ lib ]
+ solibpath = WhereIsFile('lib' + lib + '.so', paths = searchlibs)
if solibpath is None:
continue