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

全部博文(231)

文章存档

2015年(1)

2013年(10)

2012年(92)

2011年(128)

分类: LINUX

2012-07-02 14:52:16

scons安装:
在redhat: #yum install scons  或者#rpm -Uvh scons-1.3.0.1.noarch.rpm
安装文件在/usr/bin,库文件在/usr/lib/scons
 
Installing SCons on Debian Linux Systems
# apt-get install scons
 
Building and Installing SCons on Any System
从网站.上下载进行安装:
 # cd scons-1.3.0
# python setup.py install
 
To install SCons in a version-specific location, add the --version-lib option when you call
setup.py:
# python setup.py install --version-lib
3
Chapter 1. Building and Installing SCons
This will install the SCons build engine in the /usr/lib/scons-1.3.0 or
C:\Python25\scons-1.3.0 directory, for example
 
Installing SCons in Other Locations
# python setup.py install --prefix=/opt/scons
 
 
Building Simple C / C++ Programs: hello.c
#include
#include
int main()
{
printf("hello world\n");
}
在同一个目录建立SConstruct:
Program('hello','hello.c')
执行下面的步骤:
# gedit SConstruct
# scons
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
gcc -o hello.o -c hello.c
gcc -o hello hello.o
scons: done building targets.
# ./hello
hello world
 
Building Object Files
建立object方法告诉SCons建立一个object文件。
Object(’hello.c’)
# scons
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
gcc -o hello.o -c hello.c
scons: done building targets.
# ls
hello.c  hello.o  SConstruct
Cleaning Up After a Build:清除
# scons -c
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Cleaning targets ...
Removed hello.o
scons: done cleaning targets.
# ls
hello.c  SConstruct
SConstruct等效于makefile的功能,它与makefile文件的区别在于SConstruct是python脚本文件。在SConstruct中使用print输出状态信息:
scons
scons: Reading SConscript files ...
Calling Program(’hello.c’)
Calling Program(’goodbye.c’)
Finished calling Program()
scons: done reading SConscript files.
scons: Building targets ...
cc -o goodbye.o -c goodbye.c
cc -o goodbye goodbye.o
cc -o hello.o -c hello.c
cc -o hello hello.o
scons: done building targets.
 
 
Making the SCons Output Less Verbose减少输出状态信息:
# scons
scons: Reading SConscript files ...
bianyi hello,c wenjian
scons: done reading SConscript files.
scons: Building targets ...
gcc -o hello.o -c hello.c
gcc -o hello hello.o
scons: done building targets.
# scons -c
scons: Reading SConscript files ...
bianyi hello,c wenjian
scons: done reading SConscript files.
scons: Cleaning targets ...
Removed hello.o
Removed hello
scons: done cleaning targets.
# scons -Q
bianyi hello,c wenjian
gcc -o hello.o -c hello.c
gcc -o hello hello.o
让输出程序命名为自己想要的名字的,可以使用Program('new_hello','hello.c')
# scons
scons: Reading SConscript files ...
bianyi hello,c wenjian
scons: done reading SConscript files.
scons: Building targets ...
gcc -o hello.o -c hello.c
gcc -o new_hello hello.o
scons: done building targets.
# ls
hello  hello.c  hello.o  new_hello  SConstruct
Compiling Multiple Source Files编译多个源文件:
Program('prog.c','file1.c','file2.c')
% scons -Q
cc -o file1.o -c file1.c
cc -o file2.o -c file2.c
cc -o prog.o -c prog.c
cc -o prog prog.o file1.o file2.o
 
