]> Lady’s Gitweb - Yseme/blob - GNUmakefile
8baaf0f9190e01eae193120e5646f5b14eea24b1
[Yseme] / GNUmakefile
1 SHELL = /bin/sh
2
3 # © 2023–2024 Lady [@ Lady’s Computer].
4 #
5 # This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
6 # If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
7
8 BUILDTARGET := .grass
9 DESTDIR := .
10
11 CLIENTCHARSET := utf-8-mac
12 SERVER := computer
13 SERVERCHARSET := utf-8
14 SERVERPATH := $(notdir $(abspath .))
15
16 AWK := awk
17 ECHO := echo
18 SED := sed
19 TEST := test
20
21 GIT := git
22 GITFORCE :=
23 GITOPTS :=
24
25 # This Makefile requires rsync 3 or newer.
26 RSYNC := rsync
27 ifneq ($(wildcard .rsync-filter),)
28 RSYNCFILTER := .rsync-filter
29 endif
30 RSYNCOPTS := --checksum --compress --del --links --omit-dir-times --prune-empty-dirs --recursive --times --verbose
31
32 override comma := ,
33
34 ifneq ($(wildcard $(BUILDTARGET)),)
35 override buildtime := $(shell stat -f '%m' $(BUILDTARGET))
36 endif
37
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)
41 endif
42
43 ensure-build:
44 ifeq ($(committime),)
45 @$(ECHO) 'Error: Unable to get commit time of most recent commit!' >&2
46 @false
47 endif
48 ifeq ($(buildtime),)
49 @$(ECHO) 'Error: The website has not been built yet!' >&2
50 @$(ECHO) 'Run `make´ before syncing.' >&2
51 @false
52 endif
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
54
55 ensure-branch-up-to-date:
56 ifeq ($(committime),)
57 @$(ECHO) 'Error: Unable to get commit time of most recent commit!' >&2
58 @false
59 endif
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
62
63 ensure-clean:
64 ifneq ($(gitstatus),)
65 @$(ECHO) 'Error: There are uncommitted changes!' >&2
66 @$(ECHO) 'Commit changes and run `make´ before syncing.' >&2
67 @false
68 endif
69
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)
72
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)
76
77 .PHONY: dry-sync ensure-branch-up-to-date ensure-build ensure-clean sync;
This page took 0.041495 seconds and 3 git commands to generate.