From ff22886482aa3a2d97af3a793e644d2fde9e977b Mon Sep 17 00:00:00 2001 From: PHO Date: Thu, 6 Feb 2020 22:05:32 +0900 Subject: [PATCH] Add ./configure option "--with-varpath=PATH" On Unix-like platforms, it is often desirable to install files that will be modified after installation under a separate directory tree from that containing read-only data files. This is so that read-only files can reside in a read-only file system, and also package managers can update or remove read-only files without worrying about removing user data. The new option "--with-varpath=PATH", when specified, configures the game so that certain directories, namely apex, bone, data, edit, user, and save, will be created under the given path, as opposed to the path specified with "--with-libpath=PATH". When the option is not given, those directories will be created under the lib directory as before. --- configure.ac | 21 +++++++++++----- lib/apex/Makefile.am | 2 +- lib/bone/Makefile.am | 2 +- lib/data/Makefile.am | 2 +- lib/edit/Makefile.am | 2 +- lib/file/Makefile.am | 2 +- lib/help/Makefile.am | 2 +- lib/info/Makefile.am | 2 +- lib/pref/Makefile.am | 2 +- lib/save/Makefile.am | 2 +- lib/script/Makefile.am | 2 +- lib/user/Makefile.am | 2 +- lib/xtra/graf/Makefile.am | 2 +- src/externs.h | 2 +- src/init2.c | 64 +++++++++++++++++++++++------------------------ src/main-mac.c | 2 +- src/main-win.c | 2 +- src/main.c | 22 +++++++++------- src/z-config.h | 15 +++++++++-- 19 files changed, 88 insertions(+), 64 deletions(-) diff --git a/configure.ac b/configure.ac index d66a84893..a393165f7 100644 --- a/configure.ac +++ b/configure.ac @@ -19,20 +19,29 @@ AC_LANG_C dnl generate the installation path for the ./lib/ folder if test "$GAMEGROUP" != ""; then - MY_EXPAND_DIR(game_datadir, "$datadir/games/$PACKAGE/lib/") + MY_EXPAND_DIR(game_libpath, "$datadir/games/$PACKAGE/lib/") else - MY_EXPAND_DIR(game_datadir, "./lib/") + MY_EXPAND_DIR(game_libpath, "./lib/") bindir=".." fi dnl overwrite the path with an user-specified value AC_ARG_WITH(libpath, [ --with-libpath=path specify the path to the Hengband lib folder], -[game_datadir="$withval"]) +[game_libpath="$withval"]) -AC_DEFINE_UNQUOTED(DEFAULT_PATH, "$game_datadir", [Path to the Hengband lib folder]) -DEFAULT_PATH="$game_datadir" -AC_SUBST(DEFAULT_PATH) +AC_ARG_WITH(varpath, +[ --with-varpath=path specify the path to the Hengband var folder], +[game_varpath="$withval"], +[game_varpath="$game_libpath"]) + +AC_DEFINE_UNQUOTED(DEFAULT_LIB_PATH, "$game_libpath", [Path to the Hengband lib folder]) +DEFAULT_LIB_PATH="$game_libpath" +AC_SUBST(DEFAULT_LIB_PATH) + +AC_DEFINE_UNQUOTED(DEFAULT_VAR_PATH, "$game_varpath", [Path to the Hengband var folder]) +DEFAULT_VAR_PATH="$game_varpath" +AC_SUBST(DEFAULT_VAR_PATH) dnl Checks for programs. AC_PROG_CC diff --git a/lib/apex/Makefile.am b/lib/apex/Makefile.am index 81ca89c36..d5e771ac8 100644 --- a/lib/apex/Makefile.am +++ b/lib/apex/Makefile.am @@ -7,7 +7,7 @@ EXTRA_DIST = \ $(angband_files) if SET_GID -angbanddir = @DEFAULT_PATH@apex +angbanddir = @DEFAULT_VAR_PATH@/apex angband_DATA = \ $(angband_files) diff --git a/lib/bone/Makefile.am b/lib/bone/Makefile.am index 3a23eda8b..e7c6cac06 100644 --- a/lib/bone/Makefile.am +++ b/lib/bone/Makefile.am @@ -7,7 +7,7 @@ EXTRA_DIST = \ $(angband_files) if SET_GID -angbanddir = @DEFAULT_PATH@bone +angbanddir = @DEFAULT_VAR_PATH@/bone angband_DATA = \ $(angband_files) diff --git a/lib/data/Makefile.am b/lib/data/Makefile.am index 28358201a..adf8564f6 100644 --- a/lib/data/Makefile.am +++ b/lib/data/Makefile.am @@ -7,7 +7,7 @@ EXTRA_DIST = \ $(angband_files) if SET_GID -angbanddir = @DEFAULT_PATH@data +angbanddir = @DEFAULT_VAR_PATH@/data angband_DATA = \ $(angband_files) diff --git a/lib/edit/Makefile.am b/lib/edit/Makefile.am index c26d9a344..71511fefa 100644 --- a/lib/edit/Makefile.am +++ b/lib/edit/Makefile.am @@ -22,7 +22,7 @@ EXTRA_DIST = \ $(angband_files) if SET_GID -angbanddir = @DEFAULT_PATH@edit +angbanddir = @DEFAULT_LIB_PATH@/edit angband_DATA = \ $(angband_files) diff --git a/lib/file/Makefile.am b/lib/file/Makefile.am index e96b4973e..142b9de0b 100644 --- a/lib/file/Makefile.am +++ b/lib/file/Makefile.am @@ -20,7 +20,7 @@ EXTRA_DIST = \ $(angband_files) if SET_GID -angbanddir = @DEFAULT_PATH@file +angbanddir = @DEFAULT_LIB_PATH@/file angband_DATA = \ $(angband_files) diff --git a/lib/help/Makefile.am b/lib/help/Makefile.am index 785681c80..1e1724c41 100644 --- a/lib/help/Makefile.am +++ b/lib/help/Makefile.am @@ -26,7 +26,7 @@ EXTRA_DIST = \ $(angband_files) if SET_GID -angbanddir = @DEFAULT_PATH@help +angbanddir = @DEFAULT_LIB_PATH@/help angband_DATA = \ $(angband_files) diff --git a/lib/info/Makefile.am b/lib/info/Makefile.am index 8a6b5ef18..e7d0eed56 100644 --- a/lib/info/Makefile.am +++ b/lib/info/Makefile.am @@ -7,7 +7,7 @@ EXTRA_DIST = \ $(angband_files) if SET_GID -angbanddir = @DEFAULT_PATH@info +angbanddir = @DEFAULT_LIB_PATH@/info angband_DATA = \ $(angband_files) diff --git a/lib/pref/Makefile.am b/lib/pref/Makefile.am index 34772e7e5..65e6bf0d7 100644 --- a/lib/pref/Makefile.am +++ b/lib/pref/Makefile.am @@ -18,7 +18,7 @@ EXTRA_DIST = \ $(angband_files) if SET_GID -angbanddir = @DEFAULT_PATH@pref +angbanddir = @DEFAULT_LIB_PATH@/pref angband_DATA = \ $(angband_files) diff --git a/lib/save/Makefile.am b/lib/save/Makefile.am index c92fde577..d967ae9e5 100644 --- a/lib/save/Makefile.am +++ b/lib/save/Makefile.am @@ -7,7 +7,7 @@ EXTRA_DIST = \ $(angband_files) if SET_GID -angbanddir = @DEFAULT_PATH@save +angbanddir = @DEFAULT_VAR_PATH@/save angband_DATA = \ $(angband_files) diff --git a/lib/script/Makefile.am b/lib/script/Makefile.am index ce5ddb5ff..aef9b0aeb 100644 --- a/lib/script/Makefile.am +++ b/lib/script/Makefile.am @@ -7,7 +7,7 @@ EXTRA_DIST = \ $(angband_files) if SET_GID -angbanddir = @DEFAULT_PATH@script +angbanddir = @DEFAULT_LIB_PATH@/script angband_DATA = \ $(angband_files) diff --git a/lib/user/Makefile.am b/lib/user/Makefile.am index 0d34a7c7f..263c2c5ce 100644 --- a/lib/user/Makefile.am +++ b/lib/user/Makefile.am @@ -7,7 +7,7 @@ EXTRA_DIST = \ $(angband_files) if SET_GID -angbanddir = @DEFAULT_PATH@user +angbanddir = @DEFAULT_VAR_PATH@/user angband_DATA = \ $(angband_files) diff --git a/lib/xtra/graf/Makefile.am b/lib/xtra/graf/Makefile.am index 7098ee02b..bbd77a46c 100644 --- a/lib/xtra/graf/Makefile.am +++ b/lib/xtra/graf/Makefile.am @@ -7,7 +7,7 @@ EXTRA_DIST = \ $(angband_files) if SET_GID -angbanddir = @DEFAULT_PATH@xtra/graf +angbanddir = @DEFAULT_LIB_PATH@/xtra/graf angband_DATA = \ $(angband_files) diff --git a/src/externs.h b/src/externs.h index 1eddbcaf0..a64acfda2 100644 --- a/src/externs.h +++ b/src/externs.h @@ -796,7 +796,7 @@ extern byte color_char_to_attr(char c); extern errr process_dungeon_file(cptr name, int ymin, int xmin, int ymax, int xmax); /* init2.c */ -extern void init_file_paths(char *path); +extern void init_file_paths(char *libpath, char *varpath); extern cptr err_str[PARSE_ERROR_MAX]; extern errr init_v_info(void); extern errr init_buildings(void); diff --git a/src/init2.c b/src/init2.c index 3e08d39e9..660a8c24f 100644 --- a/src/init2.c +++ b/src/init2.c @@ -79,9 +79,9 @@ * this function to be called multiple times, for example, to * try several base "path" values until a good one is found. */ -void init_file_paths(char *path) +void init_file_paths(char *libpath, char *varpath) { - char *tail; + char *libtail, *vartail; #ifdef PRIVATE_USER_PATH char buf[1024]; @@ -109,11 +109,11 @@ void init_file_paths(char *path) /*** Prepare the "path" ***/ /* Hack -- save the main directory */ - ANGBAND_DIR = string_make(path); - - /* Prepare to append to the Base Path */ - tail = path + strlen(path); + ANGBAND_DIR = string_make(libpath); + /* Prepare to append to the Base Paths */ + libtail = libpath + strlen(libpath); + vartail = varpath + strlen(varpath); #ifdef VM @@ -139,44 +139,44 @@ void init_file_paths(char *path) /*** Build the sub-directory names ***/ /* Build a path name */ - strcpy(tail, "apex"); - ANGBAND_DIR_APEX = string_make(path); + strcpy(vartail, "apex"); + ANGBAND_DIR_APEX = string_make(varpath); /* Build a path name */ - strcpy(tail, "bone"); - ANGBAND_DIR_BONE = string_make(path); + strcpy(vartail, "bone"); + ANGBAND_DIR_BONE = string_make(varpath); /* Build a path name */ - strcpy(tail, "data"); - ANGBAND_DIR_DATA = string_make(path); + strcpy(vartail, "data"); + ANGBAND_DIR_DATA = string_make(varpath); /* Build a path name */ - strcpy(tail, "edit"); - ANGBAND_DIR_EDIT = string_make(path); + strcpy(libtail, "edit"); + ANGBAND_DIR_EDIT = string_make(libpath); /* Build a path name */ - strcpy(tail, "script"); - ANGBAND_DIR_SCRIPT = string_make(path); + strcpy(libtail, "script"); + ANGBAND_DIR_SCRIPT = string_make(libpath); /* Build a path name */ - strcpy(tail, "file"); - ANGBAND_DIR_FILE = string_make(path); + strcpy(libtail, "file"); + ANGBAND_DIR_FILE = string_make(libpath); /* Build a path name */ - strcpy(tail, "help"); - ANGBAND_DIR_HELP = string_make(path); + strcpy(libtail, "help"); + ANGBAND_DIR_HELP = string_make(libpath); /* Build a path name */ - strcpy(tail, "info"); - ANGBAND_DIR_INFO = string_make(path); + strcpy(libtail, "info"); + ANGBAND_DIR_INFO = string_make(libpath); /* Build a path name */ - strcpy(tail, "pref"); - ANGBAND_DIR_PREF = string_make(path); + strcpy(libtail, "pref"); + ANGBAND_DIR_PREF = string_make(libpath); /* Build a path name */ - strcpy(tail, "save"); - ANGBAND_DIR_SAVE = string_make(path); + strcpy(vartail, "save"); + ANGBAND_DIR_SAVE = string_make(varpath); #ifdef PRIVATE_USER_PATH @@ -189,14 +189,14 @@ void init_file_paths(char *path) #else /* PRIVATE_USER_PATH */ /* Build a path name */ - strcpy(tail, "user"); - ANGBAND_DIR_USER = string_make(path); + strcpy(vartail, "user"); + ANGBAND_DIR_USER = string_make(varpath); #endif /* PRIVATE_USER_PATH */ /* Build a path name */ - strcpy(tail, "xtra"); - ANGBAND_DIR_XTRA = string_make(path); + strcpy(libtail, "xtra"); + ANGBAND_DIR_XTRA = string_make(libpath); #endif /* VM */ @@ -231,8 +231,8 @@ void init_file_paths(char *path) string_free(ANGBAND_DIR_DATA); /* Build a new path name */ - sprintf(tail, "data-%s", next); - ANGBAND_DIR_DATA = string_make(path); + sprintf(vartail, "data-%s", next); + ANGBAND_DIR_DATA = string_make(varpath); } } diff --git a/src/main-mac.c b/src/main-mac.c index bfe9aafab..141ecc267 100644 --- a/src/main-mac.c +++ b/src/main-mac.c @@ -6128,7 +6128,7 @@ static void init_stuff(void) while (1) { /* Prepare the paths */ - init_file_paths(path); + init_file_paths(path, path); /* Build the filename */ #ifdef JP diff --git a/src/main-win.c b/src/main-win.c index a34e32773..05d9b6ba7 100644 --- a/src/main-win.c +++ b/src/main-win.c @@ -4946,7 +4946,7 @@ static void init_stuff(void) validate_dir(path, TRUE); /* Init the file paths */ - init_file_paths(path); + init_file_paths(path, path); /* Hack -- Validate the paths */ validate_dir(ANGBAND_DIR_APEX, FALSE); diff --git a/src/main.c b/src/main.c index 3ea3b3ab7..99f4a70db 100644 --- a/src/main.c +++ b/src/main.c @@ -96,12 +96,13 @@ static void create_user_dir(void) * Initialize and verify the file paths, and the score file. * * Use the ANGBAND_PATH environment var if possible, else use - * DEFAULT_PATH, and in either case, branch off appropriately. + * DEFAULT_(LIB|VAR)_PATH, and in either case, branch off + * appropriately. * * First, we'll look for the ANGBAND_PATH environment variable, * and then look for the files in there. If that doesn't work, - * we'll try the DEFAULT_PATH constant. So be sure that one of - * these two things works... + * we'll try the DEFAULT_(LIB|VAR)_PATH constants. So be sure + * that one of these two things works... * * We must ensure that the path ends with "PATH_SEP" if needed, * since the "init_file_paths()" function will simply append the @@ -116,7 +117,7 @@ static void create_user_dir(void) */ static void init_stuff(void) { - char path[1024]; + char libpath[1024], varpath[1024]; #if defined(AMIGA) || defined(VM) @@ -131,18 +132,21 @@ static void init_stuff(void) tail = getenv("ANGBAND_PATH"); /* Use the angband_path, or a default */ - strncpy(path, tail ? tail : DEFAULT_PATH, 511); + strncpy(libpath, tail ? tail : DEFAULT_LIB_PATH, 511); + strncpy(varpath, tail ? tail : DEFAULT_VAR_PATH, 511); - /* Make sure it's terminated */ - path[511] = '\0'; + /* Make sure they're terminated */ + libpath[511] = '\0'; + varpath[511] = '\0'; /* Hack -- Add a path separator (only if needed) */ - if (!suffix(path, PATH_SEP)) strcat(path, PATH_SEP); + if (!suffix(libpath, PATH_SEP)) strcat(libpath, PATH_SEP); + if (!suffix(varpath, PATH_SEP)) strcat(varpath, PATH_SEP); #endif /* AMIGA / VM */ /* Initialize */ - init_file_paths(path); + init_file_paths(libpath, varpath); } diff --git a/src/z-config.h b/src/z-config.h index 1737f83a0..d407d188b 100644 --- a/src/z-config.h +++ b/src/z-config.h @@ -427,8 +427,19 @@ * actual location of the "lib" folder, for example, "/tmp/angband/lib/" * or "/usr/games/lib/angband/", or "/pkg/angband/lib". */ -#ifndef DEFAULT_PATH -# define DEFAULT_PATH "./lib/" +#ifndef DEFAULT_LIB_PATH +# define DEFAULT_LIB_PATH "./lib/" +#endif + + +/* + * OPTION: Set the "default" path to the angband "var" directory. + * + * This is like DEFAULT_LIB_PATH, but is for files that will be + * modified after installation. + */ +#ifndef DEFAULT_VAR_PATH +# define DEFAULT_VAR_PATH DEFAULT_LIB_PATH #endif -- 2.11.0