]> Lady’s Gitweb - Yseme/blob - GNUmakefile
Only use utf-8-mac when iconv supports it
[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 M·P·L was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
7
8 AWK := awk
9 ECHO := echo
10 GREP := grep
11 ICONV := iconv
12 SED := sed
13 TEST := test
14
15 GIT := git
16 GITFORCE :=
17 GITOPTS :=
18
19 # This Makefile requires rsync 3 or newer.
20 RSYNC := rsync
21 ifneq ($(wildcard .rsync-filter),)
22 RSYNCFILTER := .rsync-filter
23 endif
24 RSYNCOPTS := --checksum --compress --del --links --omit-dir-times --prune-empty-dirs --recursive --times --verbose
25
26 BUILDTARGET := .grass
27 DESTDIR := .
28
29 CLIENTCHARSET := $(if $(shell $(ICONV) -l | $(GREP) -i 'utf-8-mac' - || true),utf-8-mac,utf-8)
30 SERVER := computer
31 SERVERCHARSET := utf-8
32 SERVERPATH := $(notdir $(abspath .))
33
34 override comma := ,
35
36 ifneq ($(wildcard $(BUILDTARGET)),)
37 override buildtime := $(shell stat -f '%m' $(BUILDTARGET))
38 endif
39
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)
43 endif
44
45 ensure-build:
46 ifeq ($(committime),)
47 @$(ECHO) 'Error: Unable to get commit time of most recent commit!' >&2
48 @false
49 endif
50 ifeq ($(buildtime),)
51 @$(ECHO) 'Error: The website has not been built yet!' >&2
52 @$(ECHO) 'Run `make´ before syncing.' >&2
53 @false
54 endif
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
56
57 ensure-branch-up-to-date:
58 ifeq ($(committime),)
59 @$(ECHO) 'Error: Unable to get commit time of most recent commit!' >&2
60 @false
61 endif
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
64
65 ensure-clean:
66 ifneq ($(gitstatus),)
67 @$(ECHO) 'Error: There are uncommitted changes!' >&2
68 @$(ECHO) 'Commit changes and run `make´ before syncing.' >&2
69 @false
70 endif
71
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)
74
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)
78
79 .PHONY: dry-sync ensure-branch-up-to-date ensure-build ensure-clean sync;
This page took 0.055556 seconds and 5 git commands to generate.