3 # © 2023–2024 Lady [@ Lady’s Computer].
5 # This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
6 # If a copy of the M·P·L was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
19 # This Makefile requires rsync 3 or newer.
21 ifneq ($(wildcard .rsync-filter),)
22 RSYNCFILTER := .rsync-filter
24 RSYNCOPTS := --checksum --compress --del --links --omit-dir-times --prune-empty-dirs --recursive --times --verbose
29 CLIENTCHARSET := $(if $(shell $(ICONV) -l | $(GREP) -i 'utf-8-mac' - || true),utf-8-mac,utf-8)
31 SERVERCHARSET := utf-8
32 SERVERPATH := $(notdir $(abspath .))
36 ifneq ($(wildcard $(BUILDTARGET)),)
37 override buildtime := $(shell stat -f '%m' $(BUILDTARGET))
40 override committime := $(shell $(GIT) $(GITOPTS) log -1 --format='%ct' | $(AWK) '{print $$NF}' || true)
41 ifneq ($(committime),)
42 override gitstatus := $(shell $(GIT) $(GITOPTS) status --porcelain)
47 @$(ECHO) 'Error: Unable to get commit time of most recent commit!' >&2
51 @$(ECHO) 'Error: The website has not been built yet!' >&2
52 @$(ECHO) 'Run `make´ before syncing.' >&2
55 @if $(TEST) '$(committime)' -gt '$(buildtime)'; then $(ECHO) 'Error: A commit was made after the last build!' >&2; $(ECHO) 'Run `make´ before syncing.' >&2; false; fi
57 ensure-branch-up-to-date:
59 @$(ECHO) 'Error: Unable to get commit time of most recent commit!' >&2
62 $(GIT)$(if $(GITOPTS), $(GITOPTS),) fetch
63 @if ! $(GIT) $(GITOPTS) merge-base --is-ancestor @{u} HEAD; then $(ECHO) 'Error: This branch is currently out‐of‐date!' >&2; $(ECHO) 'Pull in changes with `$(GIT)$(if $(GITOPTS), $(GITOPTS),) pull´ before syncing.' >&2; false; fi
67 @$(ECHO) 'Error: There are uncommitted changes!' >&2
68 @$(ECHO) 'Commit changes and run `make´ before syncing.' >&2
72 dry-sync: ensure-clean$(if $(GITFORCE),, ensure-branch-up-to-date) ensure-build
73 cd $(DESTDIR) && $(RSYNC) --dry-run$(if $(RSYNCFILTER), --filter='. $(abspath $(RSYNCFILTER))',)$(if $(and $(CLIENTCHARSET),$(SERVERCHARSET),$(filter-out $(CLIENTCHARSET),$(SERVERCHARSET))), --iconv='$(CLIENTCHARSET)$(comma)$(SERVERCHARSET)',) $(RSYNCOPTS) . $(SERVER):$(SERVERPATH)
75 sync: ensure-clean$(if $(GITFORCE),, ensure-branch-up-to-date) ensure-build
76 $(GIT)$(if $(GITOPTS), $(GITOPTS),) push$(if $(GITFORCE), --force,)
77 cd $(DESTDIR) && $(RSYNC)$(if $(RSYNCFILTER), --filter='. $(abspath $(RSYNCFILTER))',)$(if $(and $(CLIENTCHARSET),$(SERVERCHARSET),$(filter-out $(CLIENTCHARSET),$(SERVERCHARSET))), --iconv='$(CLIENTCHARSET)$(comma)$(SERVERCHARSET)',) $(RSYNCOPTS) . $(SERVER):$(SERVERPATH)
79 .PHONY: dry-sync ensure-branch-up-to-date ensure-build ensure-clean sync;