Skip to content

Commit 7e14d5a

Browse files
committed
Fix Version variable, add Makefile
1 parent 4179dc5 commit 7e14d5a

File tree

3 files changed

+66
-2
lines changed

3 files changed

+66
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
# Output of the go coverage tool, specifically when used with LiteIDE
1414
*.out
15+
build/
1516

1617
wurl
1718
!wurl/

Makefile

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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

main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ import (
1515
"gopkg.in/urfave/cli.v2/altsrc"
1616
)
1717

18-
var Version = semver.MustParse("0.0.1-alpha")
18+
var Version = "0.0.1-alpha"
1919

2020
func main() {
2121
app := &cli.App{
2222
Name: "wurl",
2323
Usage: "console websocket client",
24-
Version: Version.String(),
24+
Version: semver.MustParse(Version).String(),
2525
Flags: []cli.Flag{
2626
flags.InsecureSSLFlag,
2727
flags.HeadersFlag,

0 commit comments

Comments
 (0)