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')
54 opt.add_option('--force-cpp11', action='store_true', default=False, help='force use of C++11')
57 conf.load('compiler_cxx')
58 conf.env.append_value('CXXFLAGS', ['-Wall', '-Wextra', '-D_FILE_OFFSET_BITS=64', '-D__STDC_FORMAT_MACROS'])
59 if conf.options.force_cpp11:
60 conf.env.append_value('CXXFLAGS', ['-std=c++11', '-DBOOST_NO_CXX11_SCOPED_ENUMS'])
61 conf.env.append_value('CXXFLAGS', ['-DLIBSUB_VERSION="%s"' % VERSION])
63 conf.env.ENABLE_DEBUG = conf.options.enable_debug
64 conf.env.STATIC = conf.options.static
65 conf.env.TARGET_WINDOWS = conf.options.target_windows
66 conf.env.DISABLE_TESTS = conf.options.disable_tests
67 conf.env.API_VERSION = API_VERSION
69 if conf.options.enable_debug:
70 conf.env.append_value('CXXFLAGS', '-g')
72 conf.env.append_value('CXXFLAGS', '-O3')
74 # Disable libxml++ deprecation warnings for now
75 conf.env.append_value('CXXFLAGS', ['-Wno-deprecated-declarations'])
77 conf.check_cfg(package='openssl', args='--cflags --libs', uselib_store='OPENSSL', mandatory=True)
79 if conf.options.static:
80 conf.check_cfg(package='libcxml', atleast_version='0.14.0', args='--cflags', uselib_store='CXML', mandatory=True)
81 conf.env.HAVE_CXML = 1
82 conf.env.LIB_CXML = ['glibmm-2.4', 'glib-2.0', 'pcre', 'sigc-2.0', 'rt', 'xml++-2.6', 'xml2', 'pthread', 'lzma', 'dl', 'z']
83 conf.env.STLIB_CXML = ['cxml']
84 conf.check_cfg(package='libdcp-1.0', atleast_version='1.4.4', args='--cflags', uselib_store='DCP', mandatory=True)
86 conf.env.STLIB_DCP = ['dcp-1.0', 'asdcp-cth', 'kumu-cth', 'openjp2']
87 conf.env.LIB_DCP = ['ssl', 'crypto', 'xmlsec1-openssl', 'xmlsec1']
89 conf.check_cfg(package='libcxml', atleast_version='0.15.2', args='--cflags --libs', uselib_store='CXML', mandatory=True)
90 conf.check_cfg(package='libdcp-1.0', atleast_version='1.4.4', args='--cflags --libs', uselib_store='DCP', mandatory=True)
92 conf.env.DEFINES_DCP = [f.replace('\\', '') for f in conf.env.DEFINES_DCP]
95 if conf.env.TARGET_WINDOWS:
96 boost_lib_suffix = '-mt'
98 conf.check_cxx(fragment="""
99 #include <boost/version.hpp>\n
100 #if BOOST_VERSION < 104500\n
101 #error boost too old\n
103 int main(void) { return 0; }\n
106 msg='Checking for boost library >= 1.45',
108 errmsg='too old\nPlease install boost version 1.45 or higher.')
110 conf.check_cxx(fragment="""
111 #include <boost/filesystem.hpp>\n
112 int main() { boost::filesystem::copy_file ("a", "b"); }\n
114 msg='Checking for boost filesystem library',
115 libpath='/usr/local/lib',
116 lib=['boost_filesystem%s' % boost_lib_suffix, 'boost_system%s' % boost_lib_suffix],
117 uselib_store='BOOST_FILESYSTEM')
119 # Find the icu- libraries on the system as we need to link to them when we look for boost locale.
120 locale_libs = ['boost_locale%s' % boost_lib_suffix, 'boost_system%s' % boost_lib_suffix]
121 for pkg in subprocess.check_output(['pkg-config', '--list-all']).splitlines():
122 pkg = pkg.decode('utf-8')
123 if pkg.startswith("icu"):
124 for lib in subprocess.check_output(['pkg-config', '--libs-only-l', pkg.split()[0]]).split():
126 if not name in locale_libs:
127 locale_libs.append(name.decode('utf-8'))
129 conf.check_cxx(fragment="""
130 #include <boost/locale.hpp>\n
131 int main() { boost::locale::conv::to_utf<char> ("a", "cp850"); }\n
133 msg='Checking for boost locale library',
134 libpath='/usr/local/lib',
136 uselib_store='BOOST_LOCALE')
138 conf.check_cxx(fragment="""
139 #include <boost/regex.hpp>\n
140 int main() { boost::regex re ("foo"); }\n
142 msg='Checking for boost regex library',
143 libpath='/usr/local/lib',
144 lib=['boost_regex%s' % boost_lib_suffix, 'boost_system%s' % boost_lib_suffix],
145 uselib_store='BOOST_REGEX')
147 if not conf.env.DISABLE_TESTS:
151 create_version_cc(bld, VERSION)
153 if bld.env.TARGET_WINDOWS:
154 boost_lib_suffix = '-mt'
156 boost_lib_suffix = ''
158 bld(source='libsub%s.pc.in' % bld.env.API_VERSION,
160 includedir='%s/include/libsub%s' % (bld.env.PREFIX, bld.env.API_VERSION),
161 libs="-L${libdir} -lsub%s -lboost_system%s" % (bld.env.API_VERSION, boost_lib_suffix),
162 install_path='${LIBDIR}/pkgconfig')
165 if not bld.env.DISABLE_TESTS:
169 bld.add_post_fun(post)
172 ctx.excl = 'TODO core *~ .git build .waf* .lock* doc/*~ src/*~ test/ref/*~ __pycache__ GPATH GRTAGS GSYMS GTAGS'
174 def create_version_cc(bld, version):
175 if os.path.exists('.git'):
176 cmd = "LANG= git log --abbrev HEAD^..HEAD ."
177 output = subprocess.Popen(cmd, shell=True, stderr=subprocess.STDOUT, stdout=subprocess.PIPE).communicate()[0].splitlines()
178 o = output[0].decode('utf-8')
179 commit = o.replace ("commit ", "")[0:10]
184 text = '#include "version.h"\n'
185 text += 'char const * sub::git_commit = \"%s\";\n' % commit
186 text += 'char const * sub::version = \"%s\";\n' % version
187 if bld.env.ENABLE_DEBUG:
188 debug_string = 'true'
190 debug_string = 'false'
191 text += 'bool const built_with_debug = %s;\n' % debug_string
192 print('Writing version information to src/version.cc')
193 o = open('src/version.cc', 'w')
197 print('Could not open src/version.cc for writing\n')
201 if ctx.cmd == 'install':
202 ctx.exec_command('/sbin/ldconfig')
205 os.system('etags src/*.cc src/*.h')