Search code examples
cross-platformscons

Force scons append suffix anyway.


Normally scons would automatically append suffix, fx the SConstruct

 StaticLibrary("foo", ["t.c"])

would produce the static library libfoo.a or foo.lib or whatever the platform fancies, but if the basic name of the library already seem to have an extension this won't happen. fx the SConstruct file

 StaticLibrary("foo.bar", ["t.c"])

produces libfoo.bar (and I guess it would produce foo.bar using MS toolchain).

What I would like is it to produce libfoo.bar.a using GNU toolchain and foo.bar.lib using MS toolchain (and so on). Is there a (simple) way to achieve this?

Note that it won't work to do

 StaticLibrary("foo.bar.a", ["t.c"])

since it would produce libfoo.bar.a as wanted using GNU toolchain, but I'd guess that it would produce foo.bar.a with MS toolchain (and not foo.bar.lib as I wanted).


Solution

  • This is the easiest workaround that I can think of right now:

    env = Environment()
    env['MYLIB'] = "foo.bar"
    t = env.StaticLibrary('${MYLIB}', Glob('*.cpp'))
    

    By defining the name of the library as environment variable, you prevent the Builder logic (suffix/src_suffix arguments) from detecting the already existing extension. Later in the processing chain, the name for the target library gets fully expanded, such that the right things happen.