Split up kore cli tools into new binary.

Having the create, build, run tools baked into the kore binary
made things harder then they had to be for multiple projects with
each different build flavors.

So move away this functionality into a new "kodev" (name may change)
binary that is installed next to kore.

The new build tools will automatically pick up the correct flavors
the kore binary it points to is installed with. Or for single builds
what flavors where enabled.

The new tool also will honor looking into PREFIX for the kore binary
when doing a `kodev run`.

Additionally add a new command "info" that shows some basic info
about your project and how it will be built. For example it will
show you the flavors of the kore binary installed on the system
or the flavors you configured for a single binary build.

Obligitory, hacking on a plane comment.
This commit is contained in:
Joris Vink 2017-02-19 00:52:29 -05:00
parent a0c545884f
commit fc6b3bf740
7 changed files with 584 additions and 292 deletions

View File

@ -4,7 +4,9 @@ CC?=gcc
PREFIX?=/usr/local PREFIX?=/usr/local
OBJDIR?=obj OBJDIR?=obj
KORE=kore KORE=kore
KODEV=kodev/kodev
INSTALL_DIR=$(PREFIX)/bin INSTALL_DIR=$(PREFIX)/bin
SHARE_DIR=$(PREFIX)/share/kore
INCLUDE_DIR=$(PREFIX)/include/kore INCLUDE_DIR=$(PREFIX)/include/kore
S_SRC= src/kore.c src/buf.c src/config.c src/connection.c \ S_SRC= src/kore.c src/buf.c src/config.c src/connection.c \
@ -13,6 +15,7 @@ S_SRC= src/kore.c src/buf.c src/config.c src/connection.c \
src/keymgr.c src/keymgr.c
FEATURES= FEATURES=
FEATURES_INC=
CFLAGS+=-Wall -Werror -Wstrict-prototypes -Wmissing-prototypes CFLAGS+=-Wall -Werror -Wstrict-prototypes -Wmissing-prototypes
CFLAGS+=-Wmissing-declarations -Wshadow -Wpointer-arith -Wcast-qual CFLAGS+=-Wmissing-declarations -Wshadow -Wpointer-arith -Wcast-qual
@ -20,9 +23,7 @@ CFLAGS+=-Wsign-compare -Iincludes -std=c99 -pedantic
CFLAGS+=-DPREFIX='"$(PREFIX)"' CFLAGS+=-DPREFIX='"$(PREFIX)"'
LDFLAGS=-rdynamic -lssl -lcrypto LDFLAGS=-rdynamic -lssl -lcrypto
ifeq ("$(KORE_SINGLE_BINARY)", "") ifneq ("$(KORE_SINGLE_BINARY)", "")
S_SRC+=src/cli.c
else
CFLAGS+=-DKORE_SINGLE_BINARY CFLAGS+=-DKORE_SINGLE_BINARY
FEATURES+=-DKORE_SINGLE_BINARY FEATURES+=-DKORE_SINGLE_BINARY
endif endif
@ -62,7 +63,8 @@ ifneq ("$(PGSQL)", "")
LDFLAGS+=-L$(shell pg_config --libdir) -lpq LDFLAGS+=-L$(shell pg_config --libdir) -lpq
CFLAGS+=-I$(shell pg_config --includedir) -DKORE_USE_PGSQL \ CFLAGS+=-I$(shell pg_config --includedir) -DKORE_USE_PGSQL \
-DPGSQL_INCLUDE_PATH="\"$(shell pg_config --includedir)\"" -DPGSQL_INCLUDE_PATH="\"$(shell pg_config --includedir)\""
FEATURES+=-I$(shell pg_config --includedir) -DKORE_USE_PGSQL FEATURES+=-DKORE_USE_PGSQL
FEATURES_INC+=-I$(shell pg_config --includedir)
endif endif
ifneq ("$(TASKS)", "") ifneq ("$(TASKS)", "")
@ -83,7 +85,8 @@ ifneq ("$(PYTHON)", "")
S_SRC+=src/python.c S_SRC+=src/python.c
LDFLAGS+=$(shell python3-config --ldflags) LDFLAGS+=$(shell python3-config --ldflags)
CFLAGS+=$(shell python3-config --includes) -DKORE_USE_PYTHON CFLAGS+=$(shell python3-config --includes) -DKORE_USE_PYTHON
FEATURES+=$(shell python3-config --includes) -DKORE_USE_PYTHON FEATURES+=-DKORE_USE_PYTHON
FEATURES_INC+=$(shell python3-config --includes)
endif endif
OSNAME=$(shell uname -s | sed -e 's/[-_].*//g' | tr A-Z a-z) OSNAME=$(shell uname -s | sed -e 's/[-_].*//g' | tr A-Z a-z)
@ -105,33 +108,43 @@ endif
S_OBJS= $(S_SRC:src/%.c=$(OBJDIR)/%.o) S_OBJS= $(S_SRC:src/%.c=$(OBJDIR)/%.o)
all: $(KORE) $(KODEV)
$(KODEV):
$(MAKE) -C kodev
$(KORE): $(OBJDIR) $(S_OBJS) $(KORE): $(OBJDIR) $(S_OBJS)
$(CC) $(S_OBJS) $(LDFLAGS) -o $(KORE) $(CC) $(S_OBJS) $(LDFLAGS) -o $(KORE)
@echo $(FEATURES) > kore.features
objects: $(OBJDIR) $(S_OBJS) objects: $(OBJDIR) $(S_OBJS)
@echo $(LDFLAGS) > $(OBJDIR)/ldflags @echo $(LDFLAGS) > $(OBJDIR)/ldflags
@echo $(FEATURES) > $(OBJDIR)/features @echo "$(FEATURES) $(FEATURES_INC)" > $(OBJDIR)/features
all: $(KORE)
$(OBJDIR): $(OBJDIR):
@mkdir -p $(OBJDIR) @mkdir -p $(OBJDIR)
install: install: $(KORE) $(KODEV)
mkdir -p $(SHARE_DIR)
mkdir -p $(INCLUDE_DIR) mkdir -p $(INCLUDE_DIR)
mkdir -p $(INSTALL_DIR) mkdir -p $(INSTALL_DIR)
install -m 555 $(KORE) $(INSTALL_DIR)/$(KORE) install -m 555 $(KORE) $(INSTALL_DIR)/$(KORE)
install -m 644 kore.features $(SHARE_DIR)/features
install -m 644 includes/*.h $(INCLUDE_DIR) install -m 644 includes/*.h $(INCLUDE_DIR)
$(MAKE) -C kodev install
uninstall: uninstall:
rm -f $(INSTALL_DIR)/$(KORE) rm -f $(INSTALL_DIR)/$(KORE)
rm -rf $(INCLUDE_DIR) rm -rf $(INCLUDE_DIR)
rm -rf $(SHARE_DIR)
$(MAKE) -C kodev uninstall
$(OBJDIR)/%.o: src/%.c $(OBJDIR)/%.o: src/%.c
$(CC) $(CFLAGS) -c $< -o $@ $(CC) $(CFLAGS) -c $< -o $@
clean: clean:
find . -type f -name \*.o -exec rm {} \; find . -type f -name \*.o -exec rm {} \;
rm -rf $(KORE) $(OBJDIR) rm -rf $(KORE) $(OBJDIR) kore.features
$(MAKE) -C kodev clean
.PHONY: all clean .PHONY: all clean

View File

@ -19,10 +19,6 @@
#ifndef __H_HTTP_H #ifndef __H_HTTP_H
#define __H_HTTP_H #define __H_HTTP_H
#if defined(KORE_USE_PYTHON)
#include "python_api.h"
#endif
#include <sys/types.h> #include <sys/types.h>
#include <sys/queue.h> #include <sys/queue.h>
@ -212,7 +208,7 @@ struct http_request {
struct kore_module_handle *hdlr; struct kore_module_handle *hdlr;
#if defined(KORE_USE_PYTHON) #if defined(KORE_USE_PYTHON)
PyObject *py_coro; void *py_coro;
#endif #endif
LIST_HEAD(, kore_task) tasks; LIST_HEAD(, kore_task) tasks;

View File

@ -477,9 +477,6 @@ extern struct kore_domain_h domains;
extern struct kore_domain *primary_dom; extern struct kore_domain *primary_dom;
extern struct kore_pool nb_pool; extern struct kore_pool nb_pool;
void kore_cli_usage(int);
int kore_cli_main(int, char **);
void kore_signal(int); void kore_signal(int);
void kore_worker_wait(int); void kore_worker_wait(int);
void kore_worker_init(void); void kore_worker_init(void);

53
kodev/Makefile Normal file
View File

@ -0,0 +1,53 @@
# kodev Makefile
CC?=gcc
PREFIX?=/usr/local
OBJDIR?=obj
KODEV=kodev
INSTALL_DIR=$(PREFIX)/bin
S_SRC= ../src/cli.c
CFLAGS+=-Wall -Werror -Wstrict-prototypes -Wmissing-prototypes
CFLAGS+=-Wmissing-declarations -Wshadow -Wpointer-arith -Wcast-qual
CFLAGS+=-Wsign-compare -Iincludes -std=c99 -pedantic
CFLAGS+=-DPREFIX='"$(PREFIX)"'
LDFLAGS=-rdynamic -lcrypto
ifneq ("$(NOOPT)", "")
CFLAGS+=-O0
else
CFLAGS+=-O2
endif
OSNAME=$(shell uname -s | sed -e 's/[-_].*//g' | tr A-Z a-z)
ifeq ("$(OSNAME)", "darwin")
CFLAGS+=-I/opt/local/include/ -I/usr/local/opt/openssl/include
LDFLAGS+=-L/opt/local/lib -L/usr/local/opt/openssl/lib
else ifeq ("$(OSNAME)", "linux")
CFLAGS+=-D_GNU_SOURCE=1
endif
S_OBJS= $(S_SRC:../src/%.c=$(OBJDIR)/%.o)
$(KODEV): $(OBJDIR) $(S_OBJS)
$(CC) $(S_OBJS) $(LDFLAGS) -o $(KODEV)
$(OBJDIR):
@mkdir -p $(OBJDIR)
install: $(KODEV)
mkdir -p $(INSTALL_DIR)
install -m 555 $(KODEV) $(INSTALL_DIR)/$(KODEV)
uninstall:
rm -f $(INSTALL_DIR)/$(KODEV)
$(OBJDIR)/%.o: ../src/%.c
$(CC) $(CFLAGS) -c $< -o $@
clean:
find . -type f -name \*.o -exec rm {} \;
rm -rf $(KODEV) $(OBJDIR)
.PHONY: all clean

