forked from submariner-io/submariner
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
140 lines (110 loc) · 5.72 KB
/
Makefile
File metadata and controls
140 lines (110 loc) · 5.72 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
BASE_BRANCH ?= devel
export BASE_BRANCH
# Running in Dapper
ifneq (,$(DAPPER_HOST_ARCH))
IMAGES ?= submariner-gateway submariner-route-agent submariner-globalnet
export LOCAL_COMPONENTS := submariner-gateway submariner-globalnet submariner-routeagent
MULTIARCH_IMAGES ?= $(IMAGES)
PLATFORMS ?= linux/amd64,linux/arm64
RESTART ?= all
ifneq (,$(filter ovn,$(USING)))
SETTINGS ?= $(DAPPER_SOURCE)/.shipyard.e2e.ovn.yml
else
SETTINGS ?= $(DAPPER_SOURCE)/.shipyard.e2e.yml
endif
include $(SHIPYARD_DIR)/Makefile.inc
GO ?= go
TARGETS := $(shell ls -p scripts | grep -v -e /)
GIT_COMMIT_HASH := $(shell git show -s --format='format:%H')
GIT_COMMIT_DATE := $(shell git show -s --format='format:%cI')
VERSIONS_MODULE := github.com/submariner-io/submariner/pkg/versions
export LDFLAGS = -X $(VERSIONS_MODULE).version=$(VERSION) \
-X $(VERSIONS_MODULE).gitCommitHash=$(GIT_COMMIT_HASH) \
-X $(VERSIONS_MODULE).gitCommitDate=$(GIT_COMMIT_DATE)
ifneq (,$(filter external-net,$(_using)))
export TESTDIR = test/external
override export PLUGIN = scripts/e2e/external/hook
endif
# When cross-building, we need to map Go architectures and operating systems to Docker buildx platforms:
# Docker buildx platform | Fedora support? | Go
# --------------------------------------------------
# linux/amd64 | Yes (x86_64) | linux/amd64
# linux/arm64 | Yes (aarch64) | linux/arm64
# linux/riscv64 | No | linux/riscv64
# linux/ppc64le | Yes (ppc64le) | linux/ppc64le
# linux/s390x | Yes (s390x) | linux/s390x
# linux/386 | No | linux/386
# linux/arm/v7 | Yes (armv7hl) | linux/arm
# linux/arm/v6 | No | N/A
#
# References: https://github.com/golang/go/blob/master/src/go/build/syslist.go
gotodockerarch = $(patsubst arm,arm/v7,$(1))
dockertogoarch = $(patsubst arm/v7,arm,$(1))
# Targets to make
deploy: images
golangci-lint: pkg/natdiscovery/proto/natdiscovery.pb.go
unit: pkg/natdiscovery/proto/natdiscovery.pb.go
%.pb.go: %.proto bin/protoc-gen-go
PATH="$(CURDIR)/bin:$$PATH" protoc --go_out=$$(go env GOPATH)/src $<
bin/protoc-gen-go:
mkdir -p $(@D)
GOFLAGS="" GOBIN="$(CURDIR)/bin" go install google.golang.org/protobuf/cmd/protoc-gen-go@$(shell awk '/google.golang.org\/protobuf/ {print $$2}' go.mod)
basepkg = github.com/submariner-io/submariner
# This lists non-test Go files inside each directory corresponding
# to the first argument and any Go-determined dependencies
godeps = $(filter-out %_test.go,$(wildcard $(patsubst %,%/*.go,$(1) $(shell go list -json $(1) | jq -r '.Deps[] | select(startswith("$(basepkg)/")) | sub("$(basepkg)"; ".")'))))
# This lists embedded files in Go dependencies
embeddeddeps = $(wildcard $(shell grep //go:embed $(call godeps,$(1)) | sed -E 'sX[^/]+.go:.*//go:embed XX'))
# This lists all dependencies from a given package
pkgdeps = $(call godeps,$(1)) $(call embeddeddeps,$(1))
# Generated YAMLs
GENERATED_YAMLS := deploy/crds/submariner.io_clusterglobalegressips.yaml \
deploy/crds/submariner.io_clusters.yaml \
deploy/crds/submariner.io_endpoints.yaml \
deploy/crds/submariner.io_gatewayroutes.yaml \
deploy/crds/submariner.io_gateways.yaml \
deploy/crds/submariner.io_globalegressips.yaml \
deploy/crds/submariner.io_globalingressips.yaml \
deploy/crds/submariner.io_nongatewayroutes.yaml \
deploy/crds/submariner.io_routeagents.yaml
generatedyamls: $(GENERATED_YAMLS)
CONTROLLER_GEN = $(shell $(GO) -C tools tool -n sigs.k8s.io/controller-tools/cmd/controller-gen)
CRD_OPTIONS ?= "crd:crdVersions=v1"
$(GENERATED_YAMLS): pkg/apis/submariner.io/v1/types.go
$(CONTROLLER_GEN) $(CRD_OPTIONS) paths="./pkg/apis/..." output:crd:artifacts:config=deploy/crds
test -f $@
# natdiscovery.pb.go must be listed explicitly because it might not exist when Make evaluates pkgdeps
bin/%/submariner-gateway: $(call pkgdeps,.) pkg/natdiscovery/proto/natdiscovery.pb.go
GOARCH=$(call dockertogoarch,$(patsubst bin/linux/%/,%,$(dir $@))) ${SCRIPTS_DIR}/compile.sh $@ .
bin/%/submariner-route-agent: $(call pkgdeps,./pkg/routeagent_driver)
GOARCH=$(call dockertogoarch,$(patsubst bin/linux/%/,%,$(dir $@))) ${SCRIPTS_DIR}/compile.sh $@ ./pkg/routeagent_driver
bin/%/submariner-globalnet: $(call pkgdeps,./pkg/globalnet)
GOARCH=$(call dockertogoarch,$(patsubst bin/linux/%/,%,$(dir $@))) ${SCRIPTS_DIR}/compile.sh $@ ./pkg/globalnet
bin/%/await-node-ready: $(call pkgdeps,./pkg/await_node_ready)
GOARCH=$(call dockertogoarch,$(patsubst bin/linux/%/,%,$(dir $@))) ${SCRIPTS_DIR}/compile.sh $@ ./pkg/await_node_ready
nullstring :=
space := $(nullstring) # end of the line
comma := ,
# Single-architecture only for now (we need to support manifests in Shipyard)
# This can be overridden to build for other supported architectures; the reference is the Go architecture,
# so "make images ARCHES=arm" will build a linux/arm/v7 image
ARCHES ?= amd64
BINARIES = submariner-gateway submariner-route-agent submariner-globalnet await-node-ready
ARCH_BINARIES := $(foreach arch,$(subst $(comma),$(space),$(ARCHES)),$(foreach binary,$(BINARIES),bin/linux/$(call gotodockerarch,$(arch))/$(binary)))
build: $(ARCH_BINARIES)
LICHEN = $(shell $(GO) -C tools tool -n github.com/uw-labs/lichen)
licensecheck: export BUILD_DEBUG = true
licensecheck: $(ARCH_BINARIES)
$(LICHEN) -c .lichen.yaml $(ARCH_BINARIES)
$(TARGETS):
./scripts/$@
.PHONY: $(TARGETS) build licensecheck
# Not running in Dapper
else
Makefile.dapper:
@echo Downloading $@
@curl -sfLO https://raw.githubusercontent.com/submariner-io/shipyard/$(BASE_BRANCH)/$@
include Makefile.dapper
endif
# Disable rebuilding Makefile
Makefile Makefile.inc: ;