-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
63 lines (50 loc) · 1.61 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# 检查操作系统类型
ifeq ($(OS),Windows_NT)
IGNORE_OUTPUT := >NUL 2>&1
RM := powershell.exe -Command "Remove-Item -Force -Recurse"
else
IGNORE_OUTPUT := >/dev/null 2>&1
RM := rm -rf
endif
GOOS := $(shell go env GOOS)
GOARCH := $(shell go env GOARCH)
ifeq ($(VERSION),)
$(error VERSION environment variable is not set)
endif
VERSION ?= $(VERSION)
EXE_NAME = video-thumb
EXTENSION ?=
ifeq ($(GOOS),windows)
EXTENSION = .exe
endif
# 输出文件名
OUTPUT_NAME := $(EXE_NAME)-$(VERSION)-$(GOARCH)_$(GOOS)$(EXTENSION)
# 编译目标文件夹
BUILD_DIR := build
# 编译命令
BUILD_CMD_RELEASE := go build -a -v -trimpath -ldflags="-s -w -X main.BuildVersion=${VERSION}" -tags="release" -o $(BUILD_DIR)/$(OUTPUT_NAME) github.com/kmou424/go-video-thumb/cmd
BUILD_CMD_DEBUG := go build -a -v -trimpath -ldflags="-s -w -X main.BuildVersion=${VERSION}" -o $(BUILD_DIR)/$(OUTPUT_NAME) github.com/kmou424/go-video-thumb/cmd
.PHONY: all build clean
all: clean build
build:
@echo "Building $(OUTPUT_NAME)..."
@mkdir -p $(BUILD_DIR)
$(BUILD_CMD_RELEASE)
@if [ -n "$$UPX_ENABLED" ]; then \
echo "Compressing executable using UPX..."; \
upx -9 $(BUILD_DIR)/$(OUTPUT_NAME) $(IGNORE_OUTPUT); \
fi
@echo "Build completed."
debug:
@echo "Building debugging $(OUTPUT_NAME)..."
@mkdir -p $(BUILD_DIR)
$(BUILD_CMD_RELEASE)
@if [ -n "$$UPX_ENABLED" ]; then \
echo "Compressing executable using UPX..."; \
upx -9 $(BUILD_DIR)/$(OUTPUT_NAME) $(IGNORE_OUTPUT); \
fi
@echo "Build completed."
clean:
@echo "Cleaning..."
@$(RM) $(BUILD_DIR)
@echo "Clean completed."