|
| 1 | +# must be valid semver 2.0 version |
| 2 | +ifndef $(VERSION) |
| 3 | +LATEST_TAG=$(shell git describe --tags $(git rev-list --tags --max-count=1)) |
| 4 | +VERSION=$(LATEST_TAG:v%=%) |
| 5 | +endif |
| 6 | +EXECUTABLE=wurl |
| 7 | + |
| 8 | +GO?=vgo |
| 9 | +LDFLAGS+=-X main.Version=$(VERSION) |
| 10 | + |
| 11 | +.PHONY: build install uninstall github-release build |
| 12 | +.DEFAULT_GOAL := build |
| 13 | + |
| 14 | +build: |
| 15 | + @echo "Building for current OS/architecture" |
| 16 | + $(GO) build -o ./$(EXECUTABLE) -v -ldflags="$(LDFLAGS)" |
| 17 | + |
| 18 | +PREFIX ?= /usr/local |
| 19 | +DESTDIR= |
| 20 | +BIN=$(DESTDIR)$(PREFIX)/bin/ |
| 21 | + |
| 22 | +install: |
| 23 | + install -D ./$(EXECUTABLE) $(BIN) |
| 24 | + |
| 25 | +uninstall: |
| 26 | + rm $(install_dir)/$(EXECUTABLE) |
| 27 | + |
| 28 | +BUILD_DIR=build |
| 29 | + |
| 30 | +temp_dir_name=$(EXECUTABLE)_$(1)_$(2)_v$(3) |
| 31 | +build_os_arch=GOOS=$(1) GOARCH=$(2) $(GO) build -o $(3) -v -ldflags="$(LDFLAGS)" |
| 32 | +pack_zip=zip -r -j $(1).zip $(1) && rm -rf $(1) |
| 33 | +pack_tgz=tar -C $(1) -cpzf $(1).tar.gz ./ && rm -rf $(1) |
| 34 | + |
| 35 | +define build_github_release |
| 36 | +@echo "Building release package for OS $(1), arch $(2)" |
| 37 | +$(eval temp_build_dir=$(BUILD_DIR)/$(call temp_dir_name,$(1),$(2),$(VERSION))) |
| 38 | +@mkdir -p $(temp_build_dir) |
| 39 | +$(eval ifeq ($(1),windows) |
| 40 | + temp_executable=$(temp_build_dir)/$(EXECUTABLE).exe |
| 41 | +else |
| 42 | + temp_executable=$(temp_build_dir)/$(EXECUTABLE) |
| 43 | +endif) |
| 44 | +$(call build_os_arch,$(1),$(2),$(temp_executable)) |
| 45 | +$(eval ifeq ($(1),windows) |
| 46 | + pack_cmd = $(call pack_zip,$(temp_build_dir)) |
| 47 | +else |
| 48 | + pack_cmd = $(call pack_tgz,$(temp_build_dir)) |
| 49 | +endif) |
| 50 | +@$(pack_cmd) |
| 51 | +endef |
| 52 | + |
| 53 | +github-release: |
| 54 | + $(call build_github_release,linux,amd64) |
| 55 | + $(call build_github_release,linux,386) |
| 56 | + $(call build_github_release,linux,arm) |
| 57 | + $(call build_github_release,darwin,amd64) |
| 58 | + $(call build_github_release,windows,amd64) |
| 59 | + $(call build_github_release,windows,386) |
| 60 | + |
| 61 | +clean: |
| 62 | + rm -rf $(BUILD_DIR) |
| 63 | + $(GO) clean |
0 commit comments