Mercurial > molko
changeset 307:363024b76da7
make: create install-data rather than fakeroot
author | David Demelier <markand@malikania.fr> |
---|---|
date | Tue, 29 Jun 2021 09:49:48 +0200 |
parents | 6a7bca547f9a |
children | 8523fb0c8540 |
files | GNUmakefile INSTALL.md libmlk-adventure/adventure/molko.c libmlk-core/core/sys.c |
diffstat | 4 files changed, 76 insertions(+), 92 deletions(-) [+] |
line wrap: on
line diff
--- a/GNUmakefile Mon Jun 28 21:08:11 2021 +0200 +++ b/GNUmakefile Tue Jun 29 09:49:48 2021 +0200 @@ -268,12 +268,10 @@ ${SDL2_INCS} \ ${JANSSON_INCS} \ ${ZSTD_INCS} -DEFS= -DMOLKO_BINDIR=\"${BINDIR}\" \ +DEFS= -DMOLKO_PREFIX=\"${PREFIX}\" \ + -DMOLKO_BINDIR=\"${BINDIR}\" \ -DMOLKO_DATADIR=\"${DATADIR}\" \ - -DMOLKO_LOCALEDIR=\"${LOCALEDIR}\" \ - -DMOLKO_ABS_BINDIR=\"${PREFIX}/${BINDIR}\" \ - -DMOLKO_ABS_DATADIR=\"${PREFIX}/${DATADIR}\" \ - -DMOLKO_ABS_LOCALEDIR=\"${PREFIX}/${LOCALEDIR}\" + -DMOLKO_LOCALEDIR=\"${LOCALEDIR}\" ifeq (${NLS},1) SED.nls= s/@define WITH_NLS@/\#define MOLKO_WITH_NLS/ @@ -372,12 +370,11 @@ # define pot-install for mo in ${2}; do \ - mkdir -p ${3}${LOCALEDIR}/$$(basename $${mo%.mo})/LC_MESSAGES; \ - cp $$mo ${3}${LOCALEDIR}/$$(basename $${mo%.mo})/LC_MESSAGES/${1}.mo; \ + mkdir -p ${3}${PREFIX}/${LOCALEDIR}/$$(basename $${mo%.mo})/LC_MESSAGES; \ + cp $$mo ${3}${PREFIX}/${LOCALEDIR}/$$(basename $${mo%.mo})/LC_MESSAGES/${1}.mo; \ done endef - # {{{ libmlk-sqlite ${LIBMLK_SQLITE}: ${LIBMLK_SQLITE_OBJS} @@ -400,7 +397,7 @@ # {{{ libmlk-ui ${LIBMLK_UI_ASTS}: ${MLK_BCC} -${LIBMLK_UI_OBJS}: ${LIBMLK_UI_ASTS} ${LIBMLK_CORE} +${LIBMLK_UI_OBJS}: ${LIBMLK_UI_ASTS} config.h ${LIBMLK_UI}: ${LIBMLK_UI_OBJS} ${LIBMLK_UI_MO} ${CMD.ar} @@ -413,7 +410,7 @@ # {{{ libmlk-rpg ${LIBMLK_RPG_ASTS}: ${MLK_BCC} -${LIBMLK_RPG_OBJS}: ${LIBMLK_RPG_ASTS} ${LIBMLK_UI} ${LIBMLK_SQLITE} +${LIBMLK_RPG_OBJS}: ${LIBMLK_RPG_ASTS} config.h ${LIBMLK_RPG}: ${LIBMLK_RPG_OBJS} ${LIBMLK_RPG_MO} ${CMD.ar} @@ -426,7 +423,7 @@ # {{{ libmlk-adventure ${LIBMLK_ADVENTURE_ASTS}: ${MLK_BCC} -${LIBMLK_ADVENTURE_OBJS}: ${LIBMLK_ADVENTURE_ASTS} ${LIBMLK_RPG} +${LIBMLK_ADVENTURE_OBJS}: ${LIBMLK_ADVENTURE_ASTS} config.h ${LIBMLK_ADVENTURE}: ${LIBMLK_ADVENTURE_OBJS} ${LIBMLK_ADVENTURE_MO} ${CMD.ar} @@ -460,7 +457,7 @@ # {{{ mlk-adventure -${MLK_ADVENTURE_OBJS}: ${LIBMLK_ADVENTURE} ${LIBMLK_DATA_ASTS} +${MLK_ADVENTURE_OBJS}: ${LIBRARIES} ${LIBMLK_DATA_ASTS} ${MLK_ADVENTURE}: LIBS := ${LIBMLK_ALL} ${MLK_ADVENTURE}: ${MLK_ADVENTURE_OBJS} @@ -470,7 +467,7 @@ # {{{ examples -${EXAMPLES}: ${LIBMLK_ADVENTURE} +${EXAMPLES}: ${LIBRARIES} examples/example-%/main: LIBS := ${LIBMLK_ALL} examples/example-%/main: examples/example-%/main.c @@ -497,7 +494,6 @@ # {{{ clean clean: - rm -rf fakeroot rm -f config.h tags rm -f ${LIBMLK_ADVENTURE} ${LIBMLK_ADVENTURE_OBJS} ${LIBMLK_ADVENTURE_DEPS} rm -f ${LIBMLK_CORE} ${LIBMLK_CORE_OBJS} ${LIBMLK_CORE_DEPS} @@ -513,21 +509,26 @@ # }}} -# {{{ fakeroot +install: + mkdir -p ${DESTDIR}${PREFIX}/${BINDIR} + cp ${TOOLS} ${TARGETS} ${DESTDIR}${PREFIX}/${BINDIR} + mkdir -p ${DESTDIR}${PREFIX}/${LIBDIR} + cp ${LIBRARIES} ${DESTDIR}${PREFIX}/${LIBDIR} -fakeroot: - mkdir -p fakeroot - mkdir -p fakeroot/${BINDIR} - mkdir -p fakeroot/${DATADIR}/mlk-adventure - cp ${PROGS} fakeroot/${BINDIR} - for e in ${EXAMPLES}; do cp $$e fakeroot/${BINDIR}/$$(basename $$(dirname $$e)); done - rsync -a libmlk-data/ fakeroot/${DATADIR}/mlk-adventure - $(call pot-install,libmlk-core,${LIBMLK_CORE_MO},fakeroot/) - $(call pot-install,libmlk-ui,${LIBMLK_UI_MO},fakeroot/) - $(call pot-install,libmlk-rpg,${LIBMLK_RPG_MO},fakeroot/) - $(call pot-install,libmlk-adventure,${LIBMLK_ADVENTURE_MO},fakeroot/) - -# }}} +install-data: + mkdir -p ${DESTDIR}${PREFIX}/${DATADIR}/mlk-adventure + cp -R libmlk-data/fonts ${DESTDIR}${PREFIX}/${DATADIR}/mlk-adventure/fonts + cp -R libmlk-data/images ${DESTDIR}${PREFIX}/${DATADIR}/mlk-adventure/images + cp -R libmlk-data/music ${DESTDIR}${PREFIX}/${DATADIR}/mlk-adventure/music + cp -R libmlk-data/sounds ${DESTDIR}${PREFIX}/${DATADIR}/mlk-adventure/sounds + cp -R libmlk-data/sprites ${DESTDIR}${PREFIX}/${DATADIR}/mlk-adventure/sprites + cp -R libmlk-data/maps ${DESTDIR}${PREFIX}/${DATADIR}/mlk-adventure/maps +ifeq (${NLS},1) + $(call pot-install,libmlk-core,${LIBMLK_CORE_MO},${DESTDIR}) + $(call pot-install,libmlk-ui,${LIBMLK_UI_MO},${DESTDIR}) + $(call pot-install,libmlk-rpg,${LIBMLK_RPG_MO},${DESTDIR}) + $(call pot-install,libmlk-adventure,${LIBMLK_ADVENTURE_MO},${DESTDIR}) +endif # {{{ meta targets @@ -539,4 +540,4 @@ # }}} -.PHONY: all clean examples everything fakeroot nls pot tests tools +.PHONY: all clean examples everything install install-data pot tests tools
--- a/INSTALL.md Mon Jun 28 21:08:11 2021 +0200 +++ b/INSTALL.md Tue Jun 29 09:49:48 2021 +0200 @@ -41,9 +41,14 @@ directory, when building those are not already discoverable because targets are not already installed. -It's still possible to build a fakeroot directory to run examples and -`mlk-adventure` without installing. To do this you simply need to use `fakeroot` -target. +You need to install at least the data once using `install-data` target, you can +do this without root access by using a temporary directory and set the +`MLK_ROOT` environment variable. + + $ make DESTDIR=datadir install + $ MLK_ROOT=datadir ./mlk-adventure/mlk-adventure + (or to run examples) + $ MLK_ROOT=datadir ./examples/ Note: you need rsync installed, in contrast to `install` with a `DESTDIR` macro it only copies runtime data and avoid re-copying what didn't
--- a/libmlk-adventure/adventure/molko.c Mon Jun 28 21:08:11 2021 +0200 +++ b/libmlk-adventure/adventure/molko.c Tue Jun 29 09:49:48 2021 +0200 @@ -89,7 +89,6 @@ molko.team.members[0] = &character_neth; molko.team.members[1] = &character_neth; inventory_add(&molko.inventory, &item_potion, 100); - molko_teleport("maps/map-world.map", -1, -1); /* Init unrecoverable panic state. */ molko.panic = state_panic_new();
--- a/libmlk-core/core/sys.c Mon Jun 28 21:08:11 2021 +0200 +++ b/libmlk-core/core/sys.c Tue Jun 29 09:49:48 2021 +0200 @@ -55,30 +55,6 @@ [SYS_DIR_LOCALE] = MOLKO_LOCALEDIR }; -static const char *abspaths[] = { - [SYS_DIR_BIN] = MOLKO_ABS_BINDIR, - [SYS_DIR_DATA] = MOLKO_ABS_DATADIR, - [SYS_DIR_LOCALE] = MOLKO_ABS_LOCALEDIR -}; - -#if defined(_WIN32) - -static inline int -is_absolute(const char *path) -{ - return !PathIsRelativeA(path); -} - -#else - -static inline int -is_absolute(const char *path) -{ - return path[0] == '/'; -} - -#endif - static inline char * normalize(char *str) { @@ -106,43 +82,46 @@ static char ret[PATH_MAX]; char *base, *binsect; - /* 1. Get current binary directory. */ - base = SDL_GetBasePath(); + if ((base = getenv("MLK_ROOT"))) { + snprintf(ret, sizeof (ret), "%s/%s/%s", base, MOLKO_PREFIX, paths[kind]); + } else { + /* + * Some system does not provide support (shame on you OpenBSD) + * to the executable path. In that case we use PREFIX+<dir> + * instead. + */ + if (!(base = SDL_GetBasePath())) + snprintf(ret, sizeof (ret), "%s/%s", MOLKO_PREFIX, paths[kind]); + else { + /* + * Decompose the path to the given special directory by + * computing relative directory to it from where the + * binary is located. + * + * Example: + * + * PREFIX/bin/mlk + * PREFIX/share/mlk-adventure + * + * The path to the data is ../share/molko starting from + * the binary. + * + * Put the base path into the path and remove the value + * of MOLKO_BINDIR. + * + * Example: + * from: /usr/local/bin + * to: /usr/local + */ + strlcpy(path, base, sizeof (path)); + SDL_free(base); - /* - * 2. Decompose the path to the given special directory by computing - * relative directory to it from where the binary is located. - * - * Example: - * PREFIX/bin/mlk - * PREFIX/share/molko - * - * The path to the data is ../share/molko starting from the binary. - * - * If path to binary is absolute we can't determine relative paths to - * any other directory and use the absolute one instead. - * - * Also, on some platforms SDL_GetBasePath isn't implemented and returns - * NULL, in that case return the fallback to the installation prefix. - */ - if (is_absolute(paths[SYS_DIR_BIN]) || is_absolute(paths[kind]) || !base) - return absolute(abspaths[kind]); + if ((binsect = strstr(path, paths[SYS_DIR_BIN]))) + *binsect = '\0'; - /* - * 3. Put the base path into the path and remove the value of - * MOLKO_BINDIR. - * - * Example: - * from: /usr/local/bin - * to: /usr/local - */ - strlcpy(path, base, sizeof (path)); - SDL_free(base); - - if ((binsect = strstr(path, paths[SYS_DIR_BIN]))) - *binsect = '\0'; - - snprintf(ret, sizeof (ret), "%s%s", path, paths[kind]); + snprintf(ret, sizeof (ret), "%s%s", path, paths[kind]); + } + } return normalize(ret); }