forked from danderson/netboot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.inc
64 lines (56 loc) · 1.33 KB
/
Makefile.inc
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
# -*- mode: makefile-gmake -*-
# Inputs. Invoke from the parent makefile with these options set.
GOARCH:=
BINARY:=
TAG:=
REGISTRY:=
GOCMD:=go
DOCKER_SUDO:=
GITCOMMIT:=
GITBRANCH:=
ifeq ($(GOARCH),)
$(error GOARCH not specified)
endif
ifeq ($(BINARY),)
$(error BINARY not specified)
endif
ifeq ($(TAG),)
$(error TAG not specified)
endif
ifeq ($(REGISTRY),)
$(error REGISTRY not specified)
endif
# Other variables.
GITCOMMIT:=$(shell git describe --dirty --always)
BUILD_DIR:=build/$(GOARCH)/$(BINARY)
DOCKERCMD:=docker
ifneq ($(DOCKER_SUDO),)
DOCKERCMD:=sudo docker
endif
DOCKERFILE_BASE:=alpine:latest
ifneq ($(GOARCH),amd64)
DOCKERFILE_BASE:=$(GOARCH)/alpine:latest
endif
ifeq ($(GOARCH),arm)
DOCKERFILE_BASE:=arm32v6/alpine:latest
endif
ifeq ($(GOARCH),arm64)
DOCKERFILE_BASE:=arm64v8/alpine:latest
endif
.PHONY: push
push: image
$(DOCKERCMD) push $(REGISTRY)/$(BINARY):$(TAG)
.PHONY: image
image: dockerfile binary
$(DOCKERCMD) build -t $(REGISTRY)/$(BINARY):$(TAG) $(BUILD_DIR)
.PHONY: dockerfile
dockerfile: build-dir
perl -pe "s#alpine:latest#$(DOCKERFILE_BASE)#g" ./cmd/$(BINARY)/Dockerfile >$(BUILD_DIR)/Dockerfile
.PHONY: binary
binary: build-dir
CGO_ENABLED=0 GOOS=linux GOARCH=$(GOARCH) GOARM=6 \
$(GOCMD) build -o $(BUILD_DIR)/$(BINARY) \
go.universe.tf/netboot/cmd/$(BINARY)
.PHONY: build-dir
build-dir:
mkdir -p $(BUILD_DIR)