about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-07-24 18:03:27 -0400
committerJune McEnroe <june@causal.agency>2020-07-24 18:12:17 -0400
commit386a8beb705a1f23417684bb890da543d13e44aa (patch)
treeac75ad23e14dc47829d373208639d7938f0feaab
parentDon't use strlcpy in dispatch (diff)
downloadpounce-386a8beb705a1f23417684bb890da543d13e44aa.tar.gz
pounce-386a8beb705a1f23417684bb890da543d13e44aa.zip
Rewrite configure script for all platforms
-rw-r--r--Makefile8
-rw-r--r--README.713
-rw-r--r--bounce.h2
-rwxr-xr-xconfigure68
4 files changed, 56 insertions, 35 deletions
diff --git a/Makefile b/Makefile
index 9cb5796..1d8b74a 100644
--- a/Makefile
+++ b/Makefile
@@ -3,9 +3,6 @@ MANDIR ?= ${PREFIX}/share/man
 ETCDIR ?= ${PREFIX}/etc
 RUNDIR ?= /var/run
 
-CFLAGS += -I${PREFIX}/include
-LDFLAGS += -L${PREFIX}/lib
-
 CFLAGS += -std=c11 -Wall -Wextra -Wpedantic
 LDLIBS = -lcrypt -ltls
 
@@ -13,7 +10,6 @@ BINS = calico pounce
 MANS = ${BINS:=.1}
 RCS  = ${BINS:%=rc.d/%}
 DIRS = ${ETCDIR}/pounce ${RUNDIR}/calico
-INSTALLS = install-rcs install-dirs
 
 -include config.mk
 
@@ -30,15 +26,13 @@ dev: tags all
 all: ${BINS}
 
 calico: dispatch.o
-	${CC} ${LDFLAGS} dispatch.o ${LDLIBS.calico} -o $@
+	${CC} ${LDFLAGS} dispatch.o -o $@
 
 pounce: ${OBJS}
 	${CC} ${LDFLAGS} ${OBJS} ${LDLIBS} -o $@
 
 ${OBJS}: bounce.h compat.h
 
-dispatch.o: compat.h
-
 .SUFFIXES: .in
 
 .in:
diff --git a/README.7 b/README.7
index d61489d..2eb4a93 100644
--- a/README.7
+++ b/README.7
@@ -1,4 +1,4 @@
-.Dd July  8, 2020
+.Dd July 24, 2020
 .Dt README 7
 .Os "Causal Agency"
 .
@@ -48,16 +48,15 @@ and primarily targets
 .Fx ,
 where it is sandboxed with
 .Xr capsicum 4 .
+Linux and macOS
+are also supported.
 .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 prefix,
 set
@@ -66,8 +65,6 @@ 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/bounce.h b/bounce.h
index a58eca1..050d818 100644
--- a/bounce.h
+++ b/bounce.h
@@ -35,7 +35,7 @@
 #include "compat.h"
 
 #ifndef CERTBOT_PATH
-#define CERTBOT_PATH "/usr/local/etc/letsencrypt"
+#define CERTBOT_PATH "/etc/letsencrypt"
 #endif
 
 #ifndef OPENSSL_BIN
diff --git a/configure b/configure
index 96224d0..c617b1f 100755
--- a/configure
+++ b/configure
@@ -1,26 +1,56 @@
 #!/bin/sh
 set -eu
 
-base='-lcrypt'
-libs='libcrypto libtls'
-[ "$(uname)" = 'Darwin' ] && base=
+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:-}"
+}
 
 exec >config.mk
 
-pkg-config --print-errors $libs
+for opt; do
+	case "${opt}" in
+		(--prefix=*) echo "PREFIX = ${opt#*=}" ;;
+		(--mandir=*) echo "MANDIR = ${opt#*=}" ;;
+		(*) echo "warning: unsupported option ${opt}" >&2 ;;
+	esac
+done
 
-cat <<EOF
-CFLAGS += $(pkg-config --cflags $libs)
-LDFLAGS += $(pkg-config --libs-only-L $libs)
-LDLIBS = ${base} $(pkg-config --libs-only-l $libs)
-CFLAGS += -D'OPENSSL_BIN="$(pkg-config --variable=exec_prefix openssl)/bin/openssl"'
-CFLAGS += -D'CERTBOT_PATH="/etc/letsencrypt"'
-INSTALLS =
-EOF
-
-if [ "$(uname)" = 'Linux' ]; then
-	cat <<-EOF
-	CFLAGS += -D_GNU_SOURCE
-	LDLIBS.calico = \${LDLIBS}
-	EOF
-fi
+case "$(uname)" in
+	(FreeBSD)
+		ldlibs -lcrypt
+		config libtls
+		defvar OPENSSL_BIN openssl exec_prefix /bin/openssl
+		defstr CERTBOT_PATH /usr/local/etc/letsencrypt
+		echo 'INSTALLS = install-rcs install-dirs'
+		;;
+	(Linux)
+		cflags -D_GNU_SOURCE
+		ldlibs -lcrypt
+		config libcrypto libtls
+		defvar OPENSSL_BIN openssl exec_prefix /bin/openssl
+		;;
+	(Darwin)
+		config libcrypto libtls
+		defvar OPENSSL_BIN openssl exec_prefix /bin/openssl
+		;;
+	(*)
+		ldlibs -lcrypt
+		config libcrypto libtls
+		defvar OPENSSL_BIN openssl exec_prefix /bin/openssl
+		;;
+esac