也可以这样表示:Program('program',['prog.c','file1.c','file2.c')
% scons -Q
cc -o file1.o -c file1.c
cc -o file2.o -c file2.c
cc -o prog.o -c prog.c
cc -o program prog.o file1.o file2.o
 
Making a list of files with Glob
You can also use the Glob function to find all files matching a certain template, using the standard shell
pattern matching characters *, ? and [abc] to match any of a, b or c. [!abc] is also supported, to
match any character except a, b or c. This makes many multi-source-file builds quite easy:
Program(’program’, Glob(’*.c’))主要是使用Glob匹配*.c文件来变异。
 
Specifying Single Files Vs. Lists of Files
文件列表编译:Program('hello',['file1.c','file2.c'])
单个文件编译:Program('hello','hello.c')等同于Program('hello',['hello.c'])
Trying to do "Python things" that mix strings and lists will cause errors or lead to incorrect results:
common_sources = [’file1.c’, ’file2.c’] 这种做法容易出现错误
13
Chapter 3. Less Simple Things to Do With Builds
# THE FOLLOWING IS INCORRECT AND GENERATES A PYTHON ERROR
# BECAUSE IT TRIES TO ADD A STRING TO A LIST:
Program(’program1’, common_sources + ’program1.c’)
# The following works correctly, because it’s adding two
# lists together to make another list.
Program(’program2’, common_sources + [’program2.c’])
 
使用split函数功能:
Program(’program’,[’main.c ','file1.c ','file2.c’])等效于Program(’program’, Split(’main.c file1.c file2.c’))
src_files=Split('main.c file1.c file2.c')
Program('program',src_files)
同时允许分行:src_files = Split("""main.c
                                   file1.c
                                   file2.c""")
                Program(’program’, src_files)
 
scons运行使用python keyword argments来识别output file和input file
src_files = Split(’main.c file1.c file2.c’)
Program(target = ’program’, source = src_files)等效于Program(source = src_files, target = ’program’)
 
 
Sharing Source Files Between Multiple Programs
多个程序共享源文件的一个方法就是建立库文件。
Program(Split(’foo.c common1.c common2.c’))
Program(’bar’, Split(’bar1.c bar2.c common1.c common2.c’))
% scons -Q
cc -o bar1.o -c bar1.c
cc -o bar2.o -c bar2.c
cc -o common1.o -c common1.c
cc -o common2.o -c common2.c
cc -o bar bar1.o bar2.o common1.o common2.o
cc -o foo.o -c foo.c
cc -o foo foo.o common1.o common2.o
 
可以用python的一些功能添加文件进行维护多个程序之间的编译:
common = [’common1.c’, ’common2.c’]
foo_files = [’foo.c’] + common
bar_files = [’bar1.c’, ’bar2.c’] + common
Program(’foo’, foo_files)
Program(’bar’, bar_files)
 
Building Libraries
Library('foo',['f1.c','f2.c','f3.c'])
% scons -Q
cc -o f1.o -c f1.c
cc -o f2.o -c f2.c
cc -o f3.o -c f3.c
ar rc libfoo.a f1.o f2.o f3.o
ranlib libfoo.a
 
Building Libraries From Source Code or Object Files
Library('foo',[''f1.c','f2.o','f3.c','f4.o'])
% scons -Q
cc -o f1.o -c f1.c
cc -o f3.o -c f3.c
ar rc libfoo.a f1.o f2.o f3.o f4.o
ranlib libfoo.a
 
Building Static Libraries Explicitly: the StaticLibrary Builder
StaticLibrary('foo',['f1.c','f2.c',''f3.c])
 
Building Shared (DLL) Libraries: the SharedLibrary Builder
SharedLibrary('foo',['f1.c','f2.c','f3.c'])
% scons -Q
cc -o f1.os -c f1.c
cc -o f2.os -c f2.c
cc -o f3.os -c f3.c
cc -o libfoo.so -shared f1.os f2.os f3.os
 
Linking with Libraries
Library('foo',['f1.c','f2.c','f3.c'])
Program('program',LIBS=['foo','bar'],LIBPATH='.')
% scons -Q
cc -o f1.o -c f1.c
cc -o f2.o -c f2.c
cc -o f3.o -c f3.c
ar rc libfoo.a f1.o f2.o f3.o
ranlib libfoo.a
cc -o prog.o -c prog.c
cc -o prog prog.o -L. -lfoo -lbar
 
 
 
 
 
 
 
阅读(1137) | 评论(0) | 转发(0) |
0

上一篇:更加抽象

下一篇:scons(二)

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