Use GOOS and GOARCH rather than PLATFORM

Also fix all-* rules to work.
master
Tim Hockin 2019-01-28 11:22:08 -08:00
parent 805dd38cb5
commit d5b61a98de
1 changed files with 27 additions and 16 deletions

View File

@ -21,12 +21,6 @@ PKG := github.com/thockin/go-build-template
# Where to push the docker image.
REGISTRY ?= thockin
# Which platform to build - see $(ALL_PLATFORMS) for options.
PLATFORM ?= linux/amd64
OS := $(firstword $(subst /, ,$(PLATFORM)))
ARCH := $(lastword $(subst /, ,$(PLATFORM)))
# This version-strategy uses git tags to set the version string
VERSION := $(shell git describe --tags --always --dirty)
#
@ -41,19 +35,23 @@ SRC_DIRS := cmd pkg # directories which hold app source (not vendored)
ALL_PLATFORMS := linux/amd64 linux/arm linux/arm64 linux/ppc64le
# Used internally. Users should pass GOOS and/or GOARCH.
OS := $(if $(GOOS),$(GOOS),$(shell go env GOOS))
ARCH := $(if $(GOARCH),$(GOARCH),$(shell go env GOARCH))
# Set default base image dynamically for each arch
# TODO: make these all consistent and tagged.
ifeq ($(ARCH),amd64)
BASEIMAGE?=alpine:3.8
BASEIMAGE ?= alpine:3.8
endif
ifeq ($(ARCH),arm)
BASEIMAGE?=armel/busybox
BASEIMAGE ?= armel/busybox
endif
ifeq ($(ARCH),arm64)
BASEIMAGE?=aarch64/busybox
BASEIMAGE ?= aarch64/busybox
endif
ifeq ($(ARCH),ppc64le)
BASEIMAGE?=ppc64le/busybox
BASEIMAGE ?= ppc64le/busybox
endif
IMAGE := $(REGISTRY)/$(BIN)
@ -66,20 +64,32 @@ BUILD_IMAGE ?= golang:1.11-alpine
# If you want to build AND push all containers, see the 'all-push' rule.
all: build
# For the following OS/ARCH expansions, we transform OS/ARCH into OS_ARCH
# because make pattern rules don't match with embedded '/' characters.
build-%:
@$(MAKE) --no-print-directory ARCH=$* build
@$(MAKE) build \
--no-print-directory \
GOOS=$(firstword $(subst _, ,$*)) \
GOARCH=$(lastword $(subst _, ,$*))
container-%:
@$(MAKE) --no-print-directory ARCH=$* container
@$(MAKE) container \
--no-print-directory \
GOOS=$(firstword $(subst _, ,$*)) \
GOARCH=$(lastword $(subst _, ,$*))
push-%:
@$(MAKE) --no-print-directory ARCH=$* push
@$(MAKE) push \
--no-print-directory \
GOOS=$(firstword $(subst _, ,$*)) \
GOARCH=$(lastword $(subst _, ,$*))
all-build: $(addprefix build-, $(ALL_PLATFORMS))
all-build: $(addprefix build-, $(subst /,_, $(ALL_PLATFORMS)))
all-container: $(addprefix container-, $(ALL_PLATFORMS))
all-container: $(addprefix container-, $(subst /,_, $(ALL_PLATFORMS)))
all-push: $(addprefix push-, $(ALL_PLATFORMS))
all-push: $(addprefix push-, $(subst /,_, $(ALL_PLATFORMS)))
build: bin/$(OS)_$(ARCH)/$(BIN)
@ -147,6 +157,7 @@ shell: $(BUILD_DIRS)
$(BUILD_IMAGE) \
/bin/sh $(CMD)
# Used to track state in hidden files.
DOTFILE_IMAGE = $(subst /,_,$(IMAGE))-$(TAG)
container: .container-$(DOTFILE_IMAGE) say_container_name