Removed obsolete code for generating matlab wrapper makefiles and build script

release/4.3a0
Richard Roberts 2012-07-05 14:04:51 +00:00
parent bf0b727d98
commit 8f8975f47f
6 changed files with 11 additions and 138 deletions

View File

@ -132,8 +132,6 @@ if (GTSAM_BUILD_WRAP)
endif() endif()
# Generate, build and install toolbox # Generate, build and install toolbox
string(TOUPPER ${CMAKE_BUILD_TYPE} build_type_toupper)
get_target_property(gtsam_library_file gtsam-static LOCATION_${build_type_toupper})
set(mexFlags ${GTSAM_BUILD_MEX_BINARY_FLAGS} -I${Boost_INCLUDE_DIR} -I${MEX_INCLUDE_ROOT} -I${MEX_INCLUDE_ROOT}/gtsam -I${MEX_INCLUDE_ROOT}/gtsam/base -I${MEX_INCLUDE_ROOT}/gtsam/geometry -I${MEX_INCLUDE_ROOT}/gtsam/linear -I${MEX_INCLUDE_ROOT}/gtsam/discrete -I${MEX_INCLUDE_ROOT}/gtsam/inference -I${MEX_INCLUDE_ROOT}/gtsam/nonlinear -I${MEX_INCLUDE_ROOT}/gtsam/slam) set(mexFlags ${GTSAM_BUILD_MEX_BINARY_FLAGS} -I${Boost_INCLUDE_DIR} -I${MEX_INCLUDE_ROOT} -I${MEX_INCLUDE_ROOT}/gtsam -I${MEX_INCLUDE_ROOT}/gtsam/base -I${MEX_INCLUDE_ROOT}/gtsam/geometry -I${MEX_INCLUDE_ROOT}/gtsam/linear -I${MEX_INCLUDE_ROOT}/gtsam/discrete -I${MEX_INCLUDE_ROOT}/gtsam/inference -I${MEX_INCLUDE_ROOT}/gtsam/nonlinear -I${MEX_INCLUDE_ROOT}/gtsam/slam)
# Macro to handle details of setting up targets # Macro to handle details of setting up targets

View File

