-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwscript
174 lines (139 loc) · 4.34 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
top = '.'
out = 'build'
APPNAME = 'mdns-announce'
VERSION = '0.0.0'
CXXFLAGS = []
CFLAGS = []
LDFLAGS = []
TOOLS = [
'compiler_cxx',
'compiler_c',
'ar',
'waf_unit_test',
]
def options(ctx):
for tool in TOOLS:
ctx.load(tool)
ctx.add_option('--variant', action='store', default='debug',
help='What variant to build ...')
ctx.add_option('--compiler', action='store', default='clang',
help='What compiler to build with.')
def configure(cfg):
print('→ configuring the project in ' + cfg.path.abspath())
cfg.env.VERSION = VERSION
cfg.env.APPNAME = APPNAME
git_version = try_git_version()
if git_version:
cfg.env.VERSION += '-' + git_version
if cfg.options.compiler == 'clang':
cfg.env['CC'] = "clang"
cfg.env['CXX'] = "clang++"
for tool in TOOLS:
cfg.load(tool)
# Add another include path...
cfg.env.append_value('INCLUDES', ['/usr/local/include'])
# Check for C++11 support
cfg.check_cxx_flag('-std=c++11', required=True)
cfg.check_cxx_flag('-stdlib=libc++', required=False)
cfg.env.append_value('LINKFLAGS', ['-stdlib=libc++'])
cfg.check_cxx(
lib='ev',
header_name='ev++.h',
msg='Checking for libev',
uselib_store='EV',
)
cfg.check_cxx(
header_name='dns_sd.h',
msg='Checking for dns_sd.h',
)
# This is untested, maybe it works, maybe it doesn't. Test it sometime =)
cfg.check_cxx(
lib='dns_sd',
msg='Checking for dns_sd (Avahi compat layer)',
define_name='AVAHI',
uselib_store='DNS_SD',
mandatory=False
)
default_env = cfg.env.derive()
default_env.detach()
cfg.env.append_value('CXXFLAGS', CXXFLAGS)
cfg.env.append_value('LINKFLAGS', LDFLAGS)
cfg.env.append_value('CFLAGS', CFLAGS)
cfg.check_cxx_flag('-Wall')
cfg.check_cxx_flag('-Wextra')
cfg.check_cxx_flag('-Werror')
#cfg.check_c_flag('-Wall')
#cfg.check_c_flag('-Wextra')
#cfg.check_c_flag('-Werror')
env = cfg.env
env.detach()
cfg.setenv('debug', env)
cfg.env.append_value('CXXFLAGS', ['-g2'])
cfg.define('DEBUG', 1)
cfg.setenv('release', env)
cfg.env.append_value('CXXFLAGS', ['-O3'])
# Create a clean default environment
cfg.setenv('default', default_env)
cfg.recurse('src')
def build(ctx):
print('→ build from ' + ctx.path.abspath())
# Just build src for now, we don't have tests... yet
ctx.recurse('src')
def init(ctx):
from waflib.Build import BuildContext, CleanContext, InstallContext, UninstallContext
for x in 'debug release'.split():
for y in (BuildContext, CleanContext, InstallContext, UninstallContext):
name = y.__name__.replace('Context','').lower()
class tmp(y):
cmd = name + '_' + x
variant = x
for y in (BuildContext, CleanContext, InstallContext, UninstallContext):
class tmp(y):
@property
def variant(self):
return ctx.options.variant
from waflib.Configure import conf
from waflib import Errors
@conf
def check_cxx_flag(ctx, flag, required=False):
env = ctx.env
env.stash()
try:
env.append_value('CXXFLAGS', flag)
ctx.check_cxx(
feature='cxx',
cxxflags='-Werror',
msg='Checking C++ compiler for flag: {}'.format(flag)
)
return True
except:
if required:
raise Errors.WafError('Compiler flag "{}" is required'.format(flag))
env.revert()
return False
@conf
def check_c_flag(ctx, flag, required=False):
env = ctx.env
env.stash()
try:
env.append_value('CFLAGS', flag)
ctx.check_cc(
feature='c',
cflags='-Werror',
msg='Checking C compiler for flag: {}'.format(flag)
)
return True
except:
if required:
raise Errors.WafError('Compiler flag "{}" is required'.format(flag))
env.revert()
return False
import os
import sys
def try_git_version():
version = None
try:
version = os.popen('git describe --always --dirty --long').read().strip()
except Exception as e:
print e
return version