Skip to content

Commit 56ca477

Browse files
committed
add 'make release' target
1 parent 9461503 commit 56ca477

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

Makefile

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,43 @@
11
CMD_PATH := cmd/git-remote-https+iap
22
CMD_NAME := git-remote-https+iap
3+
BUILD_TARGETS := \
4+
darwin-amd64 \
5+
linux-amd64
36

4-
BIN_PATH := dist/bin/
7+
DIST_PATH := dist/
8+
BIN_PATH := $(DIST_PATH)bin/
9+
RELEASE_PATH := $(DIST_PATH)releases/
510

611
version := $(shell git describe --match "v*.*" --abbrev=7 --tags --dirty)
712
build_args := -ldflags "-X main.version=${version}"
13+
tar_xform_arg := $(shell tar --version | grep -q 'GNU tar' && echo '--xform' || echo '-s')
14+
tar_xform_cmd := $(shell tar --version | grep -q 'GNU tar' && echo 's')
815

916
.PHONY: all
1017
all: build
1118

12-
$(BIN_PATH):
19+
$(BIN_PATH) $(RELEASE_PATH):
1320
mkdir -p $@
1421

15-
build: $(BIN_PATH)
16-
env CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build ${build_args} -o $(BIN_PATH)${CMD_NAME}-darwin-amd64 ${CMD_PATH}/*.go
17-
env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build ${build_args} -o $(BIN_PATH)${CMD_NAME}-linux-amd64 ${CMD_PATH}/*.go
22+
BUILDS := $(foreach target, $(BUILD_TARGETS), $(BIN_PATH)$(CMD_NAME)-$(target))
23+
$(BUILDS): OS = $(word 1, $(subst -, ,$(subst $(CMD_NAME)-,,$(notdir $@))))
24+
$(BUILDS): ARCH = $(word 2, $(subst -, ,$(subst $(CMD_NAME)-,,$(notdir $@))))
25+
$(BUILDS): $(BIN_PATH)
26+
env CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) go build ${build_args} -o $(BIN_PATH)${CMD_NAME}-$(OS)-$(ARCH) ${CMD_PATH}/*.go
27+
build: $(BUILDS)
28+
29+
RELEASE_INCLUDES = README.md
30+
RELEASE_TARGETS := $(foreach target, $(BUILDS), $(RELEASE_PATH)$(notdir $(target))-$(version).tar.gz)
31+
$(RELEASE_TARGETS): $(RELEASE_PATH)%-$(version).tar.gz: $(BIN_PATH)% $(RELEASE_INCLUDES)
32+
mkdir -p $(RELEASE_PATH)
33+
tar $(tar_xform_arg) '$(tar_xform_cmd)!$(BIN_PATH)$(CMD_NAME).*!$(CMD_NAME)!' -czf $@ $^
34+
cd $(RELEASE_PATH) && shasum -a 256 $(notdir $@) >$(notdir $@).sha256
35+
release: $(RELEASE_TARGETS)
1836

1937
.PHONY: version
2038
version:
2139
@echo "$(version)"
2240

2341
.PHONY: clean
2442
clean:
25-
rm -rf $(BIN_PATH)
43+
rm -rf $(DIST_PATH)

0 commit comments

Comments
 (0)