LinuxGem
此处为老的 LinuxGem,新版 LinuxGem 请移步 www.linuxgem.org

使用scons软件构建工具

galeki posted @ 2008年9月13日 17:55 in 编程技巧与工具 with tags scons , 5027 阅读

转自 太阳神上 的 Blog: http://moligaloo.is-programmer.com/2008/9/12/Using-Scons-Software-Building-Tool.5332.html

scons 是一个比较有意思的软件构建工具,其本意是想替代著名的autotools系列,我没有用过autotools,不过看到网上的 autotools使用教程就头晕,后来听说了scons,就仔细下载了它的文档看了一下,觉得很符合我的口味。scons与autotools和 cmake等工具不同的是,它并不是从一个类似工程配置的文件中生成Makefile,再调用make进行编译,而是直接控制编译器,从这个意义上来说, 它其实并不是替代autotools,而是make!下面是一个简单的例子,如果你想编译著名的hello.c文件:

  1. #include <stdio.h>
  2.  
  3. int main(){
  4.     printf("hello,world\n");
  5.     return 0;
  6. }

  只需在hello.c的当前目录下建立一个叫SConstruct的文件:

  1. Program('hello,'hello.c')

  然后运行scons就可以了,scons会自动调用gcc(不是make)来编译生成可执行程序hello。如果hello.c中引用了foo.h这个头文件,而foo.h声明的函数定义在foo.c,则SConstrut可以写成:

  1. Program('hello',['hello.c','foo.c'])

  Program的第一个参数是目标,后面可以是单个源文件名或源文件名数组。注意,scons是很智能的,它知道hello.c依赖于 foo.h,所以当foo.h发生改变时,就会重新编译hello.c。这个依赖关系不需要我们额外写代码。如果源文件太多了,全写在那个数组里太长了, 而源文件都是在同一个目录以.c为后辍时,我们可以简写如下:

  1. Program('hello',Glob("*.c"))

  如果程序引入了其它的库,库名为libbar.a,库的目录为/usr/local/lib:

  1. Program('hello',Glob("*.c"),LIBS='bar',LIBPATH='/usr/local/lib')

  如果使用了pkg-config来管理库,可以用环境(Enviroment)如下,例如我使用了GTK+ 2.0:

  1. env=Enviroment()
  2. env.ParseConfig("pkg-config --libs --cflags gtk+-2.0")
  3. env.Program('hello',Glob("*.c"))

  scons除了可以编译C/C++程序以外,它还可以编译LaTeX,如

  1. DVI('paper.dvi','paper.tex')

  就可以用latex命令来编译paper.dvi文件,scons还可以编译Java等其它类型的程序,具体内容见scons的官方文档。
scons本身有一些设计得很好的地方,SConstruct的本身是一个合法的Python程序,它并没有像c,make那样使用自有的配置文件格式, 可以使用所有Python的实用库来完成更高级的运用。还有它判断文件更改是默认情况下不是根据时间戳,而是MD5码!所以上面foo.h被touch 了,并不会导致重新编译。scons的缺点是其效率太低,速度太慢。

  • 无匹配
aui 说:
2008年9月13日 20:15

速度其实还可以

xiaozhu3630 说:
2008年9月14日 03:28

刚下了个游戏 不会安装 这下会了

zt 说:
2008年9月14日 05:17

也许很多人还是习惯automake啊

shili 说:
2008年9月14日 09:33

主要因为automake历史悠久,linux都预装了

Harry 说:
2021年9月29日 15:54

so happy to find good place to many here in the post, the writing is just great, thanks for the post. Best lightweight vacuum cleaner for elderly

forex market 说:
2023年8月16日 16:44

When I originally commented I clicked the -Notify me when new comments are added- checkbox and now each time a comment is added I receive four emails with similar comment. Perhaps there is by any means you are able to eliminate me from that service? Thanks! curtains floral cheap

forex market 说:
2023年8月20日 23:32

An impressive share, I just given this onto a colleague who has been performing a little analysis for this. And then he in truth bought me breakfast since I stumbled upon it for him.. smile. So let me reword that: Thnx for that treat! But yeah Thnkx for spending any time to discuss this, I feel strongly about this and really like reading more about this topic. If at all possible, as you become expertise, could you mind updating your blog with increased details? It is highly great for me. Huge thumb up with this writing! UFABETแทงบอลบนมือถือ

haider 说:
2023年8月21日 18:11

I loved as much as you will receive carried out right here. The sketch is attractive, your authored subject matter stylish. nonetheless, you command get bought an edginess over that you wish be delivering the following. unwell unquestionably come more formerly again since exactly the same nearly a lot often inside case you shield this hike. แทงใบเหลืองใบแดงUFABET

forex market 说:
2023年8月21日 23:34

Director Neil Burger (“The Illusionist”) tries to hit multiple genres and only has mild success with each. UFABETแทงบอลทายผลผู้ชนะ

forex market 说:
2023年8月23日 21:56

Good blog! I really love how it is simple on my eyes and the data are well written. I’m wondering how I might be notified when a new post has been made. I have subscribed to your RSS feed which must do the trick! Have a great day! 안전놀이터

haider 说:
2023年8月23日 22:15

Hmmm, I am not therefore ‘ consider every little thing the following, but you do offer a important information with this make a difference. I’ll instruct me personally plus revisit at a later date. เว็บพนันบอลออนไลน์อันดับ1

forex market 说:
2023年8月24日 17:50

Hello there, I discovered your blog via Google while looking for a similar subject, your site got here up, it looks good. I have bookmarked it in my google bookmarks. UFABET เว็บพนันแตกง่าย

haider 说:
2023年8月24日 18:51

Thanks for taking the time to post this data. I am recently one of your most passoniate followers. I have your RSS feed in my iphone and will check back regularly. เว็บบอลออนไลน์UFA

haider 说:
2023年8月25日 01:30

Can I just say what a aid to seek out somebody who really knows what theyre talking about on the internet. You undoubtedly know how to bring an issue to light and make it important. Extra individuals need to read this and perceive this facet of the story. I cant consider youre not more in style since you positively have the gift. สมัครแทงบอลฟรี

forex market 说:
2023年8月25日 14:24

Good post. I study one thing tougher on totally different blogs everyday. It can all the time be stimulating to learn content from different writers and observe a bit of something from their store. I’d favor to use some with the content material on my weblog whether or not you don’t mind. Natually I’ll offer you a link on your web blog. Thanks for sharing. เว็บไซต์แทงบอลอันดับ1

forex market 说:
2023年8月26日 00:58

I am curious to find out what blog system you are utilizing? I’m having some minor security problems with my latest website and I would like to find something more secure. Do you have any recommendations? เว็บพนันออนไลน์UFA

haider 说:
2023年8月27日 18:18

Can I just say what a aid to seek out somebody who really knows what theyre talking about on the internet. You undoubtedly know how to bring an issue to light and make it important. Extra individuals need to read this and perceive this facet of the story. I cant consider youre not more in style since you positively have the gift. 메이저사이트

haider 说:
2023年8月30日 16:58

Thanks a lot for providing individuals with an exceptionally wonderful opportunity to read in detail from this website. It’s always so pleasurable and full of a good time for me personally and my office colleagues to search the blog particularly thrice weekly to study the new items you will have. And of course, we’re at all times pleased with your stunning tactics you give. Selected two areas in this article are undeniably the most efficient we have ever had. 메이저사이트

haider 说:
2023年9月03日 20:10

An interesting discussion may be worth comment. There’s no doubt that you should write on this topic, it will not be a taboo subject but generally folks are inadequate to speak on such topics. Yet another. Cheers 안전놀이터

forex market 说:
2023年9月05日 00:58

Well, this Thursday I read through a couple of your posts. I must say this is one of your better ones. Thumbs up! salingsilang

sdsds 说:
2023年9月08日 22:22

After research a few of the blog posts in your website now, and I really like your method of blogging. I bookmarked it to my bookmark website listing and will probably be checking again soon. Pls check out my web page as nicely and let me know what you think. ak47 hawaiian shirt

haider 说:
2023年9月08日 23:01

Hi there, simply become aware of your blog thru Google, and found that it is truly informative. I’m gonna be careful for brussels. I will be grateful should you continue this in future. Lots of other folks can be benefited out of your writing. Cheers! filmyzilla 2023

haider 说:
2023年9月14日 21:27

For ice cream program, you would love your activities with long term ice cream flavors along with flavors of month sub method and significantly far more other system. You would get every month new taste of month for ice cream under flavor of month subprograms. Other subprograms are sherbets, rotators, sorbets, ices, small fats and yogurts gone nuts. สล็อต

haider 说:
2023年9月20日 00:54

I still can not quite think that I could often be one of those studying the important suggestions found on your website. My family and I are sincerely thankful on your generosity and for giving me potential to pursue our chosen profession path. Many thanks for the important information I acquired from your site. custom birthday crocs

haider 说:
2023年9月23日 16:46

My wife and i got quite excited when Edward managed to deal with his investigations from the precious recommendations he had when using the web site. It is now and again perplexing to simply choose to be giving out secrets and techniques which usually most people have been making money from. And we realize we’ve got the website owner to appreciate for that. All of the explanations you made, the simple web site navigation, the friendships you can make it easier to instill – it’s got all awesome, and it’s leading our son in addition to the family know that the theme is satisfying, and that is exceedingly fundamental. Many thanks for all! visit my site here – alternative medicine institute roof cleaning southampton

jmaes 说:
2023年9月24日 14:07

We are a group of volunteers and starting a new scheme in our community. Your website provided us with valuable information to work on. You have done a formidable job and our whole community will be grateful to you. shillong teer common number

jmaes 说:
2023年10月02日 23:32

I’m extremely impressed with your writing talents as smartly with the format for your blog. Is this a paid topic or did you modify it yourself? Either way keep up the nice high quality writing, it is rare to look a great blog like this one these days. Kalaastar song lyrics

james 说:
2023年10月06日 18:58

After study a handful of the blogs on your internet site now, we really like your technique for blogging. I bookmarked it to my bookmark internet site list and are checking back soon. Pls have a look at my web page too and let me know if you agree. chicken crocs

ds 说:
2023年10月12日 18:48

That can feel totally proper. Each one of more compact factors have been developed by means of several document schooling. I enjoy the application form lots. Gutter Cleaning Poole

ds 说:
2023年10月14日 01:11

Thank you for some other informative blog. The place else could I am getting that type of info written in such a perfect method? I’ve a project that I’m just now operating on, and I’ve been on the glance out for such information. transparent training bra

ds 说:
2023年10月21日 13:56

Hiya. Very nice website!! Man .. Beautiful .. Wonderful .. I’ll bookmark your blog and take the feeds additionally…I’m happy to find so much helpful information right here within the post. Thanks for sharing… แทงบอลเงินสด


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter