From 98ce34827485fe540b39c3e41319fd19ce6115e2 Mon Sep 17 00:00:00 2001 From: CismonX Date: Tue, 8 Aug 2023 17:35:49 +0800 Subject: [PATCH] refactor: change engine installation path Use `pkglibdir` instead of `libdir` as engine library installation path, since they are considered modules for `arify`. --- doc/arif.texi | 2 +- examples/Makefile.am | 24 ++++++++++++------------ include/arif_defs.h | 4 ++++ src/Makefile.am | 4 ++-- src/arify.c | 14 ++++++++++---- src/arify_cli.c | 5 +---- 6 files changed, 30 insertions(+), 23 deletions(-) diff --git a/doc/arif.texi b/doc/arif.texi index 9edf6a6..c1e6b41 100644 --- a/doc/arif.texi +++ b/doc/arif.texi @@ -242,7 +242,7 @@ If the two names match the following pattern, a @code{$@{short_name@}} can be used instead of the full name: @example -lib$@{short_name@}$@{shlib_suffix@}:arif_$@{short_name@}_engine +$@{libdir@}/arif/$@{short_name@}$@{shlib_suffix@}:arif_$@{short_name@}_engine @end example Where @code{$@{shlib_suffix@}} is the common name suffix for shared library diff --git a/examples/Makefile.am b/examples/Makefile.am index 5feccb6..76131bc 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -6,22 +6,22 @@ # this notice are preserved. This file is offered as-is, without any warranty. # -include_HEADERS = -noinst_HEADERS = -lib_LTLIBRARIES = -dist_man3_MANS = +include_HEADERS = +noinst_HEADERS = +pkglib_LTLIBRARIES = +dist_man3_MANS = if BUILD_ARIF_RIME - include_HEADERS += arif_rime.h - noinst_HEADERS += arif_rime_workaround.h - lib_LTLIBRARIES += libarifrime.la - dist_man3_MANS += arif_rime.3 + include_HEADERS += arif_rime.h + noinst_HEADERS += arif_rime_workaround.h + pkglib_LTLIBRARIES += rime.la + dist_man3_MANS += arif_rime.3 - libarifrime_la_CPPFLAGS = $(RIME_CFLAGS) -I$(top_srcdir)/include - libarifrime_la_LDFLAGS = -module - libarifrime_la_LIBADD = $(RIME_LIBS) - libarifrime_la_SOURCES = arif_rime.c arif_rime_workaround.cc + rime_la_CPPFLAGS = $(RIME_CFLAGS) -I$(top_srcdir)/include + rime_la_LDFLAGS = -module + rime_la_LIBADD = $(RIME_LIBS) + rime_la_SOURCES = arif_rime.c arif_rime_workaround.cc endif # BUILD_ARIF_RIME diff --git a/include/arif_defs.h b/include/arif_defs.h index d679275..9fe36e1 100644 --- a/include/arif_defs.h +++ b/include/arif_defs.h @@ -46,3 +46,7 @@ #else # define ARIF_DEBUG_ASSERT(expr) if (!(expr)) { ARIF_UNREACHABLE(); } #endif + +#ifndef ARIF_LIBDIR +# define ARIF_LIBDIR /usr/local/lib +#endif diff --git a/src/Makefile.am b/src/Makefile.am index 9a7f9f5..3ca8de9 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -9,7 +9,7 @@ bin_PROGRAMS = lib_LTLIBRARIES = libarif.la -ARIF_CPPFLAGS_ = -I$(top_srcdir)/include +ARIF_CPPFLAGS_ = -I$(top_srcdir)/include -DARIF_LIBDIR=$(libdir) libarif_la_CPPFLAGS = $(READLINE_CFLAGS) $(ARIF_CPPFLAGS_) libarif_la_LIBADD = $(READLINE_LIBS) @@ -27,7 +27,7 @@ if BUILD_ARIFY bin_PROGRAMS += arify lib_LTLIBRARIES += libarify.la - arify_CPPFLAGS = $(ARIF_CPPFLAGS_) -DARIFY_LIBDIR=$(libdir) + arify_CPPFLAGS = $(ARIF_CPPFLAGS_) arify_SOURCES = arify_cli.c libarify_la_CPPFLAGS = $(READLINE_CFLAGS) $(ARIF_CPPFLAGS_) diff --git a/src/arify.c b/src/arify.c index 95c8ef4..fcec586 100644 --- a/src/arify.c +++ b/src/arify.c @@ -59,6 +59,11 @@ # error "__attribute__((destructor)) not supported" #endif +#define ARIFY_ENGINE_PATH_(libdir, engine) \ + #libdir "/arif/" engine ARIF_SHLIB_SUFFIX +#define ARIFY_ENGINE_PATH(libdir, engine) ARIFY_ENGINE_PATH_(libdir, engine) +#define ARIFY_ENGINE_SYM(engine) "arif_" engine "_engine" + #ifndef ARIFY_MAX_PAGE_SIZE # define ARIFY_MAX_PAGE_SIZE 99 #endif @@ -308,15 +313,16 @@ load_engine ( char *var_tmp = NULL; if (var_name == NULL) { - size_t lib_name_len = 7 + strlen(lib_name) + sizeof ARIF_SHLIB_SUFFIX; + size_t lib_name_len + = sizeof ARIFY_ENGINE_PATH(ARIF_LIBDIR, "") + strlen(lib_name); lib_tmp = malloc(sizeof(char) * lib_name_len); assert(lib_tmp != NULL); - sprintf(lib_tmp, "libarif%s" ARIF_SHLIB_SUFFIX, lib_name); + sprintf(lib_tmp, ARIFY_ENGINE_PATH(ARIF_LIBDIR, "%s"), lib_name); - size_t var_name_len = 12 + strlen(lib_name) + 1; + size_t var_name_len = sizeof ARIFY_ENGINE_SYM("") + strlen(lib_name); var_tmp = malloc(sizeof(char) * var_name_len); assert(var_tmp != NULL); - sprintf(var_tmp, "arif_%s_engine", lib_name); + sprintf(var_tmp, ARIFY_ENGINE_SYM("%s"), lib_name); lib_name = lib_tmp; var_name = var_tmp; diff --git a/src/arify_cli.c b/src/arify_cli.c index 3bdb907..14d02d3 100644 --- a/src/arify_cli.c +++ b/src/arify_cli.c @@ -36,9 +36,6 @@ #include "arif.h" #include "arif_defs.h" -#ifndef ARIFY_LIBDIR -#define ARIFY_LIBDIR /usr/local/lib -#endif #define ARIFY_PRELOAD_LIB_(libdir) #libdir "/libarify" ARIF_SHLIB_SUFFIX #define ARIFY_PRELOAD_LIB(libdir) ARIFY_PRELOAD_LIB_(libdir) @@ -176,7 +173,7 @@ main ( assert(program != NULL); struct options opts = { - .preload = ARIFY_PRELOAD_LIB(ARIFY_LIBDIR), + .preload = ARIFY_PRELOAD_LIB(ARIF_LIBDIR), }; argv += parse_options(argc, argv, &opts); set_envs(&opts);