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 (7560B)



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