kore/Makefile

307 lines
7.5 KiB
Makefile
Raw Permalink Normal View History

2013-04-17 22:34:27 +02:00
# Kore Makefile
CC?=cc
DESTDIR?=
PREFIX?=/usr/local
OBJDIR?=obj
2014-08-01 10:46:50 +02:00
KORE=kore
KODEV=kodev/kodev
KOREPATH?=$(shell pwd)
KORE_CRYPTO?=crypto
INSTALL_DIR=$(PREFIX)/bin
SHARE_DIR=$(PREFIX)/share/kore
INCLUDE_DIR=$(PREFIX)/include/kore
TLS_BACKEND?=openssl
KORE_TMPDIR?=/tmp
2013-04-17 22:34:27 +02:00
TOOLS= kore-serve
GENERATED=
PLATFORM=platform.h
VERSION=$(OBJDIR)/version.c
PYTHON_CURLOPT=misc/curl/python_curlopt.h
S_SRC= src/kore.c src/buf.c src/config.c src/connection.c \
src/domain.c src/filemap.c src/fileref.c src/json.c src/log.c \
src/mem.c src/msg.c src/module.c src/net.c src/pool.c src/runtime.c \
src/sha1.c src/sha2.c src/timer.c src/utils.c src/worker.c
S_SRC+= src/tls_$(TLS_BACKEND).c
2013-04-17 22:34:27 +02:00
FEATURES=
FEATURES_INC=
CFLAGS+=-Wall -Werror -Wstrict-prototypes -Wmissing-prototypes
2013-04-17 22:34:27 +02:00
CFLAGS+=-Wmissing-declarations -Wshadow -Wpointer-arith -Wcast-qual
CFLAGS+=-Wsign-compare -Iinclude/kore -I$(OBJDIR) -std=c99 -pedantic
CFLAGS+=-Wtype-limits -fno-common
Rework HTTP and worker processes. The HTTP layer used to make a copy of each incoming header and its value for a request. Stop doing that and make HTTP headers zero-copy all across the board. This change comes with some api function changes, notably the http_request_header() function which now takes a const char ** rather than a char ** out pointer. This commit also constifies several members of http_request, beware. Additional rework how the worker processes deal with the accept lock. Before: if a worker held the accept lock and it accepted a new connection it would release the lock for others and back off for 500ms before attempting to grab the lock again. This approach worked but under high load this starts becoming obvious. Now: - workers not holding the accept lock and not having any connections will wait less long before returning from kore_platform_event_wait(). - workers not holding the accept lock will no longer blindly wait an arbitrary amount in kore_platform_event_wait() but will look at how long until the next lock grab is and base their timeout on that. - if a worker its next_lock timeout is up and failed to grab the lock it will try again in half the time again. - the worker process holding the lock will when releasing the lock double check if it still has space for newer connections, if it does it will keep the lock until it is full. This prevents the lock from bouncing between several non busy worker processes all the time. Additional fixes: - Reduce the number of times we check the timeout list, only do it twice per second rather then every event tick. - Fix solo worker count for TLS (we actually hold two processes, not one). - Make sure we don't accidentally miscalculate the idle time causing new connections under heavy load to instantly drop. - Swap from gettimeofday() to clock_gettime() now that MacOS caught up.
2018-02-14 13:48:49 +01:00
CFLAGS+=-DPREFIX='"$(PREFIX)"' -fstack-protector-all
2018-11-28 13:54:38 +01:00
2022-02-17 13:59:36 +01:00
LDFLAGS+=-rdynamic
ifeq ("$(TLS_BACKEND)", "openssl")
S_SRC+=src/keymgr_openssl.c
CFLAGS+=-DTLS_BACKEND_OPENSSL
FEATURES+=-DTLS_BACKEND_OPENSSL
ifneq ("$(OPENSSL_PATH)", "")
CFLAGS+=-I$(OPENSSL_PATH)/include
2022-02-17 13:59:36 +01:00
LDFLAGS+=-L$(OPENSSL_PATH)/lib -lssl -l$(KORE_CRYPTO)
else
2022-02-17 13:59:36 +01:00
LDFLAGS+=-lssl -l$(KORE_CRYPTO)
endif
else
ifneq ("$(ACME)", "")
$(error ACME not supported under TLS backend $(TLS_BACKEND))
endif
2018-11-28 13:54:38 +01:00
endif
ifneq ("$(KORE_SINGLE_BINARY)", "")
CFLAGS+=-DKORE_SINGLE_BINARY -DKORE_TMPDIR='"$(KORE_TMPDIR)"'
FEATURES+=-DKORE_SINGLE_BINARY
endif
2013-11-21 12:00:07 +01:00
ifneq ("$(DEBUG)", "")
CFLAGS+=-g
FEATURES+=-DKORE_DEBUG
endif
ifneq ("$(NOOPT)", "")
CFLAGS+=-O0
else
CFLAGS+=-O2
endif
ifneq ("$(NOSENDFILE)", "")
CFLAGS+=-DKORE_NO_SENDFILE
endif
ifneq ("$(NOHTTP)", "")
CFLAGS+=-DKORE_NO_HTTP
FEATURES+=-DKORE_NO_HTTP
else
S_SRC+= src/auth.c src/accesslog.c src/http.c \
src/route.c src/validator.c src/websocket.c
endif
ifneq ("$(PGSQL)", "")
S_SRC+=src/pgsql.c
2014-04-02 00:06:24 +02:00
LDFLAGS+=-L$(shell pg_config --libdir) -lpq
CFLAGS+=-I$(shell pg_config --includedir) -DKORE_USE_PGSQL \
-DPGSQL_INCLUDE_PATH="\"$(shell pg_config --includedir)\""
FEATURES+=-DKORE_USE_PGSQL
FEATURES_INC+=-I$(shell pg_config --includedir)
endif
ifneq ("$(TASKS)", "")
S_SRC+=src/tasks.c
LDFLAGS+=-lpthread
CFLAGS+=-DKORE_USE_TASKS
FEATURES+=-DKORE_USE_TASKS
endif
ifneq ("$(JSONRPC)", "")
S_SRC+=src/jsonrpc.c
LDFLAGS+=-lyajl
CFLAGS+=-DKORE_USE_JSONRPC
FEATURES+=-DKORE_USE_JSONRPC
endif
ifneq ("$(PYTHON)", "")
S_SRC+=src/python.c
GENERATED+=$(PYTHON_CURLOPT)
2019-10-15 10:16:53 +02:00
KORE_PYTHON_LIB?=$(shell ./misc/python3-config.sh --ldflags)
KORE_PYTHON_INC?=$(shell ./misc/python3-config.sh --includes)
LDFLAGS+=$(KORE_PYTHON_LIB)
CFLAGS+=$(KORE_PYTHON_INC) -DKORE_USE_PYTHON
FEATURES+=-DKORE_USE_PYTHON
FEATURES_INC+=$(KORE_PYTHON_INC)
endif
ifneq ("$(LUA)", "")
S_SRC+=src/lua.c
KORE_LUA_LIB?=$(shell pkg-config --libs lua$(LUA_VERSION))
KORE_LUA_INC?=$(shell pkg-config --cflags lua$(LUA_VERSION))
LDFLAGS+=$(KORE_LUA_LIB)
CFLAGS+=$(KORE_LUA_INC) -DKORE_USE_LUA
FEATURES+=-DKORE_USE_LUA
FEATURES_INC+=$(KORE_LUA_INC)
endif
OSNAME=$(shell uname -s | sed -e 's/[-_].*//g' | tr A-Z a-z)
ifeq ("$(OSNAME)", "freebsd")
KORE_CURL_LIB=-L/usr/local/lib -lcurl
KORE_CURL_INC=-I/usr/local/include
endif
Add acmev2 (RFC8555) support to Kore. A new acme process is created that communicates with the acme servers. This process does not hold any of your private keys (no account keys, no domain keys etc). Whenever the acme process requires a signed payload it will ask the keymgr process to do the signing with the relevant keys. This process is also sandboxed with pledge+unveil on OpenBSD and seccomp syscall filtering on Linux. The implementation only supports the tls-alpn-01 challenge. This means that you do not need to open additional ports on your machine. http-01 and dns-01 are currently not supported (no wildcard support). A new configuration option "acme_provider" is available and can be set to the acme server its directory. By default this will point to the live letsencrypt environment: https://acme-v02.api.letsencrypt.org/directory The acme process can be controlled via the following config options: - acme_root (where the acme process will chroot/chdir into). - acme_runas (the user the acme process will run as). If none are set, the values from 'root' and 'runas' are taken. If you want to turn on acme for domains you do it as follows: domain kore.io { acme yes } You do not need to specify certkey/certfile anymore, if they are present still they will be overwritten by the acme system. The keymgr will store all certificates and keys under its root (keymgr_root), the account key is stored as "/account-key.pem" and all obtained certificates go under "certificates/<domain>/fullchain.pem" while keys go under "certificates/<domain>/key.pem". Kore will automatically renew certificates if they will expire in 7 days or less.
2019-11-06 19:33:53 +01:00
ifneq ("$(ACME)", "")
S_SRC+=src/acme.c
CURL=1
CFLAGS+=-DKORE_USE_ACME
FEATURES+=-DKORE_USE_ACME
endif
ifneq ("$(CURL)", "")
S_SRC+=src/curl.c
2019-10-28 12:18:15 +01:00
KORE_CURL_LIB?=$(shell curl-config --libs)
KORE_CURL_INC?=$(shell curl-config --cflags)
LDFLAGS+=$(KORE_CURL_LIB)
CFLAGS+=$(KORE_CURL_INC) -DKORE_USE_CURL
FEATURES+=-DKORE_USE_CURL
FEATURES_INC+=$(KORE_CURL_INC)
endif
ifneq ("$(SANITIZE)", "")
CFLAGS+=-fsanitize=$(SANITIZE)
LDFLAGS+=-fsanitize=$(SANITIZE)
endif
ifeq ("$(OSNAME)", "darwin")
ifeq ("$(TLS_BACKEND)", "openssl")
OSSL_INCL=$(shell pkg-config openssl --cflags)
CFLAGS+=$(OSSL_INCL)
LDFLAGS+=$(shell pkg-config openssl --libs)
FEATURES_INC+=$(OSSL_INCL)
endif
S_SRC+=src/bsd.c
else ifeq ("$(OSNAME)", "linux")
CFLAGS+=-D_GNU_SOURCE=1 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2
LDFLAGS+=-ldl
S_SRC+=src/linux.c src/seccomp.c
else
S_SRC+=src/bsd.c
ifneq ("$(JSONRPC)", "")
2016-07-15 22:34:21 +02:00
CFLAGS+=-I/usr/local/include
LDFLAGS+=-L/usr/local/lib
endif
endif
S_OBJS= $(S_SRC:src/%.c=$(OBJDIR)/%.o)
S_OBJS+=$(OBJDIR)/version.o
all: $(PLATFORM) $(GENERATED) $(VERSION) $(KORE) $(KODEV)
$(PLATFORM): $(OBJDIR) force
@if [ -f misc/$(OSNAME)-platform.sh ]; then \
misc/$(OSNAME)-platform.sh > $(OBJDIR)/$(PLATFORM) ; \
fi
$(PYTHON_CURLOPT): $(OBJDIR) force
@cp $(PYTHON_CURLOPT) $(OBJDIR)
2021-03-09 15:13:45 +01:00
$(VERSION): $(OBJDIR) force
@if [ -d .git ]; then \
GIT_REVISION=`git rev-parse --short=8 HEAD`; \
GIT_BRANCH=`git rev-parse --abbrev-ref HEAD`; \
rm -f $(VERSION); \
printf "const char *kore_version = \"%s-%s\";\n" \
$$GIT_BRANCH $$GIT_REVISION > $(VERSION); \
elif [ -f RELEASE ]; then \
printf "const char *kore_version = \"%s\";\n" \
`cat RELEASE` > $(VERSION); \
else \
echo "No version information found (no .git or RELEASE)"; \
exit 1; \
fi
2021-09-07 21:58:53 +02:00
@printf "const char *kore_build_date = \"%s\";\n" \
`date +"%Y-%m-%d"` >> $(VERSION);
$(KODEV): src/cli.c
$(MAKE) -C kodev
$(KORE): $(OBJDIR) $(S_OBJS)
2014-08-02 13:01:58 +02:00
$(CC) $(S_OBJS) $(LDFLAGS) -o $(KORE)
@echo $(LDFLAGS) > kore.linker
@echo $(FEATURES) $(FEATURES_INC) > kore.features
2013-04-17 22:34:27 +02:00
objects: $(OBJDIR) $(PLATFORM) $(GENERATED) $(S_OBJS)
@echo $(LDFLAGS) > $(OBJDIR)/ldflags
@echo "$(FEATURES) $(FEATURES_INC)" > $(OBJDIR)/features
2015-07-25 19:10:48 +02:00
$(OBJDIR):
@mkdir -p $(OBJDIR)
install:
mkdir -p $(DESTDIR)$(SHARE_DIR)
mkdir -p $(DESTDIR)$(INCLUDE_DIR)
mkdir -p $(DESTDIR)$(INSTALL_DIR)
install -m 555 $(KORE) $(DESTDIR)$(INSTALL_DIR)/$(KORE)
install -m 644 kore.features $(DESTDIR)$(SHARE_DIR)/features
install -m 644 kore.linker $(DESTDIR)$(SHARE_DIR)/linker
install -m 644 include/kore/*.h $(DESTDIR)$(INCLUDE_DIR)
install -m 644 misc/ffdhe4096.pem $(DESTDIR)$(SHARE_DIR)/ffdhe4096.pem
$(MAKE) -C kodev install
$(MAKE) install-sources
install-sources:
@mkdir -p $(DESTDIR)$(SHARE_DIR)
@cp Makefile $(DESTDIR)$(SHARE_DIR)
@cp -R src $(DESTDIR)$(SHARE_DIR)
@cp -R include $(DESTDIR)$(SHARE_DIR)
@cp -R misc $(DESTDIR)$(SHARE_DIR)
@if [ -d .git ]; then \
GIT_REVISION=`git rev-parse --short=8 HEAD`; \
GIT_BRANCH=`git rev-parse --abbrev-ref HEAD`; \
rm -f $(VERSION); \
echo "$$GIT_BRANCH-$$GIT_REVISION" > \
$(DESTDIR)$(SHARE_DIR)/RELEASE; \
elif [ -f RELEASE ]; then \
cp RELEASE $(DESTDIR)$(SHARE_DIR); \
else \
echo "No version information found (no .git or RELEASE)"; \
exit 1; \
fi
2014-07-03 21:38:16 +02:00
uninstall:
rm -f $(DESTDIR)$(INSTALL_DIR)/$(KORE)
rm -rf $(DESTDIR)$(INCLUDE_DIR)
rm -rf $(DESTDIR)$(SHARE_DIR)
$(MAKE) -C kodev uninstall
2014-07-03 21:38:16 +02:00
tools-build: $(KODEV)
for t in $(TOOLS); do \
2020-09-09 22:18:59 +02:00
cd tools/$$t; \
env \
KODEV_OUTPUT=$(KOREPATH) \
KORE_SOURCE=$(KOREPATH) \
KORE_BUILD_FLAVOR=$(OSNAME) \
$(KOREPATH)/$(KODEV) build; \
2020-09-09 22:18:59 +02:00
cd $(KOREPATH); \
done
tools-clean: $(KODEV)
for t in $(TOOLS); do \
2020-09-09 22:18:59 +02:00
cd tools/$$t; \
$(KOREPATH)/$(KODEV) clean; \
2020-09-09 22:18:59 +02:00
cd $(KOREPATH); \
done
tools-install:
mkdir -p $(DESTDIR)$(INSTALL_DIR)
for t in $(TOOLS); do \
install -m 555 $$t $(DESTDIR)$(INSTALL_DIR)/$$t; \
done
$(OBJDIR)/%.o: src/%.c
2013-04-17 22:34:27 +02:00
$(CC) $(CFLAGS) -c $< -o $@
2021-09-07 21:58:53 +02:00
src/kore.c: $(VERSION)
src/python.c: $(PYTHON_CURLOPT)
src/seccomp.c: $(PLATFORM)
2013-04-17 22:34:27 +02:00
clean:
2018-06-22 23:02:57 +02:00
rm -f $(VERSION)
find . -type f -name \*.o -exec rm {} \;
rm -rf $(KORE) $(OBJDIR) kore.features kore.linker
$(MAKE) -C kodev clean
releng-build-examples:
rm -rf /tmp/kore_releng
$(MAKE) clean
$(MAKE) PYTHON=1 PGSQL=1 TASKS=1 PREFIX=/tmp/kore_releng
$(MAKE) install PREFIX=/tmp/kore_releng
$(MAKE) -C examples
.PHONY: all clean force