Use boost filesystem.
[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 and link statically to cxml')
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     if conf.options.static:
26         conf.env.HAVE_CXML = 1
27         conf.env.STLIB_CXML = ['cxml']
28     else:
29         conf.check_cfg(package='libcxml', atleast_version='0.08', args='--cflags --libs', uselib_store='CXML', mandatory=True)
30
31     conf.check_cxx(fragment="""
32                             #include <boost/version.hpp>\n
33                             #if BOOST_VERSION < 104500\n
34                             #error boost too old\n
35                             #endif\n
36                             int main(void) { return 0; }\n
37                             """,
38                    mandatory=True,
39                    msg='Checking for boost library >= 1.45',
40                    okmsg='yes',
41                    errmsg='too old\nPlease install boost version 1.45 or higher.')
42
43     conf.check_cxx(fragment = """
44                               #include <boost/filesystem.hpp>\n
45                               int main() { boost::filesystem::copy_file ("a", "b"); }\n
46                               """,
47                    msg = 'Checking for boost filesystem library',
48                    libpath = '/usr/local/lib',
49                    lib = ['boost_filesystem', 'boost_system'],
50                    uselib_store = 'BOOST_FILESYSTEM')
51
52     conf.recurse('test')
53
54 def build(bld):
55     create_version_cc(bld, VERSION)
56
57     bld(source='libsub.pc.in',
58         version=VERSION,
59         includedir='%s/include' % bld.env.PREFIX,
60         libs="-L${libdir} -lsub -lboost_system",
61         install_path='${LIBDIR}/pkgconfig')
62
63     bld.recurse('src')
64     bld.recurse('test')
65     bld.recurse('tools')
66
67     bld.add_post_fun(post)
68
69 def dist(ctx):
70     ctx.excl = 'TODO core *~ .git build .waf* .lock* doc/*~ src/*~ test/ref/*~ __pycache__ GPATH GRTAGS GSYMS GTAGS'
71
72 def create_version_cc(bld, version):
73     if os.path.exists('.git'):
74         cmd = "LANG= git log --abbrev HEAD^..HEAD ."
75         output = subprocess.Popen(cmd, shell=True, stderr=subprocess.STDOUT, stdout=subprocess.PIPE).communicate()[0].splitlines()
76         o = output[0].decode('utf-8')
77         commit = o.replace ("commit ", "")[0:10]
78     else:
79         commit = "release"
80
81     try:
82         text =  '#include "version.h"\n'
83         text += 'char const * sub::git_commit = \"%s\";\n' % commit
84         text += 'char const * sub::version = \"%s\";\n' % version
85         if bld.env.ENABLE_DEBUG:
86             debug_string = 'true'
87         else:
88             debug_string = 'false'
89         text += 'bool const built_with_debug = %s;\n' % debug_string
90         print('Writing version information to src/version.cc')
91         o = open('src/version.cc', 'w')
92         o.write(text)
93         o.close()
94     except IOError:
95         print('Could not open src/version.cc for writing\n')
96         sys.exit(-1)
97
98 def post(ctx):
99     if ctx.cmd == 'install':
100         ctx.exec_command('/sbin/ldconfig')