about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-05-20 21:40:11 -0400
committerJune McEnroe <june@causal.agency>2020-05-20 21:40:11 -0400
commit245b0cbb43e4f7745db1ef6a9082692be6a89053 (patch)
tree07e0ee90be17569f58bd95737ee457b00c6fca88
parentUpdate email addresses (diff)
downloadlitterbox-245b0cbb43e4f7745db1ef6a9082692be6a89053.tar.gz
litterbox-245b0cbb43e4f7745db1ef6a9082692be6a89053.zip
Rewrite build and install like pounce 1.3
man pages are no longer compressed!
-rw-r--r--.gitignore6
-rw-r--r--Makefile44
-rw-r--r--README.723
-rwxr-xr-xconfigure30
-rw-r--r--rc.d/litterbox.in (renamed from rc.d/litterbox)4
5 files changed, 53 insertions, 54 deletions
diff --git a/.gitignore b/.gitignore
index 55b8a36..da7d199 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,7 +1,7 @@
 *.o
 .test
-/litterbox
-/scoop
-/unscoop
 config.mk
+litterbox
+scoop
 tags
+unscoop
diff --git a/Makefile b/Makefile
index 96bd125..85eadc2 100644
--- a/Makefile
+++ b/Makefile
@@ -1,14 +1,18 @@
-PREFIX = /usr/local
-MANDIR = ${PREFIX}/share/man
-ETCDIR = ${PREFIX}/etc
+PREFIX ?= /usr/local
+MANDIR ?= ${PREFIX}/share/man
+ETCDIR ?= ${PREFIX}/etc
+
+CFLAGS += -I${PREFIX}/include
+LDFLAGS += -L${PREFIX}/lib
 
 CFLAGS += -std=c11 -Wall -Wextra -Wpedantic
 LDLIBS = -lsqlite3
-LDLIBS.litterbox = -ltls
+LDLIBS.litterbox = -lsqlite3 -ltls
 
 BINS = litterbox scoop unscoop
 MANS = ${BINS:=.1}
-RCS  =
+RCS  = rc.d/litterbox
+INSTALLS = install-rcs
 
 -include config.mk
 
@@ -20,10 +24,10 @@ dev: tags all test
 all: ${BINS}
 
 litterbox: ${OBJS.litterbox}
-	${CC} ${LDFLAGS} ${OBJS.$@} ${LDLIBS} ${LDLIBS.$@} -o $@
+	${CC} ${LDFLAGS} ${OBJS.$@} ${LDLIBS.$@} -o $@
 
 .o:
-	${CC} ${LDFLAGS} $< ${LDLIBS} ${LDLIBS.$@} -o $@
+	${CC} ${LDFLAGS} $< ${LDLIBS} -o $@
 
 ${BINS:=.o}: database.h
 
@@ -33,19 +37,27 @@ test: .test
 	set -e; for format in ${FORMATS}; do ./unscoop -n -f $$format; done
 	touch .test
 
+.SUFFIXES: .in
+
+.in:
+	sed -e 's|%%PREFIX%%|${PREFIX}|g' $< > $@
+
 tags: *.c *.h
 	ctags -w *.c *.h
 
 clean:
-	rm -f .test tags ${BINS} ${OBJS.litterbox} ${BINS:=.o}
+	rm -f .test tags ${BINS} ${RCS} ${OBJS.litterbox} ${BINS:=.o}
+
+install: ${BINS} ${MANS} ${INSTALLS}
+	install -d ${DESTDIR}${PREFIX}/bin ${DESTDIR}${MANDIR}/man1
+	install ${BINS} ${DESTDIR}${PREFIX}/bin
+	install -m 644 ${MANS} ${DESTDIR}${MANDIR}/man1
 
-install: ${BINS} ${MANS}
-	install -d ${PREFIX}/bin ${MANDIR}/man1
-	install ${BINS} ${PREFIX}/bin
-	for man in ${MANS}; do gzip -c $$man > ${MANDIR}/man1/$$man.gz; done
-	if [ -n '${RCS}' ]; then install -d ${ETCDIR}/rc.d; fi
-	if [ -n '${RCS}' ]; then install ${RCS} ${ETCDIR}/rc.d; fi
+install-rcs: ${RCS}
+	install -d ${DESTDIR}${ETCDIR}/rc.d
+	install ${RCS} ${DESTDIR}${ETCDIR}/rc.d
 
 uninstall:
