1 /* === S Y N F I G ========================================================= */
2 /*! \file synfig/module.cpp
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
10 ** This package is free software; you can redistribute it and/or
11 ** modify it under the terms of the GNU General Public License as
12 ** published by the Free Software Foundation; either version 2 of
13 ** the License, or (at your option) any later version.
15 ** This package is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ** General Public License for more details.
21 /* ========================================================================= */
23 /* === H E A D E R S ======================================================= */
25 #define SYNFIG_NO_ANGLE
36 #include <ETL/stringf>
38 #ifndef USE_CF_BUNDLES
44 /* === M A C R O S ========================================================= */
46 /* === G L O B A L S ======================================================= */
50 using namespace synfig;
52 Module::Book *synfig::Module::book_;
54 /* === P R O C E D U R E S ================================================= */
57 Module::subsys_init(const String &prefix)
59 #ifndef USE_CF_BUNDLES
60 #ifndef SYNFIG_LTDL_NO_STATIC
61 //LTDL_SET_PRELOADED_SYMBOLS();
66 error(_("Errors on lt_dlinit()"));
71 lt_dladdsearchdir(".");
73 lt_dladdsearchdir(strprintf("%s/.synfig/modules", getenv("HOME")).c_str());
74 lt_dladdsearchdir((prefix+"/lib/synfig/modules").c_str());
76 lt_dladdsearchdir(LIBDIR"/synfig/modules");
79 lt_dladdsearchdir("/Library/Frameworks/synfig.framework/Resources/modules");
81 lt_dladdsearchdir("/usr/local/lib/synfig/modules");
82 lt_dladdsearchdir(".");
93 #ifndef USE_CF_BUNDLES
100 Module::register_default_modules(ProgressCallback *callback)
102 #define REGISTER_MODULE(module) if (!Register(module, callback)) \
103 throw std::runtime_error(strprintf(_("Unable to load module '%s'"), module))
104 REGISTER_MODULE("lyr_freetype");
105 REGISTER_MODULE("mod_geometry");
106 REGISTER_MODULE("mod_gradient");
107 REGISTER_MODULE("mod_particle");
117 synfig::Module::Register(Module::Handle mod)
119 book()[mod->Name()]=mod;
123 synfig::Module::Register(const String &module_name, ProgressCallback *callback)
125 #ifndef USE_CF_BUNDLES
128 if(callback)callback->task(strprintf(_("Attempting to register \"%s\""),module_name.c_str()));
130 module=lt_dlopenext((string("lib")+module_name).c_str());
131 if(!module)module=lt_dlopenext(module_name.c_str());
135 if(callback)callback->warning(strprintf(_("Unable to find module \"%s\" (%s)"),module_name.c_str(),lt_dlerror()));
139 if(callback)callback->task(strprintf(_("Found module \"%s\""),module_name.c_str()));
141 Module::constructor_type constructor=NULL;
146 // if(callback)callback->task(string("looking for -> ")+module_name+"_LTX_new_instance()");
147 constructor=(Module::constructor_type )lt_dlsym(module,(module_name+"_LTX_new_instance").c_str());
152 // if(callback)callback->task(string("looking for -> lib")+module_name+"_LTX_new_instance()");
153 constructor=(Module::constructor_type )lt_dlsym(module,(string("lib")+module_name+"_LTX_new_instance").c_str());
157 // if(callback)callback->task(string("looking for -> lib")+module_name+"_LTX_new_instance()");
158 constructor=(Module::constructor_type )lt_dlsym(module,(string("_lib")+module_name+"_LTX_new_instance").c_str());
162 // if(callback)callback->task(string("looking for -> lib")+module_name+"_LTX_new_instance()");
163 constructor=(Module::constructor_type )lt_dlsym(module,(string("_")+module_name+"_LTX_new_instance").c_str());
168 // if(callback)callback->task(strprintf("Executing callback for \"%s\"",module_name.c_str()));
169 mod=handle<Module>((*constructor)(callback));
173 if(callback)callback->error(strprintf(_("Unable to find entrypoint in module \"%s\" (%s)"),module_name.c_str(),lt_dlerror()));
177 // if(callback)callback->task(strprintf("Done executing callback for \"%s\"",module_name.c_str()));
181 // if(callback)callback->task(strprintf("Registering \"%s\"",module_name.c_str()));
186 if(callback)callback->error(_("Entrypoint did not return a module."));
190 if(callback)callback->task(strprintf(_("Success for \"%s\""),module_name.c_str()));