forked from larsimmisch/capisuite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSConstruct
499 lines (431 loc) · 15.9 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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
# -*- mode: python ; coding: latin-1 -*-
#
# This file and all modifications and additions to the pristine
# package are under the same license as the package itself.
#
"""
Main SCons build script for CapiSuite
(c) Copyright 2004 by Hartmut Goebel <[email protected]>
CapiSuite is (c) Copyright by Gernot Hillier <[email protected]>
Use 'scons --help' for a list of available options.
Options have only to be given once, since they are cached in a file
'options.cache'. To change an option, simply pass it again with a
different value.
Example:
scons prefix=/ # build for prefix=/
scons # prefix=/ is taken from 'options.cache'
scons prefix=/usr/local # build for prefix=/usr/local
# since this is the default, the entry in
# options.cache will be removed
scons # default prefix is used
WARNING: This build method is not yet officially supported for
CapiSuite. Please use the usual 'configure; make; make install'
triplet instead!
"""
__targets__ = """
Additional targets:
configure : build the 'configure' script
(this is automatically done if 'config.h' is missing)
pycheck : check Python sources with PyChecker (not yet implemented)
install : install all files
install-pylib : install only the python library
install-scripts : install only the python scripts
install-exec : install only the executables
install-man : install only the man pages
install-data-local: create spool- and state-dirs
For all 'install'-targets the installation base may be set with
INSTALL_BASE=...
dist : build distribution archive (.tar.gz)
distcheck : test whether distribution archive is slef-contained
rpms : build source and binay rpms
"""
## install-strip: strip the _installed_ binaries
## all == .
## clean == -c: clean all file that could be made by building
## distclean: clean all file that are made by configuring and building
## config.h, .sconf.temp, ...
## uninstall == -c install
## mostlyclean: läßt selten gebaute File stehen
## maintainer-clean: clean + bison-output, info-files, tag tables, etc.
## check: perform self-test
##
## TAGS, info, dvi,
## installcheck, installdirs
###---####---###---####---###---####---###---####---###---####---###---###
# some Pythonic setup
import sys, os, os.path, glob
import SCons.Util, SCons.Script
import SCons.Node.FS
# Store signatures in ".sconsign.dbmlite" in the top-level directory.
SConsignFile()
class InstallableEnv(Environment):
"""Extended Environment which supports INSTALL_BASE and ExtraDist."""
def BasedFile(self, name):
if self.get('INSTALL_BASE'): name = ('$INSTALL_BASE/%s' % name)
return self.File(name)
def BasedDir(self, name):
if self.get('INSTALL_BASE'): name = ('$INSTALL_BASE/%s' % name)
return self.Dir(name)
def Install(self, dir, source):
"""Install specified files in the given directory."""
dir = self.arg2nodes(dir, self.BasedDir)
files = Environment.Install(self, dir, source)
self.DistSourcesOf(files)
return files
def InstallAs(self, target, source):
"""Install sources as targets."""
target = self.arg2nodes(target, self.BasedFile)
files = Environment.InstallAs(self, target, source)
self.DistSourcesOf(files)
return files
def DistSourcesOf(self, files):
"""
Add all sourcefiles of the given files to the distribution archive.
"""
files = self.arg2nodes(files, self.File)
files = map(self.DistSourceOfFile, files)
#self.DistTar('$DIST_ARCHIVE', files)
self.Append(DIST_FILES=files)
return files
def ExtraDist(self, files):
"""Additional files to be distributed."""
files = self.arg2nodes(files, self.File)
#self.DistTar('$DIST_ARCHIVE', files)
self.Append(DIST_FILES=files)
return files
_valid_man_extensions = '0123456789ln' # from info automake
def mandir(self, section):
section = str(section)
assert section in self._valid_man_extensions, section # todo: error msg
return os.path.join('$mandir', 'man%s' % section)
def InstallMan(self, source, section=None):
"""
Install man pages.
If 'section' is given, file extensions are changed to 'section'.
Otherwise, the section is taken from file extension.
"""
source = self.arg2nodes(source, self.File)
result = []
for man in source:
base = os.path.basename(man.name)
base, ext = os.path.splitext(base)
sect = section
if sect is None:
sect = ext[1] # determine section from name/extension
else:
ext = '.%s' % sect # overwrite extension
res = self.InstallAs(os.path.join(self.mandir(sect), base + ext),
man)
result.extend(res)
return result
#
# Support functions for linking with Python
#
def GetPythonModuleSetup(env):
"""
Get configuration for linking with the Python library.
"""
import distutils.sysconfig
from distutils.sysconfig import get_python_lib, get_config_vars, \
get_config_var
env.Append(
python_version = distutils.sysconfig.get_python_version(),
python_prefix = distutils.sysconfig.PREFIX,
python_execprefix = distutils.sysconfig.EXEC_PREFIX,
python_libdir = get_python_lib(plat_specific=1, standard_lib=1),
python_moduledir = get_python_lib(plat_specific=0, standard_lib=0),
python_moduleexecdir = get_python_lib(plat_specific=1, standard_lib=0),
python_includespec = get_config_vars('INCLUDEPY', 'CONFINCLUDEPY'),
python_linkforshared = get_config_var('LINKFORSHARED'),
pkgpython_moduledir = '${python_moduledir}/${PACKAGE}',
pkgpython_moduleexecdir = '${python_moduleexecdir}/${PACKAGE}',
LINKFLAGS = ['${python_linkforshared}'],
LIBS = ['python${python_version}'],
)
env.Append(
CPPPATH = env['python_includespec'],
PYTHON = sys.executable,
)
def GetPythonEmbeddedSetup(env):
"""
Get configuration for linking an embedded Python application.
"""
# Base idea on which variable to check are from the INN 2.3.1 package
import distutils.sysconfig
print 'Checking how to link an embedded Python application:',
libvars = Split("LIBS LIBC LIBM LOCALMODLIBS BASEMODLIBS")
python_libspec = []
for libvar in distutils.sysconfig.get_config_vars(*libvars):
libvar = libvar.split()
for lib in libvar:
# sanity check
if not lib.startswith('-l'):
print "Error in Python Makefile: shared lib spec does ", \
"not start with '-l':", lib
python_libspec.append(lib[2:])
env.Append(python_libspec = python_libspec,
python_configdir = distutils.sysconfig.get_config_var('LIBPL'),
# preferable these should be '$python..', but SCons
# doe not yet support this (SCons 0.94)
LIBS = python_libspec,
LIBPATH = ['${python_configdir}'],
)
print ' '.join(python_libspec)
#print '>>>', env['LIBS']
def Get_sfftobmp_Version(context):
"""
Test for the sfftobmp version installed as different versions
need different parameters. :-(
"""
import commands, re
print 'Checking for sfftobmp version ...',
status, text = commands.getstatusoutput('sfftobmp -v')
if status:
print 'failed'
print text
Exit(1)
res = re.search(r'Version ([0-9,.]+)', text, re.M) or 0
if not res:
print 'failed'
print
print '** It seams like the output of sfftobmp has changed. Please'
print '** contact the authors of capisuite to fix this.'
Exit(10)
res = res.group(1)
env.Replace(sfftobmp_major_version = res.split('.')[0])
print res
# A Shortcut
is_dist = ('dist' in COMMAND_LINE_TARGETS or
'distcheck' in COMMAND_LINE_TARGETS or
'rpms' in COMMAND_LINE_TARGETS)
###---####---###---####---###---####---###---####---###---####---###---###
# capisuite requires Python 2.2
EnsurePythonVersion(2,2)
if is_dist:
# 'dist' target requires module tarfile which is new in Python 2.3
EnsurePythonVersion(2,3)
EnsureSConsVersion(0,96)
###---####---###---####---###---####---###---####---###---####---###---###
#
# Setting up build-environment
#
# Build all files in this subdir
build_dir = Dir('#/build')
env = InstallableEnv(tools=Split('default sourcetar filesubst'),
toolpath=['scons-tools'],
# set some build variables
PACKAGE = 'capisuite',
VERSION = '0.5.cvs',
RELEASE = '1',
SVNREPOSITORY = 'https://h3281.serverkompetenz.net/repos/capisuite/',
# required for some building the docs (doxygen)
srcdir = build_dir,
# default pathes
pkgdatadir = '${datadir}/${PACKAGE}',
pkglibdir = '${libdir}/${PACKAGE}',
pkgincludedir = '${includedir}/${PACKAGE}',
pkgbindir = '${bindir}',
pkgsbindir = '${sbindir}',
pkgsysconfdir = '${sysconfdir}/${PACKAGE}',
#pkglibdir = '${prefix}/lib',
spooldir = '${localstatedir}/spool/${PACKAGE}',
docdir = '${pkgdatadir}/doc/${PACKAGE}',
# Distribution of files and sources:
DIST_ARCHIVE = '#/dist/${PACKAGE}-${VERSION}.tar.gz',
DIST_FILES = [],
# used for distcheck
SCONS = 'scons',
DISTCHECK_DIR = Dir('#/dist/check'),
)
###---####---###---####---###---####---###---####---###---####---###---###
#
# Handling of command line options
#
# Some commonly used make targets have to be done another way.
# Inform the used if he tries to use such a target:
for ct, t in (
('clean', '-c'),
('uninstall', '-c install'),
('distclean', '-c dist'),
):
if ct in COMMAND_LINE_TARGETS:
print
print "Please use 'scons %s' instead of the pseudo-target '%s'." \
% (t, ct)
print
Exit(1)
# Handle options
env.SConscript('SConscript-Options', exports=['env', '__targets__'])
### Some more setup
env.BuildDir(build_dir=build_dir, src_dir='.')
Export('env', 'is_dist')
###---####---###---####---###---####---###---####---###---####---###---###
#
# Configure build (only if neither cleaning nor 'dist'-ing)
#
if not GetOption('clean') and not is_dist:
# "configure" only if necessary or requested
if not File('config.h', build_dir).exists() \
or 'configure' in COMMAND_LINE_TARGETS:
env.SConscript('SConscript-Config', build_dir=build_dir)
GetPythonEmbeddedSetup(env)
Get_sfftobmp_Version(env)
# get some build variables we always need to evaluate,
# even for non-building targets.
GetPythonModuleSetup(env)
###---####---###---####---###---####---###---####---###---####---###---###
env.Append(
CCFLAGS = Split('-g -O2'),
# these should go into src/SConscript:
LIBS = Split('pthread capi20'),
CPPDEFINES={'LOCALSTATEDIR': r'\"${localstatedir}\"',
'PKGDATADIR' : r'\"${pkgdatadir}\"',
'PKGSYSCONFDIR': r'\"${pkgsysconfdir}\"',
'PKGLIBDIR' : r'\"${pkglibdir}\"',
'HAVE_CONFIG_H': 1, # we always have config.h
},
)
## # build debug?
## if ARGUMENTS.get('debug', 0):
## env.Append(CXXFLAGS = ['-g', '-DDEBUG'])
## else:
## env.Append(CXXFLAGS = ['-O2'])
##
## if env['CXX'] in ('g++', 'c++'):
## env.Append(CXXFLAGS = ['-Wall', '-Wno-non-virtual-dtor'])
###---####---###---####---###---####---###---####---###---####---###---###
#
# Build everything defined in the 'Sconscript' files.
#
env.SConscript(dirs=[Dir('.', build_dir),
Dir('src', build_dir),
Dir('scripts', build_dir),
Dir('scripts/waves', build_dir),
Dir('docs', build_dir),
Dir('packages/rpm'),
])
#--- additional files to be distributed ---
env.ExtraDist(Split("""
ChangeLog.2003 ChangeLog.2004
TODO
SConstruct
SConscript-Config
SConscript-Options
scons-tools/sourcetar.py
scons-tools/filesubst.py
scons-tools/textfile.py
SConscript
src/SConscript
scripts/SConscript
scripts/waves/SConscript
packages/rpm/SConscript
docs/SConscript
"""))
# ChangeLog and ChangeLog.complete are build in SConscript
#--- additional files to be distributed (automake/autoconf stuff) ---
# only add these files if they exist
for f in Split("""
INSTALL
acinclude.m4
aclocal.m4
config.h.in
configure
configure.in
depcomp
install-sh
missing
mkinstalldirs
Makefile.am
Makefile.in
docs/Makefile.am
docs/Makefile.in
scripts/Makefile.am
scripts/Makefile.in
scripts/waves/Makefile.am
scripts/waves/Makefile.in
src/Makefile.am
src/Makefile.in
src/application/Makefile.am
src/application/Makefile.in
src/backend/Makefile.am
src/backend/Makefile.in
src/capisuite-py/Makefile.am
src/capisuite-py/Makefile.in
src/modules/Makefile.am
src/modules/Makefile.in
"""):
if os.path.exists(f):
env.ExtraDist(f)
#env.SourceCode('.',
# env.CVS('pserver:[email protected]:/cvsroot/capisuite',
# 'capisuite'))
"""
make DESTDIR=$RPM_BUILD_ROOT install
mkdir -p $RPM_BUILD_ROOT/usr/sbin
ln -sf ../../etc/init.d/capisuite $RPM_BUILD_ROOT/usr/sbin/rccapisuite
"""
###---####---###---####---###---####---###---####---###---####---###---###
#
# Install targets
#
for d in (
'${localstatedir}/log',
'${spooldir}/sendq',
'${spooldir}/done',
'${spooldir}/failed',
'${spooldir}/users',
):
d = env.BasedDir(d)
if not d.exists():
d = env.Command(d, None, Mkdir('$TARGET'))
env.Alias('install-data-local', d)
# 'install' includes the other parts, too
env.Alias('install', env.Alias('install-pylib'))
env.Alias('install', env.Alias('install-scripts'))
env.Alias('install', env.Alias('install-exec'))
env.Alias('install', env.Alias('install-data-local'))
env.Alias('install', env.Alias('install-man'))
###---####---###---####---###---####---###---####---###---####---###---###
#
# 'Dist' target
#
if is_dist or 'rpms' in COMMAND_LINE_TARGETS:
dist = env.DistTar('$DIST_ARCHIVE', env['DIST_FILES'])[0]
env.Alias('dist', dist)
###---####---###---####---###---####---###---####---###---####---###---###
#
# 'Dist' target
#
if 'distcheck' in COMMAND_LINE_TARGETS:
distcheck = env.Command('distcheck',
env.Dir('$DISTCHECK_DIR/${PACKAGE}-${VERSION}'),
[Delete('$SOURCE'),
Mkdir('$SOURCE'),
'$TAR xz -C ${SOURCE.dir} -f ' + dist.abspath,
'$SCONS -C $SOURCE .',
'$SCONS -C $SOURCE dist',
'echo ; echo checkdist passed ; echo'
])
env.Clean(distcheck, env['DISTCHECK_DIR'])
env.Depends(distcheck, dist)
###---####---###---####---###---####---###---####---###---####---###---###
#
# 'rpm' target
#
if 'rpms' in COMMAND_LINE_TARGETS:
_builddir = build_dir
_distdir = dist.dir
_arch = 'i586'
_rpmbasename = env.subst('capisuite-$VERSION-$RELEASE')
env.Alias('rpms',
env.Command([File('%s.%s.rpm' % (_rpmbasename, _arch), _distdir),
File('%s.%s.rpm' % (_rpmbasename, 'src'), _distdir)],
['packages/rpm/capisuite-mdk-9.2.spec', dist], [ \
['rpmbuild',
'--define', '_builddir %s' % _builddir.abspath,
'--define', '_sourcedir %s' % _distdir.abspath,
'--define', '_srcrpmdir %s' % _distdir.abspath,
'--define', '_rpmdir %s' % _distdir.abspath,
'--define', '_rpmfilename $TARGET.name',
'-ba', '$SOURCE'],
]))