15 files changed, 102 insertions(+), 110 deletions(-)
M INSTALL
A Makefile
D all.do
D clean.do
A config.mk
D config.redo
D default.do
D default.o.do
D install.do
D lav-sdl.do
A lib/mkpack
A lib/replacepat
D pack.do
D rebuild.do
D uninstall.do
M INSTALL => INSTALL +12 -20
@@ 1,7 1,7 @@
Prerequisites
=============
-* C compiler - defaults in config.redo
+* C compiler - defaults in config.mk
* libSDL (SDL2, SDL2_image)
@@ 11,33 11,25 @@ Install
$ git clone https://git.sr.ht/~strahinja/lav-sdl
$ cd lav-sdl
$ su
-
-If you have djb redo:
-
- # redo install
-
-if you don't:
-
- # ./do install
+ # make install
Persistent build configuration file
-----------------------------------
-The file config.redo will be sourced when building targets which also accept
-configuration through environment variables. For example, CC and PREFIX
-are specified in config.redo.
+The file config.mk will be sourced when building targets which also accept
+configuration through environment variables. For example, CPPFLAGS and PREFIX
+are specified in config.mk.
OpenBSD
-------
-Replace gcc in CC with cc and add -D_BSD_SOURCE, eg:
-
- # CC='cc -g -Wall -pedantic -std=c99 -D_POSIX_C_SOURCE=200809L
- -D_XOPEN_SOURCE=700 -D_BSD_SOURCE}' \
- ./do install
-
-and change MANDIR to
+Before running make(1), comment the _CPPFLAGS definition in config.mk above the
+line with the "OpenBSD" comment and uncomment the one below it:
- MANDIR=$PREFIX/man/man1
+ #_CPPFLAGS = -D_DEFAULT_SOURCE -D_POSIX_C_SOURCE=200809L \
+ # -D_XOPEN_SOURCE=700
+ # OpenBSD
+ _CPPFLAGS = -D_DEFAULT_SOURCE -D_POSIX_C_SOURCE=200809L \
+ -D_XOPEN_SOURCE=700 -D_BSD_SOURCE
A Makefile => Makefile +41 -0
@@ 0,0 1,41 @@
+.POSIX:
+
+include config.mk
+
+.SUFFIXES: .c .o .h.in .h
+
+.h.in.h:
+ sh -c 'DATADIR=$(DATADIR) lib/replacepat $< $@'
+
+all: $(PROG)
+
+local.h: local.h.in
+
+lav-sdl.o: lav-sdl.c local.h
+
+$(PROG): $(OBJS) $(SRC) $(HEADERS)
+ $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
+
+clean:
+ rm -f $(PROG) $(OBJS) local.h *~
+
+install: all
+ find . \( -name '*.dat' -o -name '*.png' \) -exec sh -c 'umask 022; \
+ $(INSTALL) -Dm 0644 {} $(DATADIR)/{}' shell \;
+ $(INSTALL) -Dm 0644 README $(DOCDIR)/README
+ $(INSTALL) -Dm 0644 LICENSE $(DOCDIR)/LICENSE
+ $(INSTALL) -Dm 0755 $(PROG) $(BINDIR)/$(PROG)
+
+uninstall:
+ find "$(DATADIR)" -type f -exec rm -f {} +
+ rmdir $(DATADIR) 2>/dev/null || true
+ rm -f $(DOCDIR)/README
+ rm -f $(DOCDIR)/LICENSE
+ rmdir $(DOCDIR) 2>/dev/null || true
+ rm -f $(BINDIR)/$(PROG)
+ rmdir $(BINDIR) 2>/dev/null || true
+
+pack: all
+ sh -x lib/mkpack
+
+.PHONY: all clean install pack uninstall
D all.do => all.do +0 -1
@@ 1,1 0,0 @@
-redo-ifchange lav-sdl
D clean.do => clean.do +0 -1
@@ 1,1 0,0 @@
-rm -f *.o *~ lav-sdl local.h
A config.mk => config.mk +25 -0
@@ 0,0 1,25 @@
+#CC = cc
+CFLAGS = -Os -Wall -pedantic -std=c99
+_CPPFLAGS = -D_DEFAULT_SOURCE -D_POSIX_C_SOURCE=200809L \
+ -D_XOPEN_SOURCE=700
+# OpenBSD
+#_CPPFLAGS = -D_DEFAULT_SOURCE -D_POSIX_C_SOURCE=200809L \
+# -D_XOPEN_SOURCE=700 -D_BSD_SOURCE
+INCLUDE = -I/usr/local/include/SDL2
+INSTALL = install
+LIBS = -lSDL2_image -lSDL2 -lm
+SRC = lav-sdl.c
+HEADERS = local.h
+OBJS = lav-sdl.o
+PREFIX = /usr/local
+PROG = lav-sdl
+
+# Derived macros
+BINDIR = $(PREFIX)/bin
+CPPFLAGS = $(_CPPFLAGS) $(INCLUDE)
+DATADIR = $(PREFIX)/share/$(PROG)
+#DOCDIR = $(PREFIX)/share/doc/$(PROG)
+#MANPREFIX = $(PREFIX)/share/man
+# OpenBSD
+#MANPREFIX = $(PREFIX)/man
+#MANPAGE = $(PROG).1
D config.redo => config.redo +0 -17
@@ 1,17 0,0 @@
-PREFIX=${PREFIX:-/usr/local}
-
-BINDIR=$PREFIX/bin
-DATADIR=$PREFIX/share/lav-sdl
-DOCDIR=$PREFIX/share/doc/lav-sdl
-
-PROGS="lav-sdl"
-DATAFILES=$(find \( -name '*.dat' -o -name '*.png' \) -print)
-DOCS="README LICENSE"
-
-CC=${CC:-gcc -g -Wall -pedantic -std=c99 -D_POSIX_C_SOURCE=200809L \
--D_XOPEN_SOURCE=700}
-STRIP=${STRIP:-:}
-
-# OpenBSD
-#CC=${CC:-cc -g -Wall -pedantic -std=c99 -D_POSIX_C_SOURCE=200809L \
-#-D_XOPEN_SOURCE=700 -D_BSD_SOURCE}
D default.do => default.do +0 -14
@@ 1,14 0,0 @@
-if [ -r ./config.redo ]; then
- . ./config.redo
-fi
-PREFIX=${PREFIX:-/usr/local}
-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
D default.o.do => default.o.do +0 -6
@@ 1,6 0,0 @@
-sed -n 's/^#include "\([^"]*\)"/\1/p' ${2%.o}.c | \
- xargs redo-ifchange
-redo-ifchange $2.c
-. ./config.redo
-INCLUDES=$(pkg-config --cflags sdl2)
-${CC} ${INCLUDES} -c $2.c -o $3
D install.do => install.do +0 -12
@@ 1,12 0,0 @@
-redo-ifchange all
-. ./config.redo
-install -d "$DOCDIR" "$BINDIR" "$DATADIR"
-for docfile in $DOCS; do
- install -Dm 0644 "${docfile}" "${DOCDIR}/${docfile}"
-done
-for datafile in $DATAFILES; do
- install -m 0644 "${datafile}" "${DATADIR}/${datafile}"
-done
-for binfile in $PROGS; do
- install -Dm 0755 "${binfile}" "${BINDIR}/${binfile}"
-done
D lav-sdl.do => lav-sdl.do +0 -13
@@ 1,13 0,0 @@
-. ./config.redo
-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
-LIBS=$(pkg-config --libs sdl2)
-LIBS="$LIBS $(pkg-config --libs SDL2_image)"
-LIBS="$LIBS -lm"
-${CC} -o $3 lav-sdl.o ${LIBS}
-${STRIP} $3
A lib/mkpack => lib/mkpack +14 -0
@@ 0,0 1,14 @@
+#!/bin/sh -x
+# vim: set ft=bash:
+DISTDIR=$(grep ^PROG config.mk |
+ sed -E 's,.*=[[:space:]]+([[:alpha:]]+),\1,')
+# To be able to create the directory with the same name
+rm lav-sdl
+mkdir "$DISTDIR"
+for f in $(git ls-files); do
+ d="$DISTDIR"/"$(dirname "$f")"
+ mkdir -p "$d"
+ cp "$f" "$d"/
+done
+tar -cf - "$DISTDIR" | xz -9v - > "$DISTDIR".tar.xz
+rm -fr "$DISTDIR"
A lib/replacepat => lib/replacepat +10 -0
@@ 0,0 1,10 @@
+#!/bin/sh
+# vim: set ft=bash:
+infile="$1"
+outfile="$2"
+DATE=$(cat date 2>/dev/null)
+VERSION=$(cat version 2>/dev/null)
+
+sed -e 's|%VERSION%|'"$VERSION"'|g' -e 's|%DATE%|'"$DATE"'|g' \
+ -e 's|%DATADIR%|'"$DATADIR"'|g' "$infile" \
+ > "$outfile"
D pack.do => pack.do +0 -15
@@ 1,15 0,0 @@
-redo all
-#redo-ifchange version
-#read VERSION <version
-#VERSION=$(echo $VERSION | sed 's/^v//')
-DISTDIR=lav-sdl
-# To be able to create the directory with the same name
-rm lav-sdl
-mkdir $DISTDIR
-for f in $(git ls-files); do
- d=$DISTDIR/$(dirname $f)
- mkdir -p $d
- cp $f $d
-done
-tar cvf $DISTDIR.tar.xz $DISTDIR >/dev/null
-rm -fr $DISTDIR
D rebuild.do => rebuild.do +0 -1
@@ 1,1 0,0 @@
-redo clean all
D uninstall.do => uninstall.do +0 -10
@@ 1,10 0,0 @@
-. ./config.redo
-for docfile in $DOCS; do
- rm -f "${DOCDIR}/${docfile}"
-done
-for datafile in $DATAFILES; do
- rm -f "${MANDIR}/${manfile}"
-done
-for binfile in $PROGS; do
- rm -f "${BINDIR}/${binfile}"
-done