761
src/cli.c

File diff suppressed because it is too large Load Diff

View File

@ -29,6 +29,10 @@
#include "kore.h" #include "kore.h"
#include "http.h" #include "http.h"
#if defined(KORE_USE_PYTHON)
#include "python_api.h"
#endif
#if defined(KORE_USE_PGSQL) #if defined(KORE_USE_PGSQL)
#include "pgsql.h" #include "pgsql.h"
#endif #endif

View File

@ -63,7 +63,7 @@ static void
usage(void) usage(void)
{ {
#if !defined(KORE_SINGLE_BINARY) #if !defined(KORE_SINGLE_BINARY)
fprintf(stderr, "Usage: kore [options | command]\n"); fprintf(stderr, "Usage: kore [options]\n");
#else #else
fprintf(stderr, "Usage: %s [options]\n", __progname); fprintf(stderr, "Usage: %s [options]\n", __progname);
#endif #endif
@ -81,12 +81,8 @@ usage(void)
fprintf(stderr, "\t-r\tdo not drop privileges\n"); fprintf(stderr, "\t-r\tdo not drop privileges\n");
fprintf(stderr, "\t-v\tdisplay kore build information\n"); fprintf(stderr, "\t-v\tdisplay kore build information\n");
#if !defined(KORE_SINGLE_BINARY) fprintf(stderr, "\nFind more information on https://kore.io\n");
kore_cli_usage(0);
#else
fprintf(stderr, "\nbuilt with https://kore.io\n");
exit(1); exit(1);
#endif
} }
static void static void
@ -171,14 +167,6 @@ main(int argc, char *argv[])
kore_mem_init(); kore_mem_init();
#if !defined(KORE_SINGLE_BINARY)
if (argc > 0) {
if (flags)
fatal("You cannot specify kore flags and a command");
return (kore_cli_main(argc, argv));
}
#endif
kore_pid = getpid(); kore_pid = getpid();
nlisteners = 0; nlisteners = 0;
LIST_INIT(&listeners); LIST_INIT(&listeners);