forked from ArduPilot/waf
/
wscript
142 lines (113 loc) · 5.02 KB
/
wscript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/env python3
# encoding: utf-8
# Thomas Nagy, 2006-2012 (ita)
# the following two variables are used by the target "waf dist"
VERSION='0.0.1'
APPNAME='cc_test'
# if you want to cross-compile, use a different command line:
# CC=mingw-gcc AR=mingw-ar waf configure build
top = '.'
from waflib import Configure, Logs, Utils
#Configure.autoconfig = True # True/False/'clobber'
def options(opt):
opt.load('compiler_c gnu_dirs')
def configure(conf):
conf.load('compiler_c gnu_dirs')
# compile and link in the default mode, which is c++ if present
conf.check(fragment='int main() { return 0; }\n')
# just compile in c mode, and do not link
conf.check(fragment='int main() { return 0; }\n', features='c')
try:
conf.check(fragment="int main() { return 0; }\n", execute=True) # 1
except conf.errors.WafError:
Logs.warn('You are probably using a cross-compiler (disabling specific configuration tests)')
conf.check_library(test_exec=False)
else:
conf.check(fragment="""#include<stdio.h>\nint main(){fprintf(stderr, "mu"); printf("%d", 22);return 0;}\n""", execute=True, define_name='HAVE_MU')
conf.check_library(test_exec=True)
conf.check(lib='m', cflags='-Wall', defines=['var=foo', 'x=y'], uselib_store='M', mandatory=False)
conf.check_large_file(mandatory=False)
conf.check_inline()
endianness = conf.check_endianness()
conf.define_cond("BIG_ENDIAN", endianness == "big")
def test_build(ctx):
ctx(rule='echo hello', shell=True, always=True)
# Configuration tests may even be re-used:
#ctx.in_msg = True # suppress console outputs
#ctx.check_large_file(mandatory=False)
conf.multicheck(
# list of conf.check() arguments
{'header_name':'stdio.h', 'msg':'... stdio', 'uselib_store': 'STDIO'},
{'header_name':'xyztabcd.h', 'msg':'... optional xyztabcd.h', 'mandatory': False},
{'header_name':'stdlib.h', 'msg':'... stdlib', 'okmsg': 'aye', 'errmsg': 'nope'},
{'func': test_build, 'msg':'... testing an arbitrary build function', 'okmsg':'ok'},
# parallelism control with after_tests/before_tests
{'header_name':'malloc.h', 'msg':'... malloc', 'uselib_store':'MALLOC', 'id':'malloc_t', 'mandatory':False},
{'header_name':'unistd.h', 'msg':'... unistd', 'uselib_store':'UNISTD', 'before_tests':['malloc_t'], 'mandatory':False},
msg = 'Checking for headers in parallel',
#mandatory = False, # set to False to make all tests non-mandatory
#run_all_tests = False # set to False to stop at the first error
)
conf.check(header_name='stdio.h', auto_add_header_name=True)
#conf.check(header_name='unistd.h')
conf.check(fragment='int main() {return 0;}\n')
conf.write_config_header('config.h')
# exclude system libraries, force a particular folder (see strictlib below)
#conf.check(features='c cprogram strictlib', lib = 'gif', libpath = ['/opt/lib'])
def build(bld):
bld.env.DEFINES=['WAF=1']
bld.recurse('program stlib shlib')
#bld.install_files('/tmp/foo', 'wscript')
#bld.env.PREFIX='/tmp/foo'
bld.install_files('${PREFIX}/', 'program/a.h program/main.c', relative_trick=False)
bld.install_as('${PREFIX}/gnigni.txt', 'wscript')
bld.symlink_as('${PREFIX}/libfoo.so', 'wscript')
p = Utils.subst_vars('${PREFIX}/gnigni.txt', bld.env)
bld.symlink_as('${PREFIX}/share/gnigni-abs.txt', p, relative_trick=False)
bld.symlink_as('${PREFIX}/share/gnigni-rel.txt', p, relative_trick=True)
bld.env.FOO =['m', 'ncurses']
bld.env.ST = '-L%s'
bld.env.A = 'aye'
bld.env.B = 'doh'
bld.env.SRCA = ['aaa']
bld(rule='echo ${ST:FOO} ${ST:SRC} ${A}${B} ${ST:SRCA} ${ST:SRC[0].abspath()}',
always=True, source='wscript', shell=1, name='Shell')
if not Utils.is_win32:
bld(rule='echo ${ST:FOO} ${ST:SRC} ${A}${B} ${ST:SRCA} ${ST:SRC[0].abspath()}',
always=True, source='wscript', shell=0,
stdout=None, stderr=None, # disable synchronized outputs on this rule
cls_keyword=lambda x:'Trying again', name='NoShell')
# illustrate how to add a command 'foo' and to execute things in it
if bld.cmd == 'foo':
def bar(bld):
print('myprogram exit status is',
bld.exec_command(bld.get_tgen_by_name('myprogram').link_task.outputs[0].abspath()))
bld.add_post_fun(bar)
#bld(rule='echo ${SRC} ${tsk.generator.newsize}', newsize='256x256', source='wscript')
# command examples
from waflib.Build import BuildContext
class foo_class(BuildContext):
cmd = 'foo'
from waflib.Context import Context
class package_class(Context):
"""just a test, try calling 'waf package' """
cmd = 'package'
fun = 'package'
def package(ctx):
print('just a test', ctx.path.ant_glob('wscript'))
# and a task generator method example
from waflib import TaskGen
@TaskGen.feature('strictlib')
def check_lib_in_libpath(self):
#For use in a configuration check: raise an exception
#if the library file does not exist in the folders pointed by 'libpath'
pths = self.to_list(getattr(self, 'libpath', []))
if pths:
for l in self.to_list(Utils.to_list(getattr(self, 'lib', []))):
for x in pths:
names = Utils.listdir(x)
lname = self.env.cshlib_PATTERN % l
if lname in names:
break
else:
self.bld.fatal('wrong path for the library %s' % l)