# 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)