lav-sdl

SDL верзија програма Лавиринт
Дневник | Датотеке | Референце | ПРОЧИТАЈМЕ | ЛИЦЕНЦА

чување 9d695ac41f3321f691c92e881b8c7f7e6aa0ead1
родитељ a3842c2701d7fe9fa3db64c515d384a3a9782414
Аутор: Страхиња Радић <contact@strahinja.org>
Датум:   Tue, 15 Aug 2023 18:44:01 +0200

Add support for installed datafiles

Signed-off-by: Страхиња Радић <contact@strahinja.org>

Diffstat:
Mclean.do | 2+-
Adefault.do | 13+++++++++++++
Minstall.do | 8+++++++-
Mlav-sdl.c | 9++++++---
Mlav-sdl.do | 8+++++++-
Alocal.h | 5+++++
Alocal.h.in | 5+++++
Muninstall.do | 5++++-
измењених датотека: 8, додавања: 48(+), брисања: 7(-)

diff --git a/clean.do b/clean.do @@ -1 +1 @@ -rm -f *.o lav-sdl +rm -f *.o lav-sdl local.h diff --git a/default.do b/default.do @@ -0,0 +1,13 @@ +if [ -r ./config.redo ]; then + . ./config.redo +fi +if [ -z "$DATADIR" ]; then + DATADIR=$PREFIX/share/lav-sdl +fi +if [ -r $1.in ]; then + redo-ifchange $1.in + sed -e "s,%DATADIR%,$DATADIR,g" <$1.in >$3 +else + printf "%s: don't know how to build '%s'\n" "$0" "$1" >&2 + exit 99 +fi diff --git a/install.do b/install.do @@ -4,5 +4,11 @@ if [ -r ./config.redo ]; then fi PREFIX=${PREFIX:-/usr/local} BINDIR=$PREFIX/bin -install -d $BINDIR +if [ -z "$DATADIR" ]; then + DATADIR=$PREFIX/share/lav-sdl +fi +install -d $BINDIR $DATADIR install -m 0755 lav-sdl $BINDIR +for datafile in *.dat; do + install -m 0644 $datafile $DATADIR/$datafile +done diff --git a/lav-sdl.c b/lav-sdl.c @@ -14,6 +14,8 @@ #include <stdio.h> #include <stdlib.h> +#include "local.h" + #define ANIM_STEPS 10 #define ANIM_DELAY 10 #define CELL_SIZE 32 @@ -145,8 +147,9 @@ cleanup(void) { free(location_stack); - for (int y = 0; y < LABYRINTH_MAXHEIGHT; y++) - free(labyrinth.cells[y]); + if (labyrinth.cells) + for (int y = 0; y < LABYRINTH_MAXHEIGHT; y++) + free(labyrinth.cells[y]); free(labyrinth.cells); if (ter16_texture) @@ -757,7 +760,7 @@ main(int argc, char** argv) if (argc > 1) load_labyrinth(*(argv + 1)); else - load_labyrinth("lavirint.dat"); + load_labyrinth(DEFAULT_DATAFILE); location_stack = (SDL_Point*)calloc(LOCATION_STACK_MAX, sizeof(SDL_Point)); update_size(); diff --git a/lav-sdl.do b/lav-sdl.do @@ -1,7 +1,13 @@ -redo-ifchange lav-sdl.o if [ -r ./config.redo ]; then . ./config.redo fi +for f in *.h.in; do + echo $f | sed -e's/\.in$//g' +done | xargs redo-ifchange +for f in *.h *.c; do + echo $f + echo $f | sed -e's/\.c$/.o/g' +done | xargs redo-ifchange CC=${CC:-gcc -g} LIBS=$(pkg-config --libs sdl2) LIBS="$LIBS $(pkg-config --libs SDL2_image)" diff --git a/local.h b/local.h @@ -0,0 +1,5 @@ +/* This program is licensed under the terms of GNU GPL v3 or (at your option) + * any later version. Copyright (C) 2023 Страхиња Радић. + * See the file LICENSE for exact copyright and license details. */ + +#define DEFAULT_DATAFILE "/usr/share/lav-sdl/lavirint.dat" diff --git a/local.h.in b/local.h.in @@ -0,0 +1,5 @@ +/* This program is licensed under the terms of GNU GPL v3 or (at your option) + * any later version. Copyright (C) 2023 Страхиња Радић. + * See the file LICENSE for exact copyright and license details. */ + +#define DEFAULT_DATAFILE "%DATADIR%/lavirint.dat" diff --git a/uninstall.do b/uninstall.do @@ -3,4 +3,7 @@ if [ -r ./config.redo ]; then fi PREFIX=${PREFIX:-/usr/local} BINDIR=$PREFIX/bin -rm -f $BINDIR/lav-sdl +if [ -z "$DATADIR" ]; then + DATADIR=$PREFIX/share/lav-sdl +fi +rm -f $BINDIR/lav-sdl $(find $DATADIR -type f)