~bigbes/sr-ht-dolt

ref: bfe53099cbeea7c5e8b6b9927ac0b752a24fa10b sr-ht-dolt/Makefile -rw-r--r-- 2.7 KiB
bfe53099 — Eugene Blikh ci: cache Go module and build dirs via cacher 13 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
95
96
97
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

# Pure-Go build (default): no cgo, no ICU/zstd C libraries, statically linkable.
# Two things make it work: the `gms_pure_go` tag swaps go-mysql-server's ICU
# regex for the stdlib regexp (this service never runs the SQL engine), and a
# `replace github.com/dolthub/gozstd => ./third_party/gozstd-purego` directive
# backs dolt's only other hard cgo dependency with a pure-Go klauspost shim.
# To build the cgo variant instead: `make CGO_ENABLED=1 GO_TAGS=`.
GO_TAGS?=gms_pure_go
CGO_ENABLED?=0
export CGO_ENABLED
GO=go
GOBUILD=$(GO) build $(if $(GO_TAGS),-tags "$(GO_TAGS)",)

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 "$(GOBUILD) -o $@ ./cmd/doltsrht"; \
		$(GOBUILD) -o $@ ./cmd/doltsrht; \
	else \
		echo "skip $@: ./cmd/doltsrht not present yet"; \
	fi

doltsrht-migrate:
	@if [ -d ./cmd/doltsrht-migrate ]; then \
		echo "$(GOBUILD) -o $@ ./cmd/doltsrht-migrate"; \
		$(GOBUILD) -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:
	$(GOBUILD) ./...

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