0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-25 15:04:10 +01:00

configure/ircd: Overhaul install system directory related.

This commit is contained in:
Jason Volk 2018-08-12 11:56:53 -07:00
parent e388d28585
commit 8fb580aaf5
8 changed files with 161 additions and 234 deletions

View file

@ -9,7 +9,7 @@ AC_INIT([construct], [1.0])
AC_GNU_SOURCE
AC_USE_SYSTEM_EXTENSIONS
AC_CONFIG_MACRO_DIR([m4])
AC_PREFIX_DEFAULT($HOME/ircd)
AC_PREFIX_DEFAULT([/])
AC_PATH_PROG(AUTOMAKE, automake)
AC_PATH_PROG(ACLOCAL, aclocal)
@ -713,8 +713,7 @@ AM_COND_IF(LINUX,
AC_ARG_ENABLE(aio, AC_HELP_STRING([--disable-aio], [Disable kernel AIO support]),
[
aio=$enableval
],
[
], [
aio=yes
])
], [])
@ -736,180 +735,96 @@ dnl
PKG_PROG_PKG_CONFIG
if test "$prefix" = "NONE"; then
AC_DEFINE_UNQUOTED(RB_PREFIX, "$ac_default_prefix", [Prefix where librb is installed.])
prefix="$ac_default_prefix"
else
dnl Don't get bitten by Cygwin's stupidity if the user specified
dnl a custom prefix with a trailing slash
prefix=`echo $prefix | sed 's/\/$//'`
AC_DEFINE_UNQUOTED(RB_PREFIX, "$prefix", [Prefix where librb is installed.])
AC_SUBST(RB_PREFIX)
fi
RB_DEFINE_UNQUOTED(PREFIX, ["$prefix"], [Prefix of IRCd install])
AC_SUBST_DIR([prefix])
if test "$prefix" = "NONE"; then
AC_DEFINE_UNQUOTED(IRCD_PREFIX, "$ac_default_prefix", [Prefix where the ircd is installed.])
else
dnl Don't get bitten by Cygwin's stupidity if the user specified
dnl a custom prefix with a trailing slash
prefix=`echo $prefix | sed 's/\/$//'`
AC_DEFINE_UNQUOTED(IRCD_PREFIX, "$prefix", [Prefix where the ircd is installed.])
fi
dnl
dnl bindir
dnl
RB_DEFINE_UNQUOTED([BIN_DIR], ["$(bindir)"], [Directory where binary executables are to be found.])
AC_SUBST_DIR([bindir])
AC_ARG_ENABLE([fhs-paths],
[AS_HELP_STRING([--enable-fhs-paths], [Use more FHS-like pathnames (for packagers).])],
[],
[dnl detect if the user appears to want --enable-fhs-paths
AS_IF([test "$libexecdir" = '${exec_prefix}/libexec' && \
test "$localstatedir" = '${prefix}/var' && \
test "$libdir" = '${exec_prefix}/lib'],
[enable_fhs_paths=no],
[enable_fhs_paths=yes])
])
dnl use directory structure of cached as default (hack)
AS_IF([test "x$enable_fhs_paths" = "xyes"],
[dnl Avoid name collisions.
pkglibexecdir='${libexecdir}/${PACKAGE_TARNAME}'
rundir=${rundir-'${prefix}/run'}
pkgrundir='${rundir}/${PACKAGE_TARNAME}'
pkglocalstatedir='${localstatedir}/${PACKAGE_TARNAME}'
AC_DEFINE([ENABLE_FHS_PATHS], [1], [Uncomment if FHS pathnames are enabled])],
[libexecdir='${bindir}'
pkglibexecdir='${libexecdir}'
rundir='${sysconfdir}'
pkgrundir='${rundir}'
localstatedir='${prefix}'
pkglocalstatedir='${sysconfdir}'])
pkglibdir='${libdir}/${PACKAGE_TARNAME}'
AC_SUBST([pkglibdir])
AC_SUBST([rundir])
AC_SUBST([pkgrundir])
AC_SUBST([pkglocalstatedir])
AC_DEFINE_DIR([PKGLOCALSTATEDIR], [pkglocalstatedir], [[Directory in which to store state, such as ban database]])
AC_SUBST([pkglibexecdir])
AC_DEFINE_DIR([PKGLIBEXECDIR], [pkglibexecdir], [Directory where binaries the IRCd itself spawns live])
dnl
dnl libdir
dnl
RB_DEFINE_UNQUOTED([LIB_DIR], ["$(libdir)"], [Prefix where libs are installed.])
AC_SUBST_DIR([libdir])
dnl
dnl localstatedir
dnl
dnl Avoid name collisions.
RB_DEFINE_UNQUOTED([LOCALSTATE_DIR], ["$(localstatedir)"], [Prefix where db and logs go.])
AC_SUBST_DIR([localstatedir])
dnl
dnl Check for --with-confdir [deprecated, use --sysconfdir instead]
dnl
AC_ARG_WITH([confdir],
[AC_HELP_STRING([--with-confdir=DIR],
[Directory to install config files [deprecated, use --sysconfdir instead].])],
[ sysconfdir=`echo $withval | sed 's/\/$//'` ],
[ confdir='etc' ])
RB_DEFINE_UNQUOTED([ETC_DIR], ["${prefix}/${confdir}"], [Prefix where config files are installed.])
RB_DEFINE_UNQUOTED([CONF_DIR], ["$(sysconfdir)"], [Prefix where config files are installed.])
AC_SUBST_DIR([sysconfdir])
dnl
dnl Check for --with-bindir
dnl Check for --with-dbdir
dnl
AC_MSG_CHECKING([whether to modify binary directory])
AC_ARG_WITH(bindir,
AC_HELP_STRING([--with-bindir=DIR],
[Directory where binary executables are placed.]),
[ logdir=`echo $withval | sed 's/\/$//'`
AC_MSG_RESULT(yes)],
[ AS_IF([test "x$enable_fhs_paths" = "xyes"],
[bindir="${prefix}/bin"],
[bindir="${prefix}/bin"])
AC_MSG_RESULT(no)])
RB_DEFINE_UNQUOTED([BIN_DIR], ["${bindir}"], [Directory where binary executables are to be found.])
AC_SUBST_DIR([bindir])
AC_MSG_CHECKING([whether to modify database directory])
AC_ARG_WITH(dbdir, AC_HELP_STRING([--with-dbdir=DIR], [Directory where databases are located]),
[
AC_MSG_RESULT(yes)
dbdir=`echo $withval | sed 's/\/$//'`
], [
AC_MSG_RESULT(no)
dbdir="${localstatedir}/db/${PACKAGE_TARNAME}"
])
RB_DEFINE_UNQUOTED([DB_DIR], ["$dbdir"], [Directory where databases are located])
AC_SUBST_DIR([dbdir])
dnl
dnl Check for --with-logdir
dnl
AC_MSG_CHECKING([whether to modify logdir])
AC_ARG_WITH(logdir,
AC_HELP_STRING([--with-logdir=DIR],
[Directory where to write logfiles.]),
[ logdir=`echo $withval | sed 's/\/$//'`
AC_MSG_RESULT(yes)],
[ AS_IF([test "x$enable_fhs_paths" = "xyes"],
[logdir="${prefix}/var/log"],
[logdir="${prefix}/var/${PACKAGE_TARNAME}/log"])
AC_MSG_RESULT(no)])
RB_DEFINE_UNQUOTED([LOG_DIR], ["${logdir}"], [Prefix where to write logfiles.])
AC_ARG_WITH(logdir, AC_HELP_STRING([--with-logdir=DIR], [Directory where to write logfiles.]),
[
AC_MSG_RESULT(yes)
logdir=`echo $withval | sed 's/\/$//'`
], [
AC_MSG_RESULT(no)
logdir="${localstatedir}/log/${PACKAGE_TARNAME}"
])
RB_DEFINE_UNQUOTED([LOG_DIR], ["$logdir"], [Prefix where to write logfiles.])
AC_SUBST_DIR([logdir])
dnl
dnl Check for --with-helpdir
dnl
AC_MSG_CHECKING([whether to modify helpdir])
AC_ARG_WITH(helpdir,
AC_HELP_STRING([--with-helpdir=DIR],
[Directory to install help files.]),
[ helpdir=`echo $withval | sed 's/\/$//'`
AC_MSG_RESULT(yes) ],
[ AS_IF([test "x$enable_fhs_paths" = "xyes"],
[helpdir="${prefix}/share/help"],
[helpdir="${prefix}/share/${PACKAGE_TARNAME}/help"])
AC_MSG_RESULT(no) ])
RB_DEFINE_UNQUOTED([HELP_DIR], ["${helpdir}"], [Prefix where help files are installed.])
AC_SUBST_DIR([helpdir])
dnl
dnl Check for --with-moduledir
dnl
AC_MSG_CHECKING([whether to modify moduledir])
AC_ARG_WITH(moduledir,
[AC_HELP_STRING([--with-moduledir=DIR],
[Directory to install modules.])],
[ moduledir=`echo $withval | sed 's/\/$//'`
AC_MSG_RESULT(yes)],
[ AS_IF([test "x$enable_fhs_paths" = "xyes"],
[moduledir="${prefix}/lib/modules"],
[moduledir="${prefix}/lib/${PACKAGE_TARNAME}/modules"])
AC_MSG_RESULT(no)
])
RB_DEFINE_UNQUOTED([MODULE_DIR], ["${moduledir}"], [Prefix where modules are installed.])
AC_ARG_WITH(moduledir, [AC_HELP_STRING([--with-moduledir=DIR], [Directory to install modules.])],
[
AC_MSG_RESULT(yes)
moduledir=`echo $withval | sed 's/\/$//'`
], [
AC_MSG_RESULT(no)
moduledir="${libdir}/modules/${PACKAGE_TARNAME}"
])
RB_DEFINE_UNQUOTED([MODULE_DIR], ["$moduledir"], [Prefix where modules are installed.])
AC_SUBST_DIR([moduledir])
dnl
dnl Check for --with-rundir
dnl
AC_MSG_CHECKING([whether or modify rundir])
AC_ARG_WITH([rundir],
[AC_HELP_STRING([--with-rundir=DIR],
[Directory in which to store pidfile.])],
[AC_MSG_RESULT([yes])
rundir=`echo $withval | sed 's/\/$//'`],
[AC_MSG_RESULT([no])
AS_IF([test "x$enable_fhs_paths" = "xyes"],
[rundir="${prefix}/var/run"],
[rundir="${prefix}/${PACKAGE_TARNAME}/run"])])
AC_SUBST([rundir])
AC_DEFINE_DIR([PKGRUNDIR], ["${rundir}"], [Directory to store pidfile in.])
dnl
dnl Check for --with-program-prefix
dnl
dnl Installed utility program prefixes (does not affect binaries
dnl installed into pkglibexecdir)
AC_MSG_CHECKING([for program prefix])
AC_ARG_WITH([program-prefix],
[AS_HELP_STRING([--with-program-prefix=], [If set, programs installed into PATH will be installed with names prefixed by this prefix.])],
[test "x$with_program_prefix" = "xno" && with_program_prefix=],
[with_program_prefix=])
AC_MSG_RESULT(["$with_program_prefix"])
PROGRAM_PREFIX="$with_program_prefix"
AC_SUBST([PROGRAM_PREFIX])
AC_DEFINE_UNQUOTED([PROGRAM_PREFIX], ["$with_program_prefix"], [String with which all programs intended to be in PATH are prefixed.])
dnl ***************************************************************************
dnl
dnl Third party

