aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2023-03-05 23:51:52 +0100
committerRobin Jarry <robin@jarry.cc>2023-03-06 23:54:06 +0100
commit8b26dc1d62c8ec258707527953bd0d2195684adf (patch)
tree49adb1d8e033e67a61ed4d1ec067a8bef3192255
parent4d3b1cb98bee1bed18fa6f47192186f8f3eb6e0e (diff)
downloadaerc-8b26dc1d62c8ec258707527953bd0d2195684adf.tar.gz
aerc-8b26dc1d62c8ec258707527953bd0d2195684adf.zip
mk: speed up notmuch detection
Use gcc instead of go to build a basic program and determine if notmuch is available. Building a minimal go program takes more than 300ms on a fast machine. A minimal C counterpart takes less than 100ms. To avoid lag when doing bash completion, avoid running any shell commands directly during make evaluation. Rename check-notmuch.sh to goflags.sh and make that script print the goflags directly. Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Inwit <inwit@sindominio.net>
-rw-r--r--Makefile10
-rw-r--r--README.md10
-rwxr-xr-xcontrib/check-notmuch.sh20
-rwxr-xr-xcontrib/goflags.sh19
4 files changed, 28 insertions, 31 deletions
diff --git a/Makefile b/Makefile
index dd80a895..3012757d 100644
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@
.SUFFIXES:
.SUFFIXES: .1 .5 .7 .1.scd .5.scd .7.scd
-VERSION!=git describe --long --abbrev=12 --tags --dirty 2>/dev/null || echo 0.14.0
+VERSION?=`git describe --long --abbrev=12 --tags --dirty 2>/dev/null || echo 0.14.0`
VPATH=doc
PREFIX?=/usr/local
BINDIR?=$(PREFIX)/bin
@@ -10,19 +10,17 @@ SHAREDIR?=$(PREFIX)/share/aerc
LIBEXECDIR?=$(PREFIX)/libexec/aerc
MANDIR?=$(PREFIX)/share/man
GO?=go
-default_goflags!=GO=$(GO) contrib/check-notmuch.sh 2>/dev/null && echo -tags=notmuch
-GOFLAGS?=$(default_goflags)
+GOFLAGS?=`contrib/goflags.sh`
BUILD_OPTS?=-trimpath
-flags!=echo -- $(GOFLAGS) | base64 | tr -d '\n'
# ignore environment variable
GO_LDFLAGS:=
GO_LDFLAGS+=-X main.Version=$(VERSION)
-GO_LDFLAGS+=-X main.Flags=$(flags)
+GO_LDFLAGS+=-X main.Flags=$$(echo -- $(GOFLAGS) | base64 | tr -d '\n')
GO_LDFLAGS+=-X git.sr.ht/~rjarry/aerc/config.shareDir=$(SHAREDIR)
GO_LDFLAGS+=-X git.sr.ht/~rjarry/aerc/config.libexecDir=$(LIBEXECDIR)
GO_LDFLAGS+=$(GO_EXTRA_LDFLAGS)
-GOSRC!=find * -name '*.go' | grep -v filters/wrap.go
+GOSRC!=find * -type f -name '*.go'
GOSRC+=go.mod go.sum
DOCS := \
diff --git a/README.md b/README.md
index 2383a1fb..32ac5a4e 100644
--- a/README.md
+++ b/README.md
@@ -77,12 +77,12 @@ Then compile aerc:
aerc optionally supports notmuch. To enable it, you need to have a recent
version of [notmuch](https://notmuchmail.org/#index7h2), including the header
-files (notmuch.h). The `notmuch` build tag should be automatically added.
+files (notmuch.h). The `notmuch` build tag should be automatically added. To
+check if it is, run the following command:
- $ make
- go build -trimpath -tags=notmuch -ldflags "-X ...
- ^^^^^^^^^^^^^
- ...
+ $ ./aerc -v
+ aerc 0.14.0-108-g31e1cd9af565 +notmuch (go1.19.6 amd64 linux)
+ ^^^^^^^^
If it is not, you can force it before building:
diff --git a/contrib/check-notmuch.sh b/contrib/check-notmuch.sh
deleted file mode 100755
index 6b5beb62..00000000
--- a/contrib/check-notmuch.sh
+++ /dev/null
@@ -1,20 +0,0 @@
-#!/bin/sh
-
-set -e
-
-tmp=$(mktemp -d)
-trap "rm -rf $tmp" EXIT
-
-cat > $tmp/src.go <<EOF
-package main
-
-// #cgo LDFLAGS: -lnotmuch
-// #include <notmuch.h>
-import "C"
-
-func main() {
- C.notmuch_status_to_string(C.NOTMUCH_STATUS_SUCCESS)
-}
-EOF
-
-${GO:-go} build -o $tmp/out $tmp/src.go
diff --git a/contrib/goflags.sh b/contrib/goflags.sh
new file mode 100755
index 00000000..90e4d9ee
--- /dev/null
+++ b/contrib/goflags.sh
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+set -e
+
+tags=
+
+if ${CC:-cc} -x c - -o/dev/null -lnotmuch; then
+ tags="$tags,notmuch"
+fi <<EOF
+#include <notmuch.h>
+
+void main(void) {
+ notmuch_status_to_string(NOTMUCH_STATUS_SUCCESS);
+}
+EOF
+
+if [ -n "$tags" ]; then
+ printf -- '-tags=%s\n' "${tags#,}"
+fi