-	rm -f ${BINS:%=${PREFIX}/bin/%} ${MANS:%=${MANDIR}/man1/%.gz}
-	if [ -n '${RCS}' ]; then rm -f ${RCS:%=${ETCDIR}/%}; fi
+	rm -f ${BINS:%=${DESTDIR}${PREFIX}/bin/%}
+	rm -f ${MANS:%=${DESTDIR}${MANDIR}/man1/%}
+	rm -f ${RCS:%=${DESTDIR}${ETCDIR}/%}
diff --git a/README.7 b/README.7
index 3b76e5d..affd36a 100644
--- a/README.7
+++ b/README.7
@@ -19,29 +19,30 @@ as a logging bot.
 .
 .Pp
 .Nm
-requires LibreSSL
+targets
+.Fx
+and requires LibreSSL
 .Pq Fl ltls
 and SQLite
 .Pq Fl lsqlite3 .
-It primarily targets
-.Fx ,
-as well as macOS and Linux.
-.
 .Bd -literal -offset indent
-\&./configure
 make all
 sudo make install PREFIX=/usr/local
 .Ed
 .
 .Pp
-If your system installs LibreSSL
+On other systems,
+such as macOS and Linux,
+the build is configured using
+.Xr pkg-config 1 .
+If LibreSSL is installed
 in a non-standard path, set
-.Ev PKG_CONFIG_PATH
-for
-.Nm ./configure .
-For example,
+.Ev PKG_CONFIG_PATH appropriately.
+For example:
 .Bd -literal -offset indent
 PKG_CONFIG_PATH=/opt/libressl/lib/pkgconfig ./configure
+make all
+sudo make install PREFIX=/usr/local
 .Ed
 .
 .Sh FILES
diff --git a/configure b/configure
index 5e442ba..eafde4b 100755
--- a/configure
+++ b/configure
@@ -3,33 +3,19 @@ set -eu
 
 exec >config.mk
 
-case "$(uname)" in
-	(FreeBSD)
-		if ! pkg info -e libressl || ! pkg info -e sqlite3; then
-			echo 'LibreSSL & SQLite3 required' >&2
-			exit 1
-		fi
-		prefix=$(pkg query '%p' sqlite3)
-		cat <<-EOF
-		CFLAGS += -I${prefix}/include
-		CFLAGS += -D'SQLITE3_BIN="${prefix}/bin/sqlite3"'
-		LDFLAGS += -L${prefix}/lib
-		RCS = rc.d/litterbox
-		EOF
-		exit
-		;;
-	(Linux)
-		echo 'CFLAGS += -D_GNU_SOURCE'
-		;;
-esac
-
 libs='libtls sqlite3'
 pkg-config --print-errors $libs
 
 cat <<EOF
 CFLAGS += $(pkg-config --cflags $libs)
-CFLAGS += -D'SQLITE3_BIN="$(pkg-config --variable=prefix sqlite3)/bin/sqlite3"'
+CFLAGS += -D'SQLITE3_BIN="$(pkg-config --variable=exec_prefix sqlite3)/bin/sqlite3"'
 LDFLAGS += $(pkg-config --libs-only-L $libs)
 LDLIBS = $(pkg-config --libs-only-l sqlite3)
-LDLIBS.litterbox = $(pkg-config --libs-only-l libtls)
+LDLIBS.litterbox = $(pkg-config --libs-only-l $libs)
 EOF
+
+if [ "$(uname)" = 'Linux' ]; then
+	cat <<-EOF
+	CFLAGS += -D_GNU_SOURCE
+	EOF
+fi
diff --git a/rc.d/litterbox b/rc.d/litterbox.in
index fbcc97d..cc48092 100644
--- a/rc.d/litterbox
+++ b/rc.d/litterbox.in
@@ -17,7 +17,7 @@ command='/usr/sbin/daemon'
 pidprefix="/var/run/${name}"
 pidfile="${pidprefix}.pid"
 
-child_command='/usr/local/bin/litterbox'
+child_command='%%PREFIX%%/bin/litterbox'
 
 if [ -n "$2" ]; then
 	profile=$2
@@ -34,7 +34,7 @@ else
 	if [ -n "${litterbox_profiles}" -a -n "$1" ]; then
 		for profile in ${litterbox_profiles}; do
 			echo "===> ${name} profile: ${profile}"
-			/usr/local/etc/rc.d/${name} "$1" "${profile}" || exit "$?"
+			%%PREFIX%%/etc/rc.d/${name} "$1" "${profile}" || exit "$?"
 		done
 		exit
 	fi