View file

@ -92,7 +92,7 @@ try
// argument or fall back to the default.
const std::string confpath
{
configfile?: fs::get(fs::IRCD_CONF)
configfile?: ""
};
// Associates libircd with our io_context and posts the initial routines

View file

@ -36,38 +36,17 @@ namespace ircd::fs
{
struct aio;
struct init;
enum index :int;
IRCD_EXCEPTION(ircd::error, error)
IRCD_EXCEPTION(error, filesystem_error)
constexpr auto DPATH = IRCD_PREFIX;
constexpr auto BINPATH = IRCD_PREFIX "/bin";
constexpr auto ETCPATH = RB_ETC_DIR;
constexpr auto LOGPATH = RB_LOG_DIR;
constexpr auto MODPATH = RB_MODULE_DIR;
constexpr auto CPATH = RB_ETC_DIR "/ircd.conf"; // ircd.conf file
constexpr auto SPATH = RB_BIN_DIR "/" BRANDING_NAME; // ircd executable
constexpr auto DBPATH = PKGLOCALSTATEDIR "/db"; // database prefix
constexpr size_t PATH_MAX { 2048 };
// Below are the elements for default paths.
enum index
{
PREFIX,
BIN,
ETC,
LOG,
LIBEXEC,
MODULES,
IRCD_CONF,
IRCD_EXEC,
DB,
_NUM_
};
const char *get(index) noexcept;
const char *name(index) noexcept;
extern aio *aioctx;
string_view get(index) noexcept;
string_view name(index) noexcept;
std::string make_path(const vector_view<const string_view> &);
bool exists(const string_view &path);
@ -80,17 +59,29 @@ namespace ircd::fs
bool rename(std::nothrow_t, const string_view &old, const string_view &new_);
void rename(const string_view &old, const string_view &new_);
bool remove(std::nothrow_t, const string_view &path);
bool remove(const string_view &path);
std::string cwd();
void chdir(const string_view &path);
bool mkdir(const string_view &path);
extern aio *aioctx;
std::string cwd();
}
/// elements for default paths.
enum ircd::fs::index
:int
{
PREFIX,
BIN,
CONF,
DB,
LOG,
MODULES,
_NUM_
};
#include "fd.h"
#include "read.h"
#include "write.h"

