Finding Libraries: the $LIBPATH Construction Variable
Program('program.c',LIBS='m',LIBPATH=['/usr/lib','/usr/local/lib'])
% scons -Q
cc -o prog.o -c prog.c
cc -o prog prog.o -L/usr/lib -L/usr/local/lib -lm
Explicitly Creating File and Directory Nodes
scons支持Fil和Dir两个函数功能,返回的是文件或者目录节点
hello_c = File(’hello.c’)
Program(hello_c)
classes = Dir(’classes’)
Java(classes, ’src’)
scons支持Entry函数功能返回一个文件或者目录节点
xyzzy = Entry(’xyzzy’)
Printing Node File Names
hello_c = File('hello.c')
Program(hello_c)
object_list = Object('hello.c')
program_list = Program(object_list)
print "The object file is:", object_list[0]
print "The program file is:", program_list[0]
# gedit SConstruct
# scons
scons: Reading SConscript files ...
The object file is: hello.o
The program file is: hello
scons: done reading SConscript files.
scons: Building targets ...
scons: `.' is up to date.
scons: done building targets.
# ls
hello hello.c hello.o SConstruct
# gedit SConstruct
Using a Node’s File Name as a String使用文件名字的节点当做字符:
if you want to use the Python os.path.exists to figure out whether a file exists while the SConstruct file is being read and
executed, you can fetch the string as follows:
import os.path
program_list = Program(’hello.c’)
program_name = str(program_list[0])
if not os.path.exists(program_name):
print program_name, "does not exist!"
import os.path
hello_c = File('hello.c')
Program(hello_c)
object_list = Object('hello.c')
program_list = Program(object_list)
p=str(program_list[0])
if not os.path.exists(p):
print p ,"not exit"
print "The object file is:", object_list[0]
print "The program file is:", program_list[0]
# scons
scons: Reading SConscript files ...
hello not exit
The object file is: hello.o
The program file is: hello
scons: done reading SConscript files.
scons: Building targets ...
gcc -o hello.o -c hello.c
gcc -o hello hello.o
scons: done building targets.
阅读(985) | 评论(0) | 转发(0) |