-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathcommon.mk
More file actions
63 lines (51 loc) · 2.81 KB
/
common.mk
File metadata and controls
63 lines (51 loc) · 2.81 KB
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
# Common makefile shared between Teleport OSS and Ent.
# -----------------------------------------------------------------------------
# pkg-config / pkgconf
# Set $(PKGCONF) to either pkgconf or pkg-config if either are installed
# or /usr/bin/false if not. When it is set to "false", running $(PKGCONF)
# will exit non-zero with no output.
#
# Before GNU make 4.4, exported variables were not exported for $(shell ...)
# expressions, so explicitly set PKG_CONFIG_PATH when running $(PKGCONF).
PKGCONF := PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(firstword $(shell which pkgconf pkg-config false 2>/dev/null))
# -----------------------------------------------------------------------------
# Requirements for building with BPF support:
# * linux on amd64 or amd64
# * Either using a cross-compiling buildbox or is a native build
#
# The default is without BPF support unless all the critera are met.
with_bpf := no
BPF_MESSAGE := without-BPF-support
# Is this build targeting the same OS & architecture it is being compiled on, or
# will it require cross-compilation? We need to know this (especially for ARM) so we
# can set the cross-compiler path (and possibly feature flags) correctly.
IS_NATIVE_BUILD ?= $(filter $(ARCH),$(shell go env GOARCH))
IS_CROSS_COMPILE_BB = $(filter $(BUILDBOX_MODE),cross)
# Only build with BPF for linux/amd64 and linux/arm64.
# Other builds have compilation issues that require fixing.
ifneq (,$(filter $(OS)/$(ARCH),linux/amd64 linux/arm64))
# Only build with BPF if its a native build or in a cross-compiling buildbox.
ifneq (,$(or $(IS_NATIVE_BUILD),$(IS_CROSS_COMPILE_BB)))
with_bpf := yes
BPF_TAG := bpf
BPF_MESSAGE := with-BPF-support
INCLUDES :=
# Link static version of libraries required by Teleport (pcsc) to reduce system dependencies. Avoid dependencies on dynamic libraries if we already link the static version using --as-needed.
CGOFLAG = CGO_ENABLED=1 CGO_LDFLAGS="-Wl,-Bstatic $(STATIC_LIBS) -Wl,-Bdynamic -Wl,--as-needed"
CGOFLAG_TSH = CGO_ENABLED=1 CGO_LDFLAGS="-Wl,-Bstatic $(STATIC_LIBS_TSH) -Wl,-Bdynamic -Wl,--as-needed"
endif # IS_NATIVE_BUILD || IS_CROSS_COMPILE_BB
endif # OS/ARCH == linux/amd64 OR linux/arm64
.PHONY: diag-bpf-vars
diag-bpf-vars:
@echo os/arch: $(OS)-$(ARCH)
@echo is-native: $(IS_NATIVE_BUILD)
@echo is-cross: $(IS_CROSS_COMPILE_BB)
@echo buildbox-mode: $(BUILDBOX_MODE)
# Dir of last included file, in this case common.mk:
COMMON_MK_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
# This allows $(GOTESTSUM) in any Makefile that includes common.mk:
TOOLS_DIR := $(abspath $(COMMON_MK_DIR)/build.assets/tools)
GOTESTSUM = "$$( GOWORK=off go -C $(TOOLS_DIR)/gotestsum tool -n gotestsum )"
GCI = "$$( GOWORK=off go -C $(TOOLS_DIR)/gci tool -n gci )"
GODA = "$$( GOWORK=off go -C $(TOOLS_DIR)/goda tool -n goda )"
BENCHSTAT = "$$( GOWORK=off go -C $(TOOLS_DIR)/benchstat tool -n benchstat )"