OSDN Git Service

Add ./configure option "--with-varpath=PATH"
authorPHO <pho@cielonegro.org>
Thu, 6 Feb 2020 13:05:32 +0000 (22:05 +0900)
committerEric Branlund <ebranlund@fastmail.com>
Sat, 4 Apr 2020 15:07:01 +0000 (08:07 -0700)
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.

19 files changed:
configure.ac
lib/apex/Makefile.am
lib/bone/Makefile.am
lib/data/Makefile.am
lib/edit/Makefile.am
lib/file/Makefile.am
lib/help/Makefile.am
lib/info/Makefile.am
lib/pref/Makefile.am
lib/save/Makefile.am
lib/script/Makefile.am
lib/user/Makefile.am
lib/xtra/graf/Makefile.am
src/externs.h
src/init2.c
src/main-mac.c
src/main-win.c
src/main.c
src/z-config.h

index d66a848..a393165 100644 (file)
@@ -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
index 81ca89c..d5e771a 100644 (file)
@@ -7,7 +7,7 @@ EXTRA_DIST = \
   $(angband_files)
 
 if SET_GID
-angbanddir = @DEFAULT_PATH@apex
+angbanddir = @DEFAULT_VAR_PATH@/apex
 
 angband_DATA = \
   $(angband_files)
index 3a23eda..e7c6cac 100644 (file)
@@ -7,7 +7,7 @@ EXTRA_DIST = \
   $(angband_files)
 
 if SET_GID
-angbanddir = @DEFAULT_PATH@bone
+angbanddir = @DEFAULT_VAR_PATH@/bone
 
 angband_DATA = \
   $(angband_files)
index 2835820..adf8564 100644 (file)
@@ -7,7 +7,7 @@ EXTRA_DIST = \
   $(angband_files)
 
 if SET_GID
-angbanddir = @DEFAULT_PATH@data
+angbanddir = @DEFAULT_VAR_PATH@/data
 
 angband_DATA = \
   $(angband_files)
index c26d9a3..71511fe 100644 (file)
@@ -22,7 +22,7 @@ EXTRA_DIST = \
   $(angband_files)
 
 if SET_GID
-angbanddir = @DEFAULT_PATH@edit
+angbanddir = @DEFAULT_LIB_PATH@/edit
 
 angband_DATA = \
   $(angband_files)
index e96b497..142b9de 100644 (file)
@@ -20,7 +20,7 @@ EXTRA_DIST = \
   $(angband_files)
 
 if SET_GID
-angbanddir = @DEFAULT_PATH@file
+angbanddir = @DEFAULT_LIB_PATH@/file
 
 angband_DATA = \
   $(angband_files)
index 785681c..1e1724c 100644 (file)
@@ -26,7 +26,7 @@ EXTRA_DIST = \
   $(angband_files)
 
 if SET_GID
-angbanddir = @DEFAULT_PATH@help
+angbanddir = @DEFAULT_LIB_PATH@/help
 
 angband_DATA = \
   $(angband_files)
index 8a6b5ef..e7d0eed 100644 (file)
@@ -7,7 +7,7 @@ EXTRA_DIST = \
   $(angband_files)
 
 if SET_GID
-angbanddir = @DEFAULT_PATH@info
+angbanddir = @DEFAULT_LIB_PATH@/info
 
 angband_DATA = \
   $(angband_files)
index 34772e7..65e6bf0 100644 (file)
@@ -18,7 +18,7 @@ EXTRA_DIST = \
   $(angband_files)
 
 if SET_GID
-angbanddir = @DEFAULT_PATH@pref
+angbanddir = @DEFAULT_LIB_PATH@/pref
 
 angband_DATA = \
   $(angband_files)
index c92fde5..d967ae9 100644 (file)
@@ -7,7 +7,7 @@ EXTRA_DIST = \
   $(angband_files)
 
 if SET_GID
-angbanddir = @DEFAULT_PATH@save
+angbanddir = @DEFAULT_VAR_PATH@/save
 
 angband_DATA = \
   $(angband_files)
index ce5ddb5..aef9b0a 100644 (file)
@@ -7,7 +7,7 @@ EXTRA_DIST = \
   $(angband_files)
 
 if SET_GID
-angbanddir = @DEFAULT_PATH@script
+angbanddir = @DEFAULT_LIB_PATH@/script
 
 angband_DATA = \
   $(angband_files)
index 0d34a7c..263c2c5 100644 (file)
@@ -7,7 +7,7 @@ EXTRA_DIST = \
   $(angband_files)
 
 if SET_GID
-angbanddir = @DEFAULT_PATH@user
+angbanddir = @DEFAULT_VAR_PATH@/user
 
 angband_DATA = \
   $(angband_files)
index 7098ee0..bbd77a4 100644 (file)
@@ -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)
index 1eddbca..a64acfd 100644 (file)
@@ -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);
index 3e08d39..660a8c2 100644 (file)
@@ -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);
                }
        }
 
index bfe9aaf..141ecc2 100644 (file)
@@ -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
index a34e327..05d9b6b 100644 (file)
@@ -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);
index 3ea3b3a..99f4a70 100644 (file)
@@ -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);
 }
 
 
index 1737f83..d407d18 100644 (file)
  * 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