From 931b50a7d7d5c7240c11ab7403a7f7c290a903ed Mon Sep 17 00:00:00 2001 From: Ankit Kr Chowdhury Date: Sat, 2 Aug 2025 18:01:36 +0530 Subject: [PATCH] chore(makefile): add platform-aware build, cross-compilation, and utility targets Signed-off-by: Ankit Kr Chowdhury --- Makefile | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index b76fd5f..0a10233 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,37 @@ -.PHONEY: build +.PHONY: help build build-all clean + +## Show help info +help: + @echo "Usage: make " + @echo "" + @echo "Targets:" + @echo " build Build CLI for current OS/Arch" + @echo " build-all Cross-compile CLI for all major platforms" + @echo " clean Remove all compiled binaries from ./bin" + @echo " help Show this help message" + +## Build CLI for current OS/Arch build: + @mkdir -p bin + @goos=$$(go env GOOS); \ + goarch=$$(go env GOARCH); \ + ext=""; \ + if [ "$$goos" = "windows" ]; then ext=".exe"; fi; \ + out="bin/kubeslice-cli-$$goos-$$goarch$$ext"; \ + echo "Building for $$goos/$$goarch -> $$out"; \ + go build -o $$out main.go + +## Build CLI for all target platforms +build-all: + @mkdir -p bin GOOS=windows GOARCH=amd64 go build -o bin/kubeslice-cli-windows-amd64.exe main.go GOOS=linux GOARCH=amd64 go build -o bin/kubeslice-cli-linux-amd64 main.go GOOS=linux GOARCH=arm go build -o bin/kubeslice-cli-linux-arm main.go GOOS=linux GOARCH=arm64 go build -o bin/kubeslice-cli-linux-arm64 main.go GOOS=darwin GOARCH=amd64 go build -o bin/kubeslice-cli-darwin-amd64 main.go - GOOS=darwin GOARCH=arm64 go build -o bin/kubeslice-cli-darwin-arm64 main.go \ No newline at end of file + GOOS=darwin GOARCH=arm64 go build -o bin/kubeslice-cli-darwin-arm64 main.go + +## Clean up build artifacts +clean: + @echo "Removing bin directory and compiled binaries..." + @rm -rf bin \ No newline at end of file