Reputation: 73
I have to convert a Makefile project into SCons and I am facing some problems. Lets assume a make file like below:
.PHONY : clean all
all : test_1 test_2
clean :
rm -rf *.o
test_1 :
@echo "---------------Test_1 Build Started-------------------"
g++ -std=gnu++11 test_1.cpp -o target_1
@echo "---------------Test_1 Build Finished-------------------"
test_2 :
@echo "---------------Test_2 Build Started-------------------"
g++ -std=gnu++11 test_2.cpp -o target_2
@echo "---------------Test_2 Build Finished-------------------"
Here if I run the Makefile, it will first run test_1 and then test_2. By @echo, we can print every steps where the build is. Problem with Scons is, Scons reads all the scirpt first and prints messages if there any. Then it starts building the targets. That mean's
print "---------------Test_1 Build Started-------------------"
test_1 = env.Program(source = 'test_1.cpp', target = 'target_1')
print "---------------Test_1 Build Finished-------------------"
print "---------------Test_2 Build Started-------------------"
test_2 = env.Program(source = 'test_2.cpp', target = 'target_2')
print "---------------Test_2 Build Finished-------------------"
will not work as expected. First it will print all the messages then it will start building. How can I create the exact scenario that I am doing in the Makefile?
Moreover, Using Makefile I can run only one block by running "make test_1" or "make test_2". How can I do this in Scons? Thanks In Advance :)
NB : using Alias it can be done in Scons but if I use Alias like
env.Alias('test_1', test_1)
and run "scons test_1", it can build the target but "scons -c" does not remove the target. Is there any better way to do this?
Upvotes: 2
Views: 1202
Reputation: 3509
To answer your question about building a particular target from the command line, just specify it on the command line:
scons test_1.o -> builds test_1.o and anything it depends on
scons target_1 -> builds target_1 and anything it depends on
Upvotes: 1
Reputation: 1381
You can use AddPostAction
and AddPreAction
like so:
def pre_action(target, source, env):
print("$TARGET build started")
AddPreAction(test_1, pre_action)
Upvotes: 1