Maxthecat
Maxthecat

Reputation: 1328

How can I make a target in scons depend on an external command?

How can I make a scons program depend on the output of an external program? If the output file is already there, I wouldn't want it to re-make it, either. I'm assuming a builder is the way to go, but I'm not quite sure how to hook up the output of my command as a dependency under scons.

Ie, my super contrived example:

hello.c

#include <stdio.h>

external int foo;

int main()
{
  printf("My foo is: %d\n", foo);
  return 0;
}

gen.sh

#!/bin/bash

echo "int foo = 125;" > foo.c

In make this could be:

hello: hello.c foo.c
    gcc hello.c foo.c

foo.c: gen.sh
    ./gen.sh

Upvotes: 0

Views: 40

Answers (1)

bdbaddog
bdbaddog

Reputation: 3509

Sounds like you're a new SCons user.

You'd be well served to take a read through the users guide : https://scons.org/doc/production/HTML/scons-user.html

Note we also have an IRC channel #scons on freenode, and a discord server: https://discord.gg/bXVpWAy

To help you out when you get stuck.

That said here's a very simple SConstruct which should do what you're asking for:

env=Environment()
# Note that we're listing gen.sh as a source. This ensures if it changes
# foo.c will be regenerated.
env.Command('foo.c','gen.sh','./$SOURCE')
env.Program('hello',['hello.c','foo.c'])

Hope that helps!

Upvotes: 1

Related Questions