Scons - 如何在清洁最终目标时停止清洁依赖目标/文件?

时间:2015-05-19 11:28:48

标签: scons

我有两个目标A和B. B取决于A,因此如果我们建立B,也建立A。 现在,如果B被清洁,A也被清洁。 A是.obj文件和结果库的集合。 要求:清洁B时,触摸/移除目标A的任何内容 这是我的代码:

    {env = Environment()
     src1 = ['tridip.c', 'tridip1.c', 'tridip2.c']
     obj1 = [ env.StaticObject(sf) for sf in src1 ]
     lib = env.Library('tridip', obj1)
     Alias('library', lib)
     src2 = ['tridip3.c']
     obj2 = [ env.StaticObject(sf) for sf in src2 ]
     exe = Program(obj2, LIBS=lib, LIBPATH='.')
     Alias('exe', exe)
}

目标A是tridip.lib tridip.obj tridip1.obj tridip2.obj 目标B是:tridip3.exe / LIBPATH:。 tridip.lib tridip3.obj

要求:如何停止清洁目标B上的目标A。

1 个答案:

答案 0 :(得分:0)

您需要NoClean功能。以下是更新SConstruct的方法。

env = Environment()
src1 = ['tridip.c', 'tridip1.c', 'tridip2.c']
obj1 = [ env.StaticObject(sf) for sf in src1 ]
lib = env.Library('tridip', obj1)
if 'library' not in COMMAND_LINE_TARGETS:
    env.NoClean([obj1, lib])
Alias('library', lib)
src2 = ['tridip3.c']
obj2 = [ env.StaticObject(sf) for sf in src2 ]
exe = Program(obj2, LIBS=lib, LIBPATH='.')
Alias('exe', exe)

运行时产生以下内容......

>> scons --version
SCons by Steven Knight et al.:
    script: v2.3.4, 2014/09/27 12:51:43, by garyo on lubuntu
    engine: v2.3.4, 2014/09/27 12:51:43, by garyo on lubuntu
    engine path: ['/usr/lib/scons/SCons']
Copyright (c) 2001 - 2014 The SCons Foundation

>> tree
.
├── SConstruct
├── tridip1.c
├── tridip1.h
├── tridip2.c
├── tridip2.h
├── tridip3.c
├── tridip.c
└── tridip.h

0 directories, 8 files

>> scons library
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
gcc -o tridip.o -c tridip.c
gcc -o tridip1.o -c tridip1.c
gcc -o tridip2.o -c tridip2.c
ar rc libtridip.a tridip.o tridip1.o tridip2.o
ranlib libtridip.a
scons: done building targets.

>> tree
.
├── libtridip.a
├── SConstruct
├── tridip1.c
├── tridip1.h
├── tridip1.o
├── tridip2.c
├── tridip2.h
├── tridip2.o
├── tridip3.c
├── tridip.c
├── tridip.h
└── tridip.o

0 directories, 12 files

>> scons library -c
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Cleaning targets ...
Removed tridip.o
Removed tridip1.o
Removed tridip2.o
Removed libtridip.a
scons: done cleaning targets.

>> tree
.
├── SConstruct
├── tridip1.c
├── tridip1.h
├── tridip2.c
├── tridip2.h
├── tridip3.c
├── tridip.c
└── tridip.h

0 directories, 8 files

>> scons
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
gcc -o tridip.o -c tridip.c
gcc -o tridip1.o -c tridip1.c
gcc -o tridip2.o -c tridip2.c
ar rc libtridip.a tridip.o tridip1.o tridip2.o
ranlib libtridip.a
gcc -o tridip3.o -c tridip3.c
gcc -o tridip3 tridip3.o -L. libtridip.a
scons: done building targets.

>> scons -c
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Cleaning targets ...
Removed tridip3.o
Removed tridip3
scons: done cleaning targets.

>> tree
.
├── libtridip.a
├── SConstruct
├── tridip1.c
├── tridip1.h
├── tridip1.o
├── tridip2.c
├── tridip2.h
├── tridip2.o
├── tridip3.c
├── tridip.c
├── tridip.h
└── tridip.o

0 directories, 12 files