This repository has been archived by the owner on Jun 6, 2021. It is now read-only.
/
wscript
159 lines (121 loc) · 4.56 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
#!/usr/bin/env python
import os, shutil, sys, tarfile, tempfile
from waflib import Build, Context, Options, Scripting, Utils
from waflib.Configure import conf
APPNAME = 'libffi-d'
VERSION = '1.0'
TOP = '.'
OUT = 'build'
def options(opt):
opt.load('compiler_d')
opt.add_option('--lp64', action = 'store', default = 'true', help = 'compile for 64-bit CPUs (true/false)')
opt.add_option('--mode', action = 'store', default = 'debug', help = 'the mode to compile in (debug/release)')
def configure(conf):
def add_option(option):
conf.env.append_value('DFLAGS', option)
conf.load('compiler_d')
if conf.env.COMPILER_D == 'dmd':
add_option('-w')
add_option('-wi')
add_option('-ignore')
add_option('-property')
add_option('-gc')
if conf.options.mode == 'debug':
add_option('-debug')
elif conf.options.mode == 'release':
add_option('-release')
add_option('-O')
add_option('-inline')
else:
conf.fatal('--mode must be either debug or release.')
elif conf.env.COMPILER_D == 'gdc':
add_option('-Wall')
add_option('-fignore-unknown-pragmas')
add_option('-fproperty')
add_option('-g')
add_option('-fdebug-c')
if conf.options.mode == 'debug':
add_option('-fdebug')
elif conf.options.mode == 'release':
add_option('-frelease')
add_option('-O3')
else:
conf.fatal('--mode must be either debug or release.')
conf.env.append_value('LINKFLAGS', '-lpthread')
else:
conf.fatal('Unsupported D compiler.')
if conf.options.lp64 == 'true':
add_option('-m64')
conf.env.append_value('LINKFLAGS', '-m64')
elif conf.options.lp64 == 'false':
add_option('-m32')
conf.env.append_value('LINKFLAGS', '-m32')
else:
conf.fatal('--lp64 must be either true or false.')
def build(bld):
bld.stlib(source = 'ffi.d',
target = 'ffi-d',
install_path = '${PREFIX}/lib')
def dist(dst):
'''makes a tarball for redistributing the sources'''
with open('.gitignore', 'r') as f:
dst.excl = ' '.join(l.strip() for l in f if l.strip())
class DistCheckContext(Scripting.Dist):
cmd = 'distcheck'
fun = 'distcheck'
def execute(self):
self.recurse([os.path.dirname(Context.g_module.root_path)])
self.archive()
self.check()
def check(self):
with tarfile.open(self.get_arch_name()) as t:
for x in t:
t.extract(x)
instdir = tempfile.mkdtemp('.inst', self.get_base_name())
cfg = [x for x in sys.argv if x.startswith('-')]
ret = Utils.subprocess.Popen([sys.argv[0],
'configure',
'install',
'uninstall',
'--destdir=' + instdir] + cfg, cwd = self.get_base_name()).wait()
if ret:
self.fatal('distcheck failed with code {0}'.format(ret))
if os.path.exists(instdir):
self.fatal('distcheck succeeded, but files were left in {0}'.format(instdir))
shutil.rmtree(self.get_base_name())
def distcheck(ctx):
'''checks if the project compiles (tarball from 'dist')'''
pass
class PackageContext(Build.InstallContext):
cmd = 'package'
fun = 'build'
def init_dirs(self, *k, **kw):
super(PackageContext, self).init_dirs(*k, **kw)
self.tmp = self.bldnode.make_node('package_tmp_dir')
try:
shutil.rmtree(self.tmp.abspath())
except:
pass
if os.path.exists(self.tmp.abspath()):
self.fatal('Could not remove the temporary directory {0}'.format(self.tmp))
self.tmp.mkdir()
self.options.destdir = self.tmp.abspath()
def execute(self, *k, **kw):
back = self.options.destdir
try:
super(PackageContext, self).execute(*k, **kw)
finally:
self.options.destdir = back
files = self.tmp.ant_glob('**')
appname = getattr(Context.g_module, Context.APPNAME, 'noname')
version = getattr(Context.g_module, Context.VERSION, '1.0')
ctx = Scripting.Dist()
ctx.arch_name = '{0}-{1}-bin.tar.bz2'.format(appname, version)
ctx.files = files
ctx.tar_prefix = ''
ctx.base_path = self.tmp
ctx.archive()
shutil.rmtree(self.tmp.abspath())
def package(ctx):
'''packages built binaries into a tarball'''
pass