kore

An easy to use, scalable and secure web application framework for writing web APIs in C.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

Makefile (7522B)



      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 MAN_DIR?=$(PREFIX)/share/man
     13 SHARE_DIR=$(PREFIX)/share/kore
     14 INCLUDE_DIR=$(PREFIX)/include/kore
     15 TLS_BACKEND?=openssl
     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
     60 	FEATURES+=-DKORE_SINGLE_BINARY
     61 endif
     62 
     63 ifneq ("$(DEBUG)", "")
     64 	CFLAGS+=-DKORE_DEBUG -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 OSNAME=$(shell uname -s | sed -e 's/[-_].*//g' | tr A-Z a-z)
    121 ifeq ("$(OSNAME)", "freebsd")
    122 	KORE_CURL_LIB=-L/usr/local/lib -lcurl
    123 	KORE_CURL_INC=-I/usr/local/include
    124 endif
    125 
    126 ifneq ("$(ACME)", "")
    127 	S_SRC+=src/acme.c
    128 	CURL=1
    129 	CFLAGS+=-DKORE_USE_ACME
    130 	FEATURES+=-DKORE_USE_ACME
    131 endif
    132 
    133 ifneq ("$(CURL)", "")
    134 	S_SRC+=src/curl.c
    135 	KORE_CURL_LIB?=$(shell curl-config --libs)
    136 	KORE_CURL_INC?=$(shell curl-config --cflags)
    137 	LDFLAGS+=$(KORE_CURL_LIB)
    138 	CFLAGS+=$(KORE_CURL_INC) -DKORE_USE_CURL
    139 	FEATURES+=-DKORE_USE_CURL
    140 	FEATURES_INC+=$(KORE_CURL_INC)
    141 endif
    142 
    143 ifneq ("$(SANITIZE)", "")
    144 	CFLAGS+=-fsanitize=$(SANITIZE)
    145 	LDFLAGS+=-fsanitize=$(SANITIZE)
    146 endif
    147 
    148 ifeq ("$(OSNAME)", "darwin")
    149 	ifeq ("$(TLS_BACKEND)", "openssl")
    150 		OSSL_INCL=$(shell pkg-config openssl --cflags)
    151 		CFLAGS+=$(OSSL_INCL)
    152 		LDFLAGS+=$(shell pkg-config openssl --libs)
    153 		FEATURES_INC+=$(OSSL_INCL)
    154 	endif
    155 	S_SRC+=src/bsd.c
    156 else ifeq ("$(OSNAME)", "linux")
    157 	CFLAGS+=-D_GNU_SOURCE=1 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2
    158 	LDFLAGS+=-ldl
    159 	S_SRC+=src/linux.c src/seccomp.c
    160 else
    161 	S_SRC+=src/bsd.c
    162 	ifneq ("$(JSONRPC)", "")
    163 		CFLAGS+=-I/usr/local/include
    164 		LDFLAGS+=-L/usr/local/lib
    165 	endif
    166 endif
    167 
    168 S_OBJS=	$(S_SRC:src/%.c=$(OBJDIR)/%.o)
    169 S_OBJS+=$(OBJDIR)/version.o
    170 
    171 all: $(PLATFORM) $(GENERATED) $(VERSION) $(KORE) $(KODEV)
    172 
    173 $(PLATFORM): $(OBJDIR) force
    174 	@if [ -f misc/$(OSNAME)-platform.sh ]; then \
    175 		misc/$(OSNAME)-platform.sh > $(OBJDIR)/$(PLATFORM) ; \
    176 	fi
    177 
    178 $(PYTHON_CURLOPT): $(OBJDIR) force
    179 	@cp $(PYTHON_CURLOPT) $(OBJDIR)
    180 
    181 $(VERSION): $(OBJDIR) force
    182 	@if [ -d .git ]; then \
    183 		GIT_REVISION=`git rev-parse --short=8 HEAD`; \
    184 		GIT_BRANCH=`git rev-parse --abbrev-ref HEAD`; \
    185 		rm -f $(VERSION); \
    186 		printf "const char *kore_version = \"%s-%s\";\n" \
    187 		    $$GIT_BRANCH $$GIT_REVISION > $(VERSION); \
    188 	elif [ -f RELEASE ]; then \
    189 		printf "const char *kore_version = \"%s\";\n" \
    190 		    `cat RELEASE` > $(VERSION); \
    191 	else \
    192 		echo "No version information found (no .git or RELEASE)"; \
    193 		exit 1; \
    194 	fi
    195 	@printf "const char *kore_build_date = \"%s\";\n" \
    196 	    `date +"%Y-%m-%d"` >> $(VERSION);
    197 
    198 $(KODEV): src/cli.c
    199 	$(MAKE) -C kodev
    200 
    201 $(KORE): $(OBJDIR) $(S_OBJS)
    202 	$(CC) $(S_OBJS) $(LDFLAGS) -o $(KORE)
    203 	@echo $(LDFLAGS) > kore.linker
    204 	@echo $(FEATURES) $(FEATURES_INC) > kore.features
    205 
    206 objects: $(OBJDIR) $(PLATFORM) $(GENERATED) $(S_OBJS)
    207 	@echo $(LDFLAGS) > $(OBJDIR)/ldflags
    208 	@echo "$(FEATURES) $(FEATURES_INC)" > $(OBJDIR)/features
    209 
    210 $(OBJDIR):
    211 	@mkdir -p $(OBJDIR)
    212 
    213 install:
    214 	mkdir -p $(DESTDIR)$(SHARE_DIR)
    215 	mkdir -p $(DESTDIR)$(INCLUDE_DIR)
    216 	mkdir -p $(DESTDIR)$(INSTALL_DIR)
    217 	mkdir -p $(DESTDIR)$(MAN_DIR)/man1
    218 	install -m 644 share/man/kodev.1 $(DESTDIR)$(MAN_DIR)/man1/kodev.1
    219 	install -m 555 $(KORE) $(DESTDIR)$(INSTALL_DIR)/$(KORE)
    220 	install -m 644 kore.features $(DESTDIR)$(SHARE_DIR)/features
    221 	install -m 644 kore.linker $(DESTDIR)$(SHARE_DIR)/linker
    222 	install -m 644 include/kore/*.h $(DESTDIR)$(INCLUDE_DIR)
    223 	install -m 644 misc/ffdhe4096.pem $(DESTDIR)$(SHARE_DIR)/ffdhe4096.pem
    224 	$(MAKE) -C kodev install
    225 	$(MAKE) install-sources
    226 
    227 install-sources:
    228 	@mkdir -p $(DESTDIR)$(SHARE_DIR)
    229 	@cp Makefile $(DESTDIR)$(SHARE_DIR)
    230 	@cp -R src $(DESTDIR)$(SHARE_DIR)
    231 	@cp -R include $(DESTDIR)$(SHARE_DIR)
    232 	@cp -R misc $(DESTDIR)$(SHARE_DIR)
    233 	@if [ -d .git ]; then \
    234 		GIT_REVISION=`git rev-parse --short=8 HEAD`; \
    235 		GIT_BRANCH=`git rev-parse --abbrev-ref HEAD`; \
    236 		rm -f $(VERSION); \
    237 		echo "$$GIT_BRANCH-$$GIT_REVISION" > \
    238 		    $(DESTDIR)$(SHARE_DIR)/RELEASE; \
    239 	elif [ -f RELEASE ]; then \
    240 		cp RELEASE $(DESTDIR)$(SHARE_DIR); \
    241 	else \
    242 		echo "No version information found (no .git or RELEASE)"; \
    243 		exit 1; \
    244 	fi
    245 
    246 uninstall:
    247 	rm -f $(DESTDIR)$(INSTALL_DIR)/$(KORE)
    248 	rm -rf $(DESTDIR)$(INCLUDE_DIR)
    249 	rm -rf $(DESTDIR)$(SHARE_DIR)
    250 	$(MAKE) -C kodev uninstall
    251 
    252 tools-build: $(KODEV)
    253 	for t in $(TOOLS); do \
    254 		cd tools/$$t; \
    255 		env \
    256 		    KODEV_OUTPUT=$(KOREPATH) \
    257 		    KORE_SOURCE=$(KOREPATH) \
    258 		    KORE_BUILD_FLAVOR=$(OSNAME) \
    259 		    $(KOREPATH)/$(KODEV) build; \
    260 		cd $(KOREPATH); \
    261 	done
    262 
    263 tools-clean: $(KODEV)
    264 	for t in $(TOOLS); do \
    265 		cd tools/$$t; \
    266 		$(KOREPATH)/$(KODEV) clean; \
    267 		cd $(KOREPATH); \
    268 	done
    269 
    270 tools-install:
    271 	mkdir -p $(DESTDIR)$(INSTALL_DIR)
    272 	for t in $(TOOLS); do \
    273 		install -m 555 $$t $(DESTDIR)$(INSTALL_DIR)/$$t; \
    274 	done
    275 
    276 $(OBJDIR)/%.o: src/%.c
    277 	$(CC) $(CFLAGS) -c $< -o $@
    278 
    279 src/kore.c: $(VERSION)
    280 
    281 src/python.c: $(PYTHON_CURLOPT)
    282 
    283 src/seccomp.c: $(PLATFORM)
    284 
    285 clean:
    286 	rm -f $(VERSION)
    287 	find . -type f -name \*.o -exec rm {} \;
    288 	rm -rf $(KORE) $(OBJDIR) kore.features kore.linker
    289 	$(MAKE) -C kodev clean
    290 
    291 releng-build-examples:
    292 	rm -rf /tmp/kore_releng
    293 	$(MAKE) clean
    294 	$(MAKE) PYTHON=1 PGSQL=1 TASKS=1 PREFIX=/tmp/kore_releng
    295 	$(MAKE) install PREFIX=/tmp/kore_releng
    296 	$(MAKE) -C examples
    297 
    298 .PHONY: all clean force