myip/Makefile

79 lines
2.5 KiB
Makefile
Raw Normal View History

SHELL := /bin/bash
2021-10-16 16:59:05 +00:00
VERSION=$(shell git describe --tags --abbrev=0)
2021-10-15 16:58:49 +00:00
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"
2021-10-15 19:15:49 +00:00
PLATFORMS=darwin linux
2021-10-15 16:58:49 +00:00
ARCHITECTURES=amd64
2021-10-16 21:23:55 +00:00
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
2021-10-15 16:58:49 +00:00
default: build
install:
go mod tidy
go mod download
clean:
rm -rf dist
.PHONY: basic
basic:
2021-10-16 21:23:55 +00:00
go build ${LDFLAGS} -o dist/${BASIC} ${BASIC_PATH}
2021-10-15 08:17:56 +00:00
build:
2021-10-16 21:23:55 +00:00
go build ${LDFLAGS} -o dist/${FULL} ${FULL_PATH}
2021-10-15 16:58:49 +00:00
2021-10-15 19:15:49 +00:00
build-unix:
2021-10-15 16:58:49 +00:00
$(foreach GOOS, $(PLATFORMS), $(foreach GOARCH, $(ARCHITECTURES), \
2021-10-16 21:23:55 +00:00
$(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}
2021-10-15 16:58:49 +00:00
$(foreach GOOS, $(PLATFORMS), $(foreach GOARCH, $(ARCHITECTURES), \
2021-10-16 21:23:55 +00:00
$(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}
2021-10-15 19:15:49 +00:00
build-win:
2021-10-16 21:23:55 +00:00
$(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})
2021-10-15 19:15:49 +00:00
build-mac-m1:
2021-10-16 21:23:55 +00:00
$(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})
2021-10-15 18:09:42 +00:00
build-zip:
cd dist; for f in * ;do if ! [[ $$f =~ "gz" ]] ; then tar -czf $${f}.tar.gz $${f}; fi done
2021-10-15 16:58:49 +00:00
2021-10-15 19:15:49 +00:00
binary: build-unix build-win build-mac-m1
2021-10-15 16:58:49 +00:00
docker:
docker build --target builder -t $(HUB)/$(HUB_PROJECT)/$(PROJ):builder .
docker build \
-t $(HUB)/$(HUB_PROJECT)/$(PROJ):$(VERSION) \
.
2021-10-15 17:20:39 +00:00
docker-push:
2021-10-15 16:58:49 +00:00
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
2021-10-15 17:20:39 +00:00
docker-save:
2021-10-15 18:09:42 +00:00
docker save $(HUB)/$(HUB_PROJECT)/$(PROJ):$(VERSION) | gzip > dist/$(PROJ)-image-$(VERSION)-${BUILD}.tar.gz
2021-10-15 10:57:15 +00:00
2021-10-15 17:20:39 +00:00
2021-10-15 19:15:49 +00:00
release: clean binary build-zip docker docker-save docker-push
2021-10-15 17:20:39 +00:00
2021-10-15 19:15:49 +00:00
.PHONY: build docker release clean all binary install