Fix library dependencies when the prefix is specified explicitly.
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Tue, 21 Jan 2003 22:06:11 +0000 (22:06 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Tue, 21 Jan 2003 22:06:11 +0000 (22:06 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@560 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/CHANGES.txt
src/engine/SCons/Defaults.py
src/engine/SCons/Tool/gnulink.py
test/Library.py

index be0a4c9cc92e040853132b92c39423021e1f5290..7cd7e36184e191c17ea6c6fd8bb15073b3759f7f 100644 (file)
@@ -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
index 27484360c328ce4620443cca8a249619be6b2278..6a3659dc5e1c00fbd353a90ded2a4ef5c90b4df9 100644 (file)
@@ -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)} $)',
index 2e9275259a5abcce92d68424e1d8dad30cfa1fea..db7ff4bbdd696f5e47405b15039ef3e051ccfd7f 100644 (file)
@@ -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']=''
 
index ce8acfdd5e1a9d977332822f3e6f64149df8ae54..1a71586cb16178d43a65076daa5005f4fde99414 100644 (file)
@@ -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 ])
 """)