Makefile (7718B)
1 # Kore Makefile
2
3 CC?=cc
4 DESTDIR?=
5 PREFIX?=/usr/local
6 OBJDIR?=obj
7 KORE=kore
8 KODEV=kodev/kodev
9 KOREPATH?=$(shell pwd)
10 KORE_CRYPTO?=crypto
11 INSTALL_DIR=$(PREFIX)/bin
12 SHARE_DIR=$(PREFIX)/share/kore
13 INCLUDE_DIR=$(PREFIX)/include/kore
14 TLS_BACKEND?=openssl
15 KORE_TMPDIR?=/tmp
16
17 TOOLS= kore-serve
18
19 GENERATED=
20 PLATFORM=platform.h
21 VERSION=$(OBJDIR)/version.c
22 PYTHON_CURLOPT=misc/curl/python_curlopt.h
23
24 S_SRC= src/kore.c src/buf.c src/config.c src/connection.c \
25 src/domain.c src/filemap.c src/fileref.c src/json.c src/log.c \
26 src/mem.c src/msg.c src/module.c src/net.c src/pool.c src/runtime.c \
27 src/sha1.c src/sha2.c src/timer.c src/utils.c src/worker.c
28 S_SRC+= src/tls_$(TLS_BACKEND).c
29
30 FEATURES=
31 FEATURES_INC=
32
33 CFLAGS+=-Wall -Werror -Wstrict-prototypes -Wmissing-prototypes
34 CFLAGS+=-Wmissing-declarations -Wshadow -Wpointer-arith -Wcast-qual
35 CFLAGS+=-Wsign-compare -Iinclude/kore -I$(OBJDIR) -std=c99 -pedantic
36 CFLAGS+=-Wtype-limits -fno-common
37 CFLAGS+=-DPREFIX='"$(PREFIX)"' -fstack-protector-all
38
39 LDFLAGS+=-rdynamic
40
41 ifeq ("$(TLS_BACKEND)", "openssl")
42 S_SRC+=src/keymgr_openssl.c
43 CFLAGS+=-DTLS_BACKEND_OPENSSL
44 FEATURES+=-DTLS_BACKEND_OPENSSL
45
46 ifneq ("$(OPENSSL_PATH)", "")
47 CFLAGS+=-I$(OPENSSL_PATH)/include
48 LDFLAGS+=-L$(OPENSSL_PATH)/lib -lssl -l$(KORE_CRYPTO)
49 else
50 LDFLAGS+=-lssl -l$(KORE_CRYPTO)
51 endif
52 else
53 ifneq ("$(ACME)", "")
54 $(error ACME not supported under TLS backend $(TLS_BACKEND))
55 endif
56 endif
57
58 ifneq ("$(KORE_SINGLE_BINARY)", "")
59 CFLAGS+=-DKORE_SINGLE_BINARY -DKORE_TMPDIR='"$(KORE_TMPDIR)"'
60 FEATURES+=-DKORE_SINGLE_BINARY
61 endif
62
63 ifneq ("$(DEBUG)", "")
64 CFLAGS+=-g
65 FEATURES+=-DKORE_DEBUG
66 endif
67
68 ifneq ("$(NOOPT)", "")
69 CFLAGS+=-O0
70 else
71 CFLAGS+=-O2
72 endif
73
74 ifneq ("$(NOSENDFILE)", "")
75 CFLAGS+=-DKORE_NO_SENDFILE
76 endif
77
78 ifneq ("$(NOHTTP)", "")
79 CFLAGS+=-DKORE_NO_HTTP
80 FEATURES+=-DKORE_NO_HTTP
81 else
82 S_SRC+= src/auth.c src/accesslog.c src/http.c \
83 src/route.c src/validator.c src/websocket.c
84 endif
85
86 ifneq ("$(PGSQL)", "")
87 S_SRC+=src/pgsql.c
88 LDFLAGS+=-L$(shell pg_config --libdir) -lpq
89 CFLAGS+=-I$(shell pg_config --includedir) -DKORE_USE_PGSQL \
90 -DPGSQL_INCLUDE_PATH="\"$(shell pg_config --includedir)\""
91 FEATURES+=-DKORE_USE_PGSQL
92 FEATURES_INC+=-I$(shell pg_config --includedir)
93 endif
94
95 ifneq ("$(TASKS)", "")
96 S_SRC+=src/tasks.c
97 LDFLAGS+=-lpthread
98 CFLAGS+=-DKORE_USE_TASKS
99 FEATURES+=-DKORE_USE_TASKS
100 endif
101
102 ifneq ("$(JSONRPC)", "")
103 S_SRC+=src/jsonrpc.c
104 LDFLAGS+=-lyajl
105 CFLAGS+=-DKORE_USE_JSONRPC
106 FEATURES+=-DKORE_USE_JSONRPC
107 endif
108
109 ifneq ("$(PYTHON)", "")
110 S_SRC+=src/python.c
111 GENERATED+=$(PYTHON_CURLOPT)
112 KORE_PYTHON_LIB?=$(shell ./misc/python3-config.sh --ldflags)
113 KORE_PYTHON_INC?=$(shell ./misc/python3-config.sh --includes)
114 LDFLAGS+=$(KORE_PYTHON_LIB)
115 CFLAGS+=$(KORE_PYTHON_INC) -DKORE_USE_PYTHON
116 FEATURES+=-DKORE_USE_PYTHON
117 FEATURES_INC+=$(KORE_PYTHON_INC)
118 endif
119
120 ifneq ("$(LUA)", "")
121 S_SRC+=src/lua.c
122 KORE_LUA_LIB?=$(shell pkg-config --libs lua$(LUA_VERSION))
123 KORE_LUA_INC?=$(shell pkg-config --cflags lua$(LUA_VERSION))
124 LDFLAGS+=$(KORE_LUA_LIB)
125 CFLAGS+=$(KORE_LUA_INC) -DKORE_USE_LUA
126 FEATURES+=-DKORE_USE_LUA
127 FEATURES_INC+=$(KORE_LUA_INC)
128 endif
129
130 OSNAME=$(shell uname -s | sed -e 's/[-_].*//g' | tr A-Z a-z)
131 ifeq ("$(OSNAME)", "freebsd")
132 KORE_CURL_LIB=-L/usr/local/lib -lcurl
133 KORE_CURL_INC=-I/usr/local/include
134 endif
135
136 ifneq ("$(ACME)", "")
137 S_SRC+=src/acme.c
138 CURL=1
139 CFLAGS+=-DKORE_USE_ACME
140 FEATURES+=-DKORE_USE_ACME
141 endif
142
143 ifneq ("$(CURL)", "")
144 S_SRC+=src/curl.c
145 KORE_CURL_LIB?=$(shell curl-config --libs)
146 KORE_CURL_INC?=$(shell curl-config --cflags)
147 LDFLAGS+=$(KORE_CURL_LIB)
148 CFLAGS+=$(KORE_CURL_INC) -DKORE_USE_CURL
149 FEATURES+=-DKORE_USE_CURL
150 FEATURES_INC+=$(KORE_CURL_INC)
151 endif
152
153 ifneq ("$(SANITIZE)", "")
154 CFLAGS+=-fsanitize=$(SANITIZE)
155 LDFLAGS+=-fsanitize=$(SANITIZE)
156 endif
157
158 ifeq ("$(OSNAME)", "darwin")
159 ifeq ("$(TLS_BACKEND)", "openssl")
160 OSSL_INCL=$(shell pkg-config openssl --cflags)
161 CFLAGS+=$(OSSL_INCL)
162 LDFLAGS+=$(shell pkg-config openssl --libs)
163 FEATURES_INC+=$(OSSL_INCL)
164 endif
165 S_SRC+=src/bsd.c
166 else ifeq ("$(OSNAME)", "linux")
167 CFLAGS+=-D_GNU_SOURCE=1 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2
168 LDFLAGS+=-ldl
169 S_SRC+=src/linux.c src/seccomp.c
170 else
171 S_SRC+=src/bsd.c
172 ifneq ("$(JSONRPC)", "")
173 CFLAGS+=-I/usr/local/include
174 LDFLAGS+=-L/usr/local/lib
175 endif
176 endif
177
178 S_OBJS= $(S_SRC:src/%.c=$(OBJDIR)/%.o)
179 S_OBJS+=$(OBJDIR)/version.o
180
181 all: $(PLATFORM) $(GENERATED) $(VERSION) $(KORE) $(KODEV)
182
183 $(PLATFORM): $(OBJDIR) force
184 @if [ -f misc/$(OSNAME)-platform.sh ]; then \
185 misc/$(OSNAME)-platform.sh > $(OBJDIR)/$(PLATFORM) ; \
186 fi
187
188 $(PYTHON_CURLOPT): $(OBJDIR) force
189 @cp $(PYTHON_CURLOPT) $(OBJDIR)
190
191 $(VERSION): $(OBJDIR) force
192 @if [ -d .git ]; then \
193 GIT_REVISION=`git rev-parse --short=8 HEAD`; \
194 GIT_BRANCH=`git rev-parse --abbrev-ref HEAD`; \
195 rm -f $(VERSION); \
196 printf "const char *kore_version = \"%s-%s\";\n" \
197 $$GIT_BRANCH $$GIT_REVISION > $(VERSION); \
198 elif [ -f RELEASE ]; then \
199 printf "const char *kore_version = \"%s\";\n" \
200 `cat RELEASE` > $(VERSION); \
201 else \
202 echo "No version information found (no .git or RELEASE)"; \
203 exit 1; \
204 fi
205 @printf "const char *kore_build_date = \"%s\";\n" \
206 `date +"%Y-%m-%d"` >> $(VERSION);
207
208 $(KODEV): src/cli.c
209 $(MAKE) -C kodev
210
211 $(KORE): $(OBJDIR) $(S_OBJS)
212 $(CC) $(S_OBJS) $(LDFLAGS) -o $(KORE)
213 @echo $(LDFLAGS) > kore.linker
214 @echo $(FEATURES) $(FEATURES_INC) > kore.features
215
216 objects: $(OBJDIR) $(PLATFORM) $(GENERATED) $(S_OBJS)
217 @echo $(LDFLAGS) > $(OBJDIR)/ldflags
218 @echo "$(FEATURES) $(FEATURES_INC)" > $(OBJDIR)/features
219
220 $(OBJDIR):
221 @mkdir -p $(OBJDIR)
222
223 install:
224 mkdir -p $(DESTDIR)$(SHARE_DIR)
225 mkdir -p $(DESTDIR)$(INCLUDE_DIR)
226 mkdir -p $(DESTDIR)$(INSTALL_DIR)
227 install -m 555 $(KORE) $(DESTDIR)$(INSTALL_DIR)/$(KORE)
228 install -m 644 kore.features $(DESTDIR)$(SHARE_DIR)/features
229 install -m 644 kore.linker $(DESTDIR)$(SHARE_DIR)/linker
230 install -m 644 include/kore/*.h $(DESTDIR)$(INCLUDE_DIR)
231 install -m 644 misc/ffdhe4096.pem $(DESTDIR)$(SHARE_DIR)/ffdhe4096.pem
232 $(MAKE) -C kodev install
233 $(MAKE) install-sources
234
235 install-sources:
236 @mkdir -p $(DESTDIR)$(SHARE_DIR)
237 @cp Makefile $(DESTDIR)$(SHARE_DIR)
238 @cp -R src $(DESTDIR)$(SHARE_DIR)
239 @cp -R include $(DESTDIR)$(SHARE_DIR)
240 @cp -R misc $(DESTDIR)$(SHARE_DIR)
241 @if [ -d .git ]; then \
242 GIT_REVISION=`git rev-parse --short=8 HEAD`; \
243 GIT_BRANCH=`git rev-parse --abbrev-ref HEAD`; \
244 rm -f $(VERSION); \
245 echo "$$GIT_BRANCH-$$GIT_REVISION" > \
246 $(DESTDIR)$(SHARE_DIR)/RELEASE; \
247 elif [ -f RELEASE ]; then \
248 cp RELEASE $(DESTDIR)$(SHARE_DIR); \
249 else \
250 echo "No version information found (no .git or RELEASE)"; \
251 exit 1; \
252 fi
253
254 uninstall:
255 rm -f $(DESTDIR)$(INSTALL_DIR)/$(KORE)
256 rm -rf $(DESTDIR)$(INCLUDE_DIR)
257 rm -rf $(DESTDIR)$(SHARE_DIR)
258 $(MAKE) -C kodev uninstall
259
260 tools-build: $(KODEV)
261 for t in $(TOOLS); do \
262 cd tools/$$t; \
263 env \
264 KODEV_OUTPUT=$(KOREPATH) \
265 KORE_SOURCE=$(KOREPATH) \
266 KORE_BUILD_FLAVOR=$(OSNAME) \
267 $(KOREPATH)/$(KODEV) build; \
268 cd $(KOREPATH); \
269 done
270
271 tools-clean: $(KODEV)
272 for t in $(TOOLS); do \
273 cd tools/$$t; \
274 $(KOREPATH)/$(KODEV) clean; \
275 cd $(KOREPATH); \
276 done
277
278 tools-install:
279 mkdir -p $(DESTDIR)$(INSTALL_DIR)
280 for t in $(TOOLS); do \
281 install -m 555 $$t $(DESTDIR)$(INSTALL_DIR)/$$t; \
282 done
283
284 $(OBJDIR)/%.o: src/%.c
285 $(CC) $(CFLAGS) -c $< -o $@
286
287 src/kore.c: $(VERSION)
288
289 src/python.c: $(PYTHON_CURLOPT)
290
291 src/seccomp.c: $(PLATFORM)
292
293 clean:
294 rm -f $(VERSION)
295 find . -type f -name \*.o -exec rm {} \;
296 rm -rf $(KORE) $(OBJDIR) kore.features kore.linker
297 $(MAKE) -C kodev clean
298
299 releng-build-examples:
300 rm -rf /tmp/kore_releng
301 $(MAKE) clean
302 $(MAKE) PYTHON=1 PGSQL=1 TASKS=1 PREFIX=/tmp/kore_releng
303 $(MAKE) install PREFIX=/tmp/kore_releng
304 $(MAKE) -C examples
305
306 .PHONY: all clean force