Search code examples
pythonscons

How to force scons to generate binary file with .bin extension?


I have the following sconstruct

import glob
import os
for file in glob.glob("*.cpp"):
    Program([file])

I am using this on a *nix platform so scons automatically generate executable file with the same name from the same name as the source file. I am just wondering how can I force it to generate executable files with a exe or a bin extension? Thanks!


Solution

  • The extension that gets appended to each created program is stored in the environment variable "PROGSUFFIX". You can override the default setting of "" under Posix systems with:

    env = Environment()
    env['PROGSUFFIX'] = '.bin'    # or env.Replace(PROGSUFFIX='.bin')
    for file in Glob('*.cpp'):
        env.Program([file])
    

    Note, how I don't use the Python glob.glob() here, but the SCons version Glob(). The latter has the advantage that it will find generated CPP files too, which might not exist yet physically.