-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathMakefile
More file actions
140 lines (103 loc) · 4.45 KB
/
Copy pathMakefile
File metadata and controls
140 lines (103 loc) · 4.45 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# NGINX module name (should match the exported symbol name).
MODULE_NAME = ngx_http_acme_module
# Target name used by cargo build.
TARGET_NAME = nginx_acme
# build/build-%.mk: debug, debug-static, release, release-static, sanitize, ...
BUILD ?= debug
TESTS ?= t/
NGX_CARGO ?= cargo
NGINX_CONFIGURE_BASE = \
auto/configure \
--with-http_ssl_module \
--with-http_v2_module \
--with-pcre \
--with-stream \
--with-stream_ssl_module \
--with-compat
NGINX_SOURCE_DIR ?= ../nginx
NGINX_TESTS_DIR ?= $(NGINX_SOURCE_DIR)/tests
NGINX_BUILD_DIR ?= $(CURDIR)/objs-$(BUILD)
TEST_NGINX_BINARY = $(NGINX_BUILD_DIR)/nginx
TEST_NGINX_GLOBALS += env RUST_BACKTRACE;
# Shared library generated with --add-dynamic-module=.
NGINX_BUILT_MODULE = $(NGINX_BUILD_DIR)/$(MODULE_NAME).so
# Shared libraries generated by cargo build.
CARGO_DEBUG_MODULE = target/debug/lib$(TARGET_NAME)$(SHLIB_EXT)
CARGO_RELEASE_MODULE = target/release/lib$(TARGET_NAME)$(SHLIB_EXT)
# "build" always calls cargo and causes relinking.
# Clearing this var allows to skip the build step: "make test TEST_PREREQ="
TEST_PREREQ = build
.PHONY: all
all: ## Build, lint and test the module
all: build check test
# Conditionals via include, compatible with most implementations of make
# GNU make 3.81 or earlier
MAKE_FLAVOR:= gnu
# POSIX 2024, BSD, GNU make 3.82+, etc
MAKE_FLAVOR!= echo posix
include build/compat-$(MAKE_FLAVOR).mk
include build/build-$(BUILD).mk
# Set up environment propagation
BUILD_ENV += NGINX_SOURCE_DIR="$(NGINX_SOURCE_DIR)"
BUILD_ENV += NGINX_BUILD_DIR="$(NGINX_BUILD_DIR)"
TEST_ENV += RUST_BACKTRACE=1
TEST_ENV += TEST_NGINX_BINARY="$(TEST_NGINX_BINARY)"
TEST_ENV += TEST_NGINX_GLOBALS="$(TEST_NGINX_GLOBALS)"
# Build targets
.PHONY: help build check unittest test full-test clean
help:
@echo "Available targets:"
@awk 'BEGIN {FS = ":.*?## "}; /^[ a-zA-Z_-]+:.*?## .*$$/ {printf "%-16s %s\n", $$1, $$2}' \
Makefile $(MAKEFILE_LIST) | sort -u
@echo "Pass BUILD=<configuration> to any target for desired build configuration."
@echo "Pass NGINX_SOURCE_DIR to specify path to your NGINX source checkout."
# Always rebuild targets managed by external build tool
.PHONY: $(CARGO_DEBUG_MODULE) $(CARGO_RELEASE_MODULE) $(NGINX_BUILT_MODULE) \
$(TEST_NGINX_BINARY)
$(NGINX_BUILD_DIR)/Makefile: config config.make auto/rust
$(NGINX_BUILD_DIR)/Makefile: $(NGINX_SOURCE_DIR)/src/core/nginx.h
# auto/configure unconditionally generates $NGINX_SOURCE_DIR/Makefile, even for
# out-of-tree builds. Preserve the original Makefile and restore it later.
@-cd $(NGINX_SOURCE_DIR) && rm -f Makefile.bak \
&& test -f Makefile && mv -f Makefile Makefile.bak
cd $(NGINX_SOURCE_DIR) \
&& $(BUILD_ENV) $(NGINX_CONFIGURE) --builddir=$(NGINX_BUILD_DIR) \
&& rm -f $(NGINX_SOURCE_DIR)/Makefile
@-mv $(NGINX_SOURCE_DIR)/Makefile.bak $(NGINX_SOURCE_DIR)/Makefile
$(TEST_NGINX_BINARY): $(NGINX_BUILD_DIR)/Makefile
cd $(NGINX_SOURCE_DIR) \
&& $(BUILD_ENV) $(MAKE) -f $(NGINX_BUILD_DIR)/Makefile binary
$(NGINX_BUILT_MODULE): $(NGINX_BUILD_DIR)/Makefile
cd $(NGINX_SOURCE_DIR) \
&& $(BUILD_ENV) $(MAKE) -f $(NGINX_BUILD_DIR)/Makefile modules
$(CARGO_DEBUG_MODULE): $(NGINX_BUILD_DIR)/Makefile
$(BUILD_ENV) $(NGX_CARGO) build
$(CARGO_RELEASE_MODULE): $(NGINX_BUILD_DIR)/Makefile
$(BUILD_ENV) $(NGX_CARGO) build --release
build: $(TEST_NGINX_BINARY) ## Build the module
check: $(NGINX_BUILD_DIR)/Makefile ## Check style and lint
$(BUILD_ENV) $(NGX_CARGO) fmt --all -- --check
$(BUILD_ENV) $(NGX_CARGO) clippy --all-targets --verbose -- -D warnings
unittest: $(NGINX_BUILD_DIR)/Makefile ## Run unit-tests
$(BUILD_ENV) $(NGX_CARGO) test
PROVE = env $(TEST_ENV) prove -I $(NGINX_TESTS_DIR)/lib
test: $(TEST_PREREQ) ## Run the integration test suite
if [ 0$(TEST_JOBS) -gt 1 ]; then \
$(PROVE) --state=save -j $(TEST_JOBS) $(TESTS) || \
$(PROVE) --state=failed -v; \
else \
$(PROVE) -v $(TESTS); \
fi
full-test: $(TEST_PREREQ) ## Run the module and NGINX integration test suites
# --statefile first appeared in Test-Harness-3.40_01, Jul 23, 2017
$(PROVE) --statefile=".prove-full" --state=save -j $(TEST_JOBS) \
$(TESTS) $(NGINX_TESTS_DIR) || \
$(PROVE) --statefile=".prove-full" --state=failed -v
clean: ## Cleanup everything
rm -rf $(NGINX_BUILD_DIR)
$(NGX_CARGO) clean
# GNU make convenience targets. Will be ignored by other implementations.
build-%: ## Build with the specified configuration. E.g. make build-sanitize.
$(MAKE) build BUILD="$*"
test-%: ## Test with the specified configuration.
$(MAKE) test BUILD="$*"