# compare.sr.ht — build scaffolding (git.sr.ht / sourcehut-dolt style).
#
# Go binary + Go-template SSR live under cmd/ and web/. The CSS is built from
# the shared sourcehut scss partials with sassc; the frontend diff bundle is
# built once with esbuild and vendored into web/static/. Node is a build-time
# dependency only.
SERVICE=compare.sr.ht
BIN=comparesrht
PREFIX?=/usr/local
BINDIR?=$(PREFIX)/bin
SHAREDIR?=$(PREFIX)/share
ASSETS?=/usr/share/sourcehut
STATICDIR?=$(ASSETS)/$(SERVICE)/static
SASSC?=sassc
SASSC_INCLUDE=-I$(ASSETS)/scss
all: build
# Compile the service. Intentionally tolerant: cmd/ does not exist until
# phase 3, so this is a no-op until then.
build:
@if [ -d cmd ]; then go build ./cmd/...; else \
echo "cmd/ not present yet (added in phase 3); nothing to build"; 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 to be
# installed at $(ASSETS)/scss (core.sr.ht `make install`) and scss/main.scss
# to exist (added in phase 2b).
css: web/static/main.min.css
web/static/main.css: scss/main.scss
mkdir -p $(@D)
$(SASSC) $(SASSC_INCLUDE) $< $@
web/static/main.min.css: web/static/main.css
minify -o $@ $<
cp $@ web/static/main.min.$$(sha256sum $@ | cut -c1-8).css
# Frontend diff/tree bundle: built once, output committed to web/static.
# Requires frontend/ (added in phase 2b).
bundle:
cd frontend && npm ci && \
npx esbuild src/app.ts --bundle --minify --format=esm \
--outfile=../web/static/bundle.js
# Local development run against ./config.ini. Fails until cmd/ exists (phase 3).
run-dev:
go run ./cmd/$(BIN)
install: build
mkdir -p $(DESTDIR)$(BINDIR)
go build -o $(DESTDIR)$(BINDIR)/$(BIN) ./cmd/$(BIN)
mkdir -p $(DESTDIR)$(STATICDIR)
install -Dm644 -t $(DESTDIR)$(STATICDIR) web/static/*
.PHONY: all build test css bundle run-dev install