SHELL := /bin/bash VERSION=$(shell git describe --tags --abbrev=0) BUILD=$(shell git rev-parse --short HEAD) PROJ := $(shell basename "$(PWD)") HUB=hub.kumoly.io HUB_PROJECT=tools LDFLAGS=-ldflags "-X main.Version=${VERSION} -X main.Build=${BUILD} -w" PLATFORMS=darwin linux ARCHITECTURES=amd64 BASIC_PATH=cmd/basic/main.go BASIC=myip-basic FULL_PATH=cmd/myip/main.go FULL=myip GUI_PATH=cmd/myip/main.go GUI=cmd/myip/main.go default: build install: go mod tidy go mod download clean: rm -rf dist .PHONY: basic basic: go build ${LDFLAGS} -o dist/${BASIC} ${BASIC_PATH} build: go build ${LDFLAGS} -o dist/${FULL} ${FULL_PATH} build-unix: $(foreach GOOS, $(PLATFORMS), $(foreach GOARCH, $(ARCHITECTURES), \ $(shell export GOOS=$(GOOS); export GOARCH=$(GOARCH); go build ${LDFLAGS} -o dist/${FULL} ${FULL_PATH}) \ $(shell cd dist; tar -czf ${FULL}_$(VERSION)_$(GOOS)_$(GOARCH).tar.gz ${FULL}) \ )) rm dist/${FULL} $(foreach GOOS, $(PLATFORMS), $(foreach GOARCH, $(ARCHITECTURES), \ $(shell export GOOS=$(GOOS); export GOARCH=$(GOARCH); go build ${LDFLAGS} -o dist/${BASIC} ${BASIC_PATH}) \ $(shell cd dist; tar -czf ${BASIC}_$(VERSION)_$(GOOS)_$(GOARCH).tar.gz ${BASIC}) \ )) rm dist/${BASIC} build-win: $(shell export GOOS=windows; export GOARCH=amd64; go build ${LDFLAGS} -o dist/$(PROJ)_$(VERSION)_windows_amd64/${FULL}.exe ${FULL_PATH}) $(shell export GOOS=windows; export GOARCH=amd64; go build ${LDFLAGS} -o dist/$(PROJ)-basic_$(VERSION)_windows_amd64/${BASIC}.exe ${BASIC_PATH}) build-mac-m1: $(shell export GOOS=darwin; export GOARCH=arm64; go build ${LDFLAGS} -o dist/$(PROJ)_$(VERSION)_darwin_arm64/${FULL} ${FULL_PATH}) $(shell export GOOS=darwin; export GOARCH=arm64; go build ${LDFLAGS} -o dist/$(PROJ)-basic_$(VERSION)_darwin_arm64/${BASIC} ${BASIC_PATH}) build-zip: cd dist; for f in * ;do if ! [[ $$f =~ "gz" ]] ; then tar -czf $${f}.tar.gz $${f}; fi done binary: build-unix build-win build-mac-m1 docker: docker build --target builder -t $(HUB)/$(HUB_PROJECT)/$(PROJ):builder . docker build \ -t $(HUB)/$(HUB_PROJECT)/$(PROJ):$(VERSION) \ . docker-push: docker tag $(HUB)/$(HUB_PROJECT)/$(PROJ):$(VERSION) $(HUB)/$(HUB_PROJECT)/$(PROJ):latest docker push $(HUB)/$(HUB_PROJECT)/$(PROJ):$(VERSION) docker push $(HUB)/$(HUB_PROJECT)/$(PROJ):latest docker-save: docker save $(HUB)/$(HUB_PROJECT)/$(PROJ):$(VERSION) | gzip > dist/$(PROJ)-image-$(VERSION)-${BUILD}.tar.gz release: clean binary build-zip docker docker-save docker-push .PHONY: build docker release clean all binary install