如何在SConscript中指定variant目录

时间:2015-07-21 13:06:58

标签: scons

我是SCons的新手,需要帮助才能理解为什么我的构建脚本没有产生所需的输出。任何指向我所做错事的人都会非常感激。

以下是我的文件结构:

.
├── prog_1
│   ├── hello.c
│   └── SConscript
└── SConstruct

下面是我希望它从prog_1子目录运行scons -u后的样子。

.
├── prog_1
│   ├── build
│   │   └── hello.o
│   ├── hello.c
│   ├── prog_1.out
│   └── SConscript
└── SConstruct

SConstruct文件的内容:

env = Environment()
env['CC'] = 'gcc'
env['CCFLAGS'] = Split("""
-std=c99
-Wall
""")

Export('env')

prog_1/SConscript文件的内容:

Import('env')

build = env.Clone()
build['CCFLAGS'] += ['-DENABLE_FEAT_1']

build.VariantDir('build', '.', duplicate=0)
build_src = build.Glob('build/*.c')

import os
prog_name = os.getcwd().split(os.sep)[-1]
build.Program(prog_name +'.out', source = build_src)

Clean('.','build')

当我从prog_1子目录运行scons -u时,我将其作为输出:

[ananya@firenze prog_1]$ scons -u
scons: Entering directory `/home/ananya/test/scons-test'
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
scons: `prog_1' is up to date.
scons: done building targets.

编辑:添加输出描述。

Edit2:添加了脚本更正。

1 个答案:

答案 0 :(得分:2)

你非常接近。您只需在SConstruct文件中指定SConscript文件即可。

您的SConstruct应如下...

import os
env = Environment()
env['CC'] = 'gcc'
env['CCFLAGS'] = Split("""
                       -std=c99
                       -Wall
                       """)

Export('env')

SConscript(os.path.join('prog_1', 'SConscript'))

然后当你跑步时会得到以下输出......

>> 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 ..
..
├── prog_1
│   ├── hello.c
│   └── SConscript
└── SConstruct

1 directory, 3 files

>> scons -u
scons: Entering directory `/nfs/users/bellockk/SandBox/tmp'
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
scons: building associated VariantDir targets: prog_1/build
gcc -o prog_1/build/hello.o -c -std=c99 -Wall -DENABLE_FEAT_1 prog_1/hello.c
gcc -o prog_1/prog_1.out prog_1/build/hello.o
scons: done building targets.

>> tree ..
..
├── prog_1
│   ├── build
│   │   └── hello.o
│   ├── hello.c
│   ├── prog_1.out
│   └── SConscript
└── SConstruct

2 directories, 5 files