# 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/eclipse.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) # Install ###################################################################### install/files = $(addprefix $(DESTDIR)$(bindir)/,$(go_programs)) install/files += $(DESTDIR)$(sysconfdir)/eclipse/eclipse.yml install/files += $(DESTDIR)$(sysconfdir)/eclipse/actions.d install/files += $(DESTDIR)$(systemdunitdir)/eclipse-httpd.socket install/files += $(DESTDIR)$(systemdunitdir)/eclipse-httpd.service install/files += $(DESTDIR)$(systemdunitdir)/eclipse-trigger.timer install/files += $(DESTDIR)$(systemdunitdir)/eclipse-trigger.service install/files += $(DESTDIR)$(sysusersdir)/eclipse.conf install: $(install/files) uninstall: rm -f -- $(filter-out %.d,$(install/files)) rmdir -p -- $(filter %.d,$(install/files)) || true .PHONY: install uninstall $(addprefix $(DESTDIR)$(bindir)/,$(go_programs)): $(DESTDIR)$(bindir)/%: bin/% install -Dm755 $< $@ $(DESTDIR)$(sysconfdir)/eclipse/eclipse.yml: etc/eclipse.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.conf: etc/sysusers.conf install -Dm644 $< $@