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
PREFIX?=/usr/local
BINDIR?=$(PREFIX)/bin
LIBDIR?=$(PREFIX)/lib
SHAREDIR?=$(PREFIX)/share
ASSETS?=/usr/share/sourcehut
SERVICE=dolt.sr.ht
STATICDIR=$(SHAREDIR)/sourcehut/static/$(SERVICE)
MIGRATIONDIR=$(SHAREDIR)/sourcehut/migrations/$(SERVICE)
SASSC?=sassc
SASSC_INCLUDE=-I$(ASSETS)/scss/
MINIFY?=minify
BINARIES=\
doltsrht \
doltsrht-migrate
# Default target builds the Go binaries only. CSS (all-share) is deliberately
# kept off the default path because sassc/minify are not always installed on
# dev machines; run `make css` explicitly to build stylesheets.
all: all-bin
all-bin: $(BINARIES)
all-share: static/main.min.css
css: all-share
# Build each binary if its cmd package exists yet. The cmd/ packages land in
# Phase 3; until then these targets are no-ops rather than hard failures.
doltsrht:
@if [ -d ./cmd/doltsrht ]; then \
echo "go build -o $@ ./cmd/doltsrht"; \
go build -o $@ ./cmd/doltsrht; \
else \
echo "skip $@: ./cmd/doltsrht not present yet"; \
fi
doltsrht-migrate:
@if [ -d ./cmd/doltsrht-migrate ]; then \
echo "go build -o $@ ./cmd/doltsrht-migrate"; \
go build -o $@ ./cmd/doltsrht-migrate; \
else \
echo "skip $@: ./cmd/doltsrht-migrate not present yet"; \
fi
# Compile every buildable package; used as the CI build gate.
build:
go build ./...
install: install-bin install-share
install-bin: all-bin
mkdir -p $(BINDIR)
for bin in $(BINARIES); do \
if [ -x $$bin ]; then install -Dm755 $$bin $(BINDIR)/; fi; \
done
install-share:
mkdir -p $(STATICDIR)
mkdir -p $(MIGRATIONDIR)
install -Dm644 schema.sql $(SHAREDIR)/sourcehut/$(SERVICE).sql
install -Dm644 migrations/*.sql $(MIGRATIONDIR)
if [ -d static ]; then install -Dm644 static/*.css static/*.svg $(STATICDIR) 2>/dev/null || true; fi
clean: clean-bin clean-share
clean-bin:
rm -f $(BINARIES)
clean-share:
rm -f static/main.min.css static/main.css static/main.min.*.css
.PHONY: all all-bin all-share css build install install-bin install-share
.PHONY: clean clean-bin clean-share $(BINARIES)
static/main.css: scss/main.scss
mkdir -p $(@D)
$(SASSC) $(SASSC_INCLUDE) $< $@
static/main.min.css: static/main.css
$(MINIFY) -o $@ $<
cp $@ $(@D)/main.min.$$(sha256sum $@ | cut -c1-8).css