-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
144 lines (121 loc) · 4.3 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
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
141
142
143
SHELL=bash
LAST_LOG=.build/last_build.log
PWD=$(shell pwd)
PLUGIN_NAME=Example
TRIPPLE=x86_64-apple-macosx10.12
BUILD_DIR=$(PWD)/.build/$(CONFIG)
# Generate a plugin setup to work with Vim
.PHONY: generate
generate:
@./PluginGenerator/plugin_generator.sh
.PHONY: debug
debug: CONFIG=debug
debug: plugin_so
.PHONY: release
release: CONFIG=release
release: vim_lib plugin_so
BASE_OPTS=-Xcc -I$(PYTHON_INCLUDE) \
-Xcc -DVIM_PLUGIN_NAME=$(PLUGIN_NAME) \
-Xlinker $(PYTHON_LINKED_LIB) \
-Xcc -fvisibility=hidden \
-Xlinker -undefined -Xlinker dynamic_lookup \
-Xlinker -all_load
# Build namespaced versions of Vim and VimAsync libs.
# The modules have a prefix of the plugin name, to avoid conflicts
# when the code is linked into the Vim process.
# The module is imported as "import $(PLUGIN_NAME)Vim"
# FIXME: Consider other ways to do this that work transitively and
# doesn't trigger rebuilds
.PHONY: vim_lib, renamed_vim_lib
vim_lib: SWIFT_OPTS=--product Vim \
-Xswiftc -module-name=$(PLUGIN_NAME)Vim \
-Xswiftc -module-link-name=$(PLUGIN_NAME)Vim \
$(BASE_OPTS)
renamed_vim_lib: vim_lib
@ditto $(BUILD_DIR)/Vim.swiftmodule \
$(BUILD_DIR)/$(PLUGIN_NAME)Vim.swiftmodule
@ditto $(BUILD_DIR)/Vim.swiftdoc \
$(BUILD_DIR)/$(PLUGIN_NAME)Vim.swiftdoc
@ditto $(BUILD_DIR)/libVim.dylib \
$(BUILD_DIR)/lib$(PLUGIN_NAME)Vim.dylib
.PHONY: vim_async_lib, renamed_vim_async_lib
vim_async_lib: SWIFT_OPTS=--product VimAsync \
-Xswiftc -module-name=$(PLUGIN_NAME)VimAsync \
-Xswiftc -module-link-name=$(PLUGIN_NAME)VimAsync \
$(BASE_OPTS)
renamed_vim_async_lib: vim_async_lib
@ditto $(BUILD_DIR)/VimAsync.swiftmodule \
$(BUILD_DIR)/$(PLUGIN_NAME)VimAsync.swiftmodule
@ditto $(BUILD_DIR)/VimAsync.swiftdoc \
$(BUILD_DIR)/$(PLUGIN_NAME)VimAsync.swiftdoc
@ditto $(BUILD_DIR)/libVimAsync.dylib \
$(BUILD_DIR)/lib$(PLUGIN_NAME)VimAsync.dylib
# Main plugin lib
.PHONY: plugin_lib
plugin_lib: SWIFT_OPTS=--product $(PLUGIN_NAME) \
$(BASE_OPTS)
plugin_lib: renamed_vim_lib renamed_vim_async_lib
# Build the .so, which Vim dynamically links.
.PHONY: plugin_so
plugin_so: plugin_lib
@clang -g \
-Xlinker $(PYTHON_LINKED_LIB) \
-Xlinker $(BUILD_DIR)/lib$(PLUGIN_NAME).dylib \
-Xlinker $(BUILD_DIR)/lib$(PLUGIN_NAME)VimAsync.dylib \
-Xlinker $(BUILD_DIR)/lib$(PLUGIN_NAME)Vim.dylib \
-shared -o .build/$(PLUGIN_NAME).so
# Build for the python dylib vim links
.PHONY: py_vars
py_vars:
@source VimUtils/make_lib.sh; python_info
$(eval PYTHON_LINKED_LIB=$(shell source VimUtils/make_lib.sh; linked_python))
$(eval PYTHON_INCLUDE=$(shell source VimUtils/make_lib.sh; python_inc_dir))
# SPM Build
vim_lib vim_async_lib plugin_lib test_b: py_vars
@echo "Building.."
@mkdir -p .build
@swift build -c $(CONFIG) \
$(BASE_OPTS) $(SWIFT_OPTS) $(EXTRA_OPTS) \
-Xswiftc -target -Xswiftc $(TRIPPLE) \
| tee $(LAST_LOG)
# Mark - Internal Utils:
# Overriding Python:
# USE_PYTHON=/usr/local/Cellar/python/3.6.4_4/Frameworks/Python.framework/Versions/3.6/Python make test
.PHONY: test
test: CONFIG=debug
test: EXTRA_OPTS= \
-Xcc -DSPMVIM_LOADSTUB_RUNTIME
test: debug
@echo "Testing.."
@mkdir -p .build
@swift build --product VimPackageTests \
$(BASE_OPTS) $(SWIFT_OPTS) $(EXTRA_OPTS) \
-Xlinker $(BUILD_DIR)/lib$(PLUGIN_NAME).dylib \
-Xlinker $(BUILD_DIR)/lib$(PLUGIN_NAME)VimAsync.dylib \
-Xlinker $(BUILD_DIR)/lib$(PLUGIN_NAME)Vim.dylib \
-Xswiftc -target -Xswiftc $(TRIPPLE) | tee $(LAST_LOG)
@swift test --skip-build 2>&1 | tee -a $(LAST_LOG)
.PHONY: test_generate
test_generate:
# We use the HEAD ref in the test
#git diff --quiet || (echo 'Dirty tree' && exit 1)
rm -rf ~/Desktop/Swiftvimexample || true
GIT_REPO=$(PWD)/.git \
plugin_path=~/Desktop/Swiftvimexample make generate
cd ~/Desktop/Swiftvimexample && make
clean:
rm -rf .build/debug/*
rm -rf .build/release/*
# Generate the example
PluginGenerator/PluginMain.tpl.swift: Sources/Example/Example.swift
sed "s,Example,__VIM_PLUGIN_NAME__,g" $< > $@
# Build compile_commands.json
# Unfortunately, we need to clean.
# Use the last installed product incase we messed something up during
# coding.
compile_commands.json: SWIFT_OPTS=-Xswiftc -parseable-output \
-Xcc -I$(PYTHON_INCLUDE) \
-Xlinker $(PYTHON_LINKED_LIB)
compile_commands.json: CONFIG=debug
compile_commands.json: clean build_impl
cat $(LAST_LOG) | /usr/local/bin/spm-vim compile_commands