Skip to content

Commit

Permalink
[CFE-478] Add Makefile to build, install, tag and release go-kd6rmx c…
Browse files Browse the repository at this point in the history
…li tool
  • Loading branch information
mitul93 authored and deadprogram committed Oct 1, 2021
1 parent 580d0f3 commit 6da446c
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 8 deletions.
65 changes: 65 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# current git sha of the repo
GITSHA := $(shell git rev-parse --short HEAD)

# version
VERSION := $(GITSHA)

GOOS := $(shell go env GOOS)
GOARCH := $(shell go env GOARCH)

release: bump-version build-all tag

tag:
git tag $(VERSION)
git push origin $(VERSION)

build-windows:
mkdir -p build/kd6ctl-$(VERSION)-windows-amd64
env GOOS=windows GOARCH=amd64 go build -o build/kd6ctl-$(VERSION)-windows-amd64/kd6ctl.exe ./cmd/kd6ctl

build-linux:
mkdir -p build/kd6ctl-$(VERSION)-linux-amd64
env GOOS=linux GOARCH=amd64 go build -o build/kd6ctl-$(VERSION)-linux-amd64/kd6ctl ./cmd/kd6ctl

build-macos:
mkdir -p build/kd6ctl-$(VERSION)-macos-amd64
env GOOS=darwin GOARCH=amd64 go build -o build/kd6ctl-$(VERSION)-macos-amd64/kd6ctl ./cmd/kd6ctl

build-macos-m1:
mkdir -p build/kd6ctl-$(VERSION)-macos-arm64
env GOOS=darwin GOARCH=arm64 go build -o build/kd6ctl-$(VERSION)-macos-arm64/kd6ctl ./cmd/kd6ctl

build-all: clean build-windows build-linux build-macos build-macos-m1

.PHONY: build
build:
ifeq ($(GOOS), windows)
target_name="kd6ctl.exe"
else
target_name="kd6ctl"
endif
mkdir -p build/kd6ctl-$(VERSION)-$(GOOS)-$(GOARCH)
env GOOS=$(GOOS) GOARCH=$(GOARCH) go build -o build/kd6ctl-$(VERSION)-$(GOOS)-$(GOARCH)/kd6ctl ./cmd/kd6ctl

clean:
rm -rf build/*

install:
go install ./cmd/kd6ctl

bump-version:
$(eval v := $(shell git describe --tags --abbrev=0 2>/dev/null | xargs git rev-parse | xargs git tag --points-at | tail -1 | sed -Ee 's/^v|-.*//'))
ifeq ($(bump), major)
$(eval VERSION := v$(shell echo $v | awk -F'.' '{printf("%d.0.0", $$1+1, 0, 0)}'))
else ifeq ($(bump), minor)
$(eval VERSION := v$(shell echo $v | awk -F'.' '{printf("%d.%d.0", $$1, $$2+1, 0)}'))
else ifeq ($(bump), patch)
$(eval VERSION := v$(shell echo $v | awk -F'.' '{printf("%d.%d.%d", $$1, $$2, $$3+1)}'))
else ifeq ($(bump), )
$(eval VERSION := v$(shell echo $v | awk -F'.' '{printf("%d.%d.%d", $$1, $$2, $$3+1)}'))
else ifeq ($(bump), which)
$(eval VERSION := v$(shell echo $v | awk -F'.' '{printf("%d.%d.%d", $$1, $$2, $$3)}'))
else
$(error $(bump) is not supported. available bump values are: major, minor, patch or leave empty for patch as default)
endif
@echo bump version: $(VERSION)
53 changes: 45 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,26 +92,63 @@ kd6ctl led ab on

### How to build binaries for different platforms

#### Windows
#### Windows (amd64 architecture)

```shell
env GOOS=windows GOARCH=amd64 go build -o build/kd6ctl.exe ./cmd/kd6ctl
make build-windows
```

#### Linux
#### Linux (amd64 architecture)

```shell
env GOOS=linux GOARCH=amd64 go build -o build/kd6ctl ./cmd/kd6ctl
make build-linux
```

#### macOS - Intel
#### macOS (amd64 architecture)

```shell
env GOOS=darwin GOARCH=amd64 go build -o build/kd6ctl ./cmd/kd6ctl
make build-macos
```

#### macOS - M1
#### macOS - M1 (arm64 architecture)

```shell
env GOOS=darwin GOARCH=arm64 go build -o build/kd6ctl ./cmd/kd6ctl
make build-macos-m1
```

#### All of above

``` shell
make build-all
```

#### build for the current platform (if you're unsure about the OS and architecture)

```shell
make build
```

#### Generic build command
build binaries for other Operating Systems and architectures
```shell
env GOOS=<OS> GOARCH=<ARCH> go build -o build/kd6ctl-<OS>-<ARCH> ./cmd/kd6ctl
```
replace the ```OS``` by operating system and ```ARCH``` by architecture supported by go cross-compiler.

### How to release a tagged version
Following commands build binaries for Windows (amd64), Linux (amd64), macOS (amd64) and macOS M1 (arm64).

Bump release tag to minor
```shell
make release bump=minor
```

Bump relase tag to major
```shell
make release bump=major
```

if bump argument is not mentiond, then the release will be bumped with tag patch
```shell
make release
```

0 comments on commit 6da446c

Please sign in to comment.