# Copyright (C) 2023-2024 Umorpha Systems # SPDX-License-Identifier: AGPL-3.0-or-later # User config ################################################################## # GNU standard https://www.gnu.org/prep/standards/standards.html DESTDIR ?= prefix ?= /usr/local exec_prefix ?= $(prefix) bindir ?= $(exec_prefix)/bin libdir ?= $(exec_prefix)/lib sysconfdir ?= $(prefix)/etc localstatedir ?= $(prefix)/var runstatedir ?= $(localstatedir)/run # Not quite GNU standard systemdunitdir ?= $(libdir)/systemd/system sysusersdir ?= $(libdir)/sysusers.d # Intro ######################################################################## all: build .PHONY: all go_programs := $(sort $(patsubst cmd/%/,%,$(wildcard cmd/*/))) .DELETE_ON_ERROR: .NOTINTERMEDIATE: FORCE: .PHONY: FORCE # Generate ##################################################################### generate/files = COPYING.txt COPYING.txt: curl https://www.gnu.org/licenses/agpl-3.0.txt >$@ generate: $(generate/files) generate-clean: rm -f -- $(generate/files) .PHONY: generate generate-clean # Build ######################################################################## build/go-flags = -trimpath -tags=libsqlite3 $(if $(wildcard .git),,-buildvcs=false) build/cfgvars = bindir localstatedir runstatedir sysconfdir build/etc-sources build/etc-sources = $(sort $(filter-out $(build/files),$(wildcard etc/*))) build/varsubst = sed $(foreach v,$(build/cfgvars), -e 's|@$v@|$($v)|g' ) build/cp-ifchanged = if cmp -s $< $@; then echo $@: already up to date; else PS4=; set -x; cp -f $< $@; fi build/files = $(addprefix bin/,$(go_programs)) build/files += config.go build/files += etc/leader.yml build/files += etc/follower.yml build/files += etc/eclipse-httpd.service build/files += etc/eclipse-httpd.socket build/files += etc/eclipse-trigger.service build: $(build/files) clean: rm -f -- $(filter-out bin/%,$(build/files)) .*.stamp etc/.*.stamp rm -rf bin .PHONY: build clean bin: mkdir $@ $(foreach p,$(go_programs),bin/.$p.stamp): bin/.%.stamp: cmd/% generate config.go go build $(build/go-flags) -o $@ ./$< $(foreach p,$(go_programs),bin/$p): bin/%: bin/.%.stamp @$(build/cp-ifchanged) .config.go.stamp: .%.stamp: %.in FORCE $(build/varsubst) <$< >$@ config.go: %: .%.stamp @$(build/cp-ifchanged) etc/.%.stamp: etc/%.in FORCE $(build/varsubst) <$< >$@ etc/%: etc/.%.stamp @$(build/cp-ifchanged) # QA ########################################################################### check: config.go go test $(build/go-flags) ./... .PHONY: check lint: config.go build-aux/bin/golangci-lint build-aux/bin/golangci-lint run ./... .PHONY: lint build-aux/bin: mkdir $@ build-aux/bin/%: build-aux/src/%/go.mod build-aux/src/%/pin.go | build-aux/bin cd $(