X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=autowaf.py;h=c9ac680c7b4c573c41c82705c93612c4cfbd5e81;hb=fa590d385bdd7ca2336e9c6e65bc0ca2ece758be;hp=8dc9efffc3693c53a71c8023163160f6bf5998e1;hpb=76f242cb804bd3c612ae5abfd0d3d078c0317dd0;p=ardour.git diff --git a/autowaf.py b/autowaf.py index 8dc9efffc3..c9ac680c7b 100644 --- a/autowaf.py +++ b/autowaf.py @@ -1,15 +1,18 @@ #!/usr/bin/env python # Waf utilities for easily building standard unixey packages/libraries # Licensed under the GNU GPL v2 or later, see COPYING file for details. -# Copyright (C) 2008 Dave Robillard +# Copyright (C) 2008 David Robillard # Copyright (C) 2008 Nedko Arnaudov -import os -import misc import Configure import Options import Utils +import misc +import os +import subprocess import sys +import glob + from TaskGen import feature, before, after global g_is_child @@ -36,11 +39,13 @@ def set_options(opt): return opt.tool_options('compiler_cc') opt.tool_options('compiler_cxx') - opt.add_option('--debug', action='store_true', default=False, dest='debug', - help="Build debuggable binaries [Default: False]") + opt.add_option('--debug', action='store_true', default=True, dest='debug', + help="Build debuggable binaries [Default: True]") + opt.add_option('--optimize', action='store_false', default=True, dest='debug', + help="Build optimized binaries [Default: False]") opt.add_option('--strict', action='store_true', default=False, dest='strict', help="Use strict compiler flags and show all warnings [Default: False]") - opt.add_option('--build-docs', action='store_true', default=False, dest='build_docs', + opt.add_option('--docs', action='store_true', default=False, dest='docs', help="Build documentation - requires doxygen [Default: False]") opt.add_option('--bundle', action='store_true', default=False, help="Build a self-contained bundle [Default: False]") @@ -76,23 +81,16 @@ def check_header(conf, name, define='', mandatory=False): checked = conf.env['AUTOWAF_HEADERS'] if not name in checked: checked[name] = True + includes = '' # search default system include paths + if sys.platform == "darwin": + includes = '/opt/local/include' if define != '': - conf.check(header_name=name, define_name=define, mandatory=mandatory) + conf.check(header_name=name, includes=includes, define_name=define, mandatory=mandatory) else: - conf.check(header_name=name, mandatory=mandatory) - -def check_tool(conf, name): - "Check for a tool iff it hasn't been checked for yet" - if type(conf.env['AUTOWAF_TOOLS']) != dict: - conf.env['AUTOWAF_TOOLS'] = {} - - checked = conf.env['AUTOWAF_TOOLS'] - if not name in checked: - conf.check_tool(name) - checked[name] = True + conf.check(header_name=name, includes=includes, mandatory=mandatory) def nameify(name): - return name.replace('/', '_').replace('++', 'PP').replace('-', '_') + return name.replace('/', '_').replace('++', 'PP').replace('-', '_').replace('.', '_') def check_pkg(conf, name, **args): if not 'mandatory' in args: @@ -117,96 +115,109 @@ def check_pkg(conf, name, **args): if args['mandatory'] == True: conf.fatal("Required package " + name + " not found") -def chop_prefix(conf, var): - name = conf.env[var][len(conf.env['PREFIX']):] - if len(name) > 0 and name[0] == '/': - name = name[1:] - if name == "": - name = "/" - return name; - def configure(conf): global g_step if g_step > 1: return - def append_cxx_flags(val): - conf.env.append_value('CCFLAGS', val) - conf.env.append_value('CXXFLAGS', val) - conf.line_just = 43 - check_tool(conf, 'misc') - check_tool(conf, 'compiler_cc') - check_tool(conf, 'compiler_cxx') - conf.env['BUILD_DOCS'] = Options.options.build_docs + def append_cxx_flags(vals): + conf.env.append_value('CCFLAGS', vals.split()) + conf.env.append_value('CXXFLAGS', vals.split()) + display_header('Global Configuration') + conf.check_tool('misc') + conf.check_tool('compiler_cc') + conf.check_tool('compiler_cxx') + conf.env['DOCS'] = Options.options.docs conf.env['DEBUG'] = Options.options.debug + conf.env['STRICT'] = Options.options.strict conf.env['PREFIX'] = os.path.abspath(os.path.expanduser(os.path.normpath(conf.env['PREFIX']))) if Options.options.bundle: conf.env['BUNDLE'] = True conf.define('BUNDLE', 1) conf.env['BINDIR'] = conf.env['PREFIX'] - conf.env['INCLUDEDIR'] = conf.env['PREFIX'] + '/Headers/' - conf.env['LIBDIR'] = conf.env['PREFIX'] + '/Libraries/' - conf.env['DATADIR'] = conf.env['PREFIX'] + '/Resources/' - conf.env['HTMLDIR'] = conf.env['PREFIX'] + '/Resources/Documentation/' - conf.env['MANDIR'] = conf.env['PREFIX'] + '/Resources/Man/' - conf.env['LV2DIR'] = conf.env['PREFIX'] + '/PlugIns/' + conf.env['INCLUDEDIR'] = os.path.join(conf.env['PREFIX'], 'Headers') + conf.env['LIBDIR'] = os.path.join(conf.env['PREFIX'], 'Libraries') + conf.env['DATADIR'] = os.path.join(conf.env['PREFIX'], 'Resources') + conf.env['HTMLDIR'] = os.path.join(conf.env['PREFIX'], 'Resources/Documentation') + conf.env['MANDIR'] = os.path.join(conf.env['PREFIX'], 'Resources/Man') + conf.env['LV2DIR'] = os.path.join(conf.env['PREFIX'], 'PlugIns') else: conf.env['BUNDLE'] = False if Options.options.bindir: conf.env['BINDIR'] = Options.options.bindir else: - conf.env['BINDIR'] = conf.env['PREFIX'] + '/bin/' + conf.env['BINDIR'] = os.path.join(conf.env['PREFIX'], 'bin') if Options.options.includedir: conf.env['INCLUDEDIR'] = Options.options.includedir else: - conf.env['INCLUDEDIR'] = conf.env['PREFIX'] + '/include/' + conf.env['INCLUDEDIR'] = os.path.join(conf.env['PREFIX'], 'include') if Options.options.libdir: conf.env['LIBDIR'] = Options.options.libdir else: - conf.env['LIBDIR'] = conf.env['PREFIX'] + '/lib/' + conf.env['LIBDIR'] = os.path.join(conf.env['PREFIX'], 'lib') if Options.options.datadir: conf.env['DATADIR'] = Options.options.datadir else: - conf.env['DATADIR'] = conf.env['PREFIX'] + '/share/' + conf.env['DATADIR'] = os.path.join(conf.env['PREFIX'], 'share') if Options.options.configdir: conf.env['CONFIGDIR'] = Options.options.configdir else: - conf.env['CONFIGDIR'] = conf.env['PREFIX'] + '/etc/' + conf.env['CONFIGDIR'] = os.path.join(conf.env['PREFIX'], 'etc') if Options.options.htmldir: conf.env['HTMLDIR'] = Options.options.htmldir else: - conf.env['HTMLDIR'] = conf.env['DATADIR'] + 'doc/' + Utils.g_module.APPNAME + '/' + conf.env['HTMLDIR'] = os.path.join(conf.env['DATADIR'], 'doc', Utils.g_module.APPNAME) if Options.options.mandir: conf.env['MANDIR'] = Options.options.mandir else: - conf.env['MANDIR'] = conf.env['DATADIR'] + 'man/' + conf.env['MANDIR'] = os.path.join(conf.env['DATADIR'], 'man') if Options.options.lv2dir: conf.env['LV2DIR'] = Options.options.lv2dir else: if Options.options.lv2_user: if sys.platform == "darwin": - conf.env['LV2DIR'] = os.getenv('HOME') + '/Library/Audio/Plug-Ins/LV2' + conf.env['LV2DIR'] = os.path.join(os.getenv('HOME'), 'Library/Audio/Plug-Ins/LV2') else: - conf.env['LV2DIR'] = os.getenv('HOME') + '/.lv2' + conf.env['LV2DIR'] = os.path.join(os.getenv('HOME'), '.lv2') else: if sys.platform == "darwin": conf.env['LV2DIR'] = '/Library/Audio/Plug-Ins/LV2' else: - conf.env['LV2DIR'] = conf.env['LIBDIR'] + 'lv2/' + conf.env['LV2DIR'] = os.path.join(conf.env['LIBDIR'], 'lv2') + + conf.env['BINDIRNAME'] = os.path.basename(conf.env['BINDIR']) + conf.env['LIBDIRNAME'] = os.path.basename(conf.env['LIBDIR']) + conf.env['DATADIRNAME'] = os.path.basename(conf.env['DATADIR']) + conf.env['CONFIGDIRNAME'] = os.path.basename(conf.env['CONFIGDIR']) + conf.env['LV2DIRNAME'] = os.path.basename(conf.env['LV2DIR']) + + if Options.options.docs: + doxygen = conf.find_program('doxygen') + if not doxygen: + conf.fatal("Doxygen is required to build documentation, configure without --docs") + + dot = conf.find_program('dot') + if not dot: + conf.fatal("Graphviz (dot) is required to build documentation, configure without --docs") - conf.env['BINDIRNAME'] = chop_prefix(conf, 'BINDIR') - conf.env['LIBDIRNAME'] = chop_prefix(conf, 'LIBDIR') - conf.env['DATADIRNAME'] = chop_prefix(conf, 'DATADIR') - conf.env['CONFIGDIRNAME'] = chop_prefix(conf, 'CONFIGDIR') - conf.env['LV2DIRNAME'] = chop_prefix(conf, 'LV2DIR') - if Options.options.debug: - conf.env['CCFLAGS'] = '-O0 -g -std=c99' - conf.env['CXXFLAGS'] = '-O0 -g -ansi' + conf.env['CCFLAGS'] = [ '-O0', '-g' ] + conf.env['CXXFLAGS'] = [ '-O0', '-g' ] + else: + append_cxx_flags('-DNDEBUG') + if Options.options.strict: - conf.env['CCFLAGS'] = '-O0 -g -std=c99 -pedantic' + conf.env.append_value('CCFLAGS', [ '-std=c99', '-pedantic' ]) + conf.env.append_value('CXXFLAGS', [ '-ansi', '-Woverloaded-virtual', '-Wnon-virtual-dtor']) append_cxx_flags('-Wall -Wextra -Wno-unused-parameter') - conf.env.append_value('CXXFLAGS', '-Woverloaded-virtual') - append_cxx_flags('-fPIC -DPIC') + + append_cxx_flags('-fPIC -DPIC -fshow-column') + + display_msg(conf, "Install prefix", conf.env['PREFIX']) + display_msg(conf, "Debuggable build", str(conf.env['DEBUG'])) + display_msg(conf, "Strict compiler flags", str(conf.env['STRICT'])) + display_msg(conf, "Build documentation", str(conf.env['DOCS'])) + print() + g_step = 2 def set_local_lib(conf, name, has_objects): @@ -233,10 +244,10 @@ def use_lib(bld, obj, libs): obj.uselib_local = 'lib' + l.lower() + ' ' if in_headers or in_libs: - inc_flag = '-iquote ' + abssrcdir + '/' + l.lower() + inc_flag = '-iquote ' + os.path.join(abssrcdir, l.lower()) for f in ['CCFLAGS', 'CXXFLAGS']: if not inc_flag in bld.env[f]: - bld.env.prepend_value(f, inc_flag) + bld.env.append_value(f, inc_flag) else: if hasattr(obj, 'uselib'): obj.uselib += ' ' + l @@ -253,23 +264,9 @@ def display_msg(conf, msg, status = None, color = None): color = 'GREEN' elif type(status) == bool and not status or status == "False": color = 'YELLOW' - Utils.pprint('NORMAL', "%s :" % msg.ljust(conf.line_just), sep='') + Utils.pprint('BOLD', "%s :" % msg.ljust(conf.line_just), sep='') Utils.pprint(color, status) -def print_summary(conf): - global g_step - if g_step > 2: - print - return - e = conf.env - print - display_header('Global configuration') - display_msg(conf, "Install prefix", conf.env['PREFIX']) - display_msg(conf, "Debuggable build", str(conf.env['DEBUG'])) - display_msg(conf, "Build documentation", str(conf.env['BUILD_DOCS'])) - print - g_step = 3 - def link_flags(env, lib): return ' '.join(map(lambda x: env['LIB_ST'] % x, env['LIB_' + lib])) @@ -302,7 +299,7 @@ def build_pc(bld, name, version, libs): obj.dict = { 'prefix' : pkg_prefix, 'exec_prefix' : '${prefix}', - 'libdir' : '${exec_prefix}/lib', + 'libdir' : '${prefix}/' + bld.env['LIBDIRNAME'], 'includedir' : '${prefix}/include', name + '_VERSION' : version, } @@ -314,17 +311,17 @@ def build_pc(bld, name, version, libs): # Doxygen API documentation def build_dox(bld, name, version, srcdir, blddir): - if not bld.env['BUILD_DOCS']: + if not bld.env['DOCS']: return obj = bld.new_task_gen('subst') obj.source = 'doc/reference.doxygen.in' obj.target = 'doc/reference.doxygen' if is_child(): - src_dir = srcdir + '/' + name.lower() - doc_dir = blddir + '/default/' + name.lower() + '/doc' + src_dir = os.path.join(srcdir, name.lower()) + doc_dir = os.path.join(blddir, 'default', name.lower(), 'doc') else: src_dir = srcdir - doc_dir = blddir + '/default/doc' + doc_dir = os.path.join(blddir, 'default', 'doc') obj.dict = { name + '_VERSION' : version, name + '_SRCDIR' : os.path.abspath(src_dir), @@ -332,6 +329,7 @@ def build_dox(bld, name, version, srcdir, blddir): } obj.install_path = '' out1 = bld.new_task_gen('command-output') + out1.dependencies = [obj] out1.stdout = '/doc/doxygen.out' out1.stdin = '/doc/reference.doxygen' # whatever.. out1.command = 'doxygen' @@ -346,11 +344,11 @@ def build_version_files(header_path, source_path, domain, major, minor, micro): text += "int " + domain + "_minor_version = " + str(minor) + ";\n" text += "int " + domain + "_micro_version = " + str(micro) + ";\n" try: - o = file(source_path, 'w') + o = open(source_path, 'w') o.write(text) o.close() except IOError: - print "Could not open", source_path, " for writing\n" + print("Could not open %s for writing\n", source_path) sys.exit(-1) text = "#ifndef __" + domain + "_version_h__\n" @@ -361,18 +359,122 @@ def build_version_files(header_path, source_path, domain, major, minor, micro): text += "extern int " + domain + "_micro_version;\n" text += "#endif /* __" + domain + "_version_h__ */\n" try: - o = file(header_path, 'w') + o = open(header_path, 'w') o.write(text) o.close() except IOError: - print "Could not open", header_path, " for writing\n" + print("Could not open %s for writing\n", header_path) sys.exit(-1) return None +def run_tests(ctx, appname, tests): + orig_dir = os.path.abspath(os.curdir) + failures = 0 + base = '..' + + top_level = os.path.abspath(ctx.curdir) != os.path.abspath(os.curdir) + if top_level: + os.chdir('./build/default/' + appname) + base = '../..' + else: + os.chdir('./build/default') + + lcov = True + lcov_log = open('lcov.log', 'w') + try: + # Clear coverage data + subprocess.call('lcov -d ./src -z'.split(), + stdout=lcov_log, stderr=lcov_log) + except: + lcov = False + print("Failed to run lcov, no coverage report will be generated") + + + # Run all tests + for i in tests: + print() + Utils.pprint('BOLD', 'Running %s test %s' % (appname, i)) + if subprocess.call(i) == 0: + Utils.pprint('GREEN', 'Passed %s %s' % (appname, i)) + else: + failures += 1 + Utils.pprint('RED', 'Failed %s %s' % (appname, i)) + + if lcov: + # Generate coverage data + coverage_lcov = open('coverage.lcov', 'w') + subprocess.call(('lcov -c -d ./src -d ./test -b ' + base).split(), + stdout=coverage_lcov, stderr=lcov_log) + coverage_lcov.close() + + # Strip out unwanted stuff + coverage_stripped_lcov = open('coverage-stripped.lcov', 'w') + subprocess.call('lcov --remove coverage.lcov *boost* c++*'.split(), + stdout=coverage_stripped_lcov, stderr=lcov_log) + coverage_stripped_lcov.close() + + # Generate HTML coverage output + if not os.path.isdir('./coverage'): + os.makedirs('./coverage') + subprocess.call('genhtml -o coverage coverage-stripped.lcov'.split(), + stdout=lcov_log, stderr=lcov_log) + + lcov_log.close() + + print() + Utils.pprint('BOLD', 'Summary:', sep=''), + if failures == 0: + Utils.pprint('GREEN', 'All ' + appname + ' tests passed') + else: + Utils.pprint('RED', str(failures) + ' ' + appname + ' test(s) failed') + + Utils.pprint('BOLD', 'Coverage:', sep='') + print(os.path.abspath('coverage/index.html')) + + os.chdir(orig_dir) + def shutdown(): # This isn't really correct (for packaging), but people asking is annoying if Options.commands['install']: try: os.popen("/sbin/ldconfig") except: pass +def build_i18n(bld,srcdir,dir,name,sources): + pwd = os.getcwd() + os.chdir(os.path.join (srcdir, dir)) + + pot_file = '%s.pot' % name + + args = [ 'xgettext', + '--keyword=_', + '--keyword=N_', + '--from-code=UTF-8', + '-o', pot_file, + '--copyright-holder="Paul Davis"' ] + args += sources + print 'Updating ', pot_file + os.spawnvp (os.P_WAIT, 'xgettext', args) + + po_files = glob.glob ('po/*.po') + languages = [ po.replace ('.po', '') for po in po_files ] + + for po_file in po_files: + args = [ 'msgmerge', + '--update', + po_file, + pot_file ] + print 'Updating ', po_file + os.spawnvp (os.P_WAIT, 'msgmerge', args) + + for po_file in po_files: + mo_file = po_file.replace ('.po', '.mo') + args = [ 'msgfmt', + '-c', + '-f', + '-o', + mo_file, + po_file ] + print 'Generating ', po_file + os.spawnvp (os.P_WAIT, 'msgfmt', args) + os.chdir (pwd)