| 1 |
# variables that can be changed by users |
| 2 |
# |
| 3 |
VERSION ?= $(shell git describe --long --abbrev=12 --tags --dirty 2>/dev/null || echo 0.22.0) |
| 4 |
DATE_FMT = +%Y-%m-%d |
| 5 |
ifdef SOURCE_DATE_EPOCH |
| 6 |
DATE ?= $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" "$(DATE_FMT)" 2>/dev/null || \ |
| 7 |
date -u -r "$(SOURCE_DATE_EPOCH)" "$(DATE_FMT)" 2>/dev/null || \ |
| 8 |
date -u "$(DATE_FMT)") |
| 9 |
else |
| 10 |
DATE ?= $(shell date "$(DATE_FMT)") |
| 11 |
endif |
| 12 |
PREFIX ?= /usr/local |
| 13 |
BINDIR ?= $(PREFIX)/bin |
| 14 |
SHAREDIR ?= $(PREFIX)/share/aerc |
| 15 |
LIBEXECDIR ?= $(PREFIX)/libexec/aerc |
| 16 |
MANDIR ?= $(PREFIX)/share/man |
| 17 |
GO ?= go |
| 18 |
INSTALL ?= install |
| 19 |
CP ?= cp |
| 20 |
GOFLAGS ?= $(shell contrib/goflags.sh) |
| 21 |
BUILD_OPTS ?= -trimpath |
| 22 |
GO_LDFLAGS := |
| 23 |
GO_LDFLAGS += -X main.Version=$(VERSION) |
| 24 |
GO_LDFLAGS += -X main.Date=$(DATE) |
| 25 |
GO_LDFLAGS += -X git.sr.ht/~rjarry/aerc/config.shareDir=$(SHAREDIR) |
| 26 |
GO_LDFLAGS += -X git.sr.ht/~rjarry/aerc/config.libexecDir=$(LIBEXECDIR) |
| 27 |
GO_LDFLAGS += $(GO_EXTRA_LDFLAGS) |
| 28 |
CC ?= cc |
| 29 |
CFLAGS ?= -O2 -g |
| 30 |
|
| 31 |
# internal variables used for automatic rules generation with macros |
| 32 |
gosrc = $(shell find * -type f -name '*.go') go.mod go.sum |
| 33 |
man1 = $(subst .scd,,$(notdir $(wildcard doc/*.1.scd))) |
| 34 |
man5 = $(subst .scd,,$(notdir $(wildcard doc/*.5.scd))) |
| 35 |
man7 = $(subst .scd,,$(notdir $(wildcard doc/*.7.scd))) |
| 36 |
docs = $(man1) $(man5) $(man7) |
| 37 |
cfilters = $(subst .c,,$(notdir $(wildcard filters/*.c))) |
| 38 |
filters = $(filter-out filters/vectors filters/test.sh filters/%.c,$(wildcard filters/*)) |
| 39 |
gofumpt_tag = v0.7.0 |
| 40 |
|
| 41 |
# Dependencies are added dynamically to the "all" rule with macros |
| 42 |
.PHONY: all |
| 43 |
all: aerc |
| 44 |
@: |
| 45 |
|
| 46 |
aerc: $(gosrc) |
| 47 |
$(GO) build $(BUILD_OPTS) $(GOFLAGS) -ldflags "$(GO_LDFLAGS)" -o aerc |
| 48 |
|
| 49 |
.PHONY: dev |
| 50 |
dev: |
| 51 |
$(RM) aerc |
| 52 |
$(MAKE) --no-print-directory aerc BUILD_OPTS="-trimpath -race" |
| 53 |
GORACE="log_path=race.log strip_path_prefix=git.sr.ht/~rjarry/aerc/" GOTRACEBACK=crash ./aerc |
| 54 |
|
| 55 |
.PHONY: fmt |
| 56 |
fmt: |
| 57 |
$(GO) run mvdan.cc/gofumpt@$(gofumpt_tag) -w . |
| 58 |
|
| 59 |
.PHONY: lint |
| 60 |
lint: |
| 61 |
@contrib/check-whitespace `git ls-files ':!:filters/vectors' ':!:lib/jwz/testdata'` && \ |
| 62 |
echo white space ok. |
| 63 |
@contrib/check-docs && echo docs ok. |
| 64 |
@$(GO) run mvdan.cc/gofumpt@$(gofumpt_tag) -d . | grep ^ \ |
| 65 |
&& echo The above files need to be formatted, please run make fmt && exit 1 \ |
| 66 |
|| echo all files formatted. |
| 67 |
codespell * |
| 68 |
$(GO) run github.com/golangci/golangci-lint/v2/cmd/[email protected] run \ |
| 69 |
$$(echo $(GOFLAGS) | sed s/-tags=/--build-tags=/) |
| 70 |
$(GO) run $(GOFLAGS) contrib/linters.go ./... |
| 71 |
|
| 72 |
.PHONY: vulncheck |
| 73 |
vulncheck: |
| 74 |
$(GO) run golang.org/x/vuln/cmd/govulncheck@latest ./... |
| 75 |
|
| 76 |
.PHONY: tests |
| 77 |
tests: $(cfilters) |
| 78 |
$(GO) test $(GOFLAGS) ./... |
| 79 |
filters/test.sh |
| 80 |
|
| 81 |
.PHONY: debug |
| 82 |
debug: aerc.debug |
| 83 |
@echo 'Run `./aerc.debug` and use this command in another terminal to attach a debugger:' |
| 84 |
@echo ' dlv attach $$(pidof aerc.debug)' |
| 85 |
|
| 86 |
aerc.debug: $(gosrc) |
| 87 |
$(GO) build $(subst -trimpath,,$(GOFLAGS)) -gcflags=all="-N -l" -ldflags="$(GO_LDFLAGS)" -o aerc.debug |
| 88 |
|
| 89 |
.PHONY: doc |
| 90 |
doc: $(docs) |
| 91 |
@: |
| 92 |
|
| 93 |
.PHONY: clean |
| 94 |
clean: |
| 95 |
$(RM) $(docs) aerc $(cfilters) |
| 96 |
|
| 97 |
# Dependencies are added dynamically to the "install" rule with macros |
| 98 |
.PHONY: install |
| 99 |
install: |
| 100 |
@: |
| 101 |
|
| 102 |
.PHONY: checkinstall |
| 103 |
checkinstall: |
| 104 |
$(DESTDIR)$(BINDIR)/aerc -v |
| 105 |
for m in $(man1); do test -e $(DESTDIR)$(MANDIR)/man1/$$m || exit; done |
| 106 |
for m in $(man5); do test -e $(DESTDIR)$(MANDIR)/man5/$$m || exit; done |
| 107 |
for m in $(man7); do test -e $(DESTDIR)$(MANDIR)/man7/$$m || exit; done |
| 108 |
|
| 109 |
.PHONY: uninstall |
| 110 |
uninstall: |
| 111 |
@echo $(installed) | tr ' ' '\n' | sort -ru | while read -r f; do \ |
| 112 |
echo rm -f $$f && rm -f $$f || exit; \ |
| 113 |
done |
| 114 |
@echo $(dirs) | tr ' ' '\n' | sort -ru | while read -r d; do \ |
| 115 |
if [ -d $$d ] && ! ls -Aq1 $$d | grep -q .; then \ |
| 116 |
echo rmdir $$d && rmdir $$d || exit; \ |
| 117 |
fi; \ |
| 118 |
done |
| 119 |
|
| 120 |
.PHONY: gitconfig |
| 121 |
gitconfig: |
| 122 |
git config format.subjectPrefix "PATCH aerc" |
| 123 |
git config sendemail.to "~rjarry/[email protected]" |
| 124 |
git config format.notes true |
| 125 |
git config notes.rewriteRef refs/notes/commits |
| 126 |
git config notes.rewriteMode concatenate |
| 127 |
@mkdir -p .git/hooks |
| 128 |
@rm -f .git/hooks/commit-msg* |
| 129 |
ln -s ../../contrib/commit-msg .git/hooks/commit-msg |
| 130 |
@rm -f .git/hooks/sendemail-validate* |
| 131 |
@if grep -q GIT_SENDEMAIL_FILE_COUNTER `git --exec-path`/git-send-email 2>/dev/null; then \ |
| 132 |
set -xe; \ |
| 133 |
ln -s ../../contrib/sendemail-validate .git/hooks/sendemail-validate && \ |
| 134 |
git config sendemail.validate true; \ |
| 135 |
fi |
| 136 |
|
| 137 |
.PHONY: check-patches |
| 138 |
check-patches: |
| 139 |
@contrib/check-patches origin/master.. |
| 140 |
|
| 141 |
.PHONY: validate |
| 142 |
validate: CFLAGS = -Wall -Wextra -Wconversion -Werror -Wformat-security -Wstack-protector -Wpedantic -Wmissing-prototypes |
| 143 |
validate: all tests lint check-patches |
| 144 |
|
| 145 |
# Generate build and install rules for one man page |
| 146 |
# |
| 147 |
# $1: man page name (e.g: aerc.1) |
| 148 |
# |
| 149 |
define install_man |
| 150 |
$1: doc/$1.scd |
| 151 |
scdoc < $$< > $$@ |
| 152 |
|
| 153 |
$1_section = $$(subst .,,$$(suffix $1)) |
| 154 |
$1_install_dir = $$(DESTDIR)$$(MANDIR)/man$$($1_section) |
| 155 |
dirs += $$($1_install_dir) |
| 156 |
installed += $$($1_install_dir)/$1 |
| 157 |
|
| 158 |
$$($1_install_dir)/$1: $1 | $$($1_install_dir) |
| 159 |
$$(INSTALL) -m644 $$< $$@ |
| 160 |
|
| 161 |
all: $1 |
| 162 |
install: $$($1_install_dir)/$1 |
| 163 |
endef |
| 164 |
|
| 165 |
# Generate build and install rules for one filter |
| 166 |
# |
| 167 |
# $1: filter source path or name |
| 168 |
# |
| 169 |
define install_filter |
| 170 |
ifneq ($(wildcard filters/$1.c),) |
| 171 |
$1: filters/$1.c |
| 172 |
$$(CC) $$(CFLAGS) $$(LDFLAGS) -o $$@ $$< |
| 173 |
|
| 174 |
all: $1 |
| 175 |
endif |
| 176 |
|
| 177 |
$1_install_dir = $$(DESTDIR)$$(LIBEXECDIR)/filters |
| 178 |
dirs += $$($1_install_dir) |
| 179 |
installed += $$($1_install_dir)/$$(notdir $1) |
| 180 |
|
| 181 |
$$($1_install_dir)/$$(notdir $1): $1 | $$($1_install_dir) |
| 182 |
$$(CP) -af $$< $$@ |
| 183 |
|
| 184 |
install: $$($1_install_dir)/$$(notdir $1) |
| 185 |
endef |
| 186 |
|
| 187 |
# Generate install rules for any file |
| 188 |
# |
| 189 |
# $1: source file |
| 190 |
# $2: mode |
| 191 |
# $3: target dir |
| 192 |
# |
| 193 |
define install_file |
| 194 |
dirs += $3 |
| 195 |
installed += $3/$$(notdir $1) |
| 196 |
|
| 197 |
$3/$$(notdir $1): $1 | $3 |
| 198 |
$$(INSTALL) -m$2 $$< $$@ |
| 199 |
|
| 200 |
install: $3/$$(notdir $1) |
| 201 |
endef |
| 202 |
|
| 203 |
# Call macros to generate build and install rules |
| 204 |
$(foreach m,$(docs),\ |
| 205 |
$(eval $(call install_man,$m))) |
| 206 |
$(foreach f,$(filters) $(cfilters),\ |
| 207 |
$(eval $(call install_filter,$f))) |
| 208 |
$(foreach f,$(wildcard config/*.conf),\ |
| 209 |
$(eval $(call install_file,$f,644,$(DESTDIR)$(SHAREDIR)))) |
| 210 |
$(foreach s,$(wildcard stylesets/*),\ |
| 211 |
$(eval $(call install_file,$s,644,$(DESTDIR)$(SHAREDIR)/stylesets))) |
| 212 |
$(foreach t,$(wildcard templates/*),\ |
| 213 |
$(eval $(call install_file,$t,644,$(DESTDIR)$(SHAREDIR)/templates))) |
| 214 |
$(eval $(call install_file,contrib/aerc.desktop,644,$(DESTDIR)$(PREFIX)/share/applications)) |
| 215 |
$(eval $(call install_file,contrib/aerc.svg,644,$(DESTDIR)$(PREFIX)/share/icons/hicolor/scalable/apps)) |
| 216 |
$(eval $(call install_file,aerc,755,$(DESTDIR)$(BINDIR))) |
| 217 |
$(eval $(call install_file,contrib/carddav-query,755,$(DESTDIR)$(BINDIR))) |
| 218 |
|
| 219 |
$(sort $(dirs)): |
| 220 |
mkdir -p $@ |
| 221 |
|
| 222 |
.DELETE_ON_ERROR: |