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/>.
11 CLIENTCHARSET := utf-8-mac
13 SERVERCHARSET := utf-8
14 SERVERPATH := $(notdir $(abspath .))
25 # This Makefile requires rsync 3 or newer.
27 ifneq ($(wildcard .rsync-filter),)
28 RSYNCFILTER := .rsync-filter
30 RSYNCOPTS := --checksum --compress --del --links --omit-dir-times --prune-empty-dirs --recursive --times --verbose
34 ifneq ($(wildcard $(BUILDTARGET)),)
35 override buildtime := $(shell stat -f '%m' $(BUILDTARGET))
38 override committime := $(shell $(GIT) $(GITOPTS) log -1 --format='%ct' | $(AWK) '{print $$NF}' || true)
39 ifneq ($(committime),)
40 override gitstatus := $(shell $(GIT) $(GITOPTS) status --porcelain)
45 @$(ECHO) 'Error: Unable to get commit time of most recent commit!' >&2
49 @$(ECHO) 'Error: The website has not been built yet!' >&2
50 @$(ECHO) 'Run `make´ before syncing.' >&2
53 @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
55 ensure-branch-up-to-date:
57 @$(ECHO) 'Error: Unable to get commit time of most recent commit!' >&2
60 $(GIT)$(if $(GITOPTS), $(GITOPTS),) fetch
61 @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
65 @$(ECHO) 'Error: There are uncommitted changes!' >&2
66 @$(ECHO) 'Commit changes and run `make´ before syncing.' >&2
70 dry-sync: ensure-clean$(if $(GITFORCE),, ensure-branch-up-to-date) ensure-build
71 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)
73 sync: ensure-clean$(if $(GITFORCE),, ensure-branch-up-to-date) ensure-build
74 $(GIT)$(if $(GITOPTS), $(GITOPTS),) push$(if $(GITFORCE), --force,)
75 cd $(DESTDIR) && $(RSYNC)$(if $(RSYNCFILTER), --filter='. $(abspath $(RSYNCFILTER))',)$(if $(and $(CLIENTCHARSET),$(SERVERCHARSET),$(filter-out $(CLIENTCHARSET),$(SERVERCHARSET))), --iconv='$(CLIENTCHARSET)$(comma)$(SERVERCHARSET)',) $(RSYNCOPTS) . $(SERVER):$(SERVERPATH)
77 .PHONY: dry-sync ensure-branch-up-to-date ensure-build ensure-clean sync;