|
| 1 | +MODULE = nginx_acme |
| 2 | +# build/build-%.mk: debug, debug-static, release, release-static, sanitize |
| 3 | +BUILD ?= debug |
| 4 | +TESTS ?= t/ |
| 5 | +NGX_CARGO ?= cargo |
| 6 | +# will be used to print host-tuple |
| 7 | +NGX_RUSTC ?= rustc |
| 8 | + |
| 9 | +NGINX_CONFIGURE_BASE = \ |
| 10 | + auto/configure \ |
| 11 | + --with-http_ssl_module \ |
| 12 | + --with-http_v2_module \ |
| 13 | + --with-pcre \ |
| 14 | + --with-stream \ |
| 15 | + --with-stream_ssl_module \ |
| 16 | + --with-compat |
| 17 | + |
| 18 | +NGINX_SOURCE_DIR ?= ../nginx |
| 19 | +NGINX_TESTS_DIR ?= $(NGINX_SOURCE_DIR)/tests |
| 20 | +NGINX_BUILD_DIR ?= $(CURDIR)/objs-$(BUILD) |
| 21 | + |
| 22 | +TEST_NGINX_BINARY = $(NGINX_BUILD_DIR)/nginx |
| 23 | + |
| 24 | +# "build" always calls cargo and causes relinking. |
| 25 | +# Clearing this var allows to skip the build step: "make test TEST_PREREQ=" |
| 26 | +TEST_PREREQ = build |
| 27 | + |
| 28 | +# Conditionals via include, compatible with most implementations of make |
| 29 | + |
| 30 | +# GNU make 3.81 or earlier |
| 31 | +MAKE_FLAVOR:= gnu |
| 32 | +# POSIX 2024, BSD, GNU make 3.82+, etc |
| 33 | +MAKE_FLAVOR!= echo posix |
| 34 | + |
| 35 | +include build/compat-$(MAKE_FLAVOR).mk |
| 36 | +include build/build-$(BUILD).mk |
| 37 | + |
| 38 | +# Set up environment propagation |
| 39 | + |
| 40 | +BUILD_ENV += NGINX_SOURCE_DIR="$(NGINX_SOURCE_DIR)" |
| 41 | +BUILD_ENV += NGINX_BUILD_DIR="$(NGINX_BUILD_DIR)" |
| 42 | + |
| 43 | +TEST_ENV += RUST_BACKTRACE=1 |
| 44 | +TEST_ENV += TEST_NGINX_BINARY="$(TEST_NGINX_BINARY)" |
| 45 | +TEST_ENV += TEST_NGINX_GLOBALS="$(TEST_NGINX_GLOBALS)" |
| 46 | + |
| 47 | +# Build targets |
| 48 | + |
| 49 | +.PHONY: all help build check test clean |
| 50 | + |
| 51 | +all: ## Build, lint and test the module |
| 52 | +all: build check unittest test |
| 53 | + |
| 54 | +help: |
| 55 | + @echo "Available targets:" |
| 56 | + @awk 'BEGIN {FS = ":.*?## "}; /^[ a-zA-Z_-]+:.*?## .*$$/ {printf "%-16s %s\n", $$1, $$2}' \ |
| 57 | + Makefile $(MAKEFILE_LIST) | sort -u |
| 58 | + @echo "Pass BUILD=<configuration> to any target for desired build configuration." |
| 59 | + @echo "Pass NGINX_SOURCE_DIR to specify path to your NGINX source checkout." |
| 60 | + |
| 61 | +# Always rebuild targets managed by external build tool |
| 62 | +.PHONY: target/debug/lib$(MODULE)$(NGX_MODEXT) \ |
| 63 | + target/release/lib$(MODULE)$(NGX_MODEXT) \ |
| 64 | + $(TEST_NGINX_BINARY) |
| 65 | + |
| 66 | +$(NGINX_BUILD_DIR)/Makefile: config config.make auto/rust |
| 67 | +$(NGINX_BUILD_DIR)/Makefile: $(NGINX_SOURCE_DIR)/src/core/nginx.h |
| 68 | +# auto/configure unconditionally generates $NGINX_SOURCE_DIR/Makefile, even for |
| 69 | +# out-of-tree builds. Preserve the original Makefile and restore it later. |
| 70 | + @-cd $(NGINX_SOURCE_DIR) && rm -f Makefile.bak \ |
| 71 | + && test -f Makefile && mv -f Makefile Makefile.bak |
| 72 | + cd $(NGINX_SOURCE_DIR) \ |
| 73 | + && $(BUILD_ENV) $(NGINX_CONFIGURE) --builddir=$(NGINX_BUILD_DIR) \ |
| 74 | + && rm -f $(NGINX_SOURCE_DIR)/Makefile |
| 75 | + @-mv $(NGINX_SOURCE_DIR)/Makefile.bak $(NGINX_SOURCE_DIR)/Makefile |
| 76 | + |
| 77 | +$(TEST_NGINX_BINARY): $(NGINX_BUILD_DIR)/Makefile |
| 78 | + cd $(NGINX_SOURCE_DIR) \ |
| 79 | + && $(BUILD_ENV) $(MAKE) -f $(NGINX_BUILD_DIR)/Makefile |
| 80 | + |
| 81 | +target/debug/lib$(MODULE)$(NGX_MODEXT): $(NGINX_BUILD_DIR)/Makefile |
| 82 | + $(BUILD_ENV) $(NGX_CARGO) build |
| 83 | + |
| 84 | +target/release/lib$(MODULE)$(NGX_MODEXT): $(NGINX_BUILD_DIR)/Makefile |
| 85 | + $(BUILD_ENV) $(NGX_CARGO) build --release |
| 86 | + |
| 87 | +build: $(TEST_NGINX_BINARY) ## Build the module |
| 88 | + |
| 89 | +check: $(NGINX_BUILD_DIR)/Makefile ## Check style and lint |
| 90 | + $(BUILD_ENV) $(NGX_CARGO) fmt --all -- --check |
| 91 | + $(BUILD_ENV) $(NGX_CARGO) clippy --all-targets --verbose -- -D warnings |
| 92 | + |
| 93 | +unittest: $(NGINX_BUILD_DIR)/Makefile ## Run unit-tests |
| 94 | + $(BUILD_ENV) $(NGX_CARGO) test |
| 95 | + |
| 96 | +test: $(TEST_PREREQ) ## Run the integration test suite |
| 97 | + env $(TEST_ENV) prove -I $(NGINX_TESTS_DIR)/lib --state=save $(TESTS) ||\ |
| 98 | + env $(TEST_ENV) prove -I $(NGINX_TESTS_DIR)/lib --state=failed -v |
| 99 | + |
| 100 | +clean: ## Cleanup everything |
| 101 | + rm -rf $(NGINX_BUILD_DIR) |
| 102 | + $(NGX_CARGO) clean |
| 103 | + |
| 104 | +# GNU make convenience targets. Will be ignored by other implementations. |
| 105 | + |
| 106 | +build-%: ## Build with the specified configuration. E.g. make build-sanitize. |
| 107 | + $(MAKE) build BUILD="$*" |
| 108 | + |
| 109 | +test-%: ## Test with the specified configuration. |
| 110 | + $(MAKE) test BUILD="$*" |
0 commit comments