about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-07-23 16:28:38 -0400
committerJune McEnroe <june@causal.agency>2020-07-23 16:28:38 -0400
commitf37ad399fe064056c438fb3f1103fe339e5fe9e5 (patch)
treebcfc438f58259d970583e19878b594f9253f7494
parentRemove tls_close error handling (diff)
downloadcatgirl-f37ad399fe064056c438fb3f1103fe339e5fe9e5.tar.gz
catgirl-f37ad399fe064056c438fb3f1103fe339e5fe9e5.zip
Rewrite configure script for all platforms
-rw-r--r--Makefile3
-rw-r--r--README.716
-rwxr-xr-xconfigure60
3 files changed, 44 insertions, 35 deletions
diff --git a/Makefile b/Makefile
index 8bf93ab..6081163 100644
--- a/Makefile
+++ b/Makefile
@@ -1,9 +1,6 @@
 PREFIX ?= /usr/local
 MANDIR ?= ${PREFIX}/share/man
 
-CFLAGS += -I${PREFIX}/include
-LDFLAGS += -L${PREFIX}/lib
-
 CEXTS = gnu-case-range gnu-conditional-omitted-operand
 CFLAGS += -std=c11 -Wall -Wextra -Wpedantic ${CEXTS:%=-Wno-%}
 LDLIBS = -lncursesw -ltls
diff --git a/README.7 b/README.7
index 66c6a7c..39da90a 100644
--- a/README.7
+++ b/README.7
@@ -1,4 +1,4 @@
-.Dd July  8, 2020
+.Dd July 23, 2020
 .Dt README 7
 .Os "Causal Agency"
 .\" To view this file, run: man ./README.7
@@ -86,17 +86,11 @@ requires LibreSSL
 .Pq Fl ltls
 and ncurses
 .Pq Fl lncursesw .
-It primarily targets
+It targets
 .Fx ,
-.Ox
-and macOS,
-as well as Linux.
-The
-.Pa configure
-step is not necessary on
-.Fx
-or
-.Ox .
+.Ox ,
+macOS
+and Linux.
 On
 .Ox ,
 additionally set
diff --git a/configure b/configure
index 68fce73..d1f940d 100755
--- a/configure
+++ b/configure
@@ -1,26 +1,44 @@
 #!/bin/sh
 set -eu
 
-exec >config.mk
-
-if [ $# -gt 0 ]; then
-	echo 'warning: this script does not process arguments' >&2
-fi
-
-libs='libcrypto libtls ncursesw'
+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:-}"
+}
 
-pkg-config --print-errors $libs
-exec_prefix=$(pkg-config --variable=exec_prefix openssl)
-
-cat <<EOF
-CFLAGS += $(pkg-config --cflags $libs)
-CFLAGS += -D'OPENSSL_BIN="${exec_prefix}/bin/openssl"'
-LDFLAGS += $(pkg-config --libs-only-L $libs)
-LDLIBS = $(pkg-config --libs-only-l $libs)
-EOF
+exec >config.mk
 
-if [ "$(uname)" = 'Linux' ]; then
-	cat <<-EOF
-	CFLAGS += -D_GNU_SOURCE
-	EOF
-fi
+case "$(uname)" in
+	(FreeBSD)
+		ldlibs -lncursesw
+		config libtls
+		defvar OPENSSL_BIN openssl exec_prefix /bin/openssl
+		;;
+	(OpenBSD)
+		ldlibs -lncursesw -ltls
+		defstr OPENSSL_BIN /usr/bin/openssl
+		;;
+	(Linux)
+		cflags -Wno-pedantic -D_GNU_SOURCE
+		config libcrypto libtls ncursesw
+		defvar OPENSSL_BIN openssl exec_prefix /bin/openssl
+		;;
+	(*)
+		config libcrypto libtls ncursesw
+		defvar OPENSSL_BIN openssl exec_prefix /bin/openssl
+		;;
+esac