From d69101924b6e6bde7e44c2452df7c671caaf21be Mon Sep 17 00:00:00 2001 From: Andreas Huber Date: Fri, 6 Oct 2023 12:53:25 +0200 Subject: [PATCH] Add build for macOS --- Makefile | 16 ++++++++++------ README.md | 8 +++++--- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 4fe3d975..154b24d1 100644 --- a/Makefile +++ b/Makefile @@ -12,15 +12,15 @@ SHELL = /bin/bash BUILD = go build MKDIR = mkdir -p -.PHONY: build build_linux build_win tag_checked_out mostlyclean +.PHONY: build build_linux build_win build_mac_amd64 build_mac_arm64 tag_checked_out mostlyclean all: - @echo choose a target from: build build_linux build_win mostlyclean + @echo choose a target from: build build_linux build_win build_mac_amd64 build_mac_arm64 mostlyclean @echo prepend \`make BUILDTAG=1\` to checkout the highest git tag before building @echo or set BUILDTAG to a specific tag # Build all binaries -build: build_linux build_win +build: build_linux build_win build_mac_amd64 build_mac_arm64 # if BUILDTAG == 1 set it to the highest git tag ifeq ($(strip $(BUILDTAG)),1) @@ -29,7 +29,7 @@ endif ifdef BUILDTAG # add the git tag checkout to the requirements of our build targets -build_linux build_win: tag_checked_out +build_linux build_win build_mac_amd64 build_mac_arm64: tag_checked_out endif tag_checked_out: @@ -67,15 +67,19 @@ LDFLAGS = -ldflags "-X github.com/csaf-poc/csaf_distribution/v3/util.SemVersion= GOARCH = amd64 build_linux: GOOS = linux build_win: GOOS = windows +build_mac_amd64: GOOS = darwin -build_linux build_win: +build_mac_arm64: GOARCH = arm64 +build_mac_arm64: GOOS = darwin + +build_linux build_win build_mac_amd64 build_mac_arm64: $(eval BINDIR = bin-$(GOOS)-$(GOARCH)/ ) $(MKDIR) $(BINDIR) env GOARCH=$(GOARCH) GOOS=$(GOOS) $(BUILD) -o $(BINDIR) $(LDFLAGS) -v ./cmd/... DISTDIR := csaf_distribution-$(SEMVER) -dist: build_linux build_win +dist: build_linux build_win build_mac_amd64 build_mac_arm64 mkdir -p dist mkdir -p dist/$(DISTDIR)-windows-amd64/bin-windows-amd64 cp README.md dist/$(DISTDIR)-windows-amd64 diff --git a/README.md b/README.md index 6003f702..5c1a8a73 100644 --- a/README.md +++ b/README.md @@ -47,9 +47,11 @@ Download the binaries from the most recent release assets on Github. - Build Go components Makefile supplies the following targets: - Build For GNU/Linux System: `make build_linux` - - Build For Windows System (cross build): `make build_win` - - Build For both linux and windows: `make build` - - Build from a specific github tag by passing the intended tag to the `BUILDTAG` variable. + - Build For Windows System (cross build): `make build_win` + - Build For macOS on Intel Processor (AMD64) (cross build): `make build_mac_amd64` + - Build For macOS on Apple Silicon (ARM64) (cross build): `make build_mac_arm64` + - Build For Linux, Mac and Windows: `make build` + - Build from a specific GitHub tag by passing the intended tag to the `BUILDTAG` variable. E.g. `make BUILDTAG=v1.0.0 build` or `make BUILDTAG=1 build_linux`. The special value `1` means checking out the highest github tag for the build. - Remove the generated binaries und their directories: `make mostlyclean`