Skip to content

Commit

Permalink
Modified Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
steffenfritz committed Oct 25, 2024
1 parent 3e6bb8b commit d6358be
Showing 1 changed file with 15 additions and 23 deletions.
38 changes: 15 additions & 23 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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

0 comments on commit d6358be

Please sign in to comment.