-
Notifications
You must be signed in to change notification settings - Fork 1
/
wscript
203 lines (178 loc) · 7.51 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
import platform, os.path
srcdir="."
APPNAME = "bgen"
VERSION = "1.1.6"
def options( opt ):
opt.load( 'compiler_cxx' )
opt.load( 'compiler_c' )
opt.add_option( '--mode', action = 'store', default = 'release', dest = 'mode' )
def configure( cfg ):
cfg.load( 'compiler_c')
cfg.load( 'compiler_cxx')
cfg.env.CXXFLAGS = [ '-Wall', '-pedantic', '-Wno-unused-local-typedefs', '-Wno-c++11-long-long', '-Wno-deprecated-declarations', '-Wno-long-long', '-fPIC' ]
cfg.env.CFLAGS = [ '-Wall', '-pedantic', '-Wno-unused-local-typedefs', '-Wno-c++11-long-long', 'Wno-deprecated-declarations', '-Wno-long-long', '-fPIC' ]
if cfg.options.mode == 'release':
cfg.env.CXXFLAGS += [ '-O3' ]
cfg.env.CFLAGS = [ '-O3' ]
elif cfg.options.mode == 'debug':
cfg.env.CXXFLAGS += [ '-g' ]
cfg.env.CFLAGS = [ '-g' ]
else:
raise Exception( "Unknown value for --mode, please specify --mode=debug or --mode=release" )
cfg.check_cxx( lib='z', uselib_store='zlib', msg = 'zlib' )
if platform.system() != "Darwin":
cfg.check_cxx( lib='rt', uselib_store='rt', msg = 'rt' )
cfg.check_cxx( lib='pthread', uselib_store='pthread', msg = 'pthread' )
cfg.check_cxx( lib='dl', uselib_store='dl', msg = 'dl' )
def build( bld ):
print ("Creating %s build..." % bld.options.mode )
bld(
rule = """printf '#ifndef BGEN_REVISION_HPP\n#define BGEN_REVISION_HPP\nnamespace globals {\n\tchar const* bgen_version = \"%%s\" ;\n\tchar const* const bgen_revision = \"%%s\" ;\n}\n#endif\n' `echo """ + VERSION + "` `hg parents --template={node}` > ${TGT}""",
always = True,
target = "bgen_revision_autogenerated.hpp",
name = "bgen_revision_autogenerated",
uselib = "",
#on_results = True
on_results = False
)
bgen_sources =bld.path.ant_glob( 'src/*.cpp' )
bld.stlib(
source = bgen_sources,
target = 'bgen',
includes = 'genfile/include',
use = 'zlib zstd sqlite3 db',
export_includes = 'genfile/include'
)
bld.recurse( [ '3rd_party', 'appcontext', 'genfile', 'db', 'apps', 'example', 'test', 'R' ] )
# Copy files into rbgen package directory
for source in bgen_sources:
bld( rule = 'cp ${SRC} ${TGT}', source = source, target = 'R/rbgen/src/bgen/' + os.path.basename( source.abspath() ), always = True )
class ReleaseBuilder:
def __init__( self, APPNAME, VERSION ):
self.APPNAME = APPNAME
self.VERSION = VERSION
self.apps = [ 'bgenix', 'cat-bgen', 'edit-bgen' ]
def makedirs( self, path ):
try:
os.makedirs( path )
except os.error as e:
pass
def create_pkgname_stub( self, packageName, includePlatform = True ):
import platform
stub = '%s_v%s' % ( packageName, self.VERSION )
if includePlatform:
if platform.system() == 'Darwin':
stub = '%s-osx' % stub
elif platform.system() == 'Linux':
distro = platform.linux_distribution()
stub = '%s-%s%s-%s' % ( stub, distro[0], distro[1], platform.machine() )
return stub
def build_bgen( self ):
import os, tempfile, shutil, subprocess
tempdir = tempfile.mkdtemp()
release_stub = self.create_pkgname_stub( 'bgen' )
release_dir = os.path.join( tempdir, release_stub )
os.mkdir( release_dir )
shutil.copyfile( "LICENSE_1_0.txt", os.path.join( release_dir, "LICENSE_1_0.txt" ) )
for app in self.apps:
source = os.path.join( 'build', 'apps', app )
target = os.path.join( release_dir, app )
shutil.copyfile( source, target )
shutil.copymode( source, target )
shutil.copytree( 'example', os.path.join( release_dir, 'example' ), ignore = shutil.ignore_patterns( '*.cpp', 'wscript' ))
tarball = self.create_tarball( 'bgen', release_stub, tempdir )
return os.path.join( tempdir, tarball )
def create_tarball( self, name, source, workingdir ):
import subprocess
tarball = "%s.tgz" % source
tarballPath = os.path.join( workingdir, tarball )
process = subprocess.Popen( [ 'tar', '-czf', tarball, source ], cwd = workingdir )
process.wait()
print ('Created %s release tarball in "%s"' % ( name, tarball ))
print ("Contents are:")
print (subprocess.Popen( [ 'tar', '-tzf',tarballPath ], stdout = subprocess.PIPE ).communicate()[0])
return tarball
def build_rbgen( self ):
import os, tempfile, shutil, subprocess, platform
tempdir = tempfile.mkdtemp()
release_stub = self.create_pkgname_stub( 'rbgen', includePlatform = False )
rbgen_dir = os.path.join( tempdir, release_stub )
shutil.copytree( 'R/package/', rbgen_dir )
os.makedirs( os.path.join( rbgen_dir, "src", "include" ))
os.makedirs( os.path.join( rbgen_dir, "src", "include", "boost" ))
os.makedirs( os.path.join( rbgen_dir, "src", "include", "zstd-1.1.0" ))
os.makedirs( os.path.join( rbgen_dir, "src", "db" ))
os.makedirs( os.path.join( rbgen_dir, "src", "bgen" ))
os.makedirs( os.path.join( rbgen_dir, "src", "boost" ))
os.makedirs( os.path.join( rbgen_dir, "src", "sqlite3" ))
os.makedirs( os.path.join( rbgen_dir, "src", "zstd-1.1.0" ))
# Copy source files in
from glob import glob
for filename in glob( 'src/*.cpp' ):
shutil.copy( filename, os.path.join( rbgen_dir, "src", "bgen", os.path.basename( filename ) ) )
for filename in glob( 'db/src/*.cpp' ):
shutil.copy( filename, os.path.join( rbgen_dir, "src", "db", os.path.basename( filename ) ) )
for filename in glob( '3rd_party/sqlite3/sqlite3/sqlite3.c' ):
shutil.copy( filename, os.path.join( rbgen_dir, "src", "sqlite3", os.path.basename( filename ) ) )
for filename in glob( '3rd_party/zstd-1.1.0/lib/common/*.c' ) + glob( '3rd_party/zstd-1.1.0/lib/compress/*.c' ) + glob( '3rd_party/zstd-1.1.0/lib/decompress/*.c' ):
shutil.copy( filename, os.path.join( rbgen_dir, "src", "zstd-1.1.0", os.path.basename( filename ) ) )
boostGlobs = [
'libs/system/src/*.cpp',
'libs/thread/src/*.cpp',
'libs/thread/src/*.inl',
'libs/thread/src/pthread/once_atomic.cpp',
'libs/thread/src/pthread/thread.cpp',
'libs/thread/src/pthread/timeconv.inl',
'libs/filesystem/src/*.cpp',
'libs/date_time/src/posix_time/*.cpp',
'libs/timer/src/*.cpp',
'libs/chrono/src/*.cpp',
]
for pattern in boostGlobs:
for filename in glob( '3rd_party/boost_1_55_0/%s' % pattern ):
shutil.copy( filename, os.path.join( rbgen_dir, "src", "boost", os.path.basename( filename ) ) )
include_paths = [
"3rd_party/boost_1_55_0/boost/",
"3rd_party/zstd-1.1.0/",
"3rd_party/sqlite3/",
"genfile/include/genfile",
"db/include/db"
]
boostHeaderLibs = [
'system',
'thread',
'filesystem',
'date_time',
'timer',
'chrono',
'preprocessor',
'function',
'optional',
'mpl'
]
for include_path in include_paths:
for root, path, filenames in os.walk( include_path ):
self.makedirs( os.path.join( rbgen_dir, "src", "include", root ))
for name in filenames:
fullname = os.path.join( root, name )
if os.path.isfile( fullname ) and (
name.endswith( '.h')
or name.endswith( ".hpp" )
or name.endswith( ".ipp" )
or name.endswith( ".inl" )
):
dest = os.path.join( rbgen_dir, "src", "include", root, name )
shutil.copy( fullname, os.path.join( rbgen_dir, "src", "include", fullname ))
#print "Copied \"%s\"." % fullname
tarball = self.create_tarball( 'rbgen', release_stub, tempdir )
return os.path.join( tempdir, tarball )
def release( bld ):
print ("Building bgen release tarball...")
release = ReleaseBuilder( APPNAME, VERSION )
result = release.build_bgen()
print ("Created %s release tarball in \"%s\"" % ( 'bgen', result ))
def build_rbgen( bld ):
print ("Building rbgen source package tarball...")
release = ReleaseBuilder( APPNAME, VERSION )
result = release.build_rbgen()
print ("Created %s release tarball in \"%s\"" % ( 'rbgen', result ))