-
Notifications
You must be signed in to change notification settings - Fork 0
/
SConstruct
195 lines (155 loc) · 5.41 KB
/
SConstruct
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/usr/bin/python
# vim: set fileencoding=utf-8 :
import SCons
import SCons.Script as scons
from distutils import sysconfig, version
import os, sys, re, platform
EnsurePythonVersion(2, 5)
EnsureSConsVersion(2, 0)
colors = {}
colors['cyan'] = '\033[96m'
colors['purple'] = '\033[95m'
colors['blue'] = '\033[94m'
colors['green'] = '\033[92m'
colors['yellow'] = '\033[93m'
colors['red'] = '\033[91m'
colors['end'] = '\033[0m'
#If the output is not a terminal, remove the colors
if not sys.stdout.isatty():
for key, value in colors.iteritems():
colors[key] = ''
env = Environment()
AddOption(
"--verbose",
action="store_true",
dest="verbose_flag",
default=False,
help="verbose output"
)
if not GetOption("verbose_flag"):
env["CXXCOMSTR"] = \
'%(blue)sCompiling%(purple)s: %(yellow)s$SOURCE%(end)s' % colors,
env["CCCOMSTR"] = \
'%(blue)sCompiling%(purple)s: %(yellow)s$SOURCE%(end)s' % colors,
env["SHCCCOMSTR"] = \
'%(blue)sCompiling shared%(purple)s: %(yellow)s$SOURCE%(end)s' % colors,
env["SHCXXCOMSTR"] = \
'%(blue)sCompiling shared%(purple)s: %(yellow)s$SOURCE%(end)s' % colors,
env["ARCOMSTR"] = \
'%(red)sLinking Static Library%(purple)s: %(yellow)s$TARGET%(end)s' % colors,
env["RANLIBCOMSTR"] = \
'%(red)sRanlib Library%(purple)s: %(yellow)s$TARGET%(end)s' % colors,
env["SHLINKCOMSTR"] = \
'%(red)sLinking Shared Library%(purple)s: %(yellow)s$TARGET%(end)s' % colors,
env["LINKCOMSTR"] = \
'%(red)sLinking Program%(purple)s: %(yellow)s$TARGET%(end)s' % colors,
env["INSTALLSTR"] = \
'%(green)sInstalling%(purple)s: %(yellow)s$SOURCE%(purple)s => %(yellow)s$TARGET%(end)s' % colors
AddOption(
'--prefix',
dest='prefix',
type='string',
nargs=1,
action='store',
metavar='DIR',
default='/usr',
help='installation prefix'
)
prefix = GetOption('prefix')
AddOption(
'--sbindir',
dest='sbindir',
type='string',
nargs=1,
action='store',
metavar='DIR',
default='%s/sbin' % prefix,
help='installation binary files prefix'
)
sbindir = GetOption('sbindir')
# below three variables are not yet used
bindir = "%s/bin" % prefix
libdir = "%s/lib" % prefix
includedir = "%s/include" % prefix
datadir = "%s/share" % prefix
# Configuration:
checked_packages = dict()
def CheckPKGConfig(context, version):
context.Message( 'Checking for pkg-config... ' )
ret = context.TryAction('pkg-config --atleast-pkgconfig-version=%s' % version)[0]
context.Result( ret )
return ret
def CheckPKG(context, name):
context.Message( 'Checking for %s... ' % name )
m = re.match(r"(\w+)(?:-[\d.]+)?(?: (?:\=|\<|\>) \S+)?", name)
key = m.group(1)
if key in checked_packages:
context.Result(checked_packages[key])
return checked_packages[key]
ret = context.TryAction('pkg-config --exists \'%s\'' % name)[0]
context.sconf.config_h_text += "\n"
context.sconf.Define(
'HAVE_%s' % re.sub(r"\W",'_',key.upper()),
1,
"Define to 1 if you have the `%(name)s' package installed"
% { 'name': name }
)
depends = os.popen('pkg-config --print-requires \'%s\'' %
name).readline()
depends = re.findall(r"([-.\w]+(?: (?:\=|\<|\>) \S+)?)", depends)
context.Result( ret )
for dep in depends:
ret &= context.sconf.CheckPKG(dep.strip())
checked_packages[key] = ret
return ret
conf = Configure(
env,
config_h="config.h",
custom_tests = {
'CheckPKGConfig' : CheckPKGConfig,
'CheckPKG' : CheckPKG
}
)
destdir=""
if 'DESTDIR' in os.environ:
destdir = os.environ['DESTDIR']
print(">> Using destdir " + destdir)
if not env.GetOption('clean') and not env.GetOption('help'):
if 'CC' in os.environ:
env.Replace(CC = os.environ['CC'])
print(">> Using compiler " + os.environ['CC'])
if 'CFLAGS' in os.environ:
env.Replace(CFLAGS = os.environ['CFLAGS'])
print(">> Appending custom build flags : " + os.environ['CFLAGS'])
if 'LDFLAGS' in os.environ:
env.Append(LINKFLAGS = os.environ['LDFLAGS'])
print(">> Appending custom link flags : " + os.environ['LDFLAGS'])
conf.config_h_text += "\n"
if 'VERSION' in os.environ:
ver = os.environ['VERSION']
conf.Define("VERSION", "\"%s\""%os.environ['VERSION'], "Current package version")
print(">> Setting custom version : " + os.environ['VERSION'])
else:
conf.Define("VERSION", "\"0.0\"", "Current package version")
if not conf.CheckPKGConfig('0.15.0'):
print 'pkg-config >= 0.15.0 not found.'
Exit(1)
if not conf.CheckPKG('gupnp-1.0'):
Exit(1)
if not conf.CheckPKG('libbsd'):
Exit(1)
if not conf.CheckLib('boost_regex-mt'):
Exit(1)
if not conf.CheckLib('boost_thread-mt'):
Exit(1)
if not conf.CheckLib('boost_program_options-mt'):
Exit(1)
conf.env.Append(CCFLAGS='-Wall -Wextra -ggdb -O3')
conf.env.Append(CPPDEFINES=['_GNU_SOURCE', ('_FILE_OFFSET_BITS','64'), '_REENTRANT',
'HAVE_CONFIG_H'])
conf.env.ParseConfig("pkg-config --cflags --libs gupnp-1.0 libbsd")
env = conf.Finish()
sources = [ 'main.cpp', 'igd.cpp' ]
bubba_igd = env.Program(target = "bubba-igd", source = sources)
env.Install(destdir + sbindir, [bubba_igd])
env.Alias('install', destdir + sbindir)