diff --git a/binding/meson.build b/binding/meson.build index 3edb0365..e6959457 100644 --- a/binding/meson.build +++ b/binding/meson.build @@ -5,13 +5,13 @@ if ver.version_compare('>1.8') == true binding_dependencies += dependency('ruby-' + ver) else lib = get_option('ruby_lib') - binding_dependencies += meson.get_compiler('cpp').find_library(lib) + binding_dependencies += compiler.find_library(lib) if host_system == 'windows' if lib.endswith('-static') - binding_dependencies += meson.get_compiler('cpp').find_library('wsock32') + binding_dependencies += compiler.find_library('wsock32') endif else - binding_dependencies += meson.get_compiler('cpp').find_library('dl') + binding_dependencies += compiler.find_library('dl') endif add_project_arguments('-DOLD_RUBY', language: 'cpp') endif diff --git a/binding/minidl-binding.cpp b/binding/minidl-binding.cpp index 39d14911..b65cc6a9 100644 --- a/binding/minidl-binding.cpp +++ b/binding/minidl-binding.cpp @@ -2,20 +2,7 @@ // it's just as basic but should work fine for the moment #include - -#ifdef __WIN32__ - -#include -#define LIBHANDLE HINSTANCE -#define FUNCHANDLE HANDLE - -#else - -#include -#define LIBHANDLE void* -#define FUNCHANDLE void* - -#endif +#include #define _T_VOID 0 #define _T_NUMBER 1 @@ -24,44 +11,10 @@ typedef void* (*MINIDL_FUNC)(...); -static void -dl_freelib(LIBHANDLE lib) -{ -#ifdef __WIN32__ - FreeLibrary(lib); -#else - dlclose(lib); -#endif -} - -static LIBHANDLE -dl_loadlib(const char *filename) -{ - LIBHANDLE ret; -#ifdef __WIN32__ - ret = LoadLibrary(filename); -#else - ret = dlopen(filename, RTLD_NOW); -#endif - return ret; -} - -static FUNCHANDLE -dl_getfunc(LIBHANDLE lib, const char *filename) -{ - FUNCHANDLE ret; -#ifdef __WIN32__ - ret = (FUNCHANDLE)GetProcAddress(lib, filename); -#else - ret = dlsym(lib, filename); -#endif - return ret; -} - static VALUE MiniDL_alloc(VALUE self) { - return Data_Wrap_Struct(self, 0, dl_freelib, 0); + return Data_Wrap_Struct(self, 0, SDL_UnloadObject, 0); } static VALUE @@ -71,22 +24,22 @@ MiniDL_initialize(VALUE self, VALUE libname, VALUE func, VALUE imports, VALUE ex SafeStringValue(func); - LIBHANDLE hlib = dl_loadlib(RSTRING_PTR(libname)); + void *hlib = SDL_LoadObject(RSTRING_PTR(libname)); if (!hlib) - rb_raise(rb_eRuntimeError, "Failed to load library %s", RSTRING_PTR(libname)); + rb_raise(rb_eRuntimeError, "Failed to load library %s: %s", RSTRING_PTR(libname), SDL_GetError()); DATA_PTR(self) = hlib; - FUNCHANDLE hfunc = dl_getfunc(hlib, RSTRING_PTR(func)); + void *hfunc = SDL_LoadFunction(hlib, RSTRING_PTR(func)); #ifdef __WIN32__ if (!hfunc) { VALUE func_a = rb_str_new3(func); func_a = rb_str_cat(func_a, "A", 1); - hfunc = dl_getfunc(hlib, RSTRING_PTR(func_a)); + hfunc = SDL_LoadFunction(hlib, RSTRING_PTR(func_a)); } #endif if (!hfunc) - rb_raise(rb_eRuntimeError, "Failed to find function %s within %s", RSTRING_PTR(func), RSTRING_PTR(libname)); + rb_raise(rb_eRuntimeError, "Failed to find function %s within %s: %s", RSTRING_PTR(func), RSTRING_PTR(libname), SDL_GetError()); rb_iv_set(self, "_func", OFFT2NUM((unsigned long)hfunc)); diff --git a/meson.build b/meson.build index e962ad43..e0503734 100644 --- a/meson.build +++ b/meson.build @@ -2,6 +2,8 @@ project('mkxp-z', 'cpp', version: '1.0') xxd = find_program('xxd') host_system = host_machine.system() +compiler = meson.get_compiler('cpp') +static = get_option('static') if get_option('workdir_current') == true add_project_arguments('-DWORKDIR_CURRENT', language: 'cpp') @@ -27,6 +29,10 @@ elif host_system == 'darwin' endif endif +if static == true and host_system != 'darwin' + add_project_link_arguments('--static', 'cpp') +endif + executable(meson.project_name(), sources: all_sources, dependencies: [main_dependencies, binding_dependencies], diff --git a/meson_options.txt b/meson_options.txt index 915dbe41..48096994 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,4 +1,6 @@ option('shared_fluid', type: 'boolean', value: false, description: 'Dynamically link fluidsynth at build time') option('mri_version', type: 'string', value: '1.8', description: 'Version of MRI to link with') option('workdir_current', type: 'boolean', value: false, description: 'Keep current directory on startup') -option('ruby_lib', type: 'string', value: 'ruby', description: 'Name of legacy Ruby library') \ No newline at end of file +option('ruby_lib', type: 'string', value: 'ruby', description: 'Name of legacy Ruby library') + +option('static', type: 'boolean', value: 'false', description: 'Statically link as many libraries as possible') \ No newline at end of file diff --git a/src/meson.build b/src/meson.build index 5231123d..d2c9ed14 100644 --- a/src/meson.build +++ b/src/meson.build @@ -14,7 +14,7 @@ zlib = dependency('zlib') main_dependencies = [sigcxx, openal, boost, zlib, pixman, physfs, vorbisfile, sdl2, sdl2_ttf, sdl2_image, sdl_sound] if host_system == 'darwin' - main_dependencies += meson.get_compiler('cpp').find_library('iconv') + main_dependencies += compiler.find_library('iconv') if openal.type_name() != 'pkgconfig' add_project_arguments('-DUSE_MAC_OPENAL', language: 'cpp')