View file

@ -139,4 +139,5 @@ libircd_la_SOURCES += \
endif
install-data-local:
test -d $(prefix)/@logdir@ || mkdir -p $(prefix)/@logdir@
test -d $(logdir) || mkdir -p $(logdir)
test -d $(dbdir) || mkdir -p $(dbdir)

View file

@ -10,8 +10,10 @@
namespace ircd::conf
{
extern const string_view default_filename;
std::string _config;
static std::string read_json_file(string_view filename);
static std::string read_json_file(std::string filename);
}
//TODO: X
@ -21,10 +23,16 @@ ircd::conf::config
_config
};
decltype(ircd::conf::default_filename)
ircd::conf::default_filename
{
"ircd.conf"
};
void
ircd::conf::init(const string_view &filename)
{
_config = read_json_file(filename);
_config = read_json_file(std::string{filename});
}
bool
@ -149,7 +157,7 @@ const
//
std::string
ircd::conf::read_json_file(string_view filename)
ircd::conf::read_json_file(std::string filename)
try
{
if(!filename.empty())
@ -159,7 +167,10 @@ try
};
if(filename.empty())
filename = fs::CPATH;
filename = fs::make_path(
{
fs::get(fs::CONF), conf::default_filename
});
if(!fs::exists(filename))
return {};

