First version.
[libsub.git] / wscript
1 import subprocess
2 import os
3
4 APPNAME = 'libsub'
5 VERSION = '0.01.0devel'
6
7 def options(opt):
8     opt.load('compiler_cxx')
9     opt.add_option('--enable-debug', action='store_true', default=False, help='build with debugging information and without optimisation')
10     opt.add_option('--static', action='store_true', default=False, help='build libsub statically')
11
12 def configure(conf):
13     conf.load('compiler_cxx')
14     conf.env.append_value('CXXFLAGS', ['-Wall', '-Wextra', '-D_FILE_OFFSET_BITS=64', '-D__STDC_FORMAT_MACROS'])
15     conf.env.append_value('CXXFLAGS', ['-DLIBSUB_VERSION="%s"' % VERSION])
16
17     conf.env.ENABLE_DEBUG = conf.options.enable_debug
18     conf.env.STATIC = conf.options.static
19
20     if conf.options.enable_debug:
21         conf.env.append_value('CXXFLAGS', '-g')
22     else:
23         conf.env.append_value('CXXFLAGS', '-O3')
24
25     conf.check_cxx(fragment="""
26                             #include <boost/version.hpp>\n
27                             #if BOOST_VERSION < 104500\n
28                             #error boost too old\n
29                             #endif\n
30                             int main(void) { return 0; }\n
31                             """,
32                    mandatory=True,
33                    msg='Checking for boost library >= 1.45',
34                    okmsg='yes',
35                    errmsg='too old\nPlease install boost version 1.45 or higher.')
36
37     conf.recurse('test')
38
39 def build(bld):
40     create_version_cc(bld, VERSION)
41
42     bld(source='libsub.pc.in',
43         version=VERSION,
44         includedir='%s/include' % bld.env.PREFIX,
45         libs="-L${libdir} -lsub -lboost_system",
46         install_path='${LIBDIR}/pkgconfig')
47
48     bld.recurse('src')
49     bld.recurse('test')
50
51     bld.add_post_fun(post)
52
53 def dist(ctx):
54     ctx.excl = 'TODO core *~ .git build .waf* .lock* doc/*~ src/*~ test/ref/*~ __pycache__ GPATH GRTAGS GSYMS GTAGS'
55
56 def create_version_cc(bld, version):
57     if os.path.exists('.git'):
58         cmd = "LANG= git log --abbrev HEAD^..HEAD ."
59         output = subprocess.Popen(cmd, shell=True, stderr=subprocess.STDOUT, stdout=subprocess.PIPE).communicate()[0].splitlines()
60         o = output[0].decode('utf-8')
61         commit = o.replace ("commit ", "")[0:10]
62     else:
63         commit = "release"
64
65     try:
66         text =  '#include "version.h"\n'
67         text += 'char const * sub::git_commit = \"%s\";\n' % commit
68         text += 'char const * sub::version = \"%s\";\n' % version
69         if bld.env.ENABLE_DEBUG:
70             debug_string = 'true'
71         else:
72             debug_string = 'false'
73         text += 'bool const built_with_debug = %s;\n' % debug_string
74         print('Writing version information to src/version.cc')
75         o = open('src/version.cc', 'w')
76         o.write(text)
77         o.close()
78     except IOError:
79         print('Could not open src/version.cc for writing\n')
80         sys.exit(-1)
81
82 def post(ctx):
83     if ctx.cmd == 'install':
84         ctx.exec_command('/sbin/ldconfig')