blender-open-data/launcher/Makefile

247 lines
8.1 KiB
Makefile

include Makeenv
GO ?= go
GO_BUILD_TAGS ?= imguifreetype
GO_LDFLAGS ?=
GO_LDFLAGS_CLI ?=
GO_LDFLAGS_GUI ?=
GO_EXTLDFLAGS ?=
VERSION ?= $(patsubst launcher/%,%,$(shell git describe --match launcher/\*))
ifeq ($(VERSION),)
VERSION := 0.0.0
endif
SENTRY_DSN ?=
ETC_DIR ?= $(abspath etc)
BIN_DIR ?= $(abspath bin)
DIST_DIR ?= $(abspath dist)
SRC_DIR ?= $(abspath .)
CMD_DIR ?= $(SRC_DIR)/cmd
ASSETS_DIR ?= $(SRC_DIR)/assets
FREETYPE2_DIR ?= $(SRC_DIR)/freetype2
CLI_RESOURCES_DIR ?= $(SRC_DIR)/etc/cli
CLI_README_TXT ?= README.txt
DEBUG ?= false
STAGING ?= false
EXE_SUFFIX :=
ifeq ($(DEBUG),true)
GO_BUILD_TAGS += dev
endif
ifeq ($(STAGING),true)
GO_BUILD_TAGS += staging
endif
ifneq ($(GO_BUILD_TAGS),)
GO_BUILD_TAGS := -tags "$(GO_BUILD_TAGS)"
endif
ifneq ($(VERSION),)
GO_LDFLAGS := -X git.blender.org/blender-open-data/launcher/internal/config.Version=$(VERSION) $(GO_LDFLAGS)
endif
ifneq ($(SENTRY_DSN),)
GO_LDFLAGS := -X git.blender.org/blender-open-data/launcher/internal/config.SentryDSN=$(SENTRY_DSN) $(GO_LDFLAGS)
endif
DEPENDENCIES_GUI ?=
DEPENDENCIES_CLI ?=
ifeq ($(OS),Windows_NT)
DEPENDENCIES_GUI := $(DEPENDENCIES_GUI) $(ETC_DIR)/windows_resources/resources.o
DEPENDENCIES_CLI := $(DEPENDENCIES_CLI) $(ETC_DIR)/windows_resources/resources.o
GO_EXTLDFLAGS := $(shell cygpath --windows "$(ETC_DIR)/windows_resources/resources.o") $(GO_EXTLDFLAGS)
GO_EXTLDFLAGS := -static-libgcc -static-libstdc++ -Wl,-Bstatic -lstdc++ -lpthread -Wl,-Bdynamic $(GO_EXTLDFLAGS)
GO_LDFLAGS_GUI := -H windowsgui $(GO_LDFLAGS_GUI)
EXE_SUFFIX := .exe
BIN_PLATFORM_DIR ?= $(BIN_DIR)/windows
PKG_GUI_FILE ?= $(DIST_DIR)/benchmark-launcher-$(VERSION)-windows.zip
PKG_CLI_FILE ?= $(DIST_DIR)/benchmark-launcher-cli-$(VERSION)-windows.zip
ENVSUBST ?= envsubst
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
BIN_PLATFORM_DIR ?= $(BIN_DIR)/linux
PKG_GUI_FILE ?= $(DIST_DIR)/benchmark-launcher-$(VERSION)-linux.tar.gz
PKG_CLI_FILE ?= $(DIST_DIR)/benchmark-launcher-cli-$(VERSION)-linux.tar.gz
ENVSUBST ?= envsubst
else ifeq ($(UNAME_S),Darwin)
BIN_PLATFORM_DIR ?= $(BIN_DIR)/darwin
PKG_GUI_FILE ?= $(DIST_DIR)/benchmark-launcher-$(VERSION)-macos.tar.gz
PKG_CLI_FILE ?= $(DIST_DIR)/benchmark-launcher-cli-$(VERSION)-macos.tar.gz
ENVSUBST ?= /usr/local/opt/gettext/bin/envsubst
DEPLOYMENT_TARGET_AMD64 := 10.13
DEPLOYMENT_TARGET_ARM64 := 11.0
else
$(error Unsupported platform: only Windows, Linux and macOS are supported)
endif
endif
GUI_EXE_FILE := $(BIN_PLATFORM_DIR)/benchmark-launcher$(EXE_SUFFIX)
CLI_EXE_FILE := $(BIN_PLATFORM_DIR)/benchmark-launcher-cli$(EXE_SUFFIX)
.PHONY: default
default: build
.PHONY: build
build: $(GUI_EXE_FILE) $(CLI_EXE_FILE)
define run-build-gui
mkdir -p "$(@D)"
cd "$(CMD_DIR)/benchmark-launcher/" && \
PKG_CONFIG_PATH="$(FREETYPE2_DIR)/build-$(ARCH)/bin/lib/pkgconfig/:$(PKG_CONFIG_PATH)" \
CGO_ENABLED=1 \
CGO_CFLAGS="-I$(FREETYPE2_DIR)/build-$(ARCH)/bin/include/freetype2" \
CGO_CXXFLAGS="-I$(FREETYPE2_DIR)/build-$(ARCH)/bin/include/freetype2" \
CGO_LDFLAGS="-L$(FREETYPE2_DIR)/build-$(ARCH)/bin/lib" \
GOARCH=$(ARCH) \
$(GO) build -o "$(@)" -ldflags "$(GO_LDFLAGS) $(GO_LDFLAGS_GUI) -linkmode external -extldflags '$(GO_EXTLDFLAGS)'" $(GO_BUILD_TAGS) "$(CMD_DIR)/benchmark-launcher/main.go"
endef
define run-build-cli
mkdir -p "$(@D)"
cd "$(CMD_DIR)/benchmark-launcher-cli/" && \
CGO_ENABLED=1 \
GOARCH=$(ARCH) \
$(GO) build -o "$(@)" -ldflags "$(GO_LDFLAGS) $(GO_LDFLAGS_CLI) -linkmode external -extldflags '$(GO_EXTLDFLAGS)'" $(GO_BUILD_TAGS) "$(CMD_DIR)/benchmark-launcher-cli/main.go"
endef
ifeq ($(UNAME_S),Darwin)
.PHONY: $(GUI_EXE_FILE)-amd64
$(GUI_EXE_FILE)-amd64: export CGO_CFLAGS = -mmacosx-version-min=$(DEPLOYMENT_TARGET_AMD64)
$(GUI_EXE_FILE)-amd64: export CGO_LDFLAGS = -mmacosx-version-min=$(DEPLOYMENT_TARGET_AMD64)
$(GUI_EXE_FILE)-amd64: export MACOSX_DEPLOYMENT_TARGET = $(DEPLOYMENT_TARGET_AMD64)
$(GUI_EXE_FILE)-amd64: freetype2 assets $(DEPENDENCIES_GUI)
$(eval ARCH := amd64)
$(call run-build-gui)
.PHONY: $(GUI_EXE_FILE)-arm64
$(GUI_EXE_FILE)-arm64: export CGO_CFLAGS = -mmacosx-version-min=$(DEPLOYMENT_TARGET_ARM64)
$(GUI_EXE_FILE)-arm64: export CGO_LDFLAGS = -mmacosx-version-min=$(DEPLOYMENT_TARGET_ARM64)
$(GUI_EXE_FILE)-arm64: export MACOSX_DEPLOYMENT_TARGET = $(DEPLOYMENT_TARGET_ARM64)
$(GUI_EXE_FILE)-arm64: freetype2 assets $(DEPENDENCIES_GUI)
$(eval ARCH := arm64)
$(call run-build-gui)
$(GUI_EXE_FILE): $(GUI_EXE_FILE)-amd64 $(GUI_EXE_FILE)-arm64
lipo -create -output $(@) $(GUI_EXE_FILE)-amd64 $(GUI_EXE_FILE)-arm64
.PHONY: $(CLI_EXE_FILE)-amd64
$(CLI_EXE_FILE)-amd64: export CGO_CFLAGS = -mmacosx-version-min=$(DEPLOYMENT_TARGET_AMD64)
$(CLI_EXE_FILE)-amd64: export CGO_LDFLAGS = -mmacosx-version-min=$(DEPLOYMENT_TARGET_AMD64)
$(CLI_EXE_FILE)-amd64: export MACOSX_DEPLOYMENT_TARGET = $(DEPLOYMENT_TARGET_AMD64)
$(CLI_EXE_FILE)-amd64:
$(eval ARCH := amd64)
$(call run-build-cli)
.PHONY: $(CLI_EXE_FILE)-arm64
$(CLI_EXE_FILE)-arm64: export CGO_CFLAGS = -mmacosx-version-min=$(DEPLOYMENT_TARGET_ARM64)
$(CLI_EXE_FILE)-arm64: export CGO_LDFLAGS = -mmacosx-version-min=$(DEPLOYMENT_TARGET_ARM64)
$(CLI_EXE_FILE)-arm64: export MACOSX_DEPLOYMENT_TARGET = $(DEPLOYMENT_TARGET_ARM64)
$(CLI_EXE_FILE)-arm64: $(DEPENDENCIES_CLI)
$(eval ARCH := arm64)
$(call run-build-cli)
.PHONY: $(CLI_EXE_FILE)
$(CLI_EXE_FILE): $(CLI_EXE_FILE)-amd64 $(CLI_EXE_FILE)-arm64
lipo -create -output $(@) $(CLI_EXE_FILE)-amd64 $(CLI_EXE_FILE)-arm64
else
.PHONY: $(GUI_EXE_FILE)
$(GUI_EXE_FILE): freetype2 assets $(DEPENDENCIES_GUI)
$(eval ARCH := amd64)
$(call run-build-gui)
.PHONY: $(CLI_EXE_FILE)
$(CLI_EXE_FILE): $(DEPENDENCIES_CLI)
$(eval ARCH := amd64)
$(call run-build-cli)
endif
.PHONY: package
package: $(PKG_GUI_FILE) $(PKG_CLI_FILE)
$(DIST_DIR)/benchmark-launcher-$(VERSION)-windows.zip: $(BIN_DIR)/windows/benchmark-launcher.exe
mkdir -p "$(@D)"
rm -f "$(@)"
cd "$(BIN_DIR)/windows/" && zip "$(@)" "benchmark-launcher.exe"
$(DIST_DIR)/benchmark-launcher-cli-$(VERSION)-windows.zip: $(BIN_DIR)/windows/benchmark-launcher-cli.exe
mkdir -p "$(@D)"
rm -f "$(@)"
cd "$(BIN_DIR)/windows/" && zip -j "$(@)" "benchmark-launcher-cli.exe" "$(CLI_RESOURCES_DIR)/$(CLI_README_TXT)"
$(DIST_DIR)/benchmark-launcher-$(VERSION)-linux.tar.gz: $(BIN_DIR)/linux/benchmark-launcher
mkdir -p "$(@D)"
rm -f "$(@)"
tar -czvf "$(@)" -C "$(BIN_DIR)/linux/" "benchmark-launcher"
$(DIST_DIR)/benchmark-launcher-cli-$(VERSION)-linux.tar.gz: $(BIN_DIR)/linux/benchmark-launcher-cli
mkdir -p "$(@D)"
rm -f "$(@)"
tar -czvf "$(@)" -C "$(BIN_DIR)/linux/" "benchmark-launcher-cli" -C "$(CLI_RESOURCES_DIR)" "$(CLI_README_TXT)"
$(DIST_DIR)/benchmark-launcher-$(VERSION)-macos.tar.gz: $(BIN_DIR)/darwin/benchmark-launcher
mkdir -p "$(@D)"
rm -f "$(@)"
set -eu; \
TMP_DIR="$$(mktemp -d)"; \
BUNDLE_DIR="$${TMP_DIR:?}/Blender Benchmark Launcher.app"; \
mkdir -p "$${BUNDLE_DIR:?}/Contents/MacOS"; \
cp "$(BIN_DIR)/darwin/benchmark-launcher" "$${BUNDLE_DIR:?}/Contents/MacOS/benchmark-launcher"; \
cp -R "$(ETC_DIR)/macos_bundle/Resources" "$${BUNDLE_DIR:?}/Contents/Resources"; \
VERSION="$(VERSION)" "$(ENVSUBST)" < "$(ETC_DIR)/macos_bundle/Info.template.plist" > "$${BUNDLE_DIR:?}/Contents/Info.plist"; \
tar -czvf "$(@)" -C "$${TMP_DIR:?}" "Blender Benchmark Launcher.app"; \
rm -rf "$${TMP_DIR:?}"
$(DIST_DIR)/benchmark-launcher-cli-$(VERSION)-macos.tar.gz: $(BIN_DIR)/darwin/benchmark-launcher-cli
mkdir -p "$(@D)"
rm -f "$(@)"
tar -czvf "$(@)" -C "$(BIN_DIR)/darwin/" "benchmark-launcher-cli" -C "$(CLI_RESOURCES_DIR)" "$(CLI_README_TXT)"
.PHONY: clean
clean: clean_dist clean_bin clean_go clean_freetype2 clean_assets clean_resources
.PHONY: clean_dist
clean_dist:
rm -rf "$(DIST_DIR)"
.PHONY: clean_bin
clean_bin:
rm -rf "$(BIN_DIR)"
.PHONY: clean_go
clean_go:
$(GO) clean -cache
.PHONY: freetype2
freetype2:
$(MAKE) -C freetype2
.PHONY: clean_freetype2
clean_freetype2:
$(MAKE) -C freetype2 clean
.PHONY: assets
assets:
$(GO) generate "$(ASSETS_DIR)"
.PHONY: clean_assets
clean_assets:
rm -f "$(ASSETS_DIR)/assets.go"
.PHONY: clean_resources
clean_resources:
rm -rf "$(ETC_DIR)/windows_resources/resources.o"
$(ETC_DIR)/windows_resources/resources.o:
cd "$(@D)" && windres resources.rc -O coff -o "$(@)"