Skip to content

Commit 4d571aa

Browse files
committed
Makefile: fulfill version
Signed-off-by: Akihiro Suda <[email protected]>
1 parent b89d4c9 commit 4d571aa

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

Makefile

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
.DEFAULT_GOAL := binary
22

3-
GO := go
3+
GO ?= go
4+
5+
PACKAGE := github.com/lima-vm/sshocker
6+
7+
VERSION=$(shell git describe --match 'v[0-9]*' --dirty='.m' --always --tags)
8+
VERSION_TRIMMED := $(VERSION:v%=%)
9+
10+
GO_BUILD := CGO_ENABLED=0 $(GO) build -ldflags="-s -w -X $(PACKAGE)/pkg/version.Version=$(VERSION)"
411

512
binary: bin/sshocker
613

@@ -11,14 +18,15 @@ uninstall:
1118
rm -f /usr/local/bin/sshocker
1219

1320
bin/sshocker:
14-
CGO_ENABLED=0 $(GO) build -o $@ ./cmd/sshocker
21+
$(GO_BUILD) -o $@ ./cmd/sshocker
1522
if [ $(shell go env GOOS) = linux ]; then LANG=C LC_ALL=C file $@ | grep -qw "statically linked"; fi
1623

1724
# The file name convention for Unix: ./bin/sshocker-$(uname -s)-$(uname -m)
1825
cross:
19-
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GO) build -o ./bin/sshocker-Linux-x86_64 ./cmd/sshocker
20-
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 $(GO) build -o ./bin/sshocker-Linux-aarch64 ./cmd/sshocker
21-
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 $(GO) build -o ./bin/sshocker-Darwin-x86_64 ./cmd/sshocker
26+
GOOS=linux GOARCH=amd64 $(GO_BUILD) -o ./bin/sshocker-Linux-x86_64 ./cmd/sshocker
27+
GOOS=linux GOARCH=arm64 $(GO_BUILD) -o ./bin/sshocker-Linux-aarch64 ./cmd/sshocker
28+
GOOS=darwin GOARCH=amd64 $(GO_BUILD) -o ./bin/sshocker-Darwin-x86_64 ./cmd/sshocker
29+
GOOS=darwin GOARCH=arm64 $(GO_BUILD) -o ./bin/sshocker-Darwin-arm64 ./cmd/sshocker
2230

2331
clean:
2432
rm -rf bin

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ chmod +x sshocker
2020

2121
To compile from source:
2222
```console
23-
go get github.com/lima-vm/sshocker/cmd/sshocker
23+
make
24+
sudo make install
2425
```
2526

2627
Tested on macOS client and Linux server. May not work on other environments, especially on Windows.

pkg/version/version.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
package version
22

3-
const Version = "0.1.0+dev"
3+
var (
4+
// Version is filled on compilation time
5+
Version = "<unknown>"
6+
)

0 commit comments

Comments
 (0)