~bigbes/sr-ht-spec

ref: 4ad8525764dbfb0f7f03eae106b4436cc44040cc sr-ht-spec/Makefile -rw-r--r-- 3.4 KiB
4ad85257 — bigbes feat(cmd): reindex a space when a push lands 27 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# spec.sr.ht — build scaffolding (compare.sr.ht / sourcehut-dolt style).
#
# One Go binary plus a brant migration wrapper, both under cmd/. The CSS is
# built from the shared sourcehut scss partials with sassc; there is no
# frontend bundle — the prose differ renders server-side.

SERVICE=spec.sr.ht
BIN=specsrht
MIGRATE_BIN=specsrht-migrate

PREFIX?=/usr/local
BINDIR?=$(PREFIX)/bin
# ASSETS is the RUNTIME lookup root: specsrht-migrate resolves migrations and
# the schema under [sr.ht]assets (default /usr/share/sourcehut), NOT under
# PREFIX. Deriving these from PREFIX instead would install to
# /usr/local/share/... on a default build while the binary kept looking in
# /usr/share/sourcehut — the two would only agree at PREFIX=/usr. Keep every
# installed data path anchored to ASSETS so a default `make install` works.
ASSETS?=/usr/share/sourcehut
STATICDIR?=$(ASSETS)/$(SERVICE)/static
MIGRATIONDIR?=$(ASSETS)/migrations/$(SERVICE)
SCHEMAFILE?=$(ASSETS)/$(SERVICE).sql

SASSC?=sassc
SASSC_INCLUDE=-I$(ASSETS)/scss

all: build

# Compile the binaries. cmd/ lands in Phase 1's Wave B, so until then each
# target skips rather than failing — a red default target during the build-out
# trains everyone to ignore it.
build: $(BIN) $(MIGRATE_BIN)

$(BIN):
	@if [ -d ./cmd/$(BIN) ]; then \
		echo "go build -o $@ ./cmd/$(BIN)"; \
		go build -o $@ ./cmd/$(BIN); \
	else \
		echo "skip $@: ./cmd/$(BIN) not present yet"; \
	fi

$(MIGRATE_BIN):
	@if [ -d ./cmd/$(MIGRATE_BIN) ]; then \
		echo "go build -o $@ ./cmd/$(MIGRATE_BIN)"; \
		go build -o $@ ./cmd/$(MIGRATE_BIN); \
	else \
		echo "skip $@: ./cmd/$(MIGRATE_BIN) not present yet"; \
	fi

test:
	go test ./...

# CSS pipeline: sassc -> minify -> content-hashed filename. The running service
# globs web/static/main.min.*.css at startup, so the hash in the name is the
# cache-busting version. Requires the shared scss partials installed at
# $(ASSETS)/scss (core.sr.ht `make install`) and scss/main.scss to exist.
# Produces exactly ONE web/static/main.min.<sha256[:8]>.css; old ones and the
# intermediate main.css are removed.
css:
	mkdir -p web/static
	rm -f web/static/main.css web/static/main.min.*.css
	$(SASSC) $(SASSC_INCLUDE) scss/main.scss web/static/main.css
	minify -o web/static/main.min.css web/static/main.css
	mv web/static/main.min.css \
		web/static/main.min.$$(sha256sum web/static/main.min.css | cut -c1-8).css
	rm -f web/static/main.css

# Local development run. Requires a ./config.ini in the working directory (or
# ../config.ini, /etc/sr.ht/config.ini) carrying the instance's shared
# [sr.ht]/[webhooks] keys plus a [spec.sr.ht] section.
run-dev: build
	./$(BIN) -b localhost:5091

# schema.sql is installed as $(SCHEMAFILE) because `specsrht-migrate init`
# applies it wholesale on a fresh database; without it, init works from a
# checkout and fails on a packaged install.
install: build
	install -Dm755 $(BIN) $(DESTDIR)$(BINDIR)/$(BIN)
	install -Dm755 $(MIGRATE_BIN) $(DESTDIR)$(BINDIR)/$(MIGRATE_BIN)
	mkdir -p $(DESTDIR)$(MIGRATIONDIR)
	install -Dm644 -t $(DESTDIR)$(MIGRATIONDIR) migrations/*.sql
	install -Dm644 schema.sql $(DESTDIR)$(SCHEMAFILE)
	@if [ -d web/static ]; then \
		mkdir -p $(DESTDIR)$(STATICDIR); \
		install -Dm644 -t $(DESTDIR)$(STATICDIR) web/static/*; \
	else \
		echo "skip static assets: web/static not present yet"; \
	fi

clean:
	rm -f $(BIN) $(MIGRATE_BIN)
	rm -f web/static/main.css web/static/main.min.*.css

.PHONY: all build test css run-dev install clean $(BIN) $(MIGRATE_BIN)