-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
100 lines (74 loc) · 2.96 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# Makefile for squircy, a proper IRC bot.
# https://code.dopame.me/veonik/squircy3
SUBPACKAGES := cli config event irc plugin vm
PLUGINS ?= $(patsubst plugins/%,%,$(wildcard plugins/*))
SOURCES := $(wildcard cmd/*/*.go) $(wildcard $(patsubst %,%/*.go,$(SUBPACKAGES)))
GENERATOR_SOURCES := $(wildcard cmd/squircy/defconf/*)
OUTPUT_BASE := out
RACE ?= -race
TEST_ARGS ?= -count 1
# Include PLUGIN_TYPE=linked in the command-line when invoking make to link
# extra plugins directly in the main binary rather than generating shared object files.
PLUGIN_TYPE ?= shared
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
GOARM ?= $(shell go env GOARM)
CC ?= $(shell go env CC)
PACKR ?= $(shell which packr2)
SQUIRCY_TARGET := $(OUTPUT_BASE)/squircy
SQUIRCY_DIST := $(SQUIRCY_TARGET)_$(GOOS)_$(GOARCH)$(GOARM)
PLUGIN_DIST := $(patsubst %,$(OUTPUT_BASE)/%_$(GOOS)_$(GOARCH)$(GOARM).so,$(PLUGINS))
ifeq ($(PLUGIN_TYPE),linked)
PLUGIN_TARGETS :=
EXTRA_TAGS := -tags linked_plugins
DIST_TARGETS := $(SQUIRCY_DIST)
LINKED_PLUGINS_FILE := cmd/squircy/plugins_linked.go
else
PLUGIN_TARGETS := $(patsubst %,$(OUTPUT_BASE)/%.so,$(PLUGINS))
EXTRA_TAGS :=
DIST_TARGETS := $(SQUIRCY_DIST) $(PLUGIN_DIST)
LINKED_PLUGINS_FILE := cmd/squircy/plugins_shared.go
endif
TESTDATA_NODEMODS_TARGET := testdata/node_modules
SQUIRCY3_VERSION := $(if $(shell test -d .git && echo "1"),$(shell git describe --always --tags),SNAPSHOT)
.PHONY: all build run plugins clean test dist
all: build plugins
clean:
cd cmd/squircy && \
$(PACKR) clean
rm -rf $(OUTPUT_BASE)
build: $(SQUIRCY_TARGET)
plugins: $(PLUGIN_TARGETS)
dist: $(DIST_TARGETS)
run: build
$(SQUIRCY_TARGET)
test: $(TESTDATA_NODEMODS_TARGET)
go test -tags netgo $(RACE) $(TEST_ARGS) ./...
$(TESTDATA_NODEMODS_TARGET):
cd testdata && \
yarn install
.SECONDEXPANSION:
$(PLUGIN_TARGETS): $(OUTPUT_BASE)/%.so: $$(wildcard plugins/%/*) $(SOURCES)
go build -tags netgo $(RACE) -o $@ -buildmode=plugin plugins/$*/plugin/*.go
.SECONDEXPANSION:
$(PLUGIN_DIST): $(OUTPUT_BASE)/%_$(GOOS)_$(GOARCH)$(GOARM).so: $$(wildcard plugins/%/*) $(SOURCES)
GOOS=$(GOOS) GOARCH=$(GOARCH) GOARM=$(GOARM) CC=$(CC) CGO_ENABLED=1 \
go build -tags netgo $(EXTRA_TAGS) \
-ldflags "-s -w -X main.Version=$(SQUIRCY3_VERSION)" \
-o $@ -buildmode=plugin plugins/$*/plugin/*.go
$(SQUIRCY_TARGET): $(SOURCES)
go build -tags netgo $(EXTRA_TAGS) $(RACE) -ldflags "-X main.Version=$(SQUIRCY3_VERSION)-dev" \
-o $@ cmd/squircy/main*.go cmd/squircy/repl.go $(LINKED_PLUGINS_FILE)
$(SQUIRCY_DIST): $(OUTPUT_BASE) $(SOURCES)
cd cmd/squircy/defconf && \
yarn install
cd cmd/squircy && \
$(PACKR)
GOOS=$(GOOS) GOARCH=$(GOARCH) GOARM=$(GOARM) CC=$(CC) CGO_ENABLED=1 \
go build -tags netgo $(EXTRA_TAGS) \
-ldflags "-s -w -X main.Version=$(SQUIRCY3_VERSION)" \
-o $@ cmd/squircy/main*.go cmd/squircy/repl.go $(LINKED_PLUGINS_FILE)
upx $@
$(OUTPUT_BASE):
mkdir -p $(OUTPUT_BASE)
$(SOURCES): $(OUTPUT_BASE)