diff --git a/Makefile b/Makefile index 3b7f771..9c2c313 100644 --- a/Makefile +++ b/Makefile @@ -1,25 +1,69 @@ -.PHONY: build build-386 build-amd64 build-arm build-arm64 build-all test test-integration test-all bench clean vet fmt +.PHONY: build build-386 build-amd64 build-arm build-arm64 build-all test test-integration \ + test-all bench clean vet fmt PACKAGE_NAME := github.com/keygen-sh/keygen-relay PACKAGE_VERSION := $(shell cat VERSION) -LD_FLAGS := "-s -w -X $(PACKAGE_NAME)/cli.Version=$(PACKAGE_VERSION)" +PACKAGE_CHANNEL = stable + +ifeq ($(findstring -rc.,$(PACKAGE_VERSION)), -rc.) + PACKAGE_CHANNEL = rc +else ifeq ($(findstring -beta.,$(PACKAGE_VERSION)), -beta.) + PACKAGE_CHANNEL = beta +else ifeq ($(findstring -alpha.,$(PACKAGE_VERSION)), -alpha.) + PACKAGE_CHANNEL = alpha +else ifeq ($(findstring -dev.,$(PACKAGE_VERSION)), -dev.) + PACKAGE_CHANNEL = dev +endif + +BUILD_LDFLAGS := "-s -w -X $(PACKAGE_NAME)/cli.Version=$(PACKAGE_VERSION)" +BUILD_FLAGS = + +ifdef DEBUG + BUILD_FLAGS += -x +endif build: - go build -ldflags $(LD_FLAGS) -o bin/relay ./cmd/relay + go build -ldflags $(BUILD_LDFLAGS) -o bin/relay ./cmd/relay + +build-linux-386: + CGO_ENABLED=1 GOOS=linux GOARCH=386 CC="zig cc -target x86-linux" go build $(BUILD_FLAGS) -ldflags $(BUILD_LDFLAGS) -o dist/relay_linux_386 ./cmd/relay + +build-linux-amd64: + CGO_ENABLED=1 GOOS=linux GOARCH=amd64 CC="zig cc -target x86_64-linux" go build $(BUILD_FLAGS) -ldflags $(BUILD_LDFLAGS) -o dist/relay_linux_amd64 ./cmd/relay + +build-linux-arm: + CGO_ENABLED=1 GOOS=linux GOARCH=arm GOARM=7 CC="zig cc -target arm-linux-gnueabihf" go build $(BUILD_FLAGS) -ldflags $(BUILD_LDFLAGS) -o dist/relay_linux_arm ./cmd/relay + +build-linux-arm64: + CGO_ENABLED=1 GOOS=linux GOARCH=arm64 CC="zig cc -target aarch64-linux" go build $(BUILD_FLAGS) -ldflags $(BUILD_LDFLAGS) -o dist/relay_linux_arm64 ./cmd/relay + +build-darwin-amd64: + CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 CC="zig cc -target x86_64-macos" go build $(BUILD_FLAGS) -ldflags $(BUILD_LDFLAGS) -o dist/relay_darwin_amd64 ./cmd/relay + +build-darwin-arm64: + CGO_ENABLED=1 GOOS=darwin GOARCH=arm64 CC="zig cc -target aarch64-macos" go build $(BUILD_FLAGS) -ldflags $(BUILD_LDFLAGS) -o dist/relay_darwin_arm64 ./cmd/relay + +build-windows-386: + CGO_ENABLED=1 GOOS=windows GOARCH=386 CC="zig cc -target x86-windows" go build $(BUILD_FLAGS) -ldflags $(BUILD_LDFLAGS) -o dist/relay_windows_386.exe ./cmd/relay + +build-windows-amd64: + CGO_ENABLED=1 GOOS=windows GOARCH=amd64 CC="zig cc -target x86_64-windows" go build $(BUILD_FLAGS) -ldflags $(BUILD_LDFLAGS) -o dist/relay_windows_amd64.exe ./cmd/relay -build-386: - CGO_ENABLED=1 GOOS=linux GOARCH=386 go build -ldflags $(LD_FLAGS) -o dist/relay_linux_386 ./cmd/relay +build-windows-arm: + CGO_ENABLED=1 GOOS=windows GOARCH=arm GOARM=7 CC="zig cc -target arm-windows-gnueabihf" go build $(BUILD_FLAGS) -ldflags $(BUILD_LDFLAGS) -o dist/relay_windows_arm.exe ./cmd/relay -build-amd64: - CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -ldflags $(LD_FLAGS) -o dist/relay_linux_amd64 ./cmd/relay +build-windows-arm64: + CGO_ENABLED=1 GOOS=windows GOARCH=arm64 CC="zig cc -target aarch64-windows" go build $(BUILD_FLAGS) -ldflags $(BUILD_LDFLAGS) -o dist/relay_windows_arm64.exe ./cmd/relay -build-arm: - CGO_ENABLED=1 GOOS=linux GOARCH=arm GOARM=7 CC=arm-linux-gnueabihf-gcc go build -ldflags $(LD_FLAGS) -o dist/relay_linux_arm ./cmd/relay +build-install: + cp scripts/install.sh dist/install.sh -build-arm64: - CGO_ENABLED=1 GOOS=linux GOARCH=arm64 CC=aarch64-linux-gnu-gcc go build -ldflags $(LD_FLAGS) -o dist/relay_linux_arm64 ./cmd/relay +build-version: + cp VERSION dist/version -build-all: clean build-386 build-amd64 build-arm build-arm64 +build-all: clean build-linux-386 build-linux-amd64 build-linux-arm build-linux-arm64 build-darwin-amd64 \ + build-darwin-arm64 build-windows-386 build-windows-amd64 build-windows-arm build-windows-arm64 \ + build-install build-version test: go test -race ./... diff --git a/scripts/build.sh b/scripts/build.sh deleted file mode 100755 index c193128..0000000 --- a/scripts/build.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -log_info() { - echo "[info] $1" -} - -log_err() { - echo "[error] $1" - exit 1 -} - -main() { - make build-all # build cross-platform - - # copy installer and version to dist - cp ./scripts/install.sh ./dist/install.sh - cp ./VERSION ./dist/version -} - -main