feat: add Makefile to build all locally
This commit is contained in:
58
Makefile
Normal file
58
Makefile
Normal file
@ -0,0 +1,58 @@
|
||||
BINARY := ssm
|
||||
MODULE := gitea.epss.net.cn/klesh/ss
|
||||
VERSION ?= dev
|
||||
DIST := dist
|
||||
|
||||
LDFLAGS := -s -w -X $(MODULE)/internal/cli.Version=$(VERSION)
|
||||
|
||||
# os/arch pairs matching the 3 major platforms this project ships for.
|
||||
PLATFORMS := linux/amd64 darwin/arm64 windows/amd64
|
||||
|
||||
.DEFAULT_GOAL := build
|
||||
|
||||
.PHONY: build build-all test vet fmt clean release package help
|
||||
|
||||
build: ## Build the ssm binary for the current platform
|
||||
go build -trimpath -ldflags "$(LDFLAGS)" -o $(BINARY) ./cmd/$(BINARY)
|
||||
|
||||
build-all: clean ## Cross-compile ssm for linux/amd64, darwin/arm64, windows/amd64 into dist/<os>-<arch>/, unpackaged
|
||||
@for platform in $(PLATFORMS); do \
|
||||
os=$${platform%/*}; arch=$${platform#*/}; \
|
||||
ext=""; [ "$$os" = "windows" ] && ext=".exe"; \
|
||||
echo "==> building $$os/$$arch"; \
|
||||
mkdir -p $(DIST)/$$os-$$arch; \
|
||||
GOOS=$$os GOARCH=$$arch go build -trimpath -ldflags "$(LDFLAGS)" -o $(DIST)/$$os-$$arch/$(BINARY)$$ext ./cmd/$(BINARY) || exit 1; \
|
||||
done
|
||||
|
||||
test: ## Run the test suite
|
||||
go test ./...
|
||||
|
||||
vet: ## Run go vet
|
||||
go vet ./...
|
||||
|
||||
fmt: ## Check formatting (gofmt -l)
|
||||
gofmt -l .
|
||||
|
||||
clean: ## Remove build/release artifacts
|
||||
rm -rf $(DIST) $(BINARY) $(BINARY).exe
|
||||
|
||||
release: build-all ## Cross-compile for linux/amd64, darwin/arm64, windows/amd64 and package into dist/
|
||||
@$(MAKE) --no-print-directory package
|
||||
|
||||
package: ## Archive dist/<os>-<arch>/ directories into per-platform tar.gz/zip + checksums.txt
|
||||
@cd $(DIST) && \
|
||||
for platform in $(PLATFORMS); do \
|
||||
os=$${platform%/*}; arch=$${platform#*/}; \
|
||||
name=$(BINARY)-$(VERSION)-$$os-$$arch; \
|
||||
if [ "$$os" = "windows" ]; then \
|
||||
(cd $$os-$$arch && zip -q ../$$name.zip $(BINARY).exe); \
|
||||
else \
|
||||
tar -C $$os-$$arch -czf $$name.tar.gz $(BINARY); \
|
||||
fi; \
|
||||
rm -rf $$os-$$arch; \
|
||||
done; \
|
||||
sha256sum *.tar.gz *.zip > checksums.txt; \
|
||||
ls -la
|
||||
|
||||
help: ## Show this help
|
||||
@grep -E '^[a-zA-Z_-]+:.*## ' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*## "}; {printf " %-10s %s\n", $$1, $$2}'
|
||||
Reference in New Issue
Block a user