From c2b0e1cec7d088d21dd6d61546b1e852ebcf4765 Mon Sep 17 00:00:00 2001 From: cydezen Date: Tue, 7 Oct 2025 10:25:35 +0200 Subject: [PATCH 1/2] feat: Extend Makefile to allow local cross platform build --- Makefile | 45 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 6d08b4a..82cbab1 100644 --- a/Makefile +++ b/Makefile @@ -3,31 +3,56 @@ # Define the root folder path ROOT_FOLDER_HOST := ~/temp/runtipi +# Set environment variables for golang target platform if these are passed via command line +ifdef GOOS +ifdef GOARCH + export GOOS + export GOARCH +endif +endif + +# Read golang target platform from the system +TARGET_OS := $$(go env GOOS) +TARGET_ARCH := $$(go env GOARCH) + # Main target that creates the directory and runs the program .PHONY: run -run: +run: current_platform @mkdir -p $(ROOT_FOLDER_HOST) @ROOT_FOLDER_HOST=$(ROOT_FOLDER_HOST) go run -ldflags="-X main.version=nightly -X main.commit=$(git rev-parse HEAD) -X main.buildDate=$(date +%Y-%m-%dT%H:%M:%S%z)" cmd/runtipi/main.go $(ARGS) # Build the program .PHONY: build -build: - @go build -o runtipi-cli cmd/runtipi/main.go +build: current_platform + @go build -o runtipi-cli-$(TARGET_OS)-$(TARGET_ARCH) cmd/runtipi/main.go # Clean build artifacts .PHONY: clean clean: - @rm -f runtipi-cli + @rm -f runtipi-cli-* + +# List all available golang target platforms +.PHONY: available_platforms +available_platforms: + @go tool dist list + +# Print which golang target platform is currently set +.PHONY: current_platform +current_platform: + @echo "Current golang target platform: $(TARGET_OS)/$(TARGET_ARCH)" # Help command .PHONY: help help: @echo "Available commands:" - @echo " make run ARGS=\"command arguments\" - Run the program with specified arguments" - @echo " make build - Build the program" - @echo " make clean - Clean build artifacts" - @echo " make help - Show this help message" + @echo " make run ARGS=\"command arguments\" - Run the program with specified arguments" + @echo " make build - Build the program" + @echo " make clean - Clean build artifacts" + @echo " make available_platforms - List golang target platforms available for the build" + @echo " make current_platform - Print current golang target platform" + @echo " make help - Show this help message" @echo "" @echo "Example usage:" - @echo " make run ARGS=\"start\" - Run the program with 'start' command" - @echo " make run ARGS=\"update nightly\" - Run the program with 'update nightly' command" + @echo " make run ARGS=\"start\" - Run the program with 'start' command" + @echo " make run ARGS=\"update nightly\" - Run the program with 'update nightly' command" + @echo " make build GOOS=darwin GOARCH=arm64" - Build the program for golang target platform 'darwin/arm64' (macOS silicon) From 02556f796f699e1e005a522b1abe55c57fbf02a9 Mon Sep 17 00:00:00 2001 From: cydezen Date: Tue, 7 Oct 2025 11:12:01 +0200 Subject: [PATCH 2/2] feat: Use 'printf' instead of 'echo' to enforce consistent formatting of Makefile help command --- Makefile | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 82cbab1..8794685 100644 --- a/Makefile +++ b/Makefile @@ -41,18 +41,22 @@ available_platforms: current_platform: @echo "Current golang target platform: $(TARGET_OS)/$(TARGET_ARCH)" +# String formats to use for output of help command +header_line_format='--------------------------------------\n%s\n--------------------------------------\n' +line_format=' %-40s - %s\n' # Fix padding of first column to 40 chars + # Help command .PHONY: help help: - @echo "Available commands:" - @echo " make run ARGS=\"command arguments\" - Run the program with specified arguments" - @echo " make build - Build the program" - @echo " make clean - Clean build artifacts" - @echo " make available_platforms - List golang target platforms available for the build" - @echo " make current_platform - Print current golang target platform" - @echo " make help - Show this help message" - @echo "" - @echo "Example usage:" - @echo " make run ARGS=\"start\" - Run the program with 'start' command" - @echo " make run ARGS=\"update nightly\" - Run the program with 'update nightly' command" - @echo " make build GOOS=darwin GOARCH=arm64" - Build the program for golang target platform 'darwin/arm64' (macOS silicon) + @printf -- $(header_line_format) "Available commands" + @printf $(line_format) "make run ARGS=\"command arguments\"" "Run the program with specified arguments" + @printf $(line_format) "make build" "Build the program" + @printf $(line_format) "make clean" "Clean build artifacts" + @printf $(line_format) "make available_platforms" "List golang target platforms available for the build" + @printf $(line_format) "make current_platform" "Print current golang target platform" + @printf $(line_format) "make help" "Show this help message" + @printf "\n" + @printf -- $(header_line_format) "Example usage" + @printf $(line_format) "make run ARGS=\"start\"" "Run the program with 'start' command" + @printf $(line_format) "make run ARGS=\"update nightly\"" "Run the program with 'update nightly' command" + @printf $(line_format) "make build GOOS=darwin GOARCH=arm64" "Build the program for golang target platform 'darwin/arm64' (macOS silicon)"