Here is a fragment that illustrates how to make Phony targets that run commands. The AlwaysBuild line makes sure the command runs even if there happens to be a file named the same as the target.

   1 def PhonyTarget(target, action):
   2         phony = Environment(ENV = os.environ,
   3                             BUILDERS = { 'phony' : Builder(action = action) })
   4         AlwaysBuild(phony.phony(target = target, source = 'SConstruct'))
   5 
   6 PhonyTarget('TAGS', 'tools/mktags.sh -e')

Here's a better implementation that handles multiple targets and doesn't require generating an Environment every time.

   1 def PhonyTargets(env = None, **kw):
   2     if not env: env = DefaultEnvironment()
   3     for target,action in kw.items():
   4         env.AlwaysBuild(env.Alias(target, [], action))
   5 
   6 PhonyTargets(TAGS = 'tools/mktags.sh -e')
   7 
   8 env = Environment(parse_flags = '-std=c89 -DFOO -lm')
   9 PhonyTargets(env, CFLAGS  = '@echo $CFLAGS',
  10                   DEFINES = '@echo $CPPDEFINES',
  11                   LIBS    = '@echo $LIBS')

The output looks like this:

$ scons TAGS
tools/mktags.sh -e
 ...
$ scons CFLAGS
-std=c89
$ scons DEFINES
FOO
$ scons LIBS
m

PhonyTargets (last edited 2013-08-28 20:45:10 by WilliamDeegan)