-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
194 lines (150 loc) · 5.08 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# Makefile for bmake/openbsd make
default: dged
.PHONY: default clean check run debug debug-tests install format
.OBJDIR: ./build
build:
mkdir -p build
.if ! exists(${.CURDIR}/config.mk)
. error "Please run ./configure first"
.endif
.include "config.mk"
SYNTAX_ENABLE ?= true
LSP_ENABLE ?= true
HEADERS = src/dged/settings.h src/dged/minibuffer.h src/dged/keyboard.h src/dged/binding.h \
src/dged/buffers.h src/dged/text.h src/dged/display.h src/dged/hashmap.h src/dged/path.h \
src/dged/buffer.h src/dged/btree.h src/dged/command.h src/dged/allocator.h src/dged/reactor.h \
src/dged/vec.h src/dged/window.h src/dged/hash.h src/dged/undo.h src/dged/lang.h \
src/dged/settings-parse.h src/dged/utf8.h src/main/cmds.h src/main/bindings.h \
src/main/search-replace.h src/dged/location.h src/dged/buffer_view.h src/main/completion.h \
src/dged/timers.h src/dged/s8.h src/main/version.h src/config.h src/dged/process.h
SOURCES = src/dged/binding.c src/dged/buffer.c src/dged/command.c src/dged/display.c \
src/dged/keyboard.c src/dged/minibuffer.c src/dged/text.c \
src/dged/utf8.c src/dged/buffers.c src/dged/window.c src/dged/allocator.c src/dged/undo.c \
src/dged/settings.c src/dged/lang.c src/dged/settings-parse.c src/dged/location.c \
src/dged/buffer_view.c src/dged/timers.c src/dged/s8.c src/dged/path.c src/dged/hash.c
MAIN_SOURCES = src/main/main.c src/main/cmds.c src/main/bindings.c src/main/search-replace.c src/main/completion.c
# HACK: added to MAIN_SOURCES to not be picked up in tests
# since they have their own implementation
.if "$(HAS_EPOLL)" == true
MAIN_SOURCES += src/dged/reactor-epoll.c
.elif "$(HAS_KQUEUE)" == true
MAIN_SOURCES += src/dged/reactor-kqueue.c
.endif
.if "$(PROCESS_MODEL)" == posix
SOURCES += src/dged/process-posix.c
.endif
TEST_SOURCES = test/assert.c test/buffer.c test/text.c test/utf8.c test/main.c \
test/command.c test/keyboard.c test/fake-reactor.c test/allocator.c \
test/minibuffer.c test/undo.c test/settings.c test/container.c
prefix ?= /usr/local
DESTDIR ?= $(prefix)
datadir = share/dged
.SUFFIXES:
.SUFFIXES: .c .o .d
CFLAGS += -Werror -Wall -Wextra -g -O2 -std=c99\
-I $(.CURDIR)/src\
-I $(.CURDIR)/src/main\
-DDATADIR="$(prefix)/$(datadir)"
ASAN ?= false
.if $(ASAN) == true
CFLAGS += -fsanitize=address -fno-omit-frame-pointer
LDFLAGS += -fsanitize=address
.endif
.if $(SYNTAX_ENABLE) == true
HEADERS += src/dged/syntax.h
SOURCES += src/dged/syntax.c
treesitterflags != pkg-config tree-sitter --cflags
CFLAGS += ${treesitterflags}
treesitterld != pkg-config tree-sitter --libs
LDFLAGS += ${treesitterld}
.endif
.if $(LSP_ENABLE) == true
HEADERS += src/dged/lsp.h src/main/lsp.h src/dged/json.h
SOURCES += src/dged/lsp.c src/dged/json.c
MAIN_SOURCES += src/main/lsp.c
TEST_SOURCES += test/json.c
CFLAGS += -DLSP_ENABLED
.endif
UNAME_S != uname -s | tr '[:upper:]' '[:lower:]'
.if exists(${.CURDIR}/${UNAME_S}.mk)
. include "$(.CURDIR)/$(UNAME_S).mk"
.endif
# add a define like LINUX/OPENBSD
UNAME_UPPER != uname -s | tr '[:lower:]' '[:upper:]'
CFLAGS += -D$(UNAME_UPPER)
FORMAT_TOOL ?= clang-format
DEPS = $(SOURCES:.c=.d) $(MAIN_SOURCES:.c=.d) $(TEST_SOURCES:.c=.d)
OBJS = $(SOURCES:.c=.o)
MAIN_OBJS = $(MAIN_SOURCES:.c=.o)
TEST_OBJS = $(TEST_SOURCES:.c=.o)
FILES = $(DEPS) \
$(MAIN_OBJS) \
$(OBJS) \
$(TEST_OBJS) \
dged \
libdged.a
# dependency generation
.c.d: config.mk
@mkdir -p $(@D)
$(CC) -MM $(CFLAGS) -MT $*.o $< > $@
@sed -i 's,\($*\)\.o[ :]*,\1.o $@ : ,g' $@
.c.o: config.mk
@mkdir -p $(@D)
$(CC) $(CFLAGS) -c $< -o $@
grammars:
@if [ "$(SYNTAX_ENABLE)" = "true" ] && [ -n "$$BUNDLE_TREESITTER_GRAMMARS" ]; then \
IFS=":"; for p in "$$BUNDLE_TREESITTER_GRAMMARS"; do \
cp -rL --no-preserve=mode "$$p"/ grammars; \
done \
else \
mkdir -p ./grammars; \
fi
dged: $(MAIN_OBJS) libdged.a grammars
$(CC) $(LDFLAGS) $(MAIN_OBJS) libdged.a -o dged -lm
libdged.a: $(OBJS)
$(AR) -rc libdged.a $(OBJS)
run-tests: $(TEST_OBJS) $(OBJS)
$(CC) $(LDFLAGS) $(TEST_OBJS) $(OBJS) -lm -o run-tests
check: run-tests
@echo "Running $(FORMAT_TOOL) (--dry-run --Werror)..."
@$(FORMAT_TOOL) --dry-run --Werror \
$(SOURCES:%.c=$(.CURDIR)/%.c) \
$(MAIN_SOURCES:%.c=$(.CURDIR)/%.c) \
$(TEST_SOURCES:%c=$(.CURDIR)/%c) \
$(HEADERS:%.h=$(.CURDIR)/%.h)
./run-tests
run: dged
./dged
debug: dged
gdb -ex "cd $(.CURDIR)" ./dged
debug-tests: run-tests
gdb ./run-tests
format:
@echo "Formatting with '$(FORMAT_TOOL) -i'..."
@$(FORMAT_TOOL) -i \
$(SOURCES:%.c=$(.CURDIR)/%.c) \
$(MAIN_SOURCES:%.c=$(.CURDIR)/%.c) \
$(TEST_SOURCES:%c=$(.CURDIR)/%c) \
$(HEADERS:%.h=$(.CURDIR)/%.h)
clean:
rm -f $(FILES)
rm -rf $(.CURDIR)/docs
rm -rf $(.OBJDIR)/grammars
install: dged
install -d $(DESTDIR)/bin
install -m 755 $(.OBJDIR)/dged $(DESTDIR)/bin/dged
install -d $(DESTDIR)/share/man/man1
install -m 644 $(.CURDIR)/dged.1 $(DESTDIR)/share/man/man1/dged.1
install -d $(DESTDIR)/$(datadir)/grammars
cp -RL $(.OBJDIR)/grammars "$(DESTDIR)/$(datadir)/"
docs:
CURDIR=$(.CURDIR) doxygen $(.CURDIR)/Doxyfile
depend: $(DEPS)
@:
.if !(make(clean))
. for o in ${DEPS}
. if exists(${o})
. include "$o"
. endif
. endfor
.endif