This repository has been archived by the owner on Jun 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathMakefile
97 lines (75 loc) · 2.79 KB
/
Makefile
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
# This Makefile creates a project-private prefix ".deps/usr" with all
# dependencies required for building/testing.
# local.mk is ignored by git, use it for local build settings.
-include local.mk
# Use TEST_TAG=foo to pass --tags=foo to busted.
_TEST_TAG := $(if $(TEST_TAG),--tags=$(TEST_TAG),)
# Dependencies prefix
DEPS_DIR ?= $(shell pwd)/.deps
DEPS_PREFIX ?= $(DEPS_DIR)/usr
DEPS_BIN ?= $(DEPS_PREFIX)/bin
# Lua-related configuration
LUA_URL ?= http://www.lua.org/ftp/lua-5.1.5.tar.gz
LUAROCKS_URL ?= https://github.com/keplerproject/luarocks/archive/v2.2.0.tar.gz
LUA_TARGET ?= linux
LUA ?= $(DEPS_BIN)/lua
LUAROCKS ?= $(DEPS_BIN)/luarocks
BUSTED ?= $(DEPS_BIN)/busted
LUV ?= $(DEPS_PREFIX)/lib/luarocks/rocks/luv
MPACK ?= $(DEPS_PREFIX)/lib/luarocks/rocks/mpack
COXPCALL ?= $(DEPS_PREFIX)/lib/luarocks/rocks/coxpcall
# Compilation
CC ?= gcc
CFLAGS ?= -g -fPIC -Wall -Wextra -Werror -Wconversion -Wextra \
-Wstrict-prototypes -pedantic
LDFLAGS ?= -shared -fPIC -undefined dynamic_lookup
DEPS_INCLUDE_FLAGS ?= -I$(DEPS_PREFIX)/include
# Misc
# Options used by the 'valgrind' target, which runs the tests under valgrind
VALGRIND_OPTS ?= --log-file=valgrind.log --leak-check=yes --track-origins=yes
# Command that will download a file and pipe it's contents to stdout
FETCH ?= curl -L -o -
# Command that will gunzip/untar a file from stdin to the current directory,
# stripping one directory component
UNTGZ ?= tar xfz - --strip-components=1
all: deps nvim/native.so
deps: | $(MPACK) $(COXPCALL) $(BUSTED) $(LUV)
test: all
NVIM_LOG_FILE=nvimlog $(BUSTED) -v $(_TEST_TAG) \
'--lpath=./nvim/?.lua;' '--cpath=./nvim/?.so;' -o gtest test
valgrind: all
eval $$($(LUAROCKS) path); \
valgrind $(VALGRIND_OPTS) $(LUA) \
$(DEPS_PREFIX)/lib/luarocks/rocks/busted/2.0.rc11-0/bin/busted \
'--lpath=./nvim/?.lua;' '--cpath=./nvim/?.so;' test
cat valgrind.log
clean:
rm -f nvim/*.o nvim/*.so
distclean: clean
rm -rf $(DEPS_DIR)
nvim/native.o: nvim/native.c $(LUA) $(LIBUV)
$(CC) $(CFLAGS) -o $@ -c $< $(DEPS_INCLUDE_FLAGS)
nvim/native.so: nvim/native.o
$(CC) $(LDFLAGS) $< -o $@
$(BUSTED): | $(LUAROCKS)
$(LUAROCKS) install busted
$(LUAROCKS) install inspect # helpful for debugging
$(LUV): $(LUAROCKS)
$(LUAROCKS) install luv
$(MPACK): $(LUAROCKS)
$(LUAROCKS) install mpack
$(COXPCALL): $(LUAROCKS)
$(LUAROCKS) install coxpcall
$(LUAROCKS): $(LUA)
dir="$(DEPS_DIR)/src/luarocks"; \
mkdir -p $$dir && cd $$dir && \
$(FETCH) $(LUAROCKS_URL) | $(UNTGZ) && \
./configure --prefix=$(DEPS_PREFIX) --force-config \
--with-lua=$(DEPS_PREFIX) && make bootstrap
$(LUA):
dir="$(DEPS_DIR)/src/lua"; \
mkdir -p $$dir && cd $$dir && \
$(FETCH) $(LUA_URL) | $(UNTGZ) && \
sed -i -e '/^CFLAGS/s/-O2/-g/' src/Makefile && \
make $(LUA_TARGET) install INSTALL_TOP=$(DEPS_PREFIX)
.PHONY: all deps test valgrind clean distclean