From 612b5e9861997429bc8859bffe6b93c37de1a06c Mon Sep 17 00:00:00 2001 From: gjahn <gregor.jahn@bht-berlin.de> Date: Sun, 12 Nov 2023 19:56:49 +0100 Subject: [PATCH] Add target to cross-compile for Linux (amd64) Hint in readme on how to change built target platform. --- Makefile | 7 ++++++- README.md | 7 ++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index ba692e0..92ccb30 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ export PATH := $(BIN_DIR):$(PATH) export GOMODCACHE = $(LOCAL_DIR)/cache/go export GOTMPDIR = $(TMP_DIR)/go - +export GOBIN = $(BIN_DIR) default: clean install build run @@ -39,6 +39,11 @@ $(BIN_DIR)/artifact.bin: -o $(@) \ $(SRC_DIR)/*.go +.PHONY: build-linux +build-linux: export GOOS := linux +build-linux: export GOARCH := amd64 +build-linux: $(BIN_DIR)/artifact.bin + .PHONY: test .SILENT: test diff --git a/README.md b/README.md index 0a309b8..9ef0351 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Webservice ========== A Go-based simple web service meant to be the subject for any tutorial -or even the project work. +or maybe even the project work. __Prerequisites:__ @@ -10,11 +10,12 @@ __Prerequisites:__ * Go toolchain (install via system package manager or [by hand](https://go.dev/doc/install)) -__Main interactions:__ +__Primary interactions:__ 1. Install dependencies: `go get -t ./...` 2. Run locally: `go run .` 3. Execute unit tests: `go test -race -v ./...` 4. Build artifact: `go build -o ./artifact.bin ./*.go` -For more details, please refer to the `Makefile`. +To build for another platform, set `GOOS` and `GOARCH`. For more details, +please refer to the `Makefile`. -- GitLab