build: Add cross building option
Added a cross build option using a buildrelease function Signed-off-by: Toshaan Bharvani <toshaan@vantosh.com> build: Add gitignore entry for mgmt-* binaries Signed-off-by: Toshaan Bharvani <toshaan@vantosh.com> build: Update makefile based upon feed back * rename cross to crossbuild * added crossbuild to PHONY Signed-off-by: Toshaan Bharvani <toshaan@vantosh.com> build: Change the order of .PHONY as per the rest of the file Signed-off-by: Toshaan Bharvani <toshaan@vantosh.com>
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -9,5 +9,6 @@ tmp/
|
|||||||
bindata/*.go
|
bindata/*.go
|
||||||
mgmt
|
mgmt
|
||||||
mgmt.static
|
mgmt.static
|
||||||
|
mgmt-*
|
||||||
mgmt.iml
|
mgmt.iml
|
||||||
rpmbuild/
|
rpmbuild/
|
||||||
|
|||||||
11
Makefile
11
Makefile
@@ -16,7 +16,7 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
SHELL = /usr/bin/env bash
|
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
|
.SILENT: clean bindata
|
||||||
|
|
||||||
GO_FILES := $(shell find . -name '*.go')
|
GO_FILES := $(shell find . -name '*.go')
|
||||||
@@ -40,6 +40,7 @@ REMOTE_PATH = 'pub/alt/$(USERNAME)/$(PROGRAM)'
|
|||||||
ifneq ($(GOTAGS),)
|
ifneq ($(GOTAGS),)
|
||||||
BUILD_FLAGS = -tags '$(GOTAGS)'
|
BUILD_FLAGS = -tags '$(GOTAGS)'
|
||||||
endif
|
endif
|
||||||
|
GOOSARCHES = linux/amd64 linux/ppc64 linux/ppc64le linux/arm64
|
||||||
|
|
||||||
default: build
|
default: build
|
||||||
|
|
||||||
@@ -114,6 +115,14 @@ $(PROGRAM): $(GO_FILES)
|
|||||||
@echo "Building: $(PROGRAM), version: $(SVERSION)..."
|
@echo "Building: $(PROGRAM), version: $(SVERSION)..."
|
||||||
time go build -i -ldflags "-X main.program=$(PROGRAM) -X main.version=$(SVERSION)" -o $(PROGRAM) $(BUILD_FLAGS);
|
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)
|
$(PROGRAM).static: $(GO_FILES)
|
||||||
@echo "Building: $(PROGRAM).static, version: $(SVERSION)..."
|
@echo "Building: $(PROGRAM).static, version: $(SVERSION)..."
|
||||||
go generate
|
go generate
|
||||||
|
|||||||
Reference in New Issue
Block a user