-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
121 lines (100 loc) · 2.77 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# ge
# 2023-04-05
# 2023-06-02
# make help
# Build for 64-bit with release tag for Linux
# $ make OS=linux BIT=64 TAG=release
# Build for 32-bit with develop tag for Windows
# $ make OS=windows BIT=32 TAG=develop
# Builds will be executed according to the specified options, and the build results will be generated in the ../build directory.
# Additionally, using the make clean command, you can remove the build results.
# Modify the build options and build output directory settings as needed to create a Makefile tailored to your project.
# Please refer to it.
# How to write AND condition:
# ifeq ($(variable1), value1)
# ifeq ($(variable2), value2)
# # Processing when both conditions are met
# endif
# endif
# Build for OS (linux, windows)
OS ?= linux
# Build for Bit (32, 64)
BIT ?= 64
ifeq ($(BIT), 64)
GOARCH = amd64
else ifeq ($(BIT), 32)
GOARCH = 386
else
$(error "Invalid BIT specified. Use BIT=[64|32]")
endif
# Tag (release, develop, debug)
# TAG ?= release
TAG ?= debug
# Build output directory
# BUILD_DIR = ../../build
BUILD_DIR = .
# Binary filename
BINARY_NAME = ge
# Build options
# BUILD_OPTIONS = -ldflags "-s -w"
BUILD_OPTIONS =
# Build tags
BUILD_TAGS ?= -tags debug
# Environment variables
# export CGO_ENABLED=1
# Setting build flags based on target
ifeq ($(OS), windows)
# Build flags for Windows
BUILD_FLAGS = GOOS=windows GOARCH=$(GOARCH)
# = Recursively expanded variable
# := Simply expanded variable
BINARY_NAME := $(BINARY_NAME).exe # To prevent from becoming recursively expanded variable
# ifeq ($(BIT), 32)
# export CC=i686-w64-mingw32-gcc
# else ifeq ($(BIT), 64)
# export CC=x86_64-w64-mingw32-gcc
# endif
# ifeq ($(TAG), release)
# BUILD_OPTIONS = -ldflags "-s -w -H windowsgui"
# endif
# BUILD_OPTIONS += -installsuffix cgo
else ifeq ($(OS), linux)
# Build flags for Linux
BUILD_FLAGS = GOOS=linux GOARCH=$(GOARCH)
# ifeq ($(TAG), release)
# BUILD_OPTIONS = -ldflags "-s -w"
# endif
else
$(error "Invalid OS specified. Use OS=[linux|windows]")
endif
ifeq ($(TAG), release)
BUILD_OPTIONS = -ldflags "-s -w" -trimpath -a
BUILD_TAGS += -tags release
else ifeq ($(TAG), develop)
BUILD_TAGS += -tags develop
else ifeq ($(TAG), debug)
BUILD_TAGS += -tags debug
else
$(error "Invalid TAG specified. Use TAG=[release|develop|debug]")
endif
# Build target
.PHONY: build
build:
@echo "Building $(OS) $(BIT)-bit with $(TAG) tag..."
@mkdir -p $(BUILD_DIR)
$(BUILD_FLAGS) go build $(BUILD_TAGS) $(BUILD_OPTIONS) -o $(BUILD_DIR)/$(BINARY_NAME)
# Clean target
.PHONY: clean
clean:
@echo "Cleaning up..."
# rm -rf $(BUILD_DIR)
trash $(BUILD_DIR)
# Help target
.PHONY: help
help:
@echo build:
@echo ' OS=[linux|windows]'
@echo ' BIT=[64|32]'
@echo ' TAG=[release|develop|debug]'
@echo clean
@echo help