summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--Makefile9
-rw-r--r--README.723
-rwxr-xr-xconfigure64
3 files changed, 63 insertions, 33 deletions
diff --git a/Makefile b/Makefile
index 85eadc2..19dc3b1 100644
--- a/Makefile
+++ b/Makefile
@@ -2,17 +2,12 @@ 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 = -lsqlite3 -ltls
+LDLIBS = -lsqlite3 -ltls
 
 BINS = litterbox scoop unscoop
 MANS = ${BINS:=.1}
 RCS  = rc.d/litterbox
-INSTALLS = install-rcs
 
 -include config.mk
 
@@ -24,7 +19,7 @@ dev: tags all test
 all: ${BINS}
 
 litterbox: ${OBJS.litterbox}
-	${CC} ${LDFLAGS} ${OBJS.$@} ${LDLIBS.$@} -o $@
+	${CC} ${LDFLAGS} ${OBJS.$@} ${LDLIBS} -o $@
 
 .o:
 	${CC} ${LDFLAGS} $< ${LDLIBS} -o $@
diff --git a/README.7 b/README.7
index 62ea486..d26b929 100644
--- a/README.7
+++ b/README.7
@@ -1,4 +1,4 @@
-.Dd July 21, 2020
+.Dd July 24, 2020
 .Dt README 7
 .Os "Causal Agency"
 .
@@ -30,29 +30,32 @@ is provided by
 .Sh INSTALLING
 .Nm
 targets
-.Fx
+.Fx ,
+.Ox
+and Linux,
 and requires LibreSSL
 .Pq Fl ltls
 and SQLite
-.Pq Fl lsqlite3 .
+.Pq Fl lsqite3 .
+An
+.Xr rc 8
+script for
+.Nm
+is provided on
+.Fx .
 .Bd -literal -offset indent
+\&./configure
 make all
-sudo make install PREFIX=/usr/local
+sudo make install
 .Ed
 .
 .Pp
-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 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 e0873e3..3a688cf 100755
--- a/configure
+++ b/configure
@@ -1,22 +1,54 @@
 #!/bin/sh
 set -eu
 
-exec >config.mk
+cflags() {
+	echo "CFLAGS += $*"
+}
+ldlibs() {
+	echo "LDLIBS ${o:-}= $*"
+	o=+
+}
+config() {
+	pkg-config --print-errors "$@"
+	cflags $(pkg-config --cflags "$@")
+	ldlibs $(pkg-config --libs "$@")
+}
+defstr() {
+	cflags "-D'$1=\"$2\"'"
+}
+defvar() {
+	defstr "$1" "$(pkg-config --variable=$3 $2)${4:-}"
+}
 
-libs='libtls sqlite3'
-pkg-config --print-errors $libs
+exec >config.mk
 
-cat <<EOF
-CFLAGS += $(pkg-config --cflags $libs)
-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 $libs)
-INSTALLS =
-EOF
+for opt; do
+	case "${opt}" in
+		(--prefix=*) echo "PREFIX = ${opt#*=}" ;;
+		(--mandir=*) echo "MANDIR = ${opt#*=}" ;;
+		(--sysconfdir=*) echo "ETCDIR = ${opt#*=}" ;;
+		(*) echo "warning: unsupported option ${opt}" >&2 ;;
+	esac
+done
 
-if [ "$(uname)" = 'Linux' ]; then
-	cat <<-EOF
-	CFLAGS += -D_GNU_SOURCE
-	EOF
-fi
+case "$(uname)" in
+	(FreeBSD)
+		config sqlite3 libtls
+		defvar SQLITE3_BIN sqlite3 exec_prefix /bin/sqlite3
+		echo 'INSTALLS = install-rcs'
+		;;
+	(OpenBSD)
+		ldlibs -ltls
+		config sqlite3
+		defvar SQLITE3_BIN sqlite3 exec_prefix /bin/sqlite3
+		;;
+	(Linux)
+		cflags -D_GNU_SOURCE
+		config sqlite3 libtls
+		defvar SQLITE3_BIN sqlite3 exec_prefix /bin/sqlite3
+		;;
+	(*)
+		config sqlite3 libtls
+		defvar SQLITE3_BIN sqlite3 exec_prefix /bin/sqlite3
+		;;
+esac