-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
48 lines (38 loc) · 2.29 KB
/
Makefile
File metadata and controls
48 lines (38 loc) · 2.29 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
# Overridable: `make bench LUAJIT=/path/to/luajit RESTY=/path/to/resty LUA_CPATH='...'`
OPENRESTY ?= /usr/local/openresty
OPENRESTY_LUAJIT := $(OPENRESTY)/luajit/bin/luajit
OPENRESTY_RESTY := $(OPENRESTY)/bin/resty
LUAJIT ?= $(shell if [ -x "$(OPENRESTY_LUAJIT)" ]; then echo "$(OPENRESTY_LUAJIT)"; else command -v luajit 2>/dev/null || echo luajit; fi)
RESTY ?= $(shell if [ -x "$(OPENRESTY_RESTY)" ]; then echo "$(OPENRESTY_RESTY)"; else command -v resty 2>/dev/null || echo resty; fi)
LUA_PATH ?= ./lua/?.lua;$(OPENRESTY)/lualib/?.lua;$(OPENRESTY)/lualib/?/init.lua;;
LUA_CPATH ?= ./vendor/lua-cjson/?.so;./target/release/lib?.so;./?.so;$(OPENRESTY)/lualib/?.so;/usr/local/lib/lua/5.1/?.so;$(OPENRESTY)/luajit/lib/lua/5.1/?.so
LUAJIT_PREFIX ?= $(shell dirname $$(dirname $$(command -v $(LUAJIT) 2>/dev/null || echo $(OPENRESTY_LUAJIT))))
LUAJIT_INC ?= $(LUAJIT_PREFIX)/include/luajit-2.1
LIB_DIR := $(CURDIR)/target/release
ifeq ($(shell uname),Darwin)
LUA_ENV := DYLD_LIBRARY_PATH=$(LIB_DIR) LUA_PATH='$(LUA_PATH)' LUA_CPATH='$(LUA_CPATH)'
else
LUA_ENV := LD_LIBRARY_PATH=$(LIB_DIR) LUA_PATH='$(LUA_PATH)' LUA_CPATH='$(LUA_CPATH)'
endif
.PHONY: help build test lint bench clean
help: ## Show this help
@# FS uses [^#]* (not .*) so a description containing `##` isn't truncated.
@# Consequence: targets whose prerequisite list contains `#` won't render — none today.
@awk 'BEGIN {FS = ":[^#]*## "} /^[a-zA-Z_-]+:[^#]*## / {printf " \033[36m%-10s\033[0m — %s\n", $$1, $$2}' $(MAKEFILE_LIST)
build: ## Build the release cdylib (target/release/libqjson.so)
cargo build --release
test: build ## Run cargo tests + busted Lua tests
cargo test --release
$(LUA_ENV) busted --lua=$(LUAJIT) tests/lua --lpath='./lua/?.lua'
lint: ## Run clippy with -D warnings
cargo clippy --release --all-targets -- -D warnings
bench: build vendor/lua-cjson/cjson.so ## Run the OpenResty LuaJIT benchmark
$(LUA_ENV) $(RESTY) benches/lua_bench.lua
vendor/lua-cjson/cjson.so: | vendor/lua-cjson/Makefile
ifeq ($(shell uname),Darwin)
$(MAKE) -C vendor/lua-cjson PREFIX=$(LUAJIT_PREFIX) LUA_INCLUDE_DIR=$(LUAJIT_INC) LUA=$(LUAJIT) CJSON_LDFLAGS="-bundle -undefined dynamic_lookup"
else
$(MAKE) -C vendor/lua-cjson PREFIX=$(LUAJIT_PREFIX) LUA_INCLUDE_DIR=$(LUAJIT_INC) LUA=$(LUAJIT)
endif
clean: ## Remove build artifacts
cargo clean