Fix custom javascript interpreter configuration for OSX.

This commit is contained in:
Oliver Buchtala 2014-02-26 22:46:24 +01:00
commit 424e3f4712
7 changed files with 42 additions and 15 deletions

View file

@ -16,6 +16,7 @@ CC = @CC@
# with 'c++' it works... probably some missing flags?
CXX = @JSINTERPRETERCXX@
CFLAGS = @BOOST_CPPFLAGS@ @PLATFLAGS@
LINKFLAGS = @JSINTERPRETERLINKFLAGS@
ROOT_DIR = @ROOT_DIR@
JSCFLAGS = @JSCFLAGS@
@ -32,24 +33,24 @@ JSCENABLED = @JSCENABLED@
# These settings are provided by 'configure' (see '/configure.in')
ifeq (1, $(JSV8ENABLED))
JS_INTERPRETER_SRC_V8 = v8_shell.cxx
JS_INTERPRETER_CXXFLAGS_V8 = -DENABLE_V8
JS_INTERPRETER_ENABLE_V8 = -DENABLE_V8
endif
ifeq (1, $(JSCENABLED))
JS_INTERPRETER_SRC_JSC = jsc_shell.cxx
JS_INTERPRETER_CXXFLAGS_JSC = -DENABLE_JSC
JS_INTERPRETER_ENABLE_JSC = -DENABLE_JSC
endif
JS_INTERPRETER_CXXFLAGS = $(JS_INTERPRETER_CXXFLAGS_JSC) $(JS_INTERPRETER_CXXFLAGS_V8)
JS_INTERPRETER_DEFINES = $(JS_INTERPRETER_ENABLE_JSC) $(JS_INTERPRETER_ENABLE_V8)
JS_INTERPRETER_SRC = javascript.cxx js_shell.cxx $(JS_INTERPRETER_SRC_JSC) $(JS_INTERPRETER_SRC_V8)
JS_INTERPRETER_OBJS = $(JS_INTERPRETER_SRC:.cxx=.o)
%.o: %.cxx
$(CXX) $(JS_INTERPRETER_CXXFLAGS) -g $(JSINCLUDES) -o $@ -c $<
$(CXX) $(JS_INTERPRETER_DEFINES) -g $(JSINCLUDES) -o $@ -c $<
javascript: $(JS_INTERPRETER_OBJS)
$(CXX) -g -Wl,-search_paths_first -Wl,-headerpad_max_install_names $^ $(CFLAGS) -o javascript $(JSDYNAMICLINKING)
$(CXX) $(LINKFLAGS) $^ $(CFLAGS) -o javascript $(JSDYNAMICLINKING)
clean:
rm -f *.o

View file

@ -23,13 +23,18 @@ int main(int argc, char* argv[]) {
bool interactive = false;
JSShell* shell = 0;
std::vector<std::string> modulePath;
modulePath.push_back(".");
for (int idx = 1; idx < argc; ++idx) {
if(strcmp(argv[idx], "-v8") == 0) {
shell = JSShell::Create(JSShell::V8);
shell = JSShell::Create(JSShell::V8);
} else if(strcmp(argv[idx], "-jsc") == 0) {
shell = JSShell::Create(JSShell::JSC);
shell = JSShell::Create(JSShell::JSC);
} else if(strcmp(argv[idx], "-i") == 0) {
interactive = true;
} else if(strcmp(argv[idx], "-L") == 0) {
modulePath.push_back(argv[++idx]);
} else {
scriptPath = argv[idx];
}
@ -39,6 +44,8 @@ int main(int argc, char* argv[]) {
shell = JSShell::Create();
}
shell->setModulePath(modulePath);
bool failed = false;
if(interactive) {

View file

@ -41,6 +41,7 @@ std::string JSShell::LoadModule(const std::string& name, HANDLE* library) {
std::string lib_name;
std::string module_name;
if (pathIdx == std::string::npos) {
module_name = name;
lib_name = std::string(name).append(LIBRARY_EXT);
@ -50,9 +51,18 @@ std::string JSShell::LoadModule(const std::string& name, HANDLE* library) {
lib_name = path.append(module_name).append(LIBRARY_EXT);
}
HANDLE handle = LOAD_LIBRARY(lib_name.c_str());
std::string lib_path;
HANDLE handle = 0;
for (int i = 0; i < module_path.size(); ++i) {
lib_path = module_path[i] + "/" + lib_name;
if (access( lib_path.c_str(), F_OK ) != -1) {
handle = LOAD_LIBRARY(lib_path.c_str());
}
}
if(handle == 0) {
std::cerr << "Could not load library " << lib_name << ":"
std::cerr << "Could not find module " << lib_path << ":"
<< std::endl << LIBRARY_ERROR() << std::endl;
return 0;
}

View file

@ -29,6 +29,10 @@ public:
virtual bool RunShell();
void setModulePath(const std::vector<std::string>& modulePath) {
module_path = modulePath;
}
protected:
virtual bool InitializeEngine() = 0;
@ -42,6 +46,7 @@ protected:
protected:
std::vector<HANDLE> loaded_modules;
std::vector<std::string> module_path;
};