From 0982600bcd048e02effeefad37aee45a66edcc2d Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Wed, 14 Dec 2011 03:53:56 +0000 Subject: [PATCH] Better default behavior for building the Matlab toolbox with SCons If Matlab is found on the path, build the toolbox by default, otherwise skip it. If the toolbox is required and Matlab can't be found, exit with an error. --- SConstruct | 27 ++++++++++++++++++++++++--- buildutils.py | 19 +++++++++++++++++++ 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/SConstruct b/SConstruct index b9c3aa23b..1e0fa0f39 100644 --- a/SConstruct +++ b/SConstruct @@ -33,7 +33,7 @@ opts.AddVariables( '', PathVariable.PathAccept), PathVariable('cantera_python_home', 'where to install the python package', '', PathVariable.PathAccept), - EnumVariable('matlab_toolbox', '', 'n', ('y', 'n', 'default')), + EnumVariable('matlab_toolbox', '', 'default', ('y', 'n', 'default')), PathVariable('matlab_cmd', 'Path to the matlab executable', 'matlab', PathVariable.PathAccept), BoolVariable('f90_interface', 'Build Fortran90 interface?', False), @@ -154,6 +154,19 @@ if env['python_package'] in ('full','default'): warnNoPython = True env['python_package'] = 'minimal' + +if env['matlab_toolbox'] == 'y' and which(env['matlab_cmd']) is None: + print """ERROR: Unable to find the Matlab executable '%s'""" % env['matlab_cmd'] + sys.exit(1) +elif env['matlab_toolbox'] == 'default': + cmd = which(env['matlab_cmd']) + if cmd is not None: + env['matlab_toolbox'] = 'y' + print """INFO: Building the Matlab toolbox using '%s'""" % cmd + else: + print """INFO: Skipping compilation of the Matlab toolbox. """ + + # ************************************** # *** Set options needed in config.h *** # ************************************** @@ -337,10 +350,18 @@ inst = env.Install('$ct_bindir', pjoin('bin', 'exp3to2.sh')) installTargets.extend(inst) ### Meta-targets ### -build_cantera = Alias('build', buildTargets) build_demos = Alias('demos', demoTargets) -Default(build_cantera) +def postBuildMessage(target, source, env): + print "**************************************************************" + print "Compiliation complete. Type '[sudo] scons install' to install." + print "**************************************************************" + +finish_build = env.Command('finish_build', [], postBuildMessage) +env.Depends(finish_build, buildTargets) +build_cantera = Alias('build', finish_build) + +Default('build') def postInstallMessage(target, source, env): v = sys.version_info diff --git a/buildutils.py b/buildutils.py index 8b439ed0c..ab1b44ffa 100644 --- a/buildutils.py +++ b/buildutils.py @@ -102,6 +102,25 @@ def psplit(s): return path +def which(program): + """ Replicates the functionality of the 'which' shell command """ + import os + def is_exe(fpath): + return os.path.exists(fpath) and os.access(fpath, os.X_OK) + + fpath, fname = os.path.split(program) + if fpath: + if is_exe(program): + return program + else: + for path in os.environ["PATH"].split(os.pathsep): + exe_file = os.path.join(path, program) + if is_exe(exe_file): + return exe_file + + return None + + # This tool adds the builder: # # env.RecursiveInstall(target, path)