找回密码
 用户注册

QQ登录

只需一步,快速开始

查看: 3898|回复: 0

使用 SCons 代替 Makefile 快速构建应用程序

[复制链接]
发表于 2012-3-24 00:11:27 | 显示全部楼层 |阅读模式

  • 作者:柳大·Poechant
  • 博客:blog.CSDN.net/Poechant
  • 邮箱:zhongchao.ustc@gmail.com
  • Copyright © 柳大·Poechant
    0 Introduction
    为 make 工具编写建造规则不是一件容易的事。它复杂的配置规则,即使是有经验的开发者也望而生畏。make 工具的许多替代品便因此而诞生,SCons 就是是其中之一。SCons 是一个用 Python 语言编写的类似于 make 工具的程序。与 make 工具相比较,SCons 的配置文件更加简单清晰明了,除此之外,它还有许多的优点。
    SCons 支持多种操作系统平台,实现程序的构建可移植性。
    1 Install
    1. $ tar zvf tar -zxf scons-2.0.1.tar
    2. $ cd scons-2.0.1
    3. $ sudo python setup.py install
    复制代码
    2 Hello World2.1 Source File
    1. #include <stdio.h>
    2. #include <stdlib.h>
    3. int main(int argc, char* argv[])
    4. {
    5.     printf("Hello, SCons!\n");
    6.     return 0;
    7. }
    复制代码
    2.2 Config File
    1. Program('helloscons.c')
    复制代码
    2.3 Build
    1. $ ls helloscons
    2. helloscons.c  SConstruct
    3. $ cd helloscons/
    4. $ scons
    5. scons: Reading SConscript files ...
    6. scons: done reading SConscript files.
    7. scons: Building targets ...
    8. gcc -o helloscons.o -c helloscons.c
    9. gcc -o helloscons helloscons.o
    10. scons: done building targets.
    11. $ ls
    12. helloscons  helloscons.c  helloscons.o  SConstruct
    13. $ ./helloscons
    14. Hello, SCons!
    复制代码
    2.4 Run
    1. $ ./helloscons
    2. Hello, SCons!
    复制代码
    2.5 Clean
    1. $ scons -c
    2. scons: Reading SConscript files ...
    3. scons: done reading SConscript files.
    4. scons: Cleaning targets ...
    5. Removed helloscons.o
    6. Removed helloscons
    7. scons: done cleaning targets.
    8. $ ls -a
    9. helloscons.c  SConstruct .sconsign.dblite
    复制代码
    3 Improve your skills!3.1 Specify your executable file name
    1. Program('myscons, 'helloscons.c')
    复制代码
    3.2 Be quiet when building!$ scons -Q 3.3 A little more complicated program
    1. Program('helloscons2', ['helloscons2.c', 'file1.c', 'file2.c'],
    2.     LIBS = 'm',
    3.     LIBPATH = ['/usr/lib', '/usr/local/lib'],
    4.     CCFLAGS = '-DHELLOSCONS')
    5. $ scons -Q
    6. gcc -o file1.o -c -DHELLOSCONS file1.c
    7. gcc -o file2.o -c -DHELLOSCONS file2.c
    8. gcc -o helloscons2.o -c -DHELLOSCONS helloscons2.c
    9. gcc -o helloscons2 helloscons2.o file1.o file2.o -L/usr/lib -L/usr/local/lib -lm
    复制代码
    3.4 Regular expression
    1. Program('helloscons2', Glob('*.c')
    复制代码
    4 Reference

    • http://www.ibm.com/developerworks/cn/linux/l-cn-scons/index.html?ca=drs-
    -
    转载请注明来自“柳大的CSDN博客”:blog.CSDN.net/Poechant
    -
您需要登录后才可以回帖 登录 | 用户注册

本版积分规则

Archiver|手机版|小黑屋|ACE Developer ( 京ICP备06055248号 )

GMT+8, 2024-5-5 03:05 , Processed in 0.013321 second(s), 6 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表