From 129630ad0b3a036d87bd42fdbb84c5e6f9a85da4 Mon Sep 17 00:00:00 2001 From: Egor Date: Wed, 11 Jun 2025 12:04:42 +0300 Subject: [PATCH] Make IRCDDATADIR and IRCDLUADIR configurable --- Makefile.am | 21 ++++++++++++++------- README.md | 24 +++++++++++++++--------- configure.ac | 14 ++++++++++++++ src/util.cpp | 12 ++---------- 4 files changed, 45 insertions(+), 26 deletions(-) diff --git a/Makefile.am b/Makefile.am index b912ff7..14dc60c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -24,6 +24,19 @@ AM_CXXFLAGS = $(LIBUV_CFLAGS) $(LIBTLS_CFLAGS) $(LUA_CFLAGS) LDADD = $(LIBUV_LIBS) $(LIBTLS_LIBS) $(LUA_LIBS) AM_CXXFLAGS += -Wall -Wextra @WMISSINGVAR@ +dist_ircddata_DATA = \ + data/help.example.txt +dist_ircdlua_DATA = \ + lua/channeldump.lua \ + lua/ctcp.lua \ + lua/init.lua \ + lua/irccloud.lua \ + lua/spam.lua + +if DATA_IN_PREFIX +AM_CXXFLAGS += -DIRCDDATADIR='"$(ircddatadir)"' -Dircdluadir='"$(ircdluadir)"' +endif + EXTRA_DIST = \ .gitignore \ data/.gitignore \ @@ -31,13 +44,7 @@ EXTRA_DIST = \ LICENSES/GPL-2.0-or-later.txt \ LICENSES/MIT.txt \ LICENSES/Unlicense.txt \ - libtls.supp \ - data/help.example.txt \ - lua/channeldump.lua \ - lua/ctcp.lua \ - lua/init.lua \ - lua/irccloud.lua \ - lua/spam.lua + libtls.supp .PHONY: valgrind valgrind: ircd diff --git a/README.md b/README.md index eb193d4..ed9ee80 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,12 @@ patchy IRC server????? ## How to compile and use Basic compilation: ``` -cp config.example.mk config.mk +autoreconf -iv # if you're compiling from source control +mkdir build +cd build +../configure make +make install ``` Some things are configurable via compile-time flags. See the section on paths. @@ -74,16 +78,18 @@ The server hostname can be set via `--hostname`. The default is the machine's actual hostname ## Paths -Data directory can be configured with `--datadir` argument. The default can be -configured at compile time via `IRCDDATADIR` define. Otherwise it defaults to -`LOCALSTATEDIR/lib/patchyircd` if `LOCALSTATEDIR` is defined. Otherwise it's -`data` in the working directory. +By default the data is located in `./data` and lua scripts are located in +`./lua`. -Similarly, the location of lua files is configured by `--luadir`, `IRCDLUADIR`, -defaulting to `DATADIR/patchyircd/lua`, or `lua`. +Use configure option `--enable-data-in-prefix` to search the system +prefix instead. In that case, the default paths are +`LOCALSTATEDIR/lib/patchyircd` and `DATADIR/patchyircd/lua`. -If you're installing system-wide, the following is sufficient: -`-DLOCALSTATEDIR=/var -DDATADIR=/usr/share` +These paths can be further customized with `--with-ircddatadir=DIR` and +`--with-ircdluadir=DIR`. + +The paths can also be configured at runtime via `--datadir` and `--luadir` +arguments. ## Copyright Copyright (c) 2022, 2024 Sam Smith diff --git a/configure.ac b/configure.ac index 311ddad..b046aba 100644 --- a/configure.ac +++ b/configure.ac @@ -19,6 +19,20 @@ AX_CHECK_COMPILE_FLAG([-Wmissing-variable-declarations], [AC_SUBST([WMISSINGVAR], [-Wmissing-variable-declarations])]) AC_DEFINE([_GNU_SOURCE], [1]) +AC_ARG_WITH([ircddatadir], + [AS_HELP_STRING([--with-ircddatadir=DIR], [data files @<:@LOCALSTATEDIR/lib/patchyircd@:>@])], + [ircddatadir=$withval], + [ircddatadir='${localstatedir}/lib/patchyircd']) +AC_SUBST([ircddatadir]) +AC_ARG_WITH([ircdluadir], + [AS_HELP_STRING([--with-ircdluadir=DIR], [lua scripts @<:@DATADIR/patchyircd/lua@:>@])], + [ircdluadir=$withval], + [ircdluadir='${datadir}/patchyircd/lua']) +AC_SUBST([ircdluadir]) +AC_ARG_ENABLE([data-in-prefix], + [AS_HELP_STRING([--enable-data-in-prefix], [look for data and lua scripts in prefix])]) +AM_CONDITIONAL([DATA_IN_PREFIX], [test "x$enable_data_in_prefix" = xyes]) + PKG_CHECK_MODULES(LIBUV, [libuv]) PKG_HAVE_DEFINE_WITH_MODULES(LIBTLS, [libtls]) PKG_HAVE_DEFINE_WITH_MODULES(LUA, [lua5.4]) diff --git a/src/util.cpp b/src/util.cpp index af16650..be8292a 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -156,11 +156,7 @@ static const char *getdirfile_r(char *buf, size_t size, const char *dir, const c } #ifndef IRCDDATADIR -# ifdef LOCALSTATEDIR -# define IRCDDATADIR LOCALSTATEDIR "/lib/patchyircd" -# else -# define IRCDDATADIR "data" -# endif +# define IRCDDATADIR "data" #endif const char *datadir = IRCDDATADIR; const char *getdatafile(const char *fn) @@ -172,11 +168,7 @@ const char *getdatafile(const char *fn) } #ifndef IRCDLUADIR -# ifdef DATADIR -# define IRCDLUADIR DATADIR "/patchyircd/lua" -# else -# define IRCDLUADIR "lua" -# endif +# define IRCDLUADIR "lua" #endif const char *luadir = IRCDLUADIR; const char *getluafile(const char *fn) -- 2.56.0