Chinaunix首页 | 论坛 | 博客
  • 博客访问: 685946
  • 博文数量: 231
  • 博客积分: 3217
  • 博客等级: 中校
  • 技术积分: 2053
  • 用 户 组: 普通用户
  • 注册时间: 2011-07-04 12:01
文章分类

全部博文(231)

文章存档

2015年(1)

2013年(10)

2012年(92)

2011年(128)

分类: LINUX

2012-09-04 10:35:36

If you need to find the directory from which the user invoked thesconscommand, you can use the
GetLaunchDirfunction:
                  env = Environment(
                                   LAUNCHDIR = GetLaunchDir(),
                                   )
                                 env.Command(’directory_build_info’,
                                              ’$LAUNCHDIR/build_info’
                                               Copy(’$TARGET’, ’$SOURCE’))
Because SCons is usually invoked from the top-level directory in which theSConstructfile lives, the Pythonos.getcwd()is often equivalent. However, the SCons-u, -Uand-Dcommand-line options, when invoked from a subdirectory, will cause SCons to change to the directory in which the SConstructfile is found. When those options are used,GetLaunchDirwill still return the path to the user’s invoking subdirectory, allowing theSConscriptconfiguration to still get at configuration (or other) files from the originating directory.
GetLaunchDir()函数主要是用来获取scons命令行所在的目录。

mylib_test_source_file = """
#include
int main(int argc, char **argv)
{
MyLibrary mylib(argc, argv);
return 0;
}
"""
def CheckMyLibrary(context):
context.Message(’Checking for MyLibrary...’)
result = context.TryLink(mylib_test_source_file, ’.c’)
context.Result(result)
return result
TheMessageandResultmethods should typically begin and end a custom check to let the user know
what’s going on: the Messagecall prints the specified message (with no trailing newline) and the Result call prints yes if the check succeeds andnoif it doesn’t. The TryLink method actually tests for whether the specified program text will successfully link.
从上面这段话翻译一下我觉得应该是这样的:Message打印一些特殊的信息(无尾随的符号)
Result:它代表如果检查成功打印yes否则打印no
TryLink:测试指定程序文本是否连接成功
 
Configure Contexts配置上下文
The basic framework for multi-platform build configuration in SCons is to attach aconfigure
contextto a construction environment by calling theConfigurefunction, perform a number of checks for libraries, functions, header files, etc., and to then call the configure context’sFinishmethod to finish off the configuration:
大概意思:多平台下在SCons中编译configuration是通过调用Configure函数,检查一些库,函数,头文件之类的,然后调用Finish完成配置文件。
env = Environment()
conf = Configure(env)
# Checks for libraries, header files, etc. go here!
env = conf.Finish()
检查头文件使用CheckCheader:
env = Environment()
conf = Configure(env)
if not conf.CheckCHeader(’math.h’):
print ’Math.h must be installed!’
Exit(1)
if conf.CheckCHeader(’foo.h’):
conf.env.Append(’-DHAS_FOO_H’)
env = conf.Finish()
检查函数是否有效:
env = Environment()
conf = Configure(env)
if not conf.CheckFunc(’strcpy’):
print ’Did not find strcpy(), using local version’
conf.env.Append(CPPDEFINES = ’-Dstrcpy=my_local_strcpy’)
env = conf.Finish()
检查库是否有效:
env = Environment()
conf = Configure(env)
if not conf.CheckLib(’m’):
print ’Did not find libm.a or m.lib, exiting!’
Exit(1)
env = conf.Finish()
等等更多的内容查看SCons_User_Guider.1.3.0.pdf中p145左右
 
检查可以利用的库文件:
env = Environment()
conf = Configure(env)
if not conf.CheckLib(’m’):
print ’Did not find libm.a or m.lib, exiting!’
Exit(1)
env = conf.Finish()
使用CheckLibWithHeader可以同时检查库文件和头文件的有效性:
env = Environment()
conf = Configure(env)
if not conf.CheckLibWithHeader(’m’, ’math.h’, ’c’):
print ’Did not find libm.a or m.lib, exiting!’
Exit(1)
env = conf.Finish()
 
检查typedef的有效性:
env = Environment()
conf = Configure(env)
if not conf.CheckType(’off_t’):
print ’Did not find off_t typedef, assuming int’
conf.env.Append(CCFLAGS = ’-Doff_t=int’)
env = conf.Finish()
 
 
 
 
阅读(1308) | 评论(0) | 转发(0) |
0

上一篇:os.path.dirname(__file__)

下一篇:python os.path.sep

给主人留下些什么吧!~~