about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2021-05-07 19:28:05 -0400
committerJune McEnroe <june@causal.agency>2021-05-07 19:29:21 -0400
commit5988e1a29ef1d84d6ad169c00be979c71f7f1181 (patch)
tree09ed37b240a6d19e36569a3a24ceb5e3b73d20f0
parentUse nick for color if user is "*" (diff)
downloadscooper-5988e1a29ef1d84d6ad169c00be979c71f7f1181.tar.gz
scooper-5988e1a29ef1d84d6ad169c00be979c71f7f1181.zip
Use LDADD variables, support BINDIR
Also change MANDIR default to ${PREFIX}/man.
-rw-r--r--Makefile21
-rwxr-xr-xconfigure28
2 files changed, 29 insertions, 20 deletions
diff --git a/Makefile b/Makefile
index b2fd744..4cd3419 100644
--- a/Makefile
+++ b/Makefile
@@ -1,13 +1,18 @@
 PREFIX ?= ~/.local
-MANDIR ?= ${PREFIX}/share/man
+BINDIR ?= ${PREFIX}/bin
+MANDIR ?= ${PREFIX}/man
 
 CFLAGS += -std=c11 -Wall -Wextra -Wpedantic -Wno-overlength-strings
-LDLIBS = -lkcgi -lkcgihtml -lsqlite3
+LDADD.kcgi = -lkcgi
+LDADD.kcgi-html = -lkcgihtml
+LDADD.sqlite3 = -lsqlite3
 
 TEST_DB = ~/.local/share/litterbox/litterbox.sqlite
 
 -include config.mk
 
+LDLIBS = ${LDADD.kcgi} ${LDADD.kcgi-html} ${LDADD.sqlite3}
+
 OBJS += contexts.o
 OBJS += css.o
 OBJS += events.o
@@ -21,7 +26,7 @@ dev: tags all test
 all: scooper
 
 scooper: ${OBJS}
-	${CC} ${LDFLAGS} ${OBJS} ${LDLIBS} -o $@
+	${CC} ${STATIC} ${LDFLAGS} ${OBJS} ${LDLIBS} -o $@
 
 ${OBJS}: server.h
 
@@ -34,16 +39,16 @@ test: .test
 	./scooper -c ${TEST_DB}
 	touch .test
 
-tags: *.c *.h
-	ctags -w *.c *.h
+tags: *.[ch]
+	ctags -w *.[ch]
 
 clean:
 	rm -f scooper ${OBJS} css.c .test tags
 
 install: scooper scooper.1
-	install -d ${DESTDIR}${PREFIX}/bin ${DESTDIR}${MANDIR}/man1
-	install scooper ${DESTDIR}${PREFIX}/bin
+	install -d ${DESTDIR}${BINDIR} ${DESTDIR}${MANDIR}/man1
+	install scooper ${DESTDIR}${BINDIR}
 	install -m 644 scooper.1 ${DESTDIR}${MANDIR}/man1
 
 uninstall:
-	rm -f ${DESTDIR}${PREFIX}/bin/scooper ${DESTDIR}${MANDIR}/man1/scooper.1
+	rm -f ${DESTDIR}${BINDIR}/scooper ${DESTDIR}${MANDIR}/man1/scooper.1
diff --git a/configure b/configure
index 2047624..c001b39 100755
--- a/configure
+++ b/configure
@@ -1,23 +1,25 @@
 #!/bin/sh
 set -eu
 
+: ${PKG_CONFIG:=pkg-config}
+
 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:-}"
+	defstr "$1" "$(${PKG_CONFIG} --variable=$3 $2)${4:-}"
+}
+ldadd() {
+	lib=$1; shift
+	echo "LDADD.${lib} = $*"
+}
+config() {
+	${PKG_CONFIG} --print-errors "$@"
+	cflags $(${PKG_CONFIG} --cflags "$@")
+	for lib; do ldadd $lib $(${PKG_CONFIG} --libs $lib); done
 }
 
 exec >config.mk
@@ -25,6 +27,7 @@ exec >config.mk
 for opt; do
 	case "${opt}" in
 		(--prefix=*) echo "PREFIX = ${opt#*=}" ;;
+		(--bindir=*) echo "BINDIR = ${opt#*=}" ;;
 		(--mandir=*) echo "MANDIR = ${opt#*=}" ;;
 		(*) echo "warning: unsupported option ${opt}" >&2 ;;
 	esac
@@ -32,8 +35,9 @@ done
 
 case "$(uname)" in
 	(FreeBSD|OpenBSD)
-		echo 'LDFLAGS += -static'
-		config --static kcgi kcgi-html sqlite3
+		echo 'STATIC = -static'
+		PKG_CONFIG="${PKG_CONFIG} --static"
+		config kcgi kcgi-html sqlite3
 		;;
 	(Linux)
 		cflags -D_GNU_SOURCE