From: stevenknight Date: Tue, 21 Jan 2003 22:06:11 +0000 (+0000) Subject: Fix library dependencies when the prefix is specified explicitly. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=2e6d52ca067a51c80bfe7f439979eacac1fae0d2;p=scons.git Fix library dependencies when the prefix is specified explicitly. git-svn-id: http://scons.tigris.org/svn/scons/trunk@560 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- diff --git a/src/CHANGES.txt b/src/CHANGES.txt index be0a4c9c..7cd7e361 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -20,6 +20,9 @@ RELEASE 0.11 - XXX - Allow Python function Actions to specify a list of construction variables that should be included in the Action's signature. + - Allow libraries in the LIBS variable to explicitly include the prefix + and suffix, even when using the GNU linker. + From Anthony Roach: - Use a different static object suffix (.os) when using gcc so shared diff --git a/src/engine/SCons/Defaults.py b/src/engine/SCons/Defaults.py index 27484360..6a3659dc 100644 --- a/src/engine/SCons/Defaults.py +++ b/src/engine/SCons/Defaults.py @@ -184,12 +184,12 @@ Program = SCons.Builder.Builder(action=[ StaticCheck, '$LINKCOM' ], scanner = ProgScan) def _concat(prefix, list, suffix, locals, globals, f=lambda x: x): - """Creates a new list from 'list' by first interpolating each element - in the list using 'locals' and 'globals' and then calling f on the list, and - finally concatinating 'prefix' and 'suffix' onto each element of the - list. A trailing space on 'prefix' or leading space on 'suffix' will - cause them to be put into seperate list elements rather than being - concatinated.""" + """Creates a new list from 'list' by first interpolating each + element in the list using 'locals' and 'globals' and then calling f + on the list, and finally concatenating 'prefix' and 'suffix' onto + each element of the list. A trailing space on 'prefix' or leading + space on 'suffix' will cause them to be put into seperate list + elements rather than being concatenated.""" if not list: return list @@ -202,17 +202,17 @@ def _concat(prefix, list, suffix, locals, globals, f=lambda x: x): return SCons.Util.scons_subst(x, locals, globals) else: return x - + list = map(subst, list) list = f(list) ret = [] - + # ensure that prefix and suffix are strings prefix = str(prefix) suffix = str(suffix) - + for x in list: x = str(x) @@ -226,14 +226,30 @@ def _concat(prefix, list, suffix, locals, globals, f=lambda x: x): ret.append(suffix[1:]) else: ret[-1] = ret[-1]+suffix - + return ret +def _stripixes(prefix, list, suffix, locals, globals, stripprefix, stripsuffix, c=_concat): + """This is a wrapper around _concat() that checks for the existence + of prefixes or suffixes on list elements and strips them where it + finds them. This is used by tools (like the GNU linker) that need + to turn something like 'libfoo.a' into '-lfoo'.""" + def f(list, sp=stripprefix, ss=stripsuffix): + ret = [] + for l in list: + if l[:len(sp)] == sp: + l = l[len(sp):] + if l[-len(ss):] == ss: + l = l[:-len(ss)] + ret.append(l) + return ret + return c(prefix, list, suffix, locals, globals, f) + ConstructionEnvironment = { 'BUILDERS' : { 'SharedLibrary' : SharedLibrary, 'Library' : StaticLibrary, 'StaticLibrary' : StaticLibrary, - 'Alias' : Alias, + 'Alias' : Alias, 'Program' : Program }, 'SCANNERS' : [CScan, FortranScan], 'PDFPREFIX' : '', @@ -242,6 +258,7 @@ ConstructionEnvironment = { 'PSSUFFIX' : '.ps', 'ENV' : {}, '_concat' : _concat, + '_stripixes' : _stripixes, '_LIBFLAGS' : '${_concat(LIBLINKPREFIX, LIBS, LIBLINKSUFFIX, locals(), globals())}', '_LIBDIRFLAGS' : '$( ${_concat(LIBDIRPREFIX, LIBPATH, LIBDIRSUFFIX, locals(), globals(), RDirs)} $)', '_CPPINCFLAGS' : '$( ${_concat(INCPREFIX, CPPPATH, INCSUFFIX, locals(), globals(), RDirs)} $)', diff --git a/src/engine/SCons/Tool/gnulink.py b/src/engine/SCons/Tool/gnulink.py index 2e927525..db7ff4bb 100644 --- a/src/engine/SCons/Tool/gnulink.py +++ b/src/engine/SCons/Tool/gnulink.py @@ -52,6 +52,7 @@ def generate(env, platform): env['LINKCOM'] = '$LINK $LINKFLAGS -o $TARGET $SOURCES $_LIBDIRFLAGS $_LIBFLAGS' env['LIBDIRPREFIX']='-L' env['LIBDIRSUFFIX']='' + env['_LIBFLAGS']='${_stripixes(LIBLINKPREFIX, LIBS, LIBLINKSUFFIX, locals(), globals(), LIBPREFIX, LIBSUFFIX)}' env['LIBLINKPREFIX']='-l' env['LIBLINKSUFFIX']='' diff --git a/test/Library.py b/test/Library.py index ce8acfdd..1a71586c 100644 --- a/test/Library.py +++ b/test/Library.py @@ -29,10 +29,10 @@ import TestSCons test = TestSCons.TestSCons() test.write('SConstruct', """ -env = Environment(LIBS = [ 'foo1', 'foo2' ], +env = Environment(LIBS = [ 'foo1', 'libfoo2' ], LIBPATH = [ '.' ]) env.Library(target = 'foo1', source = 'f1.c') -env.Library(target = 'foo2', source = Split('f2a.c f2b.c f2c.c')) +env.Library(target = 'libfoo2', source = Split('f2a.c f2b.c f2c.c')) libtgt=env.Library(target = 'foo3', source = ['f3a.c', 'f3b.c', 'f3c.c']) env.Program(target = 'prog', source = [ 'prog.c', libtgt ]) """)