summaryrefslogtreecommitdiff
path: root/Makefile
blob: 867bae9ffcf600192b7b6e10f5b20087a6fc12c4 (plain)
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
# Copyright (C) 2022-2023  Luke Shumaker <lukeshu@lukeshu.com>
#
# SPDX-License-Identifier: GPL-2.0-or-later

SHELL = bash

# main

check:
	go test -race ./...
.PHONY: check

lint: tools/bin/golangci-lint
	tools/bin/golangci-lint run ./...
.PHONY: lint

# generate

generate/files = LICENSE.gpl-2.0.txt

generate: generate-clean
	$(MAKE) $(generate/files)
.PHONY: generate

generate-clean:
	rm -f $(generate/files)
.PHONY: generate-clean

LICENSE.gpl-2.0.txt:
	curl https://www.gnu.org/licenses/old-licenses/gpl-2.0.txt > $@

# tools

tools/bin/%: tools/src/%/pin.go tools/src/%/go.mod
	cd $(<D) && GOOS= GOARCH= go build -o $(abspath $@) $$(sed -En 's,^import "(.*)".*,\1,p' pin.go)

# go mod tidy

goversion = 1.18

go-mod-tidy:
.PHONY: go-mod-tidy

go-mod-tidy: go-mod-tidy/main
go-mod-tidy/main:
	rm -f go.sum
	go mod tidy -go $(goversion) -compat $(goversion)
.PHONY: go-mod-tidy/main

go-mod-tidy: $(patsubst tools/src/%/go.mod,go-mod-tidy/tools/%,$(wildcard tools/src/*/go.mod))
go-mod-tidy/tools/%: tools/src/%/go.mod
	rm -f tools/src/$*/go.sum
	cd tools/src/$* && go mod tidy -go $(goversion) -compat $(goversion)
.PHONY: go-mod-tidy/tools/%

# utilities for managing borrowed tests

borrowed.patch: stock patched
	diff -ruN $^ > $@ || true
stock: FORCE
	rm -rf $@ $@.tmp
	mkdir $@.tmp
	echo module ignore > $@.tmp/go.mod
	set -e; for file in "$$(go env GOROOT)"/src/encoding/json/{*_test.go,tags.go}; do \
	  cp "$$file" $@.tmp/borrowed_$${file##*/}; \
	done
	rm -f $@.tmp/borrowed_fold_test.go
	mv $@.tmp $@
patched: FORCE
	rm -rf $@ $@.tmp
	mkdir $@.tmp
	echo module ignore > $@.tmp/go.mod
	cp $$(git ls-files :*/borrowed_*.go :borrowed_*.go :!borrowed_misc.go :!*/borrowed_misc.go) $@.tmp
	mv $@.tmp $@

.PHONY: FORCE