From 2e9ac80e998bc79d5ef9029415008198b22168dc Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 20 Jan 2020 23:08:11 +0100 Subject: Towards waf python 2+3 support --- gtk2_ardour/wscript | 32 +-- libs/ardour/wscript | 2 +- libs/pbd/wscript | 17 +- libs/plugins/a-comp.lv2/wscript | 14 +- libs/plugins/a-delay.lv2/wscript | 14 +- libs/plugins/a-eq.lv2/wscript | 14 +- libs/plugins/a-exp.lv2/wscript | 14 +- libs/plugins/a-fluidsynth.lv2/wscript | 16 +- libs/plugins/a-reverb.lv2/wscript | 14 +- libs/plugins/reasonablesynth.lv2/wscript | 14 +- libs/ptformat/wscript | 1 + libs/surfaces/contourdesign/wscript | 2 +- libs/surfaces/launch_control_xl/wscript | 2 +- libs/surfaces/osc/wscript | 2 +- libs/surfaces/push2/wscript | 4 +- libs/surfaces/wiimote/wscript | 2 +- libs/widgets/wscript | 2 +- session_utils/wscript | 2 +- tools/bb/wscript | 15 +- tools/luadevel/wscript | 2 +- tools/misc.py | 416 +++++++++++++++++++++++++++++++ wscript | 10 +- 22 files changed, 517 insertions(+), 94 deletions(-) create mode 100644 tools/misc.py diff --git a/gtk2_ardour/wscript b/gtk2_ardour/wscript index 194282cb66..7b0d6c56a7 100644 --- a/gtk2_ardour/wscript +++ b/gtk2_ardour/wscript @@ -401,20 +401,15 @@ def configure(conf): conf.env.append_value(var, ['-isystem', d]) if sys.platform == 'darwin': - retval = conf.run_c_code (code='#include \n\ - int main(void) { (void) NSWindowWillStartLiveResizeNotification; return 0; }\n', - env = conf.env.derive (), - features = [ 'c' ], - compiler = 'cc', - compile_filename='test.m', - mandatory = False, - ) - - if retval == 0: - autowaf.display_msg (conf, 'Checking for Cocoa live resizing constants', 'ok') - conf.define ('HAVE_COCOA_LIVE_RESIZING', 1) - else: - autowaf.display_msg (conf, 'Checking for Cocoa live resizing constants', 'too old - AU plugin windows will be fixed size') + conf.check( + msg ='Checking for Cocoa live resizing constants', + fragment = '#include \n int main(void) { (void) NSWindowWillStartLiveResizeNotification; return 0; }\n', + define_name = 'HAVE_COCOA_LIVE_RESIZING', + uselib_store = 'COCOA_LIVE_RESIZING', + compiler = 'cc', + compile_filename = 'test.m', + execute = True, + mandatory = False) conf.write_config_header('gtk2ardour-config.h', remove=False) @@ -507,7 +502,6 @@ def build(bld): obj.source = list(gtk2_ardour_sources) obj.target = 'luadoc' obj.includes = ['.', '../libs'] - obj.ldflags = ['-no-undefined'] obj.use = [ 'libpbd', 'libardour', @@ -547,7 +541,6 @@ def build(bld): # obj.source = [ 'ardour_button.cc', 'ui_config.cc', 'tooltips.cc' ] # obj.target = 'canvas_test' # obj.includes = ['.', '../libs'] -# obj.ldflags = ['-no-undefined'] # obj.use = [ # 'libpbd', # 'libardour', @@ -618,9 +611,8 @@ def build(bld): obj = bld (features = 'cxx c cxxprogram') # operate on copy to avoid adding sources twice obj.source = list(gtk2_ardour_sources) - obj.target = 'ardour-' + str (bld.env['VERSION']) - obj.includes = ['.'] - obj.ldflags = ['-no-undefined'] + obj.target = 'ardour-' + str (bld.env['VERSION']) + obj.includes = ['.'] if bld.is_defined('WINDOWS_VST_SUPPORT'): # Windows VST support mingw @@ -649,7 +641,7 @@ def build(bld): ] obj.install_path = bld.env['DLLDIR'] obj.linkflags = '' - obj.uselib = 'UUID FLAC FONTCONFIG GLIBMM GTHREAD GTK OGG CURL DL GTKMM CANVAS FFTW3F LO TAGLIB XML ' + obj.uselib = 'UUID FLAC FONTCONFIG GLIBMM GTHREAD GTK OGG CURL DL GTKMM CANVAS FFTW3F LO TAGLIB XML LILV' if sys.platform == 'darwin': obj.uselib += ' AUDIOUNITS OSX ' diff --git a/libs/ardour/wscript b/libs/ardour/wscript index 1b1f12e1ba..3da991be71 100644 --- a/libs/ardour/wscript +++ b/libs/ardour/wscript @@ -479,7 +479,7 @@ def build(bld): avx_cxxflags = list(bld.env['CXXFLAGS']) avx_cxxflags.append (bld.env['compiler_flags_dict']['avx']) avx_cxxflags.append (bld.env['compiler_flags_dict']['pic']) - bld(features = 'cxx', + bld(features = 'cxx cxxstlib asm', source = avx_sources, cxxflags = avx_cxxflags, includes = [ '.' ], diff --git a/libs/pbd/wscript b/libs/pbd/wscript index 3fe8b364e2..df9ce4df46 100644 --- a/libs/pbd/wscript +++ b/libs/pbd/wscript @@ -109,12 +109,21 @@ def configure(conf): autowaf.check_pkg(conf, 'glibmm-2.4', uselib_store='GLIBMM', atleast_version='2.32.0', mandatory=True) autowaf.check_pkg(conf, 'giomm-2.4', uselib_store='GIOMM', atleast_version='2.2', mandatory=True) - conf.check(function_name='getmntent', header_name='mntent.h', define_name='HAVE_GETMNTENT',mandatory=False) conf.check(header_name='execinfo.h', define_name='HAVE_EXECINFO',mandatory=False) conf.check(header_name='unistd.h', define_name='HAVE_UNISTD',mandatory=False) if not Options.options.ppc: - conf.check_cc(function_name='posix_memalign', header_name='stdlib.h', cflags='-D_XOPEN_SOURCE=600', define_name='HAVE_POSIX_MEMALIGN', mandatory=False) - conf.check(function_name='localtime_r', header_name='time.h', define_name='HAVE_LOCALTIME_R',mandatory=False) + conf.check_cc( + msg="Checking for function 'posix_memalign' in stdlib.h", + fragment = "#define _XOPEN_SOURCE 600\n #include \n int main(void) { return posix_memalign (0, 64, 1); }\n", + define_name='HAVE_POSIX_MEMALIGN', execute = False, mandatory=False) + conf.check_cc( + msg="Checking for function 'getmntent' in mntent.h", + fragment = "#include \n int main(void) { return (int)getmntent(0); }\n", + define_name='HAVE_GETMNTENT', execute = False, mandatory=False) + conf.check_cc( + msg="Checking for function 'localtime_r' in time.h", + fragment = "#include \n int main(void) { return localtime_r(NULL, NULL); }\n", + define_name='HAVE_LOCALTIME_R', execute = False, mandatory=False) # Boost headers autowaf.check_header(conf, 'cxx', 'boost/shared_ptr.hpp') @@ -162,7 +171,7 @@ def build(bld): obj.includes = ['.'] obj.name = 'libpbd' obj.target = 'pbd' - obj.uselib = 'GLIBMM SIGCPP XML UUID SNDFILE GIOMM ARCHIVE CURL' + obj.uselib = 'GLIBMM SIGCPP XML UUID SNDFILE GIOMM ARCHIVE CURL XML' if sys.platform == 'darwin': TaskGen.task_gen.mappings['.mm'] = TaskGen.task_gen.mappings['.cc'] if 'cocoa_open_uri.mm' not in obj.source: diff --git a/libs/plugins/a-comp.lv2/wscript b/libs/plugins/a-comp.lv2/wscript index fa71d2300a..9c841d08dc 100644 --- a/libs/plugins/a-comp.lv2/wscript +++ b/libs/plugins/a-comp.lv2/wscript @@ -24,15 +24,15 @@ def build(bld): module_pat = re.sub('^lib', '', bld.env.cshlib_PATTERN) module_ext = module_pat[module_pat.rfind('.'):] - if bld.is_defined ('HAVE_LV2'): + if bld.is_defined('HAVE_LV2'): # Build RDF files for i in ['manifest.ttl', 'a-comp.ttl', 'a-comp#stereo.ttl', 'presets.ttl']: - bld(features = 'subst', - source = i + '.in', - target = '../../LV2/%s/%s' % (bundle, i), - install_path = '${LV2DIR}/%s' % bundle, - chmod = Utils.O644, - LIB_EXT = module_ext) + obj = bld(features='subst') + obj.source = i + '.in' + obj.target = '../../LV2/%s/%s' % (bundle, i) + obj.install_path = '${LV2DIR}/%s' % bundle + obj.chmod = Utils.O644 + obj.dict = {'LIB_EXT': module_ext} # Build plugin library obj = bld(features = 'c cshlib', diff --git a/libs/plugins/a-delay.lv2/wscript b/libs/plugins/a-delay.lv2/wscript index be56763059..24fac5ff4a 100644 --- a/libs/plugins/a-delay.lv2/wscript +++ b/libs/plugins/a-delay.lv2/wscript @@ -24,15 +24,15 @@ def build(bld): module_pat = re.sub('^lib', '', bld.env.cshlib_PATTERN) module_ext = module_pat[module_pat.rfind('.'):] - if bld.is_defined ('HAVE_LV2'): + if bld.is_defined('HAVE_LV2'): # Build RDF files for i in ['manifest.ttl', 'a-delay.ttl', 'presets.ttl']: - bld(features = 'subst', - source = i + '.in', - target = '../../LV2/%s/%s' % (bundle, i), - install_path = '${LV2DIR}/%s' % bundle, - chmod = Utils.O644, - LIB_EXT = module_ext) + obj = bld(features='subst') + obj.source = i + '.in' + obj.target = '../../LV2/%s/%s' % (bundle, i) + obj.install_path = '${LV2DIR}/%s' % bundle + obj.chmod = Utils.O644 + obj.dict = {'LIB_EXT': module_ext} # Build plugin library obj = bld(features = 'c cshlib', diff --git a/libs/plugins/a-eq.lv2/wscript b/libs/plugins/a-eq.lv2/wscript index 36e9432499..c3f2b35cd4 100644 --- a/libs/plugins/a-eq.lv2/wscript +++ b/libs/plugins/a-eq.lv2/wscript @@ -24,15 +24,15 @@ def build(bld): module_pat = re.sub('^lib', '', bld.env.cshlib_PATTERN) module_ext = module_pat[module_pat.rfind('.'):] - if bld.is_defined ('HAVE_LV2'): + if bld.is_defined('HAVE_LV2'): # Build RDF files for i in ['manifest.ttl', 'a-eq.ttl']: - bld(features = 'subst', - source = i + '.in', - target = '../../LV2/%s/%s' % (bundle, i), - install_path = '${LV2DIR}/%s' % bundle, - chmod = Utils.O644, - LIB_EXT = module_ext) + obj = bld(features='subst') + obj.source = i + '.in' + obj.target = '../../LV2/%s/%s' % (bundle, i) + obj.install_path = '${LV2DIR}/%s' % bundle + obj.chmod = Utils.O644 + obj.dict = {'LIB_EXT': module_ext} # Build plugin library obj = bld(features = 'c cshlib', diff --git a/libs/plugins/a-exp.lv2/wscript b/libs/plugins/a-exp.lv2/wscript index 46e3b4f69e..7fb14a4e80 100644 --- a/libs/plugins/a-exp.lv2/wscript +++ b/libs/plugins/a-exp.lv2/wscript @@ -24,15 +24,15 @@ def build(bld): module_pat = re.sub('^lib', '', bld.env.cshlib_PATTERN) module_ext = module_pat[module_pat.rfind('.'):] - if bld.is_defined ('HAVE_LV2'): + if bld.is_defined('HAVE_LV2'): # Build RDF files for i in ['manifest.ttl', 'a-exp.ttl', 'a-exp#stereo.ttl']: - bld(features = 'subst', - source = i + '.in', - target = '../../LV2/%s/%s' % (bundle, i), - install_path = '${LV2DIR}/%s' % bundle, - chmod = Utils.O644, - LIB_EXT = module_ext) + obj = bld(features='subst') + obj.source = i + '.in' + obj.target = '../../LV2/%s/%s' % (bundle, i) + obj.install_path = '${LV2DIR}/%s' % bundle + obj.chmod = Utils.O644 + obj.dict = {'LIB_EXT': module_ext} # Build plugin library obj = bld(features = 'c cshlib', diff --git a/libs/plugins/a-fluidsynth.lv2/wscript b/libs/plugins/a-fluidsynth.lv2/wscript index 088fe3d876..462b4f89db 100644 --- a/libs/plugins/a-fluidsynth.lv2/wscript +++ b/libs/plugins/a-fluidsynth.lv2/wscript @@ -23,15 +23,15 @@ def build(bld): module_pat = re.sub('^lib', '', bld.env.cshlib_PATTERN) module_ext = module_pat[module_pat.rfind('.'):] - if bld.is_defined ('HAVE_LV2'): + if bld.is_defined('HAVE_LV2'): # Build RDF files for i in ['manifest.ttl', 'a-fluidsynth.ttl']: - bld(features = 'subst', - source = i + '.in', - target = '../../LV2/%s/%s' % (bundle, i), - install_path = '${LV2DIR}/%s' % bundle, - chmod = Utils.O644, - LIB_EXT = module_ext) + obj = bld(features='subst') + obj.source = i + '.in' + obj.target = '../../LV2/%s/%s' % (bundle, i) + obj.install_path = '${LV2DIR}/%s' % bundle + obj.chmod = Utils.O644 + obj.dict = {'LIB_EXT': module_ext} # Build plugin library obj = bld(features = 'cxx cshlib', @@ -41,7 +41,7 @@ def build(bld): includes = [ '../../ardour' ], target = '../../LV2/%s/a-fluidsynth' % bundle, install_path = '${LV2DIR}/%s' % bundle, - uselib = ['LIBFLUIDSYNTH'], + uselib = ['LIBFLUIDSYNTH', 'GLIB'], use = ['LV2_1_0_0'] ) diff --git a/libs/plugins/a-reverb.lv2/wscript b/libs/plugins/a-reverb.lv2/wscript index e5657ad716..04cbd11cab 100644 --- a/libs/plugins/a-reverb.lv2/wscript +++ b/libs/plugins/a-reverb.lv2/wscript @@ -23,15 +23,15 @@ def build(bld): module_pat = re.sub('^lib', '', bld.env.cshlib_PATTERN) module_ext = module_pat[module_pat.rfind('.'):] - if bld.is_defined ('HAVE_LV2'): + if bld.is_defined('HAVE_LV2'): # Build RDF files for i in ['manifest.ttl', 'a-reverb.ttl']: - bld(features = 'subst', - source = i + '.in', - target = '../../LV2/%s/%s' % (bundle, i), - install_path = '${LV2DIR}/%s' % bundle, - chmod = Utils.O644, - LIB_EXT = module_ext) + obj = bld(features='subst') + obj.source = i + '.in' + obj.target = '../../LV2/%s/%s' % (bundle, i) + obj.install_path = '${LV2DIR}/%s' % bundle + obj.chmod = Utils.O644 + obj.dict = {'LIB_EXT': module_ext} # Build plugin library obj = bld(features = 'c cshlib', diff --git a/libs/plugins/reasonablesynth.lv2/wscript b/libs/plugins/reasonablesynth.lv2/wscript index 4b51891af2..73cbe6a089 100644 --- a/libs/plugins/reasonablesynth.lv2/wscript +++ b/libs/plugins/reasonablesynth.lv2/wscript @@ -23,15 +23,15 @@ def build(bld): module_pat = re.sub('^lib', '', bld.env.cshlib_PATTERN) module_ext = module_pat[module_pat.rfind('.'):] - if bld.is_defined ('HAVE_LV2'): + if bld.is_defined('HAVE_LV2'): # Build RDF files for i in ['manifest.ttl', 'reasonablesynth.ttl']: - bld(features = 'subst', - source = i + '.in', - target = '../../LV2/%s/%s' % (bundle, i), - install_path = '${LV2DIR}/%s' % bundle, - chmod = Utils.O644, - LIB_EXT = module_ext) + obj = bld(features='subst') + obj.source = i + '.in' + obj.target = '../../LV2/%s/%s' % (bundle, i) + obj.install_path = '${LV2DIR}/%s' % bundle + obj.chmod = Utils.O644 + obj.dict = {'LIB_EXT': module_ext} # Build plugin library obj = bld(features = 'c cshlib', diff --git a/libs/ptformat/wscript b/libs/ptformat/wscript index 1f2c06a0a8..9ec3bd1a5a 100644 --- a/libs/ptformat/wscript +++ b/libs/ptformat/wscript @@ -42,6 +42,7 @@ def build(bld): obj.name = 'libptformat' obj.target = 'ptformat' obj.use = 'libpbd' + obj.uselib = 'GLIBMM' obj.vnum = LIBPTFORMAT_LIB_VERSION obj.install_path = bld.env['LIBDIR'] obj.defines += [ 'PACKAGE="' + I18N_PACKAGE + '"' ] diff --git a/libs/surfaces/contourdesign/wscript b/libs/surfaces/contourdesign/wscript index 7c1e40cb31..4f070028e2 100644 --- a/libs/surfaces/contourdesign/wscript +++ b/libs/surfaces/contourdesign/wscript @@ -27,7 +27,7 @@ def build(bld): obj.includes = ['.', '../libs', '../../widgets'] obj.name = 'libardour_contourdesign' obj.target = 'ardour_contourdesign' - obj.uselib = 'GTKMM USB' + obj.uselib = 'GTKMM USB XML' obj.use = 'libardour libardour_cp libgtkmm2ext libpbd libwidgets' obj.install_path = os.path.join(bld.env['LIBDIR'], 'surfaces') diff --git a/libs/surfaces/launch_control_xl/wscript b/libs/surfaces/launch_control_xl/wscript index d8d1fa8010..97f4f2222c 100644 --- a/libs/surfaces/launch_control_xl/wscript +++ b/libs/surfaces/launch_control_xl/wscript @@ -33,7 +33,7 @@ def build(bld): obj.includes = ['.', './launch_control_xl'] obj.name = 'libardour_launch_control_xl' obj.target = 'ardour_launch_control_xl' - obj.uselib = 'GTKMM SIGCPP' + obj.uselib = 'GTKMM SIGCPP XML' obj.use = 'libardour libardour_cp libpbd libevoral libcanvas libtemporal' obj.install_path = os.path.join(bld.env['LIBDIR'], 'surfaces') diff --git a/libs/surfaces/osc/wscript b/libs/surfaces/osc/wscript index 4d0dba6750..5bbe7d3946 100644 --- a/libs/surfaces/osc/wscript +++ b/libs/surfaces/osc/wscript @@ -30,7 +30,7 @@ def build(bld): obj.includes = ['.', './osc'] obj.name = 'libardour_osc' obj.target = 'ardour_osc' - obj.uselib = 'LO GTKMM GTK GDK' + obj.uselib = 'LO GTKMM GTK GDK XML' obj.use = 'libardour libardour_cp libgtkmm2ext libpbd' obj.install_path = os.path.join(bld.env['LIBDIR'], 'surfaces') diff --git a/libs/surfaces/push2/wscript b/libs/surfaces/push2/wscript index 806828cbd4..a025e12d59 100644 --- a/libs/surfaces/push2/wscript +++ b/libs/surfaces/push2/wscript @@ -39,10 +39,10 @@ def build(bld): obj.defines = [ 'PACKAGE="ardour_push2"' ] obj.defines += [ 'ARDOURSURFACE_DLL_EXPORTS' ] obj.defines += [ 'VERSIONSTRING="' + bld.env['VERSION'] + '"' ] - obj.includes = [ '.', './push2'] + obj.includes = ['.', './push2'] obj.name = 'libardour_push2' obj.target = 'ardour_push2' - obj.uselib = 'CAIROMM PANGOMM USB GTKMM SIGCPP' + obj.uselib = 'CAIROMM PANGOMM USB GTKMM SIGCPP XML' obj.use = 'libardour libardour_cp libgtkmm2ext libpbd libevoral libcanvas libtemporal' obj.install_path = os.path.join(bld.env['LIBDIR'], 'surfaces') diff --git a/libs/surfaces/wiimote/wscript b/libs/surfaces/wiimote/wscript index 03d01635a1..d38296f37f 100644 --- a/libs/surfaces/wiimote/wscript +++ b/libs/surfaces/wiimote/wscript @@ -24,7 +24,7 @@ def build(bld): obj.includes = ['.', '../libs'] obj.name = 'libardour_wiimote' obj.target = 'ardour_wiimote' - obj.uselib = 'GTKMM CWIID' + obj.uselib = 'GTKMM CWIID XML' obj.use = 'libardour libardour_cp libgtkmm2ext' obj.install_path = os.path.join(bld.env['LIBDIR'], 'surfaces') diff --git a/libs/widgets/wscript b/libs/widgets/wscript index 8be3c4ba32..d1b4aab0ac 100644 --- a/libs/widgets/wscript +++ b/libs/widgets/wscript @@ -74,7 +74,7 @@ def build(bld): obj.defines = [ ] obj.export_includes = ['.'] - obj.includes = ['.'] + obj.includes = ['.'] + bld.env['INCLUDES_GLIB'] obj.uselib = 'SIGCPP CAIROMM GTKMM BOOST XML' obj.use = [ 'libpbd', 'libgtkmm2ext' ] obj.name = 'libwidgets' diff --git a/session_utils/wscript b/session_utils/wscript index 0cd3c106ff..8e5dc449be 100644 --- a/session_utils/wscript +++ b/session_utils/wscript @@ -86,7 +86,7 @@ def build(bld): utils = bld.path.ant_glob('*.cc', excl=['example.cc', 'common.cc']) for util in utils: - fn = str(util)[:-3] + fn = os.path.splitext(os.path.basename(str(util)))[0] build_ardour_util(bld, fn) if bld.env['build_target'] != 'mingw': bld.symlink_as(bld.env['BINDIR'] + '/' + pgmprefix + "-" + fn, bld.env['LIBDIR'] + '/utils/ardour-util.sh') diff --git a/tools/bb/wscript b/tools/bb/wscript index e419fa2465..3e9fd8d2d7 100644 --- a/tools/bb/wscript +++ b/tools/bb/wscript @@ -12,14 +12,13 @@ def configure(ctx): pass def build(bld): - obj = bld (features = 'cxx c cxxprogram') - obj.install_path = None - obj.source = [ 'bb.cc', 'gui.cc', 'misc.cc' ] - obj.target = 'bb' - obj.includes = ['.', '../libs'] - obj.ldflags = ['-no-undefined'] - obj.use = [ 'libardour', 'libevoral', ] - obj.uselib = ' JACK GTKMM ' + obj = bld (features = 'cxx c cxxprogram') + obj.install_path = None + obj.source = [ 'bb.cc', 'gui.cc', 'misc.cc' ] + obj.target = 'bb' + obj.includes = ['.', '../libs'] + obj.use = [ 'libardour', 'libevoral', ] + obj.uselib = 'JACK GTKMM XML' wrapper_subst_dict = { 'INSTALL_PREFIX' : bld.env['PREFIX'], diff --git a/tools/luadevel/wscript b/tools/luadevel/wscript index 75fe790f39..f076e72f56 100755 --- a/tools/luadevel/wscript +++ b/tools/luadevel/wscript @@ -18,7 +18,7 @@ def options(opt): def configure(conf): conf.load('misc') conf.load('compiler_cxx') - conf.check_cc(function_name='readline', + conf.check_cc( header_name='stdio.h readline/readline.h', lib='readline', uselib_store='READLINE', diff --git a/tools/misc.py b/tools/misc.py new file mode 100644 index 0000000000..e8620fb14a --- /dev/null +++ b/tools/misc.py @@ -0,0 +1,416 @@ +#!/usr/bin/env python +# encoding: utf-8 +# Thomas Nagy, 2006-2010 (ita) + +""" +This tool is totally deprecated + +Try using: + .pc.in files for .pc files + the feature intltool_in - see demos/intltool + make-like rules +""" + +import shutil, re, os +from waflib import TaskGen, Node, Task, Utils, Build, Errors +from waflib.TaskGen import feature, after_method, before_method +from waflib.Logs import debug + +def copy_attrs(orig, dest, names, only_if_set=False): + """ + copy class attributes from an object to another + """ + for a in Utils.to_list(names): + u = getattr(orig, a, ()) + if u or not only_if_set: + setattr(dest, a, u) + +def copy_func(tsk): + "Make a file copy. This might be used to make other kinds of file processing (even calling a compiler is possible)" + env = tsk.env + infile = tsk.inputs[0].abspath() + outfile = tsk.outputs[0].abspath() + try: + shutil.copy2(infile, outfile) + except (OSError, IOError): + return 1 + else: + if tsk.chmod: os.chmod(outfile, tsk.chmod) + return 0 + +def action_process_file_func(tsk): + "Ask the function attached to the task to process it" + if not tsk.fun: raise Errors.WafError('task must have a function attached to it for copy_func to work!') + return tsk.fun(tsk) + +@feature('cmd') +def apply_cmd(self): + "call a command everytime" + if not self.fun: raise Errors.WafError('cmdobj needs a function!') + tsk = Task.TaskBase() + tsk.fun = self.fun + tsk.env = self.env + self.tasks.append(tsk) + tsk.install_path = self.install_path + +@feature('copy') +@before_method('process_source') +def apply_copy(self): + Utils.def_attrs(self, fun=copy_func) + self.default_install_path = 0 + + lst = self.to_list(self.source) + self.meths.remove('process_source') + + for filename in lst: + node = self.path.find_resource(filename) + if not node: raise Errors.WafError('cannot find input file %s for processing' % filename) + + target = self.target + if not target or len(lst)>1: target = node.name + + # TODO the file path may be incorrect + newnode = self.path.find_or_declare(target) + + tsk = self.create_task('copy', node, newnode) + tsk.fun = self.fun + tsk.chmod = getattr(self, 'chmod', Utils.O644) + + if not tsk.env: + tsk.debug() + raise Errors.WafError('task without an environment') + +def subst_func(tsk): + "Substitutes variables in a .in file" + + m4_re = re.compile('@(\w+)@', re.M) + + code = tsk.inputs[0].read() #Utils.readf(infile) + + # replace all % by %% to prevent errors by % signs in the input file while string formatting + code = code.replace('%', '%%') + + s = m4_re.sub(r'%(\1)s', code) + + env = tsk.env + di = getattr(tsk, 'dict', {}) or getattr(tsk.generator, 'dict', {}) + if not di: + names = m4_re.findall(code) + for i in names: + di[i] = env.get_flat(i) or env.get_flat(i.upper()) + + tsk.outputs[0].write(s % di) + +@feature('subst') +@before_method('process_source') +def apply_subst(self): + Utils.def_attrs(self, fun=subst_func) + lst = self.to_list(self.source) + self.meths.remove('process_source') + + self.dict = getattr(self, 'dict', {}) + + for filename in lst: + node = self.path.find_resource(filename) + if not node: raise Errors.WafError('cannot find input file %s for processing' % filename) + + if self.target: + newnode = self.path.find_or_declare(self.target) + else: + newnode = node.change_ext('') + + try: + self.dict = self.dict.get_merged_dict() + except AttributeError: + pass + + if self.dict and not self.env['DICT_HASH']: + self.env = self.env.derive() + keys = list(self.dict.keys()) + keys.sort() + lst = [self.dict[x] for x in keys] + self.env['DICT_HASH'] = str(Utils.h_list(lst)) + + tsk = self.create_task('copy', node, newnode) + tsk.fun = self.fun + tsk.dict = self.dict + tsk.dep_vars = ['DICT_HASH'] + tsk.chmod = getattr(self, 'chmod', Utils.O644) + + if not tsk.env: + tsk.debug() + raise Errors.WafError('task without an environment') + +#################### +## command-output #### +#################### + +class cmd_arg(object): + """command-output arguments for representing files or folders""" + def __init__(self, name, template='%s'): + self.name = name + self.template = template + self.node = None + +class input_file(cmd_arg): + def find_node(self, base_path): + assert isinstance(base_path, Node.Node) + self.node = base_path.find_resource(self.name) + if self.node is None: + raise Errors.WafError("Input file %s not found in " % (self.name, base_path)) + + def get_path(self, env, absolute): + if absolute: + return self.template % self.node.abspath() + else: + return self.template % self.node.srcpath() + +class output_file(cmd_arg): + def find_node(self, base_path): + assert isinstance(base_path, Node.Node) + self.node = base_path.find_or_declare(self.name) + if self.node is None: + raise Errors.WafError("Output file %s not found in " % (self.name, base_path)) + + def get_path(self, env, absolute): + if absolute: + return self.template % self.node.abspath() + else: + return self.template % self.node.bldpath() + +class cmd_dir_arg(cmd_arg): + def find_node(self, base_path): + assert isinstance(base_path, Node.Node) + self.node = base_path.find_dir(self.name) + if self.node is None: + raise Errors.WafError("Directory %s not found in " % (self.name, base_path)) + +class input_dir(cmd_dir_arg): + def get_path(self, dummy_env, dummy_absolute): + return self.template % self.node.abspath() + +class output_dir(cmd_dir_arg): + def get_path(self, env, dummy_absolute): + return self.template % self.node.abspath() + + +class command_output(Task.Task): + color = "BLUE" + def __init__(self, env, command, command_node, command_args, stdin, stdout, cwd, os_env, stderr): + Task.Task.__init__(self, env=env) + assert isinstance(command, (str, Node.Node)) + self.command = command + self.command_args = command_args + self.stdin = stdin + self.stdout = stdout + self.cwd = cwd + self.os_env = os_env + self.stderr = stderr + + if command_node is not None: self.dep_nodes = [command_node] + self.dep_vars = [] # additional environment variables to look + + def run(self): + task = self + #assert len(task.inputs) > 0 + + def input_path(node, template): + if task.cwd is None: + return template % node.bldpath() + else: + return template % node.abspath() + def output_path(node, template): + fun = node.abspath + if task.cwd is None: fun = node.bldpath + return template % fun() + + if isinstance(task.command, Node.Node): + argv = [input_path(task.command, '%s')] + else: + argv = [task.command] + + for arg in task.command_args: + if isinstance(arg, str): + argv.append(arg) + else: + assert isinstance(arg, cmd_arg) + argv.append(arg.get_path(task.env, (task.cwd is not None))) + + if task.stdin: + stdin = open(input_path(task.stdin, '%s')) + else: + stdin = None + + if task.stdout: + stdout = open(output_path(task.stdout, '%s'), "w") + else: + stdout = None + + if task.stderr: + stderr = open(output_path(task.stderr, '%s'), "w") + else: + stderr = None + + if task.cwd is None: + cwd = ('None (actually %r)' % os.getcwd()) + else: + cwd = repr(task.cwd) + debug("command-output: cwd=%s, stdin=%r, stdout=%r, argv=%r" % + (cwd, stdin, stdout, argv)) + + if task.os_env is None: + os_env = os.environ + else: + os_env = task.os_env + command = Utils.subprocess.Popen(argv, stdin=stdin, stdout=stdout, stderr=stderr, cwd=task.cwd, env=os_env) + return command.wait() + +@feature('command-output') +def init_cmd_output(self): + Utils.def_attrs(self, + stdin = None, + stdout = None, + stderr = None, + # the command to execute + command = None, + + # whether it is an external command; otherwise it is assumed + # to be an executable binary or script that lives in the + # source or build tree. + command_is_external = False, + + # extra parameters (argv) to pass to the command (excluding + # the command itself) + argv = [], + + # dependencies to other objects -> this is probably not what you want (ita) + # values must be 'task_gen' instances (not names!) + dependencies = [], + + # dependencies on env variable contents + dep_vars = [], + + # input files that are implicit, i.e. they are not + # stdin, nor are they mentioned explicitly in argv + hidden_inputs = [], + + # output files that are implicit, i.e. they are not + # stdout, nor are they mentioned explicitly in argv + hidden_outputs = [], + + # change the subprocess to this cwd (must use obj.input_dir() or output_dir() here) + cwd = None, + + # OS environment variables to pass to the subprocess + # if None, use the default environment variables unchanged + os_env = None) + +@feature('command-output') +@after_method('init_cmd_output') +def apply_cmd_output(self): + if self.command is None: + raise Errors.WafError("command-output missing command") + if self.command_is_external: + cmd = self.command + cmd_node = None + else: + cmd_node = self.path.find_resource(self.command) + assert cmd_node is not None, ('''Could not find command '%s' in source tree. +Hint: if this is an external command, +use command_is_external=True''') % (self.command,) + cmd = cmd_node + + if self.cwd is None: + cwd = None + else: + assert isinstance(cwd, CmdDirArg) + self.cwd.find_node(self.path) + + args = [] + inputs = [] + outputs = [] + + for arg in self.argv: + if isinstance(arg, cmd_arg): + arg.find_node(self.path) + if isinstance(arg, input_file): + inputs.append(arg.node) + if isinstance(arg, output_file): + outputs.append(arg.node) + + if self.stdout is None: + stdout = None + else: + assert isinstance(self.stdout, str) + stdout = self.path.find_or_declare(self.stdout) + if stdout is None: + raise Errors.WafError("File %s not found" % (self.stdout,)) + outputs.append(stdout) + + if self.stderr is None: + stderr = None + else: + assert isinstance(self.stderr, str) + stderr = self.path.find_or_declare(self.stderr) + if stderr is None: + raise Errors.WafError("File %s not found" % (self.stderr,)) + outputs.append(stderr) + + if self.stdin is None: + stdin = None + else: + assert isinstance(self.stdin, str) + stdin = self.path.find_resource(self.stdin) + if stdin is None: + raise Errors.WafError("File %s not found" % (self.stdin,)) + inputs.append(stdin) + + for hidden_input in self.to_list(self.hidden_inputs): + node = self.path.find_resource(hidden_input) + if node is None: + raise Errors.WafError("File %s not found in dir %s" % (hidden_input, self.path)) + inputs.append(node) + + for hidden_output in self.to_list(self.hidden_outputs): + node = self.path.find_or_declare(hidden_output) + if node is None: + raise Errors.WafError("File %s not found in dir %s" % (hidden_output, self.path)) + outputs.append(node) + + if not (inputs or getattr(self, 'no_inputs', None)): + raise Errors.WafError('command-output objects must have at least one input file or give self.no_inputs') + if not (outputs or getattr(self, 'no_outputs', None)): + raise Errors.WafError('command-output objects must have at least one output file or give self.no_outputs') + + cwd = self.bld.variant_dir + task = command_output(self.env, cmd, cmd_node, self.argv, stdin, stdout, cwd, self.os_env, stderr) + task.generator = self + copy_attrs(self, task, 'before after ext_in ext_out', only_if_set=True) + self.tasks.append(task) + + task.inputs = inputs + task.outputs = outputs + task.dep_vars = self.to_list(self.dep_vars) + + for dep in self.dependencies: + assert dep is not self + dep.post() + for dep_task in dep.tasks: + task.set_run_after(dep_task) + + if not task.inputs: + # the case for svnversion, always run, and update the output nodes + task.runnable_status = type(Task.TaskBase.run)(runnable_status, task, task.__class__) # always run + task.post_run = type(Task.TaskBase.run)(post_run, task, task.__class__) + + # TODO the case with no outputs? + +def post_run(self): + for x in self.outputs: + x.sig = Utils.h_file(x.abspath()) + +def runnable_status(self): + return self.RUN_ME + +Task.task_factory('copy', vars=[], func=action_process_file_func) + diff --git a/wscript b/wscript index e9fb579dc9..cb3980ed41 100644 --- a/wscript +++ b/wscript @@ -1036,9 +1036,15 @@ def configure(conf): if Options.options.dist_target != 'mingw': if Options.options.dist_target != 'msvc' and re.search ("openbsd", sys.platform) == None: if re.search ("freebsd", sys.platform) != None: - conf.check_cc(function_name='dlopen', header_name='dlfcn.h', uselib_store='DL') + conf.check_cc( + msg="Checking for function 'dlopen' in dlfcn.h", + fragment = "#include \n int main(void) { dlopen (\"\", 0); return 0;}\n", + uselib_store='DL', execute = False) else: - conf.check_cc(function_name='dlopen', header_name='dlfcn.h', lib='dl', uselib_store='DL') + conf.check_cc( + msg="Checking for function 'dlopen' in dlfcn.h", + fragment = "#include \n int main(void) { dlopen (\"\", 0); return 0;}\n", + linkflags='-ldl', uselib_store='DL', execute = False) conf.check_cxx(fragment = "#include \n#if !defined (BOOST_VERSION) || BOOST_VERSION < 105600\n#error boost >= 1.56 is not available\n#endif\nint main(void) { return 0; }\n", execute = False, -- cgit v1.2.3