2024-01-11 00:13:14 +00:00
|
|
|
# Copyright (C) 2023-2024 Umorpha Systems
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
|
2024-01-18 05:49:09 +00:00
|
|
|
# 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 ########################################################################
|
|
|
|
|
2024-01-17 21:00:28 +00:00
|
|
|
all: build
|
|
|
|
.PHONY: all
|
|
|
|
|
|
|
|
go_programs := $(sort $(patsubst cmd/%/,%,$(wildcard cmd/*/)))
|
|
|
|
|
|
|
|
.DELETE_ON_ERROR:
|
|
|
|
.NOTINTERMEDIATE:
|
|
|
|
|
2024-01-18 05:49:09 +00:00
|
|
|
FORCE:
|
|
|
|
.PHONY: FORCE
|
|
|
|
|
2024-01-17 21:00:28 +00:00
|
|
|
# Generate #####################################################################
|
2024-01-11 00:13:14 +00:00
|
|
|
|
|
|
|
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
|
2024-01-17 21:00:28 +00:00
|
|
|
|
|
|
|
# Build ########################################################################
|
|
|
|
|
2024-01-18 05:49:09 +00:00
|
|
|
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
|
2024-01-19 21:02:27 +00:00
|
|
|
build/files += etc/leader.yml
|
|
|
|
build/files += etc/follower.yml
|
2024-01-22 21:31:49 +00:00
|
|
|
build/files += etc/sysusers.conf
|
2024-01-18 05:49:09 +00:00
|
|
|
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
|
2024-01-17 21:00:28 +00:00
|
|
|
|
|
|
|
bin:
|
|
|
|
mkdir $@
|
2024-01-18 05:49:09 +00:00
|
|
|
$(foreach p,$(go_programs),bin/.$p.stamp): bin/.%.stamp: cmd/% generate config.go
|
|
|
|
go build $(build/go-flags) -o $@ ./$<
|
2024-01-17 21:00:28 +00:00
|
|
|
$(foreach p,$(go_programs),bin/$p): bin/%: bin/.%.stamp
|
2024-01-18 05:49:09 +00:00
|
|
|
@$(build/cp-ifchanged)
|
2024-01-17 21:00:28 +00:00
|
|
|
|
2024-01-18 05:49:09 +00:00
|
|
|
.config.go.stamp: .%.stamp: %.in FORCE
|
|
|
|
$(build/varsubst) <$< >$@
|
|
|
|
config.go: %: .%.stamp
|
|
|
|
@$(build/cp-ifchanged)
|
2024-01-17 21:00:28 +00:00
|
|
|
|
2024-01-18 05:49:09 +00:00
|
|
|
etc/.%.stamp: etc/%.in FORCE
|
|
|
|
$(build/varsubst) <$< >$@
|
|
|
|
etc/%: etc/.%.stamp
|
|
|
|
@$(build/cp-ifchanged)
|
2024-01-20 17:52:22 +00:00
|
|
|
|
|
|
|
# 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)
|
2024-01-18 05:49:09 +00:00
|
|
|
|
|
|
|
# Install ######################################################################
|
2024-01-17 21:00:28 +00:00
|
|
|
|
2024-01-20 16:56:45 +00:00
|
|
|
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
|
2024-01-19 21:02:27 +00:00
|
|
|
install/leader/files += $(DESTDIR)$(sysconfdir)/eclipse/leader.yml
|
2024-01-20 16:56:45 +00:00
|
|
|
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
|
2024-01-22 21:31:49 +00:00
|
|
|
install/leader/files += $(DESTDIR)$(sysusersdir)/eclipse-leader.conf
|
2024-01-20 16:56:45 +00:00
|
|
|
|
|
|
|
install/follower/files += $(DESTDIR)$(bindir)/eclipse-pick
|
|
|
|
install/follower/files += $(DESTDIR)$(bindir)/eclipse-run
|
2024-01-19 21:02:27 +00:00
|
|
|
install/follower/files += $(DESTDIR)$(sysconfdir)/eclipse/follower.yml
|
2024-01-22 23:32:57 +00:00
|
|
|
install/follower/files += $(DESTDIR)$(sysusersdir)/eclipse-follower.conf
|
2024-01-20 16:56:45 +00:00
|
|
|
|
|
|
|
install/admin/files += $(DESTDIR)$(bindir)/eclipse-keygen
|
|
|
|
|
|
|
|
install: install-leader install-follower install-admin
|
|
|
|
uninstall: uninstall-leader uninstall-follower uninstall-admin
|
2024-01-17 21:00:28 +00:00
|
|
|
.PHONY: install uninstall
|
|
|
|
|
2024-01-20 16:56:45 +00:00
|
|
|
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
|
|
|
|
|
2024-01-17 21:00:28 +00:00
|
|
|
$(addprefix $(DESTDIR)$(bindir)/,$(go_programs)): $(DESTDIR)$(bindir)/%: bin/%
|
|
|
|
install -Dm755 $< $@
|
2024-01-19 21:02:27 +00:00
|
|
|
$(DESTDIR)$(sysconfdir)/eclipse/leader.yml: etc/leader.yml
|
|
|
|
install -Dm644 $< $@
|
|
|
|
$(DESTDIR)$(sysconfdir)/eclipse/follower.yml: etc/follower.yml
|
2024-01-17 21:00:28 +00:00
|
|
|
install -Dm644 $< $@
|
2024-01-18 05:49:09 +00:00
|
|
|
$(DESTDIR)$(sysconfdir)/eclipse/actions.d:
|
|
|
|
mkdir -p $@
|
|
|
|
|
2024-01-17 21:00:28 +00:00
|
|
|
$(DESTDIR)$(systemdunitdir)/%.socket: etc/%.socket
|
|
|
|
install -Dm644 $< $@
|
|
|
|
$(DESTDIR)$(systemdunitdir)/%.timer: etc/%.timer
|
|
|
|
install -Dm644 $< $@
|
|
|
|
$(DESTDIR)$(systemdunitdir)/%.service: etc/%.service
|
2024-01-18 05:49:09 +00:00
|
|
|
install -Dm644 $< $@
|
2024-01-22 21:31:49 +00:00
|
|
|
$(DESTDIR)$(sysusersdir)/eclipse-leader.conf: etc/sysusers.conf
|
|
|
|
install -Dm644 $< $@
|
|
|
|
$(DESTDIR)$(sysusersdir)/eclipse-follower.conf: etc/sysusers.conf
|
2024-01-18 05:49:09 +00:00
|
|
|
install -Dm644 $< $@
|