mirror of https://git.kore.io/kore.git
parent
93fe8e6b42
commit
6bd0da171d
5
Makefile
5
Makefile
|
@ -22,11 +22,6 @@ ifneq ("$(DEBUG)", "")
|
|||
CFLAGS+=-DKORE_DEBUG
|
||||
endif
|
||||
|
||||
ifneq ("$(KORE_CPP_SUPPORT)", "")
|
||||
CFLAGS+=-DKORE_CPP_SUPPORT
|
||||
LDFLAGS+=-lstdc++
|
||||
endif
|
||||
|
||||
ifneq ("$(KORE_PEDANTIC_MALLOC)", "")
|
||||
CFLAGS+=-DKORE_PEDANTIC_MALLOC
|
||||
endif
|
||||
|
|
|
@ -74,7 +74,6 @@ those by setting a shell environment variable before running **_make_**.
|
|||
* DEBUG=1 (enables use of -d for debug)
|
||||
* BENCHMARK=1 (compiles Kore without OpenSSL)
|
||||
* KORE_PEDANTIC_MALLOC=1 (zero all allocated memory)
|
||||
* KORE_CPP_SUPPORT=1 (compiles Kore with support for C++ projects)
|
||||
|
||||
Example libraries
|
||||
-----------------
|
||||
|
|
172
src/cli.c
172
src/cli.c
|
@ -70,6 +70,7 @@ struct filegen {
|
|||
struct cfile {
|
||||
struct stat st;
|
||||
int build;
|
||||
int cpp;
|
||||
char *name;
|
||||
char *fpath;
|
||||
char *opath;
|
||||
|
@ -103,14 +104,7 @@ static int cli_file_requires_build(struct stat *, const char *);
|
|||
static void cli_find_files(const char *,
|
||||
void (*cb)(char *, struct dirent *));
|
||||
static void cli_add_cfile(char *, char *, char *,
|
||||
struct stat *, int);
|
||||
|
||||
#if defined(KORE_CPP_SUPPORT)
|
||||
static void cli_add_cppfile(char *, char *, char *,
|
||||
struct stat *, int);
|
||||
static void cli_register_cppfile(char *, struct dirent *);
|
||||
static void cli_compile_cppfile(void *);
|
||||
#endif
|
||||
struct stat *, int, int);
|
||||
|
||||
static void cli_run(int, char **);
|
||||
static void cli_help(int, char **);
|
||||
|
@ -196,15 +190,11 @@ static int s_fd = -1;
|
|||
static char *appl = NULL;
|
||||
static char *rootdir = NULL;
|
||||
static char *compiler = "gcc";
|
||||
static char *cppcompiler = "g++";
|
||||
static struct cfile_list source_files;
|
||||
static int cfiles_count;
|
||||
static struct cmd *command = NULL;
|
||||
|
||||
#if defined(KORE_CPP_SUPPORT)
|
||||
static char *cppcompiler = "g++";
|
||||
static struct cfile_list cpp_files;
|
||||
#endif
|
||||
|
||||
void
|
||||
kore_cli_usage(int local)
|
||||
{
|
||||
|
@ -313,18 +303,12 @@ cli_build(int argc, char **argv)
|
|||
if ((p = getenv("CC")) != NULL)
|
||||
compiler = p;
|
||||
|
||||
#if defined(KORE_CPP_SUPPORT)
|
||||
if ((p = getenv("CXX")) != NULL)
|
||||
cppcompiler = p;
|
||||
#endif
|
||||
|
||||
cfiles_count = 0;
|
||||
TAILQ_INIT(&source_files);
|
||||
|
||||
#if defined(KORE_CPP_SUPPORT)
|
||||
TAILQ_INIT(&cpp_files);
|
||||
#endif
|
||||
|
||||
(void)cli_vasprintf(&src_path, "%s/src", rootdir);
|
||||
(void)cli_vasprintf(&assets_path, "%s/assets", rootdir);
|
||||
(void)cli_vasprintf(&config, "%s/conf/%s.conf", rootdir, appl);
|
||||
|
@ -358,10 +342,6 @@ cli_build(int argc, char **argv)
|
|||
/* Build all source files. */
|
||||
cli_find_files(src_path, cli_register_cfile);
|
||||
|
||||
#if defined(KORE_CPP_SUPPORT)
|
||||
cli_find_files(src_path, cli_register_cppfile);
|
||||
#endif
|
||||
|
||||
free(src_path);
|
||||
requires_relink = 0;
|
||||
|
||||
|
@ -382,25 +362,6 @@ cli_build(int argc, char **argv)
|
|||
requires_relink++;
|
||||
}
|
||||
|
||||
#if defined(KORE_CPP_SUPPORT)
|
||||
TAILQ_FOREACH(cf, &cpp_files, list) {
|
||||
if (cf->build == 0)
|
||||
continue;
|
||||
|
||||
printf("compiling %s\n", cf->name);
|
||||
cli_spawn_proc(cli_compile_cppfile, cf);
|
||||
|
||||
times[0].tv_usec = 0;
|
||||
times[0].tv_sec = cf->st.st_mtime;
|
||||
times[1] = times[0];
|
||||
|
||||
if (utimes(cf->opath, times) == -1)
|
||||
printf("utime(%s): %s\n", cf->opath, errno_s);
|
||||
|
||||
requires_relink++;
|
||||
}
|
||||
#endif
|
||||
|
||||
(void)unlink(assets_header);
|
||||
free(assets_header);
|
||||
|
||||
|
@ -649,7 +610,7 @@ cli_build_asset(char *fpath, struct dirent *dp)
|
|||
cli_write_asset(name, ext);
|
||||
*ext = '_';
|
||||
|
||||
cli_add_cfile(name, cpath, opath, &st, 0);
|
||||
cli_add_cfile(name, cpath, opath, &st, 0, 0);
|
||||
kore_mem_free(name);
|
||||
return;
|
||||
}
|
||||
|
@ -708,12 +669,12 @@ cli_build_asset(char *fpath, struct dirent *dp)
|
|||
*--ext = '.';
|
||||
|
||||
/* Register the .c file now (cpath is free'd later). */
|
||||
cli_add_cfile(name, cpath, opath, &st, 1);
|
||||
cli_add_cfile(name, cpath, opath, &st, 1, 0);
|
||||
kore_mem_free(name);
|
||||
}
|
||||
|
||||
static void
|
||||
cli_add_cfile(char *name, char *fpath, char *opath, struct stat *st, int build)
|
||||
cli_add_cfile(char *name, char *fpath, char *opath, struct stat *st, int build, int cpp)
|
||||
{
|
||||
struct cfile *cf;
|
||||
|
||||
|
@ -722,6 +683,7 @@ cli_add_cfile(char *name, char *fpath, char *opath, struct stat *st, int build)
|
|||
|
||||
cf->st = *st;
|
||||
cf->build = build;
|
||||
cf->cpp = cpp;
|
||||
cf->fpath = fpath;
|
||||
cf->opath = opath;
|
||||
cf->name = kore_strdup(name);
|
||||
|
@ -729,65 +691,31 @@ cli_add_cfile(char *name, char *fpath, char *opath, struct stat *st, int build)
|
|||
TAILQ_INSERT_TAIL(&source_files, cf, list);
|
||||
}
|
||||
|
||||
#if defined(KORE_CPP_SUPPORT)
|
||||
static void
|
||||
cli_add_cppfile(char *name, char *fpath, char *opath, struct stat *st, int build)
|
||||
{
|
||||
struct cfile *cf;
|
||||
|
||||
cfiles_count++;
|
||||
cf = kore_malloc(sizeof(*cf));
|
||||
|
||||
cf->st = *st;
|
||||
cf->build = build;
|
||||
cf->fpath = fpath;
|
||||
cf->opath = opath;
|
||||
cf->name = kore_strdup(name);
|
||||
|
||||
TAILQ_INSERT_TAIL(&cpp_files, cf, list);
|
||||
}
|
||||
|
||||
static void
|
||||
cli_register_cppfile(char *fpath, struct dirent *dp)
|
||||
{
|
||||
struct stat st;
|
||||
char *ext, *opath;
|
||||
|
||||
if ((ext = strrchr(fpath, '.')) == NULL || strcmp(ext, ".cpp"))
|
||||
return;
|
||||
|
||||
if (stat(fpath, &st) == -1)
|
||||
cli_fatal("stat(%s): %s", fpath, errno_s);
|
||||
|
||||
(void)cli_vasprintf(&opath, "%s/.objs/%s.o", rootdir, dp->d_name);
|
||||
if (!cli_file_requires_build(&st, opath)) {
|
||||
cli_add_cppfile(dp->d_name, fpath, opath, &st, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
cli_add_cppfile(dp->d_name, fpath, opath, &st, 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
cli_register_cfile(char *fpath, struct dirent *dp)
|
||||
{
|
||||
struct stat st;
|
||||
char *ext, *opath;
|
||||
int cpp;
|
||||
|
||||
if ((ext = strrchr(fpath, '.')) == NULL || strcmp(ext, ".c"))
|
||||
if ((ext = strrchr(fpath, '.')) == NULL || !(!strcmp(ext, ".c") || !strcmp(ext, ".cpp")))
|
||||
return;
|
||||
|
||||
if (!strcmp(ext, ".cpp"))
|
||||
cpp = 1;
|
||||
else
|
||||
cpp = 0;
|
||||
|
||||
if (stat(fpath, &st) == -1)
|
||||
cli_fatal("stat(%s): %s", fpath, errno_s);
|
||||
|
||||
(void)cli_vasprintf(&opath, "%s/.objs/%s.o", rootdir, dp->d_name);
|
||||
if (!cli_file_requires_build(&st, opath)) {
|
||||
cli_add_cfile(dp->d_name, fpath, opath, &st, 0);
|
||||
cli_add_cfile(dp->d_name, fpath, opath, &st, 0, cpp);
|
||||
return;
|
||||
}
|
||||
|
||||
cli_add_cfile(dp->d_name, fpath, opath, &st, 1);
|
||||
cli_add_cfile(dp->d_name, fpath, opath, &st, 1, cpp);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -932,7 +860,7 @@ cli_compile_cfile(void *arg)
|
|||
{
|
||||
int idx;
|
||||
struct cfile *cf = arg;
|
||||
char *args[20], *ipath[2];
|
||||
char *args[24], *ipath[2], *cppdialect;
|
||||
#if defined(KORE_USE_PGSQL)
|
||||
char *ppath;
|
||||
#endif
|
||||
|
@ -970,58 +898,7 @@ cli_compile_cfile(void *arg)
|
|||
args[idx++] = "-fPIC";
|
||||
args[idx++] = "-g";
|
||||
|
||||
args[idx++] = "-c";
|
||||
args[idx++] = cf->fpath;
|
||||
args[idx++] = "-o";
|
||||
args[idx++] = cf->opath;
|
||||
args[idx] = NULL;
|
||||
|
||||
execvp(compiler, args);
|
||||
}
|
||||
|
||||
#if defined(KORE_CPP_SUPPORT)
|
||||
static void
|
||||
cli_compile_cppfile(void *arg)
|
||||
{
|
||||
int idx;
|
||||
struct cfile *cf = arg;
|
||||
char *args[24], *ipath[2], *cppdialect;
|
||||
#if defined(KORE_USE_PGSQL)
|
||||
char *ppath;
|
||||
#endif
|
||||
|
||||
(void)cli_vasprintf(&ipath[0], "-I%s/src", rootdir);
|
||||
(void)cli_vasprintf(&ipath[1], "-I%s/src/includes", rootdir);
|
||||
|
||||
/*
|
||||
* These compiler options should be settable
|
||||
* somehow by the user if they so choose.
|
||||
*/
|
||||
idx = 0;
|
||||
args[idx++] = cppcompiler;
|
||||
args[idx++] = ipath[0];
|
||||
args[idx++] = ipath[1];
|
||||
#if defined(PREFIX)
|
||||
(void)cli_vasprintf(&args[idx++], "-I%s/include", PREFIX);
|
||||
#else
|
||||
args[idx++] = "-I/usr/local/include";
|
||||
#endif
|
||||
|
||||
#if defined(KORE_USE_PGSQL)
|
||||
(void)cli_vasprintf(&ppath, "-I%s", PGSQL_INCLUDE_PATH);
|
||||
args[idx++] = ppath;
|
||||
#endif
|
||||
|
||||
args[idx++] = "-Wall";
|
||||
args[idx++] = "-Wstrict-prototypes";
|
||||
args[idx++] = "-Wmissing-prototypes";
|
||||
args[idx++] = "-Wmissing-declarations";
|
||||
args[idx++] = "-Wshadow";
|
||||
args[idx++] = "-Wpointer-arith";
|
||||
args[idx++] = "-Wcast-qual";
|
||||
args[idx++] = "-Wsign-compare";
|
||||
args[idx++] = "-fPIC";
|
||||
args[idx++] = "-g";
|
||||
if (cf->cpp) {
|
||||
|
||||
args[idx++] = "-Woverloaded-virtual";
|
||||
args[idx++] = "-Wold-style-cast";
|
||||
|
@ -1032,6 +909,7 @@ cli_compile_cppfile(void *arg)
|
|||
(void)cli_vasprintf(&cppstandard, "-std=%s", cppdialect);
|
||||
args[idx++] = cppstandard;
|
||||
}
|
||||
}
|
||||
|
||||
args[idx++] = "-c";
|
||||
args[idx++] = cf->fpath;
|
||||
|
@ -1039,9 +917,11 @@ cli_compile_cppfile(void *arg)
|
|||
args[idx++] = cf->opath;
|
||||
args[idx] = NULL;
|
||||
|
||||
if (cf->cpp)
|
||||
execvp(cppcompiler, args);
|
||||
else
|
||||
execvp(compiler, args);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
cli_link_library(void *arg)
|
||||
|
@ -1050,10 +930,7 @@ cli_link_library(void *arg)
|
|||
int idx, f, i;
|
||||
char *p, *libname, *flags[LD_FLAGS_MAX];
|
||||
char *args[cfiles_count + 11 + LD_FLAGS_MAX];
|
||||
|
||||
#if defined(KORE_CPP_SUPPORT)
|
||||
char *cpplib;
|
||||
#endif
|
||||
|
||||
if ((p = getenv("LDFLAGS")) != NULL)
|
||||
f = kore_split_string(p, " ", flags, LD_FLAGS_MAX);
|
||||
|
@ -1077,10 +954,6 @@ cli_link_library(void *arg)
|
|||
TAILQ_FOREACH(cf, &source_files, list)
|
||||
args[idx++] = cf->opath;
|
||||
|
||||
#if defined(KORE_CPP_SUPPORT)
|
||||
TAILQ_FOREACH(cf, &cpp_files, list)
|
||||
args[idx++] = cf->opath;
|
||||
|
||||
if ((cpplib = getenv("CXXLIB")) != NULL) {
|
||||
char *cpplibrary = NULL;
|
||||
(void)cli_vasprintf(&cpplibrary, "-l%s", cpplib);
|
||||
|
@ -1088,7 +961,6 @@ cli_link_library(void *arg)
|
|||
} else {
|
||||
args[idx++] = "-lstdc++";
|
||||
}
|
||||
#endif
|
||||
|
||||
for (i = 0; i < f; i++)
|
||||
args[idx++] = flags[i];
|
||||
|
|
Loading…
Reference in New Issue