0
votes

I'm developing some code for a digital signal processing card that uses a language called 'Cn' - very similar to C, with a few important differences like the introduction of 'mono' and 'poly' variables.

The compiler is called 'cscn', and is located at 'C:\Program Files (x86)\clearspeed\bin\cscn.exe' (it's a Windows host system.) I'm investigating the use of SCons to do my compiling and dependency generation, but I can't seem to get SCons to recognize/use the cscn compiler. A very simple compilation command should be

cscn pi.cn -lcn_reduction -o pi.csx

My most recent attempt at a configuration script is

env = Environment()
env.Replace(CC = ['C:\Program Files (x86)\clearspeed\bin\cscn.exe'])
env.Program('pi.csx', 'pi.cn', CFLAGS='-lcn_reduction')

What I get, however, is an error message telling me that 'No version of Visual Studio compiler found' and that I must specify at least one .exe target for my build. cscn doesn't build an .exe file, it builds a .csx file. I was hoping I could replace the compiler it attempts to use with the env.Replace() command, but evidently not.

Is there a way to do this?

2
Aside, unrelated to your question: using backslashes in Python strings will eventually bite you. Prefer 'C:/Prog...' or 'C:\\Prog...' or r'C:\Prog...'. - Robᵩ

2 Answers

1
votes

Please try

env = Environment(CC = 'C:/Program Files (x86)/clearspeed/bin/cscn.exe')
env.Program('pi.csx', 'pi.cn', CFLAGS='-lcn_reduction')

instead. The simple Environment() call defaults to

env = Environment(tools=['default'])

which means that SCons tries to find its Tools, like gcc or g++, first. If you replace their paths afterwards, it will be too late...the corresponding Builders like Program and Library won't have been initialized for the current environment because no compiler was found. Note that you may have to replace several other variables (AR and LINK come to mind) for getting your whole toolchain going properly. See also How can I use a cross compiler with Scons? .

If you continue to struggle with this, you might want to come over to our user mailing list at [email protected] (see http://scons.org/lists.html) and ask your further questions there.

1
votes

Looks like you need to make a couple changes. Firstly, since you are on windows, SCons will default to configuring Visual Studio tools if they are available,

See: SCons/Tool/init.py

c_compilers = ['msvc', 'mingw', 'gcc', 'intelc', 'icl', 'icc', 'cc', 'bcc32' ]

So first let's fix that:

env = Environment(tools=[])
env['CC'] = 'C:\Program Files (x86)\clearspeed\bin\cscn.exe'
env.Tool('cc')
env['LINK'] = 'C:\Program Files (x86)\clearspeed\bin\cscn.exe'
env.Tool('link')
env.Program('pi.csx', 'pi.cn', CFLAGS='-lcn_reduction')

Likely, that's still not enough because SCons doesn't know about .csx and .cn file suffixes. So let's fix that:

env = Environment(tools=[])
env['CC'] = 'C:\Program Files (x86)\clearspeed\bin\cscn.exe'
env.Tool('cc')
env['LINK'] = 'C:\Program Files (x86)\clearspeed\bin\cscn.exe'
env.Tool('link')
env['PROGSUFFIX'] = '.csx'
# Note we removed that from the output for program as it should automatically add it.
env.Program('pi', 'pi.cn', CFLAGS='-lcn_reduction')

Next you'll need to tell SCons that .cn's can make object files.

import SCons.Tool
import SCons.Default
static_obj, shared_obj = SCons.Tool.createObjBuilders(env)
my_suffix = '.cn'
static_obj.add_action(my_suffix, SCons.Defaults.CAction)
#shared_obj.add_action(my_suffix, SCons.Defaults.ShCAction)
static_obj.add_emitter(my_suffix, SCons.Defaults.StaticObjectEmitter)
#shared_obj.add_emitter(my_suffix, SCons.Defaults.SharedObjectEmitter)

That should take care of that.

So let's put it all together:

env = Environment(tools=[])
env['CC'] = 'C:\Program Files (x86)\clearspeed\bin\cscn.exe'
env.Tool('cc')
env['LINK'] = 'C:\Program Files (x86)\clearspeed\bin\cscn.exe'
env.Tool('link')
env['PROGSUFFIX'] = '.csx'

# Add .cn suffix as able to create objects.
import SCons.Tool
import SCons.Default
static_obj, shared_obj = SCons.Tool.createObjBuilders(env)
my_suffix = '.cn'
static_obj.add_action(my_suffix, SCons.Defaults.CAction)
#shared_obj.add_action(my_suffix, SCons.Defaults.ShCAction)
static_obj.add_emitter(my_suffix, SCons.Defaults.StaticObjectEmitter)
#shared_obj.add_emitter(my_suffix, SCons.Defaults.SharedObjectEmitter)

# Note we removed that from the output for program as it should automatically add it.
env.Program('pi', 'pi.cn', CFLAGS='-lcn_reduction')

Now, I don't have access to your compiler toolchain, so I've not tried the above, but I believe it should get you most, if not all the way there.