3 from waflib import Context
10 from subprocess import STDOUT, check_output, CalledProcessError
12 # python 2.6 (in Centos 6) doesn't include check_output
15 STDOUT = subprocess.STDOUT
17 def check_output(*popenargs, **kwargs):
18 if 'stdout' in kwargs: # pragma: no cover
19 raise ValueError('stdout argument not allowed, '
20 'it will be overridden.')
21 process = subprocess.Popen(stdout=subprocess.PIPE,
23 output, _ = process.communicate()
24 retcode = process.poll()
26 cmd = kwargs.get("args")
29 raise subprocess.CalledProcessError(retcode, cmd,
32 subprocess.check_output = check_output
34 # overwrite CalledProcessError due to `output`
35 # keyword not being available (in 2.6)
36 class CalledProcessError(Exception):
38 def __init__(self, returncode, cmd, output=None):
39 self.returncode = returncode
44 return "Command '%s' returned non-zero exit status %d" % (
45 self.cmd, self.returncode)
46 subprocess.CalledProcessError = CalledProcessError
49 opt.load('compiler_cxx')
50 opt.add_option('--enable-debug', action='store_true', default=False, help='build with debugging information and without optimisation')
51 opt.add_option('--static', action='store_true', default=False, help='build libsub statically and link statically to cxml and dcp')
52 opt.add_option('--target-windows', action='store_true', default=False, help='set up to do a cross-compile to make a Windows package')
53 opt.add_option('--disable-tests', action='store_true', default=False, help='disable building of tests')
56 conf.load('compiler_cxx')
57 conf.env.append_value('CXXFLAGS', ['-Wall', '-Wextra', '-D_FILE_OFFSET_BITS=64', '-D__STDC_FORMAT_MACROS'])
58 conf.env.append_value('CXXFLAGS', ['-DLIBSUB_VERSION="%s"' % VERSION])
60 conf.env.ENABLE_DEBUG = conf.options.enable_debug
61 conf.env.STATIC = conf.options.static
62 conf.env.TARGET_WINDOWS = conf.options.target_windows
63 conf.env.DISABLE_TESTS = conf.options.disable_tests
64 conf.env.API_VERSION = API_VERSION
66 if conf.options.enable_debug:
67 conf.env.append_value('CXXFLAGS', '-g')
69 conf.env.append_value('CXXFLAGS', '-O3')
71 # Disable libxml++ deprecation warnings for now
72 conf.env.append_value('CXXFLAGS', ['-Wno-deprecated-declarations'])
74 conf.check_cfg(package='openssl', args='--cflags --libs', uselib_store='OPENSSL', mandatory=True)
76 if conf.options.static:
77 conf.check_cfg(package='libcxml', atleast_version='0.14.0', args='--cflags', uselib_store='CXML', mandatory=True)
78 conf.env.HAVE_CXML = 1
79 conf.env.LIB_CXML = ['glibmm-2.4', 'glib-2.0', 'pcre', 'sigc-2.0', 'rt', 'xml++-2.6', 'xml2', 'pthread', 'lzma', 'dl', 'z']
80 conf.env.STLIB_CXML = ['cxml']
81 conf.check_cfg(package='libdcp-1.0', atleast_version='1.4.4', args='--cflags', uselib_store='DCP', mandatory=True)
83 conf.env.STLIB_DCP = ['dcp-1.0', 'asdcp-cth', 'kumu-cth', 'openjp2']
84 conf.env.LIB_DCP = ['ssl', 'crypto', 'xmlsec1-openssl', 'xmlsec1']
86 conf.check_cfg(package='libcxml', atleast_version='0.15.2', args='--cflags --libs', uselib_store='CXML', mandatory=True)
87 conf.check_cfg(package='libdcp-1.0', atleast_version='1.4.4', args='--cflags --libs', uselib_store='DCP', mandatory=True)
89 conf.env.DEFINES_DCP = [f.replace('\\', '') for f in conf.env.DEFINES_DCP]
92 if conf.env.TARGET_WINDOWS:
93 boost_lib_suffix = '-mt'
95 conf.check_cxx(fragment="""
96 #include <boost/version.hpp>\n
97 #if BOOST_VERSION < 104500\n
98 #error boost too old\n
100 int main(void) { return 0; }\n
103 msg='Checking for boost library >= 1.45',
105 errmsg='too old\nPlease install boost version 1.45 or higher.')
107 conf.check_cxx(fragment="""
108 #include <boost/filesystem.hpp>\n
109 int main() { boost::filesystem::copy_file ("a", "b"); }\n
111 msg='Checking for boost filesystem library',
112 libpath='/usr/local/lib',
113 lib=['boost_filesystem%s' % boost_lib_suffix, 'boost_system%s' % boost_lib_suffix],
114 uselib_store='BOOST_FILESYSTEM')
116 # Find the icu- libraries on the system as we need to link to them when we look for boost locale.
117 locale_libs = ['boost_locale%s' % boost_lib_suffix, 'boost_system%s' % boost_lib_suffix]
118 for pkg in subprocess.check_output(['pkg-config', '--list-all']).splitlines():
119 if pkg.startswith("icu"):
120 for lib in subprocess.check_output(['pkg-config', '--libs-only-l', pkg.split()[0]]).split():
122 if not name in locale_libs:
123 locale_libs.append(name)
125 conf.check_cxx(fragment="""
126 #include <boost/locale.hpp>\n
127 int main() { boost::locale::conv::to_utf<char> ("a", "cp850"); }\n
129 msg='Checking for boost locale library',
130 libpath='/usr/local/lib',
132 uselib_store='BOOST_LOCALE')
134 conf.check_cxx(fragment="""
135 #include <boost/regex.hpp>\n
136 int main() { boost::regex re ("foo"); }\n
138 msg='Checking for boost regex library',
139 libpath='/usr/local/lib',
140 lib=['boost_regex%s' % boost_lib_suffix, 'boost_system%s' % boost_lib_suffix],
141 uselib_store='BOOST_REGEX')
143 if not conf.env.DISABLE_TESTS:
146 # libxml++ 2.39.1 and later must be built with -std=c++11
147 libxmlpp_version = conf.cmd_and_log(['pkg-config', '--modversion', 'libxml++-2.6'], output=Context.STDOUT, quiet=Context.BOTH)
148 s = libxmlpp_version.split('.')
149 v = (int(s[0]) << 16) | (int(s[1]) << 8) | int(s[2])
151 conf.env.append_value('CXXFLAGS', '-std=c++11')
154 create_version_cc(bld, VERSION)
156 if bld.env.TARGET_WINDOWS:
157 boost_lib_suffix = '-mt'
159 boost_lib_suffix = ''
161 bld(source='libsub%s.pc.in' % bld.env.API_VERSION,
163 includedir='%s/include/libsub%s' % (bld.env.PREFIX, bld.env.API_VERSION),
164 libs="-L${libdir} -lsub%s -lboost_system%s" % (bld.env.API_VERSION, boost_lib_suffix),
165 install_path='${LIBDIR}/pkgconfig')
168 if not bld.env.DISABLE_TESTS:
172 bld.add_post_fun(post)
175 ctx.excl = 'TODO core *~ .git build .waf* .lock* doc/*~ src/*~ test/ref/*~ __pycache__ GPATH GRTAGS GSYMS GTAGS'
177 def create_version_cc(bld, version):
178 if os.path.exists('.git'):
179 cmd = "LANG= git log --abbrev HEAD^..HEAD ."
180 output = subprocess.Popen(cmd, shell=True, stderr=subprocess.STDOUT, stdout=subprocess.PIPE).communicate()[0].splitlines()
181 o = output[0].decode('utf-8')
182 commit = o.replace ("commit ", "")[0:10]
187 text = '#include "version.h"\n'
188 text += 'char const * sub::git_commit = \"%s\";\n' % commit
189 text += 'char const * sub::version = \"%s\";\n' % version
190 if bld.env.ENABLE_DEBUG:
191 debug_string = 'true'
193 debug_string = 'false'
194 text += 'bool const built_with_debug = %s;\n' % debug_string
195 print('Writing version information to src/version.cc')
196 o = open('src/version.cc', 'w')
200 print('Could not open src/version.cc for writing\n')
204 if ctx.cmd == 'install':
205 ctx.exec_command('/sbin/ldconfig')
208 os.system('etags src/*.cc src/*.h')