如何在 SConscript 中指定变体目录
How to specify variant directory in SConscript
我是 SCons 的新手,需要帮助来理解为什么我的构建脚本没有产生所需的输出。任何指出我做错了什么的人都将不胜感激。
下面是我的文件结构:
.
├── prog_1
│ ├── hello.c
│ └── SConscript
└── SConstruct
这是我希望它从 prog_1 子目录中查看 运行ning 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:添加了脚本更正。
你们很亲近。您只需要在 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
我是 SCons 的新手,需要帮助来理解为什么我的构建脚本没有产生所需的输出。任何指出我做错了什么的人都将不胜感激。
下面是我的文件结构:
.
├── prog_1
│ ├── hello.c
│ └── SConscript
└── SConstruct
这是我希望它从 prog_1 子目录中查看 运行ning 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:添加了脚本更正。
你们很亲近。您只需要在 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