forked from tatsushid/minssh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
65 lines (52 loc) · 1.88 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
TARGET := minssh
VERSION := v0.2.0
GOX_OS := linux darwin windows
GOX_ARCH := 386 amd64
DATE := $(shell date +%FT%T%z)
RM := rm -f
RM_R := rm -rf
ifeq ($(OS),Windows_NT)
TARGET := $(TARGET).exe
endif
SHA256 := $(shell sha256sum --help)
ifdef SHA256 # usual linux
SHA256 := sha256sum
else # macOS
SHA256 := shasum
endif
wildcard-recurse = $(wildcard $1$2)$(foreach d,$(wildcard $1*),$(call wildcard-recurse,$(d)/,$2))
SOURCES := $(filter-out %_test.go,$(call wildcard-recurse,./,*.go))
PKG_NAME := minssh
PLATFORMS := $(foreach arch,$(GOX_ARCH),$(addsuffix _$(arch),$(GOX_OS)))
PLATFORMS_DIR := $(addprefix build/platforms/,$(PLATFORMS))
RELEASE_PREFIX := build/release/$(VERSION)/$(PKG_NAME)_$(VERSION)_
OBJECTS := $(addprefix $(RELEASE_PREFIX),$(addsuffix .tar.gz,$(filter-out windows%,$(PLATFORMS))))
OBJECTS += $(addprefix $(RELEASE_PREFIX),$(addsuffix .zip,$(filter windows%,$(PLATFORMS))))
OBJECTS += $(RELEASE_PREFIX)checksums.txt
$(TARGET): $(SOURCES)
go build -ldflags \
"-X main.commitHash=$$(git rev-parse --short HEAD 2>/dev/null) \
-X main.buildDate=$(DATE) \
-w -s"
build/platforms:
mkdir -p build/platforms
$(PLATFORMS_DIR): build/platforms
gox -os="$(GOX_OS)" -arch="$(GOX_ARCH)" \
-output "build/platforms/{{.OS}}_{{.Arch}}/{{.Dir}}" \
-ldflags "-X main.commitHash=$$(git rev-parse --short HEAD 2>/dev/null) \
-X main.buildDate=$(DATE) \
-w -s"
build/release/$(VERSION):
mkdir -p build/release/$(VERSION)
$(RELEASE_PREFIX)%.tar.gz: $(PLATFORMS_DIR) build/release/$(VERSION)
cd build/platforms/$(*F) && tar czf $(CURDIR)/$@ ./*
$(RELEASE_PREFIX)%.zip: $(PLATFORMS_DIR) build/release/$(VERSION)
cd build/platforms/$(*F) && zip $(CURDIR)/$@ ./*
$(RELEASE_PREFIX)checksums.txt: build/release/$(VERSION)
cd build/release/$(VERSION) && $(SHA256) *.tar.gz *.zip > $(@F)
.PHONY: release
release: $(OBJECTS)
.PHONY: clean
clean:
$(RM) $(TARGET)
$(RM_R) build