-
Notifications
You must be signed in to change notification settings - Fork 32
/
Makefile
119 lines (89 loc) · 2.32 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# Copyright (c) 2019 Zededa, Inc.
# SPDX-License-Identifier: Apache-2.0
.PHONY: all build build-docker fmt clean lint test vet image
IMG ?= lfedge/adam
HASH ?= $(shell git show --format=%T -s)
GOVER ?= 1.20.10-alpine3.18
# check if we should append a dirty tag
DIRTY ?= $(shell git status --short)
ifneq ($(DIRTY),)
TAG = $(HASH)-dirty
else
TAG = $(HASH)
endif
# BUILDARCH is the host architecture
# ARCH is the target architecture
# we need to keep track of them separately
BUILDARCH ?= $(shell uname -m)
BUILDOS ?= $(shell uname -s | tr A-Z a-z)
# canonicalized names for host architecture
ifeq ($(BUILDARCH),aarch64)
BUILDARCH=arm64
endif
ifeq ($(BUILDARCH),x86_64)
BUILDARCH=amd64
endif
# unless otherwise set, I am building for my own architecture, i.e. not cross-compiling
# and for my OS
ARCH ?= $(BUILDARCH)
OS ?= $(BUILDOS)
# canonicalized names for target architecture
ifeq ($(ARCH),aarch64)
override ARCH=arm64
endif
ifeq ($(ARCH),x86_64)
override ARCH=amd64
endif
BINDIR := bin
BIN := adam
LOCALBIN := $(BINDIR)/$(BIN)-$(OS)-$(ARCH)
LOCALLINK := $(BINDIR)/$(BIN)
GOENV ?= GOOS=$(OS) GOARCH=$(ARCH) GO111MODULE=on CGO_ENABLED=0
GO ?= $(GOENV)
ifneq ($(BUILD),local)
GO = docker run --rm -v $(PWD):/app -w /app golang:$(GOVER) env $(GOENV)
endif
GO_FILES := $(shell find . -type f -name '*.go')
all: build
$(BINDIR):
mkdir -p $@
build: bin $(LOCALBIN) $(LOCALLINK)
$(LOCALBIN):
$(GO) go build -o $@ main.go
$(LOCALLINK):
@if [ "$(OS)" = "$(BUILDOS)" -a "$(ARCH)" = "$(BUILDARCH)" -a ! -L "$@" -a ! -e "$@" ]; then ln -s $(notdir $(LOCALBIN)) $@; fi
build-docker:
docker build -t $(IMG) .
build-docker-local: build
docker build -t $(IMG) -f Dockerfile.local .
image-local: build-docker-local
image: build-docker
ci: gitstat tag build fmt-check lint test vet image
gitstat:
@git status
tag:
@echo $(TAG)
fmt:
$(GO) gofmt -w ${GO_FILES}
fmt-check:
if [ -n "$$($(GO) gofmt -l ${GO_FILES})" ]; then \
$(GO) gofmt -s -e -d ${GO_FILES}; \
exit 1; \
fi
lint: linttools
$(GO) gometalinter --disable-all --enable=golint --vendor ./...
vet:
$(GO) go vet ./...
test:
$(GO) go test ./...
linttools:
ifeq ($(BUILD),local)
ifeq (, $(shell which golint))
$(GO) go get -u golang.org/x/lint/golint
endif
ifeq (, $(shell which gometalinter))
$(GO) go get -u github.com/alecthomas/gometalinter
endif
endif
clean:
rm -rf run/*