-
Notifications
You must be signed in to change notification settings - Fork 43
/
Makefile
109 lines (88 loc) · 3.45 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
# Copyright (c) 2024 Alibaba Group Holding Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http:#www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#-------------------------------------------------------------------------------
# General build options
# Change this parameter while releasing
MAIN_VERSION := 0.4.0
CURRENT_OS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
CURRENT_ARCH := $(shell uname -m)
MOD_NAME := github.com/alibaba/opentelemetry-go-auto-instrumentation
STRIP_DEBUG := -s -w
LDFLAGS := $(XVERSION) $(STRIP_DEBUG)
# default build cmd without ldflags
BUILD_CMD = CGO_ENABLED=0 GOOS=$(1) GOARCH=$(2) go build -a -o $(3) ./tool/cmd
OUTPUT_BASE = otel
OUTPUT_DARWIN_AMD64 = $(OUTPUT_BASE)-darwin-amd64
OUTPUT_LINUX_AMD64 = $(OUTPUT_BASE)-linux-amd64
OUTPUT_WINDOWS_AMD64 = $(OUTPUT_BASE)-windows-amd64.exe
OUTPUT_DARWIN_ARM64 = $(OUTPUT_BASE)-darwin-arm64
OUTPUT_LINUX_ARM64 = $(OUTPUT_BASE)-linux-arm64
#-------------------------------------------------------------------------------
# Prepare version
# Get the current Git commit ID
CHECK_GIT_DIRECTORY := $(if $(wildcard .git),true,false)
ifeq ($(CHECK_GIT_DIRECTORY),true)
COMMIT_ID := $(shell git rev-parse --short HEAD)
else
COMMIT_ID := default
endif
VERSION := $(MAIN_VERSION)_$(COMMIT_ID)
XVERSION := -X=$(MOD_NAME)/tool/config.ToolVersion=$(VERSION) -X=$(MOD_NAME)/pkg/inst-api/version.Tag=v$(VERSION)
LDFLAGS := $(XVERSION) $(STRIP_DEBUG)
BUILD_CMD = CGO_ENABLED=0 GOOS=$(1) GOARCH=$(2) go build -a -ldflags="$(LDFLAGS)" -o $(3) ./tool/cmd
#-------------------------------------------------------------------------------
# Multiple OS and ARCH support
ifeq ($(CURRENT_ARCH), x86_64)
CURRENT_ARCH := amd64
endif
# Check if current os contains "MINGW" or "MSYS" to determine if it is Windows
ifeq ($(findstring mingw,$(CURRENT_OS)),mingw)
CURRENT_OS := windows
endif
ifeq ($(findstring msys,$(CURRENT_OS)),msys)
CURRENT_OS := windows
endif
#-------------------------------------------------------------------------------
# Build targets
.PHONY: build
build: tidy
$(eval OUTPUT_BIN=$(OUTPUT_BASE))
ifeq ($(CURRENT_OS),windows)
$(eval OUTPUT_BIN=$(OUTPUT_BASE).exe)
endif
$(call BUILD_CMD,$(CURRENT_OS),$(CURRENT_ARCH),$(OUTPUT_BIN))
.PHONY: all test clean
all: clean darwin_amd64 linux_amd64 windows_amd64 darwin_arm64 linux_arm64
darwin_amd64: tidy
$(call BUILD_CMD,darwin,amd64,$(OUTPUT_DARWIN_AMD64))
linux_amd64: tidy
$(call BUILD_CMD,linux,amd64,$(OUTPUT_LINUX_AMD64))
windows_amd64: tidy
$(call BUILD_CMD,windows,amd64,$(OUTPUT_WINDOWS_AMD64))
darwin_arm64: tidy
$(call BUILD_CMD,darwin,arm64,$(OUTPUT_DARWIN_ARM64))
linux_arm64: tidy
$(call BUILD_CMD,linux,arm64,$(OUTPUT_LINUX_ARM64))
.PHONY: tidy
tidy:
go mod tidy
clean:
rm -f $(OUTPUT_DARWIN_AMD64) $(OUTPUT_LINUX_AMD64) $(OUTPUT_WINDOWS_AMD64) $(OUTPUT_DARWIN_ARM64) $(OUTPUT_LINUX_ARM64) $(OUTPUT_BASE)
go clean
test:
go test -timeout 50m -v $(MOD_NAME)/test
install: build
@echo "Running install process..."
cp $(OUTPUT_BASE) /usr/local/bin/
@echo "Installed at /usr/local/bin/$(OUTPUT_BASE)"