84 lines
2.8 KiB
Python
84 lines
2.8 KiB
Python
from buildutils import *
|
|
|
|
Import('env', 'buildTargets', 'installTargets')
|
|
|
|
class MatlabBuilder(object):
|
|
def __init__(self, libs):
|
|
self.libs = libs
|
|
|
|
def __call__(self, target, source, env):
|
|
filenames = [os.path.split(node.path)[1] for node in source]
|
|
sourcestr = ' '.join(filenames)
|
|
includes = ' '.join('-I%s' % quoted(Dir(s).abspath) for s in env['CPPPATH'])
|
|
libdir = ' '.join('-L%s' % quoted(Dir(s).abspath) for s in env['LIBPATH'])
|
|
libs = ' '.join('-l'+s for s in self.libs)
|
|
extraFlag = '-cxx' if os.name == 'posix' else ''
|
|
debugFlag = '-g' if not env['optimize'] else ''
|
|
outdir = "'%s'" % Dir('#interfaces/matlab/toolbox').abspath
|
|
|
|
text = ("disp('building Cantera...');\n"
|
|
"mex %(debugFlag)s %(extraFlag)s -v -output ctmethods "
|
|
"-outdir %(outdir)s "
|
|
"%(includes)s %(libdir)s "
|
|
"%(libs)s %(sourcestr)s\n"
|
|
"disp('done.');\n"
|
|
"pause(2)\n"
|
|
"exit\n") % locals()
|
|
|
|
with open(str(target[0]), 'w') as f:
|
|
f.write(text)
|
|
|
|
|
|
localenv = env.Clone()
|
|
localenv.Append(CPPPATH=['#include', '#src'])
|
|
|
|
cantera_libname = 'cantera_shared' if os.name=='nt' else 'cantera'
|
|
localenv.Command('build_cantera.m',
|
|
mglob(localenv, '.', 'cpp'),
|
|
MatlabBuilder([cantera_libname]))
|
|
|
|
localenv['ENV']['PATH'] = os.environ['PATH']
|
|
if 'TEMP' in os.environ:
|
|
localenv['ENV']['TEMP'] = os.environ['TEMP']
|
|
|
|
build_cmd = 'cd ${SOURCE.dir} && "%(matlab_cmd)s" -nojvm -nosplash -r build_cantera'
|
|
|
|
if os.name == 'posix':
|
|
mexPlatform = 'a'
|
|
elif os.name == 'nt':
|
|
mexPlatform = 'w'
|
|
if localenv['OS_BITS'] == 64:
|
|
localenv['ENV']['PROCESSOR_ARCHITECTURE'] = "AMD64"
|
|
else:
|
|
localenv['ENV']['PROCESSOR_ARCHITECTURE'] = "x86"
|
|
|
|
mexFile = ('#interfaces/matlab/toolbox/ctmethods.mex%s%i' %
|
|
(mexPlatform, localenv['OS_BITS']))
|
|
|
|
target = localenv.Command(mexFile,
|
|
'build_cantera.m',
|
|
build_cmd % localenv)
|
|
localenv.Depends(target, localenv['cantera_shlib'])
|
|
buildTargets.extend(target)
|
|
|
|
### Install the Matlab toolbox ###
|
|
|
|
# 'ctpath.m'
|
|
target = localenv.SubstFile('ctpath.m', '#interfaces/matlab/ctpath.m.in')
|
|
buildTargets.extend(target)
|
|
inst = localenv.Install('$inst_matlab_dir', target)
|
|
installTargets.extend(inst)
|
|
|
|
# 'cantera_demos.m'
|
|
inst = localenv.Install('$inst_matlab_dir', '#samples/matlab/cantera_demos.m')
|
|
installTargets.extend(inst)
|
|
|
|
inst = localenv.RecursiveInstall('$inst_matlab_dir', '#interfaces/matlab/toolbox')
|
|
installTargets.extend(inst)
|
|
|
|
inst = localenv.RecursiveInstall(pjoin('$inst_sampledir', 'matlab'), '#samples/matlab')
|
|
installTargets.extend(inst)
|
|
|
|
if os.name == 'nt':
|
|
inst = localenv.Install('$inst_matlab_dir', localenv['cantera_shlib'])
|
|
installTargets.extend(inst)
|