eclipse/Makefile

151 lines
5.2 KiB
Makefile

# 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/sysusers.conf
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 $(<D) && GOOS= GOARCH= go build -o $(abspath $@) $$(sed -En 's,^import "(.*)".*,\1,p' pin.go)
# Install ######################################################################
install/leader/files += $(DESTDIR)$(bindir)/eclipse-gitcache
install/leader/files += $(DESTDIR)$(bindir)/eclipse-httpd
install/leader/files += $(DESTDIR)$(bindir)/eclipse-trigger
install/leader/files += $(DESTDIR)$(sysconfdir)/eclipse/actions.d
install/leader/files += $(DESTDIR)$(sysconfdir)/eclipse/leader.yml
install/leader/files += $(DESTDIR)$(systemdunitdir)/eclipse-httpd.service
install/leader/files += $(DESTDIR)$(systemdunitdir)/eclipse-httpd.socket
install/leader/files += $(DESTDIR)$(systemdunitdir)/eclipse-trigger.service
install/leader/files += $(DESTDIR)$(systemdunitdir)/eclipse-trigger.timer
install/leader/files += $(DESTDIR)$(sysusersdir)/eclipse-leader.conf
install/follower/files += $(DESTDIR)$(bindir)/eclipse-pick
install/follower/files += $(DESTDIR)$(bindir)/eclipse-run
install/follower/files += $(DESTDIR)$(sysconfdir)/eclipse/follower.yml
install/follower/files += $(DESTDIR)$(sysusersdir)/eclipse-follower.conf
install/admin/files += $(DESTDIR)$(bindir)/eclipse-keygen
install: install-leader install-follower install-admin
uninstall: uninstall-leader uninstall-follower uninstall-admin
.PHONY: install uninstall
install-leader: $(install/leader/files)
install-follower: $(install/follower/files)
install-admin: $(install/admin/files)
uninstall-leader uninstall-follower uninstall-admin: uninstall-%:
rm -f -- $(filter-out %.d,$(install/$*/files))
rmdir -p -- $(filter %.d,$(install/$*/files)) || true
.PHONY: install-leader install-follower install-admin
.PHONY: uninstall-leader uninstall-follower uninstall-admin
$(addprefix $(DESTDIR)$(bindir)/,$(go_programs)): $(DESTDIR)$(bindir)/%: bin/%
install -Dm755 $< $@
$(DESTDIR)$(sysconfdir)/eclipse/leader.yml: etc/leader.yml
install -Dm644 $< $@
$(DESTDIR)$(sysconfdir)/eclipse/follower.yml: etc/follower.yml
install -Dm644 $< $@
$(DESTDIR)$(sysconfdir)/eclipse/actions.d:
mkdir -p $@
$(DESTDIR)$(systemdunitdir)/%.socket: etc/%.socket
install -Dm644 $< $@
$(DESTDIR)$(systemdunitdir)/%.timer: etc/%.timer
install -Dm644 $< $@
$(DESTDIR)$(systemdunitdir)/%.service: etc/%.service
install -Dm644 $< $@
$(DESTDIR)$(sysusersdir)/eclipse-leader.conf: etc/sysusers.conf
install -Dm644 $< $@
$(DESTDIR)$(sysusersdir)/eclipse-follower.conf: etc/sysusers.conf
install -Dm644 $< $@