From 077b6e540a4f6af8a60df8912c9961d6e34c7747 Mon Sep 17 00:00:00 2001 From: Toshaan Bharvani Date: Sat, 27 Jan 2018 01:17:05 +0100 Subject: [PATCH] build: Add cross building option Added a cross build option using a buildrelease function Signed-off-by: Toshaan Bharvani build: Add gitignore entry for mgmt-* binaries Signed-off-by: Toshaan Bharvani build: Update makefile based upon feed back * rename cross to crossbuild * added crossbuild to PHONY Signed-off-by: Toshaan Bharvani build: Change the order of .PHONY as per the rest of the file Signed-off-by: Toshaan Bharvani --- .gitignore | 1 + Makefile | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index a9b27baa..4c68c7fd 100644 --- a/.gitignore +++ b/.gitignore @@ -9,5 +9,6 @@ tmp/ bindata/*.go mgmt mgmt.static +mgmt-* mgmt.iml rpmbuild/ diff --git a/Makefile b/Makefile index 20189f32..707c8e56 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ # along with this program. If not, see . SHELL = /usr/bin/env bash -.PHONY: all art cleanart version program path deps run race bindata generate build clean test gofmt yamlfmt format docs rpmbuild mkdirs rpm srpm spec tar upload upload-sources upload-srpms upload-rpms copr +.PHONY: all art cleanart version program path deps run race bindata generate build crossbuild clean test gofmt yamlfmt format docs rpmbuild mkdirs rpm srpm spec tar upload upload-sources upload-srpms upload-rpms copr .SILENT: clean bindata GO_FILES := $(shell find . -name '*.go') @@ -40,6 +40,7 @@ REMOTE_PATH = 'pub/alt/$(USERNAME)/$(PROGRAM)' ifneq ($(GOTAGS),) BUILD_FLAGS = -tags '$(GOTAGS)' endif +GOOSARCHES = linux/amd64 linux/ppc64 linux/ppc64le linux/arm64 default: build @@ -114,6 +115,14 @@ $(PROGRAM): $(GO_FILES) @echo "Building: $(PROGRAM), version: $(SVERSION)..." time go build -i -ldflags "-X main.program=$(PROGRAM) -X main.version=$(SVERSION)" -o $(PROGRAM) $(BUILD_FLAGS); +define buildrelease +GOOS=$(1) GOARCH=$(2) go build -ldflags "-X main.program=$(PROGRAM) -X main.version=$(SVERSION) -s -w" -o $(PROGRAM)-$(1)-$(2) $(BUILD_FLAGS); +endef + +crossbuild: + @echo "Building: $(PROGRAM), version: $(SVERSION), arches: $(GOOSARCHES) ..." + $(foreach GOOSARCH,$(GOOSARCHES), $(call buildrelease,$(subst /,,$(dir $(GOOSARCH))),$(notdir $(GOOSARCH)))) + $(PROGRAM).static: $(GO_FILES) @echo "Building: $(PROGRAM).static, version: $(SVERSION)..." go generate