summary refs log tree commit diff
path: root/configure
diff options
context:
space:
mode:
Diffstat (limited to 'configure')
-rwxr-xr-xconfigure64
1 files changed, 48 insertions, 16 deletions
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