From 13c77cd890ecbf3e3a06e4007444200fa2acd58a Mon Sep 17 00:00:00 2001 From: kichikuou Date: Sun, 7 Jul 2019 22:41:01 +0900 Subject: [PATCH] Revive modules support --- CMakeLists.txt | 10 ++++++++++ config.h.cmake.in | 1 + modules/CMakeLists.txt | 9 +++++++++ modules/Gpx/CMakeLists.txt | 6 ++++++ modules/Math/CMakeLists.txt | 5 +++++ modules/lib/CMakeLists.txt | 30 ++++++++++++++++++++++++++++++ src/CMakeLists.txt | 14 ++++++++++++++ src/cmd2F60.c | 10 +++++----- src/s39ain.c | 33 ++++++++++----------------------- src/s39ain.h | 8 +------- 10 files changed, 91 insertions(+), 35 deletions(-) create mode 100644 modules/CMakeLists.txt create mode 100644 modules/Gpx/CMakeLists.txt create mode 100644 modules/Math/CMakeLists.txt create mode 100644 modules/lib/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index a88c76d..55dad57 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,6 +40,13 @@ else() include(TestBigEndian) TEST_BIG_ENDIAN(WORDS_BIGENDIAN) + if (NOT DEFINED ENABLE_MODULES) + check_library_exists(dl dlopen "" ENABLE_MODULES) + endif() + if (ENABLE_MODULES) + link_libraries(dl) + endif() + find_package(ZLIB REQUIRED) optional_find_package(X11) optional_find_package(GTK2 COMPONENTS gtk) @@ -254,3 +261,6 @@ if (ENABLE_NLS) add_subdirectory(po) endif() +if (ENABLE_MODULES) + add_subdirectory(modules) +endif() diff --git a/config.h.cmake.in b/config.h.cmake.in index 95bb946..e54691a 100644 --- a/config.h.cmake.in +++ b/config.h.cmake.in @@ -15,6 +15,7 @@ #cmakedefine ENABLE_MIDI_RAWMIDI @ENABLE_MIDI_RAWMIDI@ #cmakedefine ENABLE_MIDI_SDLMIXER @ENABLE_MIDI_SDLMIXER@ #cmakedefine ENABLE_MIDI_SEQMIDI @ENABLE_MIDI_SEQMIDI@ +#cmakedefine ENABLE_MODULES @ENABLE_MODULES@ #cmakedefine ENABLE_NLS @ENABLE_NLS@ #cmakedefine ENABLE_SDL @ENABLE_SDL@ #cmakedefine ENABLE_X11FONT @ENABLE_X11FONT@ diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt new file mode 100644 index 0000000..4529056 --- /dev/null +++ b/modules/CMakeLists.txt @@ -0,0 +1,9 @@ +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + +if (APPLE) + add_link_options("SHELL:-undefined dynamic_lookup") +endif() + +add_subdirectory(lib) +add_subdirectory(Gpx) +add_subdirectory(Math) diff --git a/modules/Gpx/CMakeLists.txt b/modules/Gpx/CMakeLists.txt new file mode 100644 index 0000000..67ba360 --- /dev/null +++ b/modules/Gpx/CMakeLists.txt @@ -0,0 +1,6 @@ +add_library(Gpx MODULE Gpx.c effectcopy.c) + +target_link_libraries(Gpx PRIVATE graph) +target_include_directories(Gpx PRIVATE ${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/modules/lib) + +install(TARGETS Gpx DESTINATION lib/xsystem35) diff --git a/modules/Math/CMakeLists.txt b/modules/Math/CMakeLists.txt new file mode 100644 index 0000000..c9cea45 --- /dev/null +++ b/modules/Math/CMakeLists.txt @@ -0,0 +1,5 @@ +add_library(Math MODULE Math.c) + +target_include_directories(Math PRIVATE ${CMAKE_SOURCE_DIR}/src) + +install(TARGETS Math DESTINATION lib/xsystem35) diff --git a/modules/lib/CMakeLists.txt b/modules/lib/CMakeLists.txt new file mode 100644 index 0000000..54f88dd --- /dev/null +++ b/modules/lib/CMakeLists.txt @@ -0,0 +1,30 @@ +add_library(graph STATIC + graph.c + surface.c + cg.c + graph_expandcolor_blend.c + graph_fillrect.c + graph_fillrect_amap.c + graph_fillrect_acolor.c + graph_rect.c + graph_copy.c + graph_copy_amap.c + graph_copy_bright.c + graph_copy_whiteout.c + graph_blend_amap.c + graph_blend_screen.c + graph_saturadd_amap.c + graph_draw_amap.c + graph_stretch.c + graph_cg.c + graph_buller.c + gre_blend_useamap.c + gre_blend.c + gre_blend_screen.c + ) + +add_library(alk STATIC alk.c) + +add_library(drawtext STATIC drawtext.c) + +include_directories(${CMAKE_SOURCE_DIR}/src) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 27e9e91..bb6e102 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -37,8 +37,22 @@ add_library(objLib OBJECT ${SRC_MISC} ${SRC_NET} ${SRC_DLL}) + +if (ENABLE_MODULES) + set(CMAKE_BUILD_RPATH ${CMAKE_CURRENT_BINARY_DIR}/../modules) + if (APPLE) + set(CMAKE_INSTALL_RPATH @loader_path/../lib/xsystem35) + else() + set(CMAKE_INSTALL_RPATH $ORIGIN/../lib/xsystem35) + endif() +endif() + add_executable(xsystem35 $) +if (ENABLE_MODULES) + target_link_libraries(xsystem35 PRIVATE -rdynamic) +endif() + if (EMSCRIPTEN) add_executable(xsystem35.asm $) diff --git a/src/cmd2F60.c b/src/cmd2F60.c index 7d0b8e4..f64db9c 100644 --- a/src/cmd2F60.c +++ b/src/cmd2F60.c @@ -22,15 +22,15 @@ /* $Id: cmd2F60.c,v 1.11 2003/01/12 10:48:50 chikama Exp $ */ #include -#ifdef ENABLE_LTDL -#include -#endif #include "portab.h" #include "system.h" #include "nact.h" #include "s39ain.h" #include "xsystem35.h" +#ifdef ENABLE_MODULES +#include +#endif #define dll nact->ain.dll #define msgi nact->ain.msg @@ -42,7 +42,7 @@ void commands2F60() { int fnum = sys_getdw(); /* function number */ entrypoint *function = NULL; -#ifdef ENABLE_LTDL +#ifdef ENABLE_MODULES if (dll == NULL) { SYSERROR("No DLL initilized\n"); } @@ -55,7 +55,7 @@ void commands2F60() { if (dll[type].function[fnum].name == NULL) goto eexit; - function = lt_dlsym((lt_dlhandle)(dll[type].handle), dll[type].function[fnum].name); + function = dlsym(dll[type].handle, dll[type].function[fnum].name); if (function) { (*function)(); diff --git a/src/s39ain.c b/src/s39ain.c index 5aca3c1..f29d55c 100644 --- a/src/s39ain.c +++ b/src/s39ain.c @@ -33,6 +33,10 @@ #include "s39ain.h" #include "xsystem35.h" +#ifdef ENABLE_MODULES +#include +#endif + /* short cut */ #define dll nact->ain.dll #define msg nact->ain.msg @@ -173,40 +177,23 @@ int s39ain_init(void) { } } -#ifndef ENABLE_LTDL +#ifndef ENABLE_MODULES free(buf); return dllnum == 0 ? OK : NG; #else - errors = lt_dlinit(); - if (errors) { - printf("lt_dlinit fail\n"); - free(buf); - return FALSE; - } /* open dll */ for (i = 0; i < dllnum; i++) { - char searchpath[512]; + char soname[64]; void *handle; if (dll[i].function_num == 0) continue; - // 最初にカレントディレクトリのソースツリーの下の - // モジュールを検索 - snprintf(searchpath, sizeof(searchpath) -1, "%s/%s", - path_to_dll, dll[i].name); - - lt_dlsetsearchpath(searchpath); - - // 次にデフォルトのモジュールを検索 - /* package default path, ex. /usr/local/lib/xsystem35/ */ - lt_dladdsearchdir(MODULE_PATH); - - // fprintf(stderr, "try to open %s/%s\n", searchpath, dll[i].name); - handle = lt_dlopenext(dll[i].name); + snprintf(soname, sizeof(soname), "lib%s.so", dll[i].name); + handle = dlopen(soname, RTLD_NOW); if (handle == NULL) { - SYSERROR("dlopen: %s(%s)\n", lt_dlerror(), dll[i].name); + SYSERROR("dlopen: %s(%s)\n", dlerror(), dll[i].name); } dll[i].handle = handle; @@ -214,5 +201,5 @@ int s39ain_init(void) { free(buf); return OK; -#endif // ENABLE_LTDL +#endif // ENABLE_MODULES } diff --git a/src/s39ain.h b/src/s39ain.h index 4445716..b8c3c62 100644 --- a/src/s39ain.h +++ b/src/s39ain.h @@ -24,12 +24,6 @@ #ifndef __S39AIN_H__ #define __S39AIN_H__ -#ifdef ENABLE_LTDL -#include -#else -typedef void lt_dlhandle; -#endif - #include "portab.h" /* DLL 内関数情報 */ @@ -41,7 +35,7 @@ typedef struct { /* DLL 情報 */ typedef struct { - lt_dlhandle *handle; /* DLL handler */ + void *handle; /* DLL handler */ char *name; /* DLL 名 */ int function_num; /* 関数の数 */ S39AIN_DLLFN *function; /* 関数本体 */