Skip to content

Commit 656ae6d

Browse files
tricktronabiosoft
andauthored
chore: refactor Makefile (#354)
* refactor: extract build logic from build.sh to Makefile * chore: add test rule to Makefile * apply review suggestion Co-authored-by: Abiola Ibrahim <[email protected]> * fix: use defined `OUTPUT_DIR` variable * chore: remove -race flag from test as it needs CGO_ENABLED=1 * chore: generate sha in binaries directory * chore: propagate Go build environment variables Co-authored-by: Abiola Ibrahim <[email protected]>
1 parent 1df2ea3 commit 656ae6d

File tree

2 files changed

+29
-30
lines changed

2 files changed

+29
-30
lines changed

Makefile

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,53 @@ GOARCH_aarch64 = arm64
88
GOARCH_arm64 = arm64
99
GOARCH ?= $(shell echo "$(GOARCH_$(ARCH))")
1010

11+
VERSION := $(shell git describe --tags --always)
12+
REVISION := $(shell git rev-parse HEAD)
13+
PACKAGE := github.com/abiosoft/colima/config
14+
VERSION_VARIABLES := -X $(PACKAGE).appVersion=$(VERSION) -X $(PACKAGE).revision=$(REVISION)
15+
16+
OUTPUT_DIR := _output/binaries
17+
OUTPUT_BIN := colima-$(OS)-$(ARCH)
18+
INSTALL_DIR := /usr/local/bin
19+
BIN_NAME := colima
20+
21+
LDFLAGS := $(VERSION_VARIABLES)
22+
23+
.PHONY: all
1124
all: build
1225

26+
.PHONY: clean
1327
clean:
1428
rm -rf _output _build
1529

30+
.PHONY: gopath
1631
gopath:
1732
go get -v ./cmd/colima
1833

34+
.PHONY: fmt
1935
fmt:
2036
go fmt ./...
2137
goimports -w .
2238

39+
.PHONY: build
2340
build:
24-
GOOS=$(GOOS) GOARCH=$(GOARCH) OS=$(OS) ARCH=$(ARCH) sh scripts/build.sh
41+
GOOS=$(GOOS) GOARCH=$(GOARCH) go build -ldflags="$(LDFLAGS)" -o $(OUTPUT_DIR)/$(OUTPUT_BIN) ./cmd/colima
42+
cd $(OUTPUT_DIR) && openssl sha256 -r -out $(OUTPUT_BIN).sha256sum $(OUTPUT_BIN)
43+
44+
.PHONY: test
45+
test:
46+
go test -v -ldflags="$(LD_FLAGS)" ./cmd/...
2547

48+
.PHONY: vmnet
2649
vmnet:
2750
sh scripts/build_vmnet.sh
2851

52+
.PHONY: install
2953
install:
30-
cp _output/binaries/colima-$(OS)-$(ARCH) /usr/local/bin/colima
31-
chmod +x /usr/local/bin/colima
54+
mkdir -p $(INSTALL_DIR)
55+
rm -f $(INSTALL_DIR)/$(BIN_NAME)
56+
cp $(OUTPUT_DIR)/colima-$(OS)-$(ARCH) $(INSTALL_DIR)/$(BIN_NAME)
57+
chmod +x $(INSTALL_DIR)/$(BIN_NAME)
3258

3359
.PHONY: lint
3460
lint: ## Assumes that golangci-lint is installed and in the path. To install: https://golangci-lint.run/usage/install/

scripts/build.sh

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)