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