Skip to content

Commit

Permalink
Makefile: fulfill version
Browse files Browse the repository at this point in the history
Signed-off-by: Akihiro Suda <[email protected]>
  • Loading branch information
AkihiroSuda committed Aug 19, 2021
1 parent b89d4c9 commit 4d571aa
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
18 changes: 13 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
.DEFAULT_GOAL := binary

GO := go
GO ?= go

PACKAGE := github.com/lima-vm/sshocker

VERSION=$(shell git describe --match 'v[0-9]*' --dirty='.m' --always --tags)
VERSION_TRIMMED := $(VERSION:v%=%)

GO_BUILD := CGO_ENABLED=0 $(GO) build -ldflags="-s -w -X $(PACKAGE)/pkg/version.Version=$(VERSION)"

binary: bin/sshocker

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

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

# The file name convention for Unix: ./bin/sshocker-$(uname -s)-$(uname -m)
cross:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GO) build -o ./bin/sshocker-Linux-x86_64 ./cmd/sshocker
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 $(GO) build -o ./bin/sshocker-Linux-aarch64 ./cmd/sshocker
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 $(GO) build -o ./bin/sshocker-Darwin-x86_64 ./cmd/sshocker
GOOS=linux GOARCH=amd64 $(GO_BUILD) -o ./bin/sshocker-Linux-x86_64 ./cmd/sshocker
GOOS=linux GOARCH=arm64 $(GO_BUILD) -o ./bin/sshocker-Linux-aarch64 ./cmd/sshocker
GOOS=darwin GOARCH=amd64 $(GO_BUILD) -o ./bin/sshocker-Darwin-x86_64 ./cmd/sshocker
GOOS=darwin GOARCH=arm64 $(GO_BUILD) -o ./bin/sshocker-Darwin-arm64 ./cmd/sshocker

clean:
rm -rf bin
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ chmod +x sshocker

To compile from source:
```console
go get github.com/lima-vm/sshocker/cmd/sshocker
make
sudo make install
```

Tested on macOS client and Linux server. May not work on other environments, especially on Windows.
Expand Down
5 changes: 4 additions & 1 deletion pkg/version/version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
package version

const Version = "0.1.0+dev"
var (
// Version is filled on compilation time
Version = "<unknown>"
)

0 comments on commit 4d571aa

Please sign in to comment.