Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Commit

Permalink
Updated the build script to build all versions
Browse files Browse the repository at this point in the history
  • Loading branch information
pieterclaerhout committed Sep 15, 2023
1 parent 9dd7271 commit 7e8a855
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 4 deletions.
48 changes: 44 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@ include .env
export

APP_NAME := export-komoot
GO := go

REVISION := $(shell git rev-parse --short HEAD)
BRANCH := $(shell git rev-parse --abbrev-ref HEAD | tr -d '\040\011\012\015\n')
LDFLAGS := "-s -w -X $(PACKAGE).GitRevision=$(REVISION) -X $(PACKAGE).GitBranch=$(BRANCH)"
BUILD_CMD := go build -buildvcs -ldflags "-s -w -X $(PACKAGE).GitRevision=$(REVISION) -X $(PACKAGE).GitBranch=$(BRANCH)" -trimpath

init:
@go mod download

build: init
@$(GO) build -v -ldflags $(LDFLAGS) -o $(APP_NAME)
$(call build-binary)

test:
@$(GO) test -cover `go list ./... | grep -v cmd`
Expand All @@ -28,3 +26,45 @@ run-filter: build

help: build
@DEBUG=0 ./$(APP_NAME) --help

build-all:
@rm -f ./$(APP_NAME)-*
$(call build-binary-mac)
$(call build-binary-linux)
$(call build-binary-windows)

## Helper functions
define build-binary
@GOOS=$(1) GOARCH=$(2) $(BUILD_CMD) -o $(APP_NAME)
endef

define build-binary-mac
@echo "Building $(APP_NAME) for macos"
$(call build-binary,darwin,arm64,arm64)
@mv $(APP_NAME) $(APP_NAME)-arm
$(call build-binary,darwin,amd64,x86_64)
@mv $(APP_NAME) $(APP_NAME)-x86
@lipo -create -output $(APP_NAME) $(APP_NAME)-x86 $(APP_NAME)-arm
@tar czf ./$(APP_NAME)-$(REVISION)-macos.tar.gz $(APP_NAME)
@rm -f $(APP_NAME)-x86 $(APP_NAME)-arm $(APP_NAME)
endef

define build-binary-linux
@echo "Building $(APP_NAME) for linux"
$(call build-binary,linux,arm64,arm64)
@tar czf ./$(APP_NAME)-$(REVISION)-linux-arm64.tar.gz $(APP_NAME)
$(call build-binary,linux,amd64,x86_64)
@tar czf ./$(APP_NAME)-$(REVISION)-linux-x86_64.tar.gz $(APP_NAME)
@rm -f $(APP_NAME)
endef

define build-binary-windows
@echo "Building $(APP_NAME) for windows"
@$(call build-binary,windows,arm64,arm64)
@mv ./$(APP_NAME) ./$(APP_NAME).exe
@zip -rq ./$(APP_NAME)-$(REVISION)-windows-arm64.zip $(APP_NAME).exe
@$(call build-binary,windows,amd64,x86_64)
@mv ./$(APP_NAME) ./$(APP_NAME).exe
@zip -rq ./$(APP_NAME)-$(REVISION)-windows-x86_64.zip $(APP_NAME).exe
@rm -f $(APP_NAME).exe $(APP_NAME)
endef
Binary file added export-komoot-9dd7271-linux-arm64.tar.gz
Binary file not shown.
Binary file added export-komoot-9dd7271-linux-x86_64.tar.gz
Binary file not shown.
Binary file added export-komoot-9dd7271-macos.tar.gz
Binary file not shown.
Binary file added export-komoot-9dd7271-windows-arm64.zip
Binary file not shown.
Binary file added export-komoot-9dd7271-windows-x86_64.zip
Binary file not shown.

0 comments on commit 7e8a855

Please sign in to comment.