-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathMakefile
79 lines (70 loc) · 2.49 KB
/
Makefile
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
VERSION:=$(shell git describe --exact-match --tags 2>/dev/null | sed 's/^v//')
ifeq ($(VERSION),)
VERSION:=$(shell git rev-list -1 HEAD)
endif
export CGO_ENABLED=0
LDFLAGS=-X main.VERSION=$(VERSION) -s -w
GCFLAGS=
ALL_SOURCES:=$(wildcard *.go)
SOURCES:=$(filter-out %_test.go,$(ALL_SOURCES))
TEST_SOURCES:=$(wildcard *_test.go)
BINARIES=
define compile
dist/cidr-merger-$(1)-$(or $(3),$(2))$(if $(filter windows,$(1)),.exe): $$(SOURCES)
mkdir -p $$(@D)
GOOS=$(1) GOARCH=$(2) $(4) go build -ldflags "$$(LDFLAGS)" -gcflags "$$(GCFLAGS)" -o $$@
BINARIES+=dist/cidr-merger-$(1)-$(or $(3),$(2))$(if $(filter windows,$(1)),.exe)
endef
dist/cidr-merger: $(SOURCES)
mkdir -p $(@D)
go build -ldflags "$(LDFLAGS)" -gcflags "$(GCFLAGS)" -o $@
$(eval $(call compile,darwin,amd64))
$(eval $(call compile,darwin,arm64))
$(eval $(call compile,dragonfly,amd64))
$(eval $(call compile,freebsd,386))
$(eval $(call compile,freebsd,amd64))
$(eval $(call compile,linux,386))
$(eval $(call compile,linux,amd64))
$(eval $(call compile,linux,arm,arm5,GOARM=5))
$(eval $(call compile,linux,arm,arm6,GOARM=6))
$(eval $(call compile,linux,arm,arm7,GOARM=7))
$(eval $(call compile,linux,arm,arm8))
$(eval $(call compile,linux,arm64))
$(eval $(call compile,linux,mips,mips-hard,GOMIPS=hardfloat))
$(eval $(call compile,linux,mips,mips-soft,GOMIPS=softfloat))
$(eval $(call compile,linux,mipsle,mipsle-hard,GOMIPS=hardfloat))
$(eval $(call compile,linux,mipsle,mipsle-soft,GOMIPS=softfloat))
$(eval $(call compile,linux,mips64,mips64-hard,GOMIPS64=hardfloat))
$(eval $(call compile,linux,mips64,mips64-soft,GOMIPS64=softfloat))
$(eval $(call compile,linux,mips64le,mips64le-hard,GOMIPS64=hardfloat))
$(eval $(call compile,linux,mips64le,mips64le-soft,GOMIPS64=softfloat))
$(eval $(call compile,netbsd,386))
$(eval $(call compile,netbsd,amd64))
$(eval $(call compile,openbsd,386))
$(eval $(call compile,openbsd,amd64))
$(eval $(call compile,windows,386))
$(eval $(call compile,windows,amd64))
all: $(BINARIES)
.PHONY: all
define TEST_SCRIPT
set -e
test_dir=target/test
mkdir -p "$$test_dir"
for i in tests/*.in; do
name="$${i##*/}"
echo "running $$name"
base="$$test_dir/$${name%.in}"
"$$BIN" --range "$$i" >"$$base.range"
"$$BIN" --cidr "$$i" >"$$base.cidr"
"$$BIN" --range "$$base.cidr" >"$$base.cidr.range"
diff -u "$$base.range" "$$base.cidr.range"
done
endef
test: export TEST_SCRIPT:=$(TEST_SCRIPT)
test: dist/cidr-merger $(TEST_SOURCES)
go test
BIN='$<' eval "$$TEST_SCRIPT"
.PHONY: test
clean:
rm -rf dist
.PHONY: clean