Merge.
[libsub.git] / wscript
1 import subprocess
2 import os
3
4 APPNAME = 'libsub'
5 VERSION = '1.1.9devel'
6 API_VERSION = '-1.0'
7
8 def options(opt):
9     opt.load('compiler_cxx')
10     opt.add_option('--enable-debug', action='store_true', default=False, help='build with debugging information and without optimisation')
11     opt.add_option('--static', action='store_true', default=False, help='build libsub statically and link statically to cxml and dcp')
12     opt.add_option('--target-windows', action='store_true', default=False, help='set up to do a cross-compile to make a Windows package')
13     opt.add_option('--disable-tests', action='store_true', default=False, help='disable building of tests')
14
15 def configure(conf):
16     conf.load('compiler_cxx')
17     conf.env.append_value('CXXFLAGS', ['-Wall', '-Wextra', '-D_FILE_OFFSET_BITS=64', '-D__STDC_FORMAT_MACROS'])
18     conf.env.append_value('CXXFLAGS', ['-DLIBSUB_VERSION="%s"' % VERSION])
19
20     conf.env.ENABLE_DEBUG = conf.options.enable_debug
21     conf.env.STATIC = conf.options.static
22     conf.env.TARGET_WINDOWS = conf.options.target_windows
23     conf.env.DISABLE_TESTS = conf.options.disable_tests
24     conf.env.API_VERSION = API_VERSION
25
26     if conf.options.enable_debug:
27         conf.env.append_value('CXXFLAGS', '-g')
28     else:
29         conf.env.append_value('CXXFLAGS', '-O3')
30
31     conf.check_cfg(package='openssl', args='--cflags --libs', uselib_store='OPENSSL', mandatory=True)
32
33     if conf.options.static:
34         conf.env.HAVE_CXML = 1
35         conf.env.LIB_CXML = ['glibmm-2.4', 'glib-2.0', 'pcre', 'sigc-2.0', 'rt', 'xml++-2.6', 'xml2', 'pthread', 'lzma', 'dl', 'z']
36         conf.env.STLIB_CXML = ['cxml']
37         conf.check_cfg(package='libcxml', atleast_version='0.14.0', args='--cflags', uselib_store='CXML', mandatory=True)
38         conf.env.HAVE_ASDCPLIB_CTH = 1
39         conf.env.STATIC_ASDCPLIB_CTH = ['asdcplib-cth', 'kumu-cth']
40         conf.check_cfg(package='libasdcp-cth', atleast_version='2.5.11-cth1', args='--cflags', uselib_store='ASDCPLIB_CTH', mandatory=True)
41     else:
42         conf.check_cfg(package='libcxml', atleast_version='0.14.0', args='--cflags --libs', uselib_store='CXML', mandatory=True)
43         conf.check_cfg(package='libasdcp-cth', atleast_version='2.5.11-cth1', args='--cflags --libs', uselib_store='ASDCPLIB_CTH', mandatory=True)
44
45     boost_lib_suffix = ''
46     if conf.env.TARGET_WINDOWS:
47         boost_lib_suffix = '-mt'
48
49     conf.check_cxx(fragment="""
50                             #include <boost/version.hpp>\n
51                             #if BOOST_VERSION < 104500\n
52                             #error boost too old\n
53                             #endif\n
54                             int main(void) { return 0; }\n
55                             """,
56                    mandatory=True,
57                    msg='Checking for boost library >= 1.45',
58                    okmsg='yes',
59                    errmsg='too old\nPlease install boost version 1.45 or higher.')
60
61     conf.check_cxx(fragment="""
62                             #include <boost/filesystem.hpp>\n
63                             int main() { boost::filesystem::copy_file ("a", "b"); }\n
64                             """,
65                    msg='Checking for boost filesystem library',
66                    libpath='/usr/local/lib',
67                    lib=['boost_filesystem%s' % boost_lib_suffix, 'boost_system%s' % boost_lib_suffix],
68                    uselib_store='BOOST_FILESYSTEM')
69
70     conf.check_cxx(fragment="""
71                             #include <boost/locale.hpp>\n
72                             int main() { boost::locale::conv::to_utf<char> ("a", "cp850"); }\n
73                             """,
74                    msg='Checking for boost locale library',
75                    libpath='/usr/local/lib',
76                    lib=['boost_locale%s' % boost_lib_suffix, 'boost_system%s' % boost_lib_suffix],
77                    uselib_store='BOOST_LOCALE')
78
79     conf.check_cxx(fragment="""
80                             #include <boost/regex.hpp>\n
81                             int main() { boost::regex re ("foo"); }\n
82                             """,
83                    msg='Checking for boost regex library',
84                    libpath='/usr/local/lib',
85                    lib=['boost_regex%s' % boost_lib_suffix, 'boost_system%s' % boost_lib_suffix],
86                    uselib_store='BOOST_REGEX')
87
88     if not conf.env.DISABLE_TESTS:
89         conf.recurse('test')
90
91 def build(bld):
92     create_version_cc(bld, VERSION)
93
94     if bld.env.TARGET_WINDOWS:
95         boost_lib_suffix = '-mt'
96     else:
97         boost_lib_suffix = ''
98
99     bld(source='libsub%s.pc.in' % bld.env.API_VERSION,
100         version=VERSION,
101         includedir='%s/include/libsub%s' % (bld.env.PREFIX, bld.env.API_VERSION),
102         libs="-L${libdir} -lsub%s -lboost_system%s" % (bld.env.API_VERSION, boost_lib_suffix),
103         install_path='${LIBDIR}/pkgconfig')
104
105     bld.recurse('src')
106     if not bld.env.DISABLE_TESTS:
107         bld.recurse('test')
108     bld.recurse('tools')
109
110     bld.add_post_fun(post)
111
112 def dist(ctx):
113     ctx.excl = 'TODO core *~ .git build .waf* .lock* doc/*~ src/*~ test/ref/*~ __pycache__ GPATH GRTAGS GSYMS GTAGS'
114
115 def create_version_cc(bld, version):
116     if os.path.exists('.git'):
117         cmd = "LANG= git log --abbrev HEAD^..HEAD ."
118         output = subprocess.Popen(cmd, shell=True, stderr=subprocess.STDOUT, stdout=subprocess.PIPE).communicate()[0].splitlines()
119         o = output[0].decode('utf-8')
120         commit = o.replace ("commit ", "")[0:10]
121     else:
122         commit = "release"
123
124     try:
125         text =  '#include "version.h"\n'
126         text += 'char const * sub::git_commit = \"%s\";\n' % commit
127         text += 'char const * sub::version = \"%s\";\n' % version
128         if bld.env.ENABLE_DEBUG:
129             debug_string = 'true'
130         else:
131             debug_string = 'false'
132         text += 'bool const built_with_debug = %s;\n' % debug_string
133         print('Writing version information to src/version.cc')
134         o = open('src/version.cc', 'w')
135         o.write(text)
136         o.close()
137     except IOError:
138         print('Could not open src/version.cc for writing\n')
139         sys.exit(-1)
140
141 def post(ctx):
142     if ctx.cmd == 'install':
143         ctx.exec_command('/sbin/ldconfig')