-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
53 lines (44 loc) · 1.79 KB
/
Copy pathMakefile
File metadata and controls
53 lines (44 loc) · 1.79 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
# Makefile for ngx_http_api_discovery_module
#
# Usage:
# make # build the dynamic module (.so)
# make install # install into the running NGINX modules directory
# make test # run the test suite (requires prove + nginx)
# make lint # run clang-tidy static analysis
# make clean # remove build artefacts
NGINX_SRC ?= /usr/src/nginx
NGINX_BIN ?= $(shell which nginx 2>/dev/null || echo /usr/sbin/nginx)
NGINX_MODULES ?= $(shell $(NGINX_BIN) -V 2>&1 | grep -oP '(?<=--modules-path=)\S+' || echo /usr/lib/nginx/modules)
MODULE_SO := ngx_http_api_discovery_module.so
BUILD_DIR := $(NGINX_SRC)/objs
.PHONY: all build install test lint clean
all: build
build:
@echo "==> Configuring NGINX with dynamic module..."
@test -d "$(NGINX_SRC)" || { echo "ERROR: NGINX_SRC=$(NGINX_SRC) not found. Set NGINX_SRC=/path/to/nginx-src"; exit 1; }
cd $(NGINX_SRC) && ./configure \
--with-compat \
--add-dynamic-module=$(CURDIR) \
$$(nginx -V 2>&1 | grep 'configure arguments' | sed 's/.*configure arguments: //' | sed 's/--add-dynamic-module=[^ ]*//g' | sed 's/--add-module=[^ ]*//g')
cd $(NGINX_SRC) && $(MAKE) modules
@cp $(BUILD_DIR)/$(MODULE_SO) .
@echo "==> Built: $(MODULE_SO)"
install: build
@echo "==> Installing $(MODULE_SO) to $(NGINX_MODULES)/"
install -d $(NGINX_MODULES)
install -m 755 $(MODULE_SO) $(NGINX_MODULES)/
@echo "==> Done. Add to nginx.conf: load_module modules/$(MODULE_SO);"
test:
@echo "==> Running test suite..."
cd tests && prove -v .
lint:
clang-tidy src/ngx_http_api_discovery.c -- \
-I$(NGINX_SRC)/src/core \
-I$(NGINX_SRC)/src/http \
-I$(NGINX_SRC)/src/http/modules \
-I$(NGINX_SRC)/src/event \
-I$(NGINX_SRC)/src/os/unix \
-I$(NGINX_SRC)/objs
clean:
rm -f $(MODULE_SO)
@echo "==> Cleaned."