@ -120,65 +120,6 @@ void Class::matlab_static_methods(const string& toolboxPath, const string& wrapp
} }
} }
/* ************************************************************************* */
void Class::matlab_make_fragment(FileWriter& file,
const string& toolboxPath,
const string& mexFlags) const {
string mex = "mex " + mexFlags + " ";
string matlabClassName = qualifiedName();
file.oss << mex << constructor.matlab_wrapper_name(matlabClassName) << ".cpp" << endl;
BOOST_FOREACH(StaticMethod sm, static_methods)
file.oss << mex << matlabClassName + "_" + sm.name << ".cpp" << endl;
file.oss << endl << "cd @" << matlabClassName << endl;
BOOST_FOREACH(Method m, methods)
file.oss << mex << m.name << ".cpp" << endl;
file.oss << endl;
}
/* ************************************************************************* */
void Class::makefile_fragment(FileWriter& file) const {
// new_Point2_.$(MEXENDING): new_Point2_.cpp
// $(MEX) $(mex_flags) new_Point2_.cpp
// new_Point2_dd.$(MEXENDING): new_Point2_dd.cpp
// $(MEX) $(mex_flags) new_Point2_dd.cpp
// @Point2/x.$(MEXENDING): @Point2/x.cpp
// $(MEX) $(mex_flags) @Point2/x.cpp -output @Point2/x
// @Point2/y.$(MEXENDING): @Point2/y.cpp
// $(MEX) $(mex_flags) @Point2/y.cpp -output @Point2/y
// @Point2/dim.$(MEXENDING): @Point2/dim.cpp
// $(MEX) $(mex_flags) @Point2/dim.cpp -output @Point2/dim
//
// Point2: new_Point2_.$(MEXENDING) new_Point2_dd.$(MEXENDING) @Point2/x.$(MEXENDING) @Point2/y.$(MEXENDING) @Point2/dim.$(MEXENDING)
string matlabName = qualifiedName();
// collect names
vector<string> file_names;
string file_base = constructor.matlab_wrapper_name(matlabName);
file_names.push_back(file_base);
BOOST_FOREACH(StaticMethod c, static_methods) {
string file_base = matlabName + "_" + c.name;
file_names.push_back(file_base);
}
BOOST_FOREACH(Method c, methods) {
string file_base = "@" + matlabName + "/" + c.name;
file_names.push_back(file_base);
}
BOOST_FOREACH(const string& file_base, file_names) {
file.oss << file_base << ".$(MEXENDING): " << file_base << ".cpp";
file.oss << " $(PATH_TO_WRAP)/matlab.h" << endl;
file.oss << "\t$(MEX) $(mex_flags) " << file_base << ".cpp -output " << file_base << endl;
}
// class target
file.oss << "\n" << matlabName << ": ";
BOOST_FOREACH(const string& file_base, file_names) {
file.oss << file_base << ".$(MEXENDING) ";
}
file.oss << "\n" << endl;
}
/* ************************************************************************* */ /* ************************************************************************* */
string Class::qualifiedName(const string& delim) const { string Class::qualifiedName(const string& delim) const {
string result; string result;

View File

@ -49,10 +49,6 @@ struct Class {
FileWriter& wrapperFile, std::vector<std::string>& functionNames) const; ///< emit proxy class FileWriter& wrapperFile, std::vector<std::string>& functionNames) const; ///< emit proxy class
void matlab_static_methods(const std::string& toolboxPath, const std::string& wrapperName, void matlab_static_methods(const std::string& toolboxPath, const std::string& wrapperName,
FileWriter& wrapperFile, std::vector<std::string>& functionNames) const; ///< emit static method wrappers FileWriter& wrapperFile, std::vector<std::string>& functionNames) const; ///< emit static method wrappers
void matlab_make_fragment(FileWriter& file,
const std::string& toolboxPath,
const std::string& mexFlags) const; ///< emit make fragment for global make script
void makefile_fragment(FileWriter& file) const; ///< emit makefile fragment
std::string qualifiedName(const std::string& delim = "") const; ///< creates a namespace-qualified name, optional delimiter std::string qualifiedName(const std::string& delim = "") const; ///< creates a namespace-qualified name, optional delimiter
}; };

View File

@ -286,19 +286,10 @@ void verifyReturnTypes(const vector<string>& validtypes, const vector<T>& vt) {
} }
/* ************************************************************************* */ /* ************************************************************************* */
void Module::matlab_code(const string& mexCommand, const string& toolboxPath, void Module::matlab_code(const string& toolboxPath, const string& headerPath) const {
const string& mexExt, const string& headerPath,const string& mexFlags) const {
fs::create_directories(toolboxPath); fs::create_directories(toolboxPath);
// create make m-file
string matlabMakeFileName = toolboxPath + "/make_" + name + ".m";
FileWriter makeModuleMfile(matlabMakeFileName, verbose, "%");
// create the (actual) make file
string makeFileName = toolboxPath + "/Makefile";
FileWriter makeModuleMakefile(makeFileName, verbose, "#");
// create the unified .cpp switch file // create the unified .cpp switch file
const string wrapperName = name + "_wrapper"; const string wrapperName = name + "_wrapper";
string wrapperFileName = toolboxPath + "/" + wrapperName + ".cpp"; string wrapperFileName = toolboxPath + "/" + wrapperName + ".cpp";
@ -309,18 +300,6 @@ void Module::matlab_code(const string& mexCommand, const string& toolboxPath,
wrapperFile.oss << "#include <boost/foreach.hpp>\n"; wrapperFile.oss << "#include <boost/foreach.hpp>\n";
wrapperFile.oss << "\n"; wrapperFile.oss << "\n";
makeModuleMfile.oss << "echo on" << endl << endl;
makeModuleMfile.oss << "toolboxpath = mfilename('fullpath');" << endl;
makeModuleMfile.oss << "delims = find(toolboxpath == '/' | toolboxpath == '\\');" << endl;
makeModuleMfile.oss << "toolboxpath = toolboxpath(1:(delims(end)-1));" << endl;
makeModuleMfile.oss << "clear delims" << endl;
makeModuleMfile.oss << "addpath(toolboxpath);" << endl << endl;
makeModuleMakefile.oss << "\nMEX = " << mexCommand << "\n";
makeModuleMakefile.oss << "MEXENDING = " << mexExt << "\n";
makeModuleMakefile.oss << "PATH_TO_WRAP = " << headerPath << "\n";
makeModuleMakefile.oss << "mex_flags = " << mexFlags << "\n\n";
// Dependency check list // Dependency check list
vector<string> validTypes = forward_declarations; vector<string> validTypes = forward_declarations;
validTypes.push_back("void"); validTypes.push_back("void");
@ -333,15 +312,10 @@ void Module::matlab_code(const string& mexCommand, const string& toolboxPath,
validTypes.push_back("double"); validTypes.push_back("double");
validTypes.push_back("Vector"); validTypes.push_back("Vector");
validTypes.push_back("Matrix"); validTypes.push_back("Matrix");
//Create a list of parsed classes for dependency checking
// add 'all' to Makefile
makeModuleMakefile.oss << "all: ";
BOOST_FOREACH(Class cls, classes) { BOOST_FOREACH(Class cls, classes) {
makeModuleMakefile.oss << cls.qualifiedName() << " ";
//Create a list of parsed classes for dependency checking
validTypes.push_back(cls.qualifiedName("::")); validTypes.push_back(cls.qualifiedName("::"));
} }
makeModuleMakefile.oss << "\n\n";
// Generate all includes // Generate all includes
BOOST_FOREACH(Class cls, classes) { BOOST_FOREACH(Class cls, classes) {
@ -391,32 +365,8 @@ void Module::matlab_code(const string& mexCommand, const string& toolboxPath,
// create constructor and method wrappers // create constructor and method wrappers
cls.matlab_static_methods(toolboxPath, wrapperName, wrapperFile, functionNames); cls.matlab_static_methods(toolboxPath, wrapperName, wrapperFile, functionNames);
// add lines to make m-file
makeModuleMfile.oss << "%% " << cls.qualifiedName() << endl;
makeModuleMfile.oss << "cd(toolboxpath)" << endl;
cls.matlab_make_fragment(makeModuleMfile, toolboxPath, mexFlags);
// add section to the (actual) make file
makeModuleMakefile.oss << "# " << cls.qualifiedName() << endl;
cls.makefile_fragment(makeModuleMakefile);
} }
// finish make m-file
makeModuleMfile.oss << "cd(toolboxpath)" << endl << endl;
makeModuleMfile.oss << "echo off" << endl;
makeModuleMfile.emit(true); // By default, compare existing file first
// make clean at end of Makefile
makeModuleMakefile.oss << "\n\nclean: \n";
makeModuleMakefile.oss << "\trm -rf *.$(MEXENDING)\n";
BOOST_FOREACH(Class cls, classes)
makeModuleMakefile.oss << "\trm -rf @" << cls.qualifiedName() << "/*.$(MEXENDING)\n";
// finish Makefile
makeModuleMakefile.oss << "\n" << endl;
makeModuleMakefile.emit(true);
// finish wrapper file // finish wrapper file
finish_wrapper(wrapperFile, functionNames); finish_wrapper(wrapperFile, functionNames);

View File

@ -41,11 +41,8 @@ struct Module {
/// MATLAB code generation: /// MATLAB code generation:
void matlab_code( void matlab_code(
const std::string& mexCommand,
const std::string& path, const std::string& path,
const std::string& mexExt, const std::string& headerPath) const;
const std::string& headerPath,
const std::string& mexFlags) const;
void finish_wrapper(FileWriter& file, const std::vector<std::string>& functionNames) const; void finish_wrapper(FileWriter& file, const std::vector<std::string>& functionNames) const;
}; };

View File

@ -24,42 +24,33 @@ using namespace std;
/** /**
* Top-level function to wrap a module * Top-level function to wrap a module
* @param mexCommand is a sufficiently qualified command to execute mex within a makefile
* @param mexExt is the extension for mex binaries for this os/cpu
* @param interfacePath path to where interface file lives, e.g., borg/gtsam * @param interfacePath path to where interface file lives, e.g., borg/gtsam
* @param moduleName name of the module to be generated e.g. gtsam * @param moduleName name of the module to be generated e.g. gtsam
* @param toolboxPath path where the toolbox should be generated, e.g. borg/gtsam/build * @param toolboxPath path where the toolbox should be generated, e.g. borg/gtsam/build
* @param headerPath is the path to matlab.h * @param headerPath is the path to matlab.h
* @param mexFlags extra arguments for mex script, i.e., include flags etc...
*/ */
void generate_matlab_toolbox( void generate_matlab_toolbox(
const string& mexCommand,
const string& mexExt,
const string& interfacePath, const string& interfacePath,
const string& moduleName, const string& moduleName,
const string& toolboxPath, const string& toolboxPath,
const string& headerPath, const string& headerPath)
const string& mexFlags)
{ {
// Parse interface file into class object // Parse interface file into class object
// This recursively creates Class objects, Method objects, etc... // This recursively creates Class objects, Method objects, etc...
wrap::Module module(interfacePath, moduleName, false); wrap::Module module(interfacePath, moduleName, false);
// Then emit MATLAB code // Then emit MATLAB code
module.matlab_code(mexCommand,toolboxPath,mexExt,headerPath,mexFlags); module.matlab_code(toolboxPath,headerPath);
} }
/** Displays usage information */ /** Displays usage information */
void usage() { void usage() {
cerr << "wrap parses an interface file and produces a MATLAB toolbox" << endl; cerr << "wrap parses an interface file and produces a MATLAB toolbox" << endl;
cerr << "usage: wrap mexExecutable mexExtension interfacePath moduleName toolboxPath [mexFlags]" << endl; cerr << "usage: wrap interfacePath moduleName toolboxPath headerPath" << endl;
cerr << " mexExecutable : command to execute mex if on path, use 'mex'" << endl;
cerr << " mexExtension : OS/CPU-dependent extension for MEX binaries" << endl;
cerr << " interfacePath : *absolute* path to directory of module interface file" << endl; cerr << " interfacePath : *absolute* path to directory of module interface file" << endl;
cerr << " moduleName : the name of the module, interface file must be called moduleName.h" << endl; cerr << " moduleName : the name of the module, interface file must be called moduleName.h" << endl;
cerr << " toolboxPath : the directory in which to generate the wrappers" << endl; cerr << " toolboxPath : the directory in which to generate the wrappers" << endl;
cerr << " headerPath : path to matlab.h" << endl; cerr << " headerPath : path to matlab.h" << endl;
cerr << " [mexFlags] : extra flags for the mex command" << endl;
} }
/** /**
@ -67,7 +58,7 @@ void usage() {
* Typically called from "make all" using appropriate arguments * Typically called from "make all" using appropriate arguments
*/ */
int main(int argc, const char* argv[]) { int main(int argc, const char* argv[]) {
if (argc<7 || argc>8) { if (argc != 5) {
cerr << "Invalid arguments:\n"; cerr << "Invalid arguments:\n";
for (int i=0; i<argc; ++i) for (int i=0; i<argc; ++i)
cerr << argv[i] << endl; cerr << argv[i] << endl;
@ -75,6 +66,6 @@ int main(int argc, const char* argv[]) {
usage(); usage();
} }
else else
generate_matlab_toolbox(argv[1],argv[2],argv[3],argv[4],argv[5],argv[6],argc==7 ? " " : argv[7]); generate_matlab_toolbox(argv[1],argv[2],argv[3],argv[4]);
return 0; return 0;
} }