From d6358be909917d46d14e3e9dca8c17fa1b9f469d Mon Sep 17 00:00:00 2001 From: Steffen Fritz Date: Sat, 26 Oct 2024 01:12:59 +0200 Subject: [PATCH] Modified Makefile --- Makefile | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/Makefile b/Makefile index 8664f64..5bab707 100755 --- a/Makefile +++ b/Makefile @@ -1,11 +1,8 @@ ROOT_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) - BINARY=mxcheck - VERSION=v1.6.1 - -BUILD=`git rev-parse --short HEAD` +BUILD=$(shell git rev-parse --short HEAD) PLATFORMS=darwin linux windows ARCHITECTURES=amd64 arm64 @@ -17,25 +14,20 @@ all: clean build_all build: go build ${BLDFLAGS} ${LDFLAGS} -o ${BINARY} -build_all: - $(foreach GOOS, $(PLATFORMS),\ - $(foreach GOARCH, $(ARCHITECTURES), $(shell export GOOS=$(GOOS); export GOARCH=$(GOARCH); go build $(BLDFLAGS) $(LDFLAGS) -v -o $(BINARY)-$(GOOS)-$(GOARCH)))) - mv mxcheck-darwin-amd64 mxcheck && tar cvfz mxcheck_macos_amd64_$(VERSION).tar.gz mxcheck - rm mxcheck - mv mxcheck-darwin-arm64 mxcheck && tar cvfz mxcheck_macos_arm64_$(VERSION).tar.gz mxcheck - rm mxcheck - mv mxcheck-linux-amd64 mxcheck && tar cvfz mxcheck_linux_amd64_$(VERSION).tar.gz mxcheck - rm mxcheck - mv mxcheck-linux-arm64 mxcheck && tar cvfz mxcheck_linux_arm64_$(VERSION).tar.gz mxcheck - rm mxcheck - mv mxcheck-windows-amd64 mxcheck.exe && tar cvfz mxcheck_win_amd64_$(VERSION).tar.gz mxcheck.exe - rm mxcheck.exe - mv mxcheck-windows-arm64 mxcheck.exe && tar cvfz mxcheck_win_arm64_$(VERSION).tar.gz mxcheck.exe - rm mxcheck.exe +build_all: $(foreach GOOS,$(PLATFORMS),$(foreach GOARCH,$(ARCHITECTURES),build_$(GOOS)_$(GOARCH))) + +define build_template +build_$(1)_$(2): + GOOS=$(1) GOARCH=$(2) go build $(BLDFLAGS) $(LDFLAGS) -o $(BINARY)-$(1)-$(2) + tar cvfz $(BINARY)_$(1)_$(2)_$(VERSION).tar.gz $(if $(findstring windows,$(1)),$(BINARY)-$(1)-$(2).exe,$(BINARY)-$(1)-$(2)) + rm $(if $(findstring windows,$(1)),$(BINARY)-$(1)-$(2).exe,$(BINARY)-$(1)-$(2)) +endef + +$(foreach GOOS,$(PLATFORMS),$(foreach GOARCH,$(ARCHITECTURES),$(eval $(call build_template,$(GOOS),$(GOARCH))))) clean: - rm -f '${BINARY}-linux' - rm -f '${BINARY}-darwin' - rm -f '${BINARY}-windows' + rm -f ${BINARY}-* + rm -f *.tar.gz + +.PHONY: clean build build_all $(foreach GOOS,$(PLATFORMS),$(foreach GOARCH,$(ARCHITECTURES),build_$(GOOS)_$(GOARCH))) -.PHONY: clean build build_all all