Skip to content

Commit b3cac3d

Browse files
committed
build: top-level Makefile
Create top-level Makefile build targets to install extra build tools. Signed-off-by: Shachar Sharon <[email protected]>
1 parent beb5242 commit b3cac3d

File tree

2 files changed

+92
-5
lines changed

2 files changed

+92
-5
lines changed

.gitignore

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
2-
# Test binary, build with `go test -c`
1+
# test binary, build with `go test -c`
32
*.test
43

5-
# Output of the go coverage tool, specifically when used with LiteIDE
6-
*.out
7-
84
# editor and IDE paraphernalia
95
*.swp
106
*.swo
@@ -19,3 +15,9 @@ devel.mk
1915

2016
# local GOBIN for build tools
2117
/.bin
18+
19+
# output bin directory
20+
/bin
21+
22+
# external vendor sources
23+
/vendor

Makefile

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Allow developer to override some defaults
2+
-include devel.mk
3+
4+
# Version
5+
VERSION?=0.0.1
6+
7+
# Commit info
8+
COMMIT_ID=$(shell git describe --abbrev=40 --always --dirty=+ 2>/dev/null)
9+
GIT_VERSION=$(shell git describe --match='v[0-9]*.[0-9].[0-9]' 2>/dev/null || echo "(unset)")
10+
11+
GO_CMD:=go
12+
GOFMT_CMD:=gofmt
13+
BUILDAH_CMD:=buildah
14+
YAMLLINT_CMD:=yamllint
15+
16+
# Image URL to use all building/pushing image targets
17+
TAG?=latest
18+
IMG?=quay.io/samba.org/samba-metrics:$(TAG)
19+
20+
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
21+
ifeq (,$(shell $(GO_CMD) env GOBIN))
22+
GOBIN=$(shell $(GO_CMD) env GOPATH)/bin
23+
else
24+
GOBIN=$(shell $(GO_CMD) env GOBIN)
25+
endif
26+
27+
# Get current GOARCH
28+
GOARCH?=$(shell $(GO_CMD) env GOARCH)
29+
30+
# Local (alternative) GOBIN for auxiliary build tools
31+
GOBIN_ALT:=$(CURDIR)/.bin
32+
33+
# Common link-flags for go programs
34+
GOLDFLAGS="-X main.Version=$(GIT_VERSION) -X main.CommitID=$(COMMIT_ID)"
35+
36+
37+
CONTAINER_BUILD_OPTS?=
38+
CONTAINER_CMD?=
39+
ifeq ($(CONTAINER_CMD),)
40+
CONTAINER_CMD:=$(shell docker version >/dev/null 2>&1 && echo docker)
41+
endif
42+
ifeq ($(CONTAINER_CMD),)
43+
CONTAINER_CMD:=$(shell podman version >/dev/null 2>&1 && echo podman)
44+
endif
45+
# handle the case where podman is present but is (defaulting) to remote and is
46+
# not not functioning correctly. Example: mac platform but not 'podman machine'
47+
# vms are ready
48+
ifeq ($(CONTAINER_CMD),)
49+
CONTAINER_CMD:=$(shell podman --version >/dev/null 2>&1 && echo podman)
50+
ifneq ($(CONTAINER_CMD),)
51+
$(warning podman detected but 'podman version' failed. \
52+
this may mean your podman is set up for remote use, but is not working)
53+
endif
54+
endif
55+
56+
# Helper function to re-format yamls using helper script
57+
define yamls_reformat
58+
YQ=$(YQ) $(CURDIR)/hack/yq-fixup-yamls.sh $(1)
59+
endef
60+
61+
62+
# Find or download auxiliary build tools
63+
.PHONY: build-tools golangci-lint yq
64+
build-tools: golangci-lint yq
65+
66+
define installtool
67+
@GOBIN=$(GOBIN_ALT) GO_CMD=$(GO_CMD) $(CURDIR)/hack/install-tools.sh $(1)
68+
endef
69+
70+
71+
GOLANGCI_LINT=$(GOBIN_ALT)/golangci-lint
72+
golangci-lint:
73+
ifeq (, $(shell command -v $(GOLANGCI_LINT) ;))
74+
@$(call installtool, --golangci-lint)
75+
@echo "golangci-lint installed in $(GOBIN_ALT)"
76+
endif
77+
78+
YQ=$(GOBIN_ALT)/yq
79+
yq:
80+
ifeq (, $(shell command -v $(YQ) ;))
81+
@$(call installtool, --yq)
82+
@echo "yq installed in $(YQ)"
83+
endif
84+
85+

0 commit comments

Comments
 (0)