From e4850f270da0799b43e6cf47b43853be1c99ddb5 Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Fri, 4 Mar 2022 11:08:48 +0100 Subject: [PATCH] Add makefile and build script Binary will be build in corresponding GOOS-GOARCH folder. Install command will build and install binary for current platform until GOOS and/or GOARCH env var is set. --- Makefile | 21 +++++++++++++++++++++ scripts/build.sh | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 Makefile create mode 100644 scripts/build.sh diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..7743202 --- /dev/null +++ b/Makefile @@ -0,0 +1,21 @@ +ifndef VERBOSE +.SILENT: +endif + +all: binary + +.PHONY: fmt +fmt: + sh ./scripts/build.sh fmt + +.PHONY: clean +clean: + sh ./scripts/build.sh clean + +.PHONY: binary +binary: + sh ./scripts/build.sh build + +.PHONY: install +install: + sh ./scripts/build.sh install \ No newline at end of file diff --git a/scripts/build.sh b/scripts/build.sh new file mode 100644 index 0000000..0a5786f --- /dev/null +++ b/scripts/build.sh @@ -0,0 +1,32 @@ +#!/bin/sh + +set -eu + +TARGET=${TARGET:-"target"} + +GOOS="$(go env GOOS)" +GOARCH="$(go env GOARCH)" + +TARGET="$TARGET/${GOOS}-${GOARCH}/docker-pps" +if [ "${GOOS}" = "windows" ]; then + TARGET="${TARGET}.exe" +fi + +case "$1" in + fmt) + go fmt $(go list) + ;; + clean) + rm -rf ./target + ;; + build) + go build -o "${TARGET}" + ;; + install) + go install + ;; + *) + echo "Usage: $0 {fmt|clean|build|install}" + exit 1 +esac +