-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile.mk
More file actions
111 lines (96 loc) · 3.76 KB
/
Makefile.mk
File metadata and controls
111 lines (96 loc) · 3.76 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
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
# OTEL_DEBUG : compile the OpenTelemetry filter in debug mode
# OTEL_INC : force the include path to libopentelemetry-c-wrapper
# OTEL_LIB : force the lib path to libopentelemetry-c-wrapper
# OTEL_RUNPATH : add libopentelemetry-c-wrapper RUNPATH to haproxy executable
# OTEL_STATIC : pass --static to pkg-config (for static linking only)
# OTEL_USE_VARS : allows the use of variables for the OpenTelemetry context
# Absolute path to the directory holding *this* Makefile.inc; resolved at
# include time so that all source / header references work regardless of the
# directory make was invoked from.
OTEL_DIR := $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
OTEL_DEFINE =
OTEL_CFLAGS =
OTEL_LDFLAGS =
OTEL_DEBUG_EXT =
OTEL_PKGSTAT =
OTELC_WRAPPER = opentelemetry-c-wrapper
ifneq ($(OTEL_DEBUG:0=),)
OTEL_DEBUG_EXT = _dbg
OTEL_DEFINE = -DDEBUG_OTEL
endif
ifeq ($(OTEL_INC),)
OTEL_PKGSTAT = $(shell pkg-config --exists $(OTELC_WRAPPER)$(OTEL_DEBUG_EXT); echo $$?)
OTEL_CFLAGS = $(shell pkg-config --silence-errors --cflags $(OTELC_WRAPPER)$(OTEL_DEBUG_EXT))
else
ifneq ($(wildcard $(OTEL_INC)/$(OTELC_WRAPPER)/.*),)
OTEL_CFLAGS = -I$(OTEL_INC) $(if $(OTEL_DEBUG),-DOTELC_DBG_MEM)
endif
endif
ifeq ($(OTEL_PKGSTAT),)
ifeq ($(OTEL_CFLAGS),)
$(error OpenTelemetry C wrapper : can't find headers)
endif
else
ifneq ($(OTEL_PKGSTAT),0)
$(error OpenTelemetry C wrapper : can't find package)
endif
endif
ifeq ($(OTEL_LIB),)
OTEL_PKG_STATIC = $(if $(OTEL_STATIC:0=),--static,)
OTEL_LDFLAGS = $(shell pkg-config --silence-errors $(OTEL_PKG_STATIC) --libs $(OTELC_WRAPPER)$(OTEL_DEBUG_EXT))
else
ifneq ($(wildcard $(OTEL_LIB)/lib$(OTELC_WRAPPER).*),)
OTEL_LDFLAGS = -L$(OTEL_LIB) -l$(OTELC_WRAPPER)$(OTEL_DEBUG_EXT)
ifneq ($(OTEL_RUNPATH),)
OTEL_LDFLAGS += -Wl,--rpath,$(OTEL_LIB)
endif
endif
endif
ifeq ($(OTEL_LDFLAGS),)
$(error OpenTelemetry C wrapper : can't find library)
endif
OPTIONS_OBJS += \
$(OTEL_DIR)/src/cli.o \
$(OTEL_DIR)/src/conf.o \
$(OTEL_DIR)/src/event.o \
$(OTEL_DIR)/src/filter.o \
$(OTEL_DIR)/src/group.o \
$(OTEL_DIR)/src/http.o \
$(OTEL_DIR)/src/otelc.o \
$(OTEL_DIR)/src/parser.o \
$(OTEL_DIR)/src/pool.o \
$(OTEL_DIR)/src/scope.o \
$(OTEL_DIR)/src/util.o
ifneq ($(OTEL_USE_VARS:0=),)
OTEL_DEFINE += -DUSE_OTEL_VARS
OPTIONS_OBJS += $(OTEL_DIR)/src/vars.o
# Auto-detect whether struct var has a 'name' member. When present,
# prefix-based variable scanning can be used instead of the tracking
# buffer approach.
OTEL_VAR_HAS_NAME := $(shell awk '/^struct var \{/,/^\}/' include/haproxy/vars-t.h 2>/dev/null | grep -q '[*]name;' && echo 1)
ifneq ($(OTEL_VAR_HAS_NAME),)
OTEL_DEFINE += -DUSE_OTEL_VARS_NAME
endif
endif
OTEL_CFLAGS := $(OTEL_CFLAGS) -I$(OTEL_DIR)/include $(OTEL_DEFINE)
# OTEL is no longer part of haproxy's use_opts list, so $(collect_opts_flags)
# would not pick these up automatically. Inject them ourselves; this include
# runs before COPTS / LDOPTS are assembled.
OPTIONS_CFLAGS += $(OTEL_CFLAGS)
OPTIONS_LDFLAGS += $(OTEL_LDFLAGS)
# Hook into haproxy's 'clean' target. A rule without a recipe only adds
# prerequisites, so this extends haproxy's clean instead of colliding with its
# recipe. The actual cleanup lives in the phony 'otel-clean' target.
#
# This fragment is included before haproxy's own first target ('all:'), so any
# rule below would otherwise become Make's default goal and a bare 'make' would
# run that rule instead of building. Clearing .DEFAULT_GOAL after all rules
# re-enables auto-selection, letting haproxy's 'all:' claim the default.
clean: otel-clean
.PHONY: otel-clean
otel-clean:
$(Q)rm -f $(OTEL_DIR)/src/*.[oas]
$(Q)rm -f $(OTEL_DIR)/src/*~ $(OTEL_DIR)/src/*.rej
$(Q)rm -f $(OTEL_DIR)/include/*~ $(OTEL_DIR)/include/*.rej
$(Q)rm -f $(OTEL_DIR)/core $(OTEL_DIR)/test/core
.DEFAULT_GOAL :=