mirror of https://git.kore.io/kore.git
Separate C and C++ files into their own lists.
This commit is contained in:
parent
faa1cf60c4
commit
45e9d26f48
117
src/cli.c
117
src/cli.c
|
@ -85,6 +85,7 @@ static void cli_run_kore(void *);
|
|||
static void cli_generate_certs(void);
|
||||
static void cli_link_library(void *);
|
||||
static void cli_compile_cfile(void *);
|
||||
static void cli_compile_cppfile(void *);
|
||||
static void cli_mkdir(const char *, int);
|
||||
static int cli_dir_exists(const char *);
|
||||
static int cli_file_exists(const char *);
|
||||
|
@ -190,6 +191,7 @@ static char *appl = NULL;
|
|||
static char *rootdir = NULL;
|
||||
static char *compiler = "gcc";
|
||||
static struct cfile_list source_files;
|
||||
static struct cfile_list cpp_files;
|
||||
static int cfiles_count;
|
||||
static struct cmd *command = NULL;
|
||||
|
||||
|
@ -303,6 +305,7 @@ cli_build(int argc, char **argv)
|
|||
|
||||
cfiles_count = 0;
|
||||
TAILQ_INIT(&source_files);
|
||||
TAILQ_INIT(&cpp_files);
|
||||
|
||||
(void)cli_vasprintf(&src_path, "%s/src", rootdir);
|
||||
(void)cli_vasprintf(&assets_path, "%s/assets", rootdir);
|
||||
|
@ -355,6 +358,23 @@ cli_build(int argc, char **argv)
|
|||
|
||||
requires_relink++;
|
||||
}
|
||||
|
||||
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++;
|
||||
}
|
||||
|
||||
(void)unlink(assets_header);
|
||||
free(assets_header);
|
||||
|
@ -684,6 +704,23 @@ cli_add_cfile(char *name, char *fpath, char *opath, struct stat *st, int build)
|
|||
TAILQ_INSERT_TAIL(&source_files, cf, list);
|
||||
}
|
||||
|
||||
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_cfile(char *fpath, struct dirent *dp)
|
||||
{
|
||||
|
@ -699,11 +736,20 @@ cli_register_cfile(char *fpath, struct dirent *dp)
|
|||
|
||||
(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);
|
||||
if (!strcmp(ext, ".cpp")) {
|
||||
cli_add_cppfile(dp->d_name, fpath, opath, &st, 0);
|
||||
} else {
|
||||
cli_add_cfile(dp->d_name, fpath, opath, &st, 0);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
cli_add_cfile(dp->d_name, fpath, opath, &st, 1);
|
||||
|
||||
if (!strcmp(ext, ".cpp")) {
|
||||
cli_add_cppfile(dp->d_name, fpath, opath, &st, 1);
|
||||
} else {
|
||||
cli_add_cfile(dp->d_name, fpath, opath, &st, 1);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -885,10 +931,6 @@ cli_compile_cfile(void *arg)
|
|||
args[idx++] = "-Wsign-compare";
|
||||
args[idx++] = "-fPIC";
|
||||
args[idx++] = "-g";
|
||||
|
||||
args[idx++] = "-Woverloaded-virtual";
|
||||
args[idx++] = "-Wold-style-cast";
|
||||
args[idx++] = "-Wnon-virtual-dtor";
|
||||
|
||||
args[idx++] = "-c";
|
||||
args[idx++] = cf->fpath;
|
||||
|
@ -899,6 +941,64 @@ cli_compile_cfile(void *arg)
|
|||
execvp(compiler, args);
|
||||
}
|
||||
|
||||
static void
|
||||
cli_compile_cppfile(void *arg)
|
||||
{
|
||||
int idx;
|
||||
struct cfile *cf = arg;
|
||||
char *args[20], *ipath[2];
|
||||
#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++] = compiler;
|
||||
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";
|
||||
|
||||
args[idx++] = "-Woverloaded-virtual";
|
||||
args[idx++] = "-Wold-style-cast";
|
||||
args[idx++] = "-Wnon-virtual-dtor";
|
||||
args[idx++] = "-std=c++11";
|
||||
args[idx++] = "-std=gnu++11";
|
||||
|
||||
args[idx++] = "-c";
|
||||
args[idx++] = cf->fpath;
|
||||
args[idx++] = "-o";
|
||||
args[idx++] = cf->opath;
|
||||
args[idx] = NULL;
|
||||
|
||||
execvp(compiler, args);
|
||||
}
|
||||
|
||||
static void
|
||||
cli_link_library(void *arg)
|
||||
{
|
||||
|
@ -928,6 +1028,9 @@ cli_link_library(void *arg)
|
|||
|
||||
TAILQ_FOREACH(cf, &source_files, list)
|
||||
args[idx++] = cf->opath;
|
||||
|
||||
TAILQ_FOREACH(cf, &cpp_files, list)
|
||||
args[idx++] = cf->opath;
|
||||
|
||||
for (i = 0; i < f; i++)
|
||||
args[idx++] = flags[i];
|
||||
|
|
Loading…
Reference in New Issue