View file

@ -19,10 +19,6 @@ namespace filesystem = boost::filesystem;
namespace ircd::fs
{
enum { NAME, PATH };
using ent = std::pair<std::string, std::string>;
extern const std::array<ent, num_of<index>()> paths;
filesystem::path path(std::string);
filesystem::path path(const string_view &);
filesystem::path path(const vector_view<const string_view> &);
@ -33,20 +29,6 @@ decltype(ircd::fs::aioctx)
ircd::fs::aioctx
{};
decltype(ircd::fs::paths)
ircd::fs::paths
{{
{ "prefix", DPATH },
{ "binary dir", BINPATH },
{ "config", ETCPATH },
{ "log", LOGPATH },
{ "libexec dir", PKGLIBEXECDIR },
{ "modules", MODPATH },
{ "ircd.conf", CPATH },
{ "ircd binary", SPATH },
{ "db", DBPATH },
}};
ircd::fs::init::init()
{
#ifdef IRCD_USE_AIO
@ -71,6 +53,55 @@ noexcept
assert(!aioctx);
}
//
// Compile-time path index
//
namespace ircd::fs
{
struct sysent;
extern const std::array<struct sysent, num_of<index>()> syspaths;
}
struct ircd::fs::sysent
{
string_view name;
string_view path;
};
decltype(ircd::fs::syspaths)
ircd::fs::syspaths
{{
{ "prefix", RB_PREFIX },
{ "binary dir", RB_BIN_DIR },
{ "database", RB_DB_DIR },
{ "conf", RB_CONF_DIR },
{ "log", RB_LOG_DIR },
{ "modules", RB_MODULE_DIR },
}};
ircd::string_view
ircd::fs::get(index index)
noexcept try
{
return syspaths.at(index).path;
}
catch(const std::out_of_range &e)
{
return {};
}
ircd::string_view
ircd::fs::name(index index)
noexcept try
{
return syspaths.at(index).name;
}
catch(const std::out_of_range &e)
{
return {};
}
///////////////////////////////////////////////////////////////////////////////
//
// fs/stdin.h
@ -355,7 +386,7 @@ catch(const std::exception &e)
namespace ircd::fs
{
thread_local char path_buf[2048];
thread_local char path_buf[PATH_MAX];
static const char *path_str(const string_view &);
static uint posix_flags(const std::ios::open_mode &mode);
}
@ -481,6 +512,20 @@ noexcept(false)
// fs.h / misc
//
std::string
ircd::fs::cwd()
try
{
return filesystem::current_path().string();
}
catch(const filesystem::filesystem_error &e)
{
throw filesystem_error
{
"%s", e.what()
};
}
void
ircd::fs::chdir(const string_view &path)
try
@ -509,20 +554,6 @@ catch(const filesystem::filesystem_error &e)
};
}
std::string
ircd::fs::cwd()
try
{
return filesystem::current_path().string();
}
catch(const filesystem::filesystem_error &e)
{
throw filesystem_error
{
"%s", e.what()
};
}
bool
ircd::fs::remove(const string_view &path)
try
@ -703,25 +734,3 @@ ircd::fs::path(std::string s)
{
return filesystem::path(std::move(s));
}
const char *
ircd::fs::get(index index)
noexcept try
{
return std::get<PATH>(paths.at(index)).c_str();
}
catch(const std::out_of_range &e)
{
return nullptr;
}
const char *
ircd::fs::name(index index)
noexcept try
{
return std::get<NAME>(paths.at(index)).c_str();
}
catch(const std::out_of_range &e)
{
return nullptr;
}

View file

@ -473,7 +473,7 @@ namespace ircd::mods
decltype(ircd::mods::modroot)
ircd::mods::modroot
{
ircd::fs::get(ircd::fs::MODULES)
std::string{ircd::fs::get(ircd::fs::MODULES)}
};
decltype(ircd::mods::paths)

View file

@ -1878,7 +1878,7 @@ console_cmd__db__list(opt &out, const string_view &line)
{
const auto name
{
replace(lstrip(lstrip(path, fs::DBPATH), '/'), "/", ":")
replace(lstrip(lstrip(path, fs::get(fs::DB)), '/'), "/", ":")
};
const auto &d