mirror of https://git.kore.io/kore.git
Formatting and slight C++ build improvements.
Do not link against libstdc++ when not having any C++ files. Let the compiler decide what subprocess to use for compiling certain files, thus killing the CXX need. Can be overwritten in the same old default in CC.
This commit is contained in:
parent
160eb791f7
commit
3a608a99bb
71
src/cli.c
71
src/cli.c
|
@ -69,8 +69,8 @@ struct filegen {
|
||||||
|
|
||||||
struct cfile {
|
struct cfile {
|
||||||
struct stat st;
|
struct stat st;
|
||||||
int build;
|
int build;
|
||||||
int cpp;
|
int cpp;
|
||||||
char *name;
|
char *name;
|
||||||
char *fpath;
|
char *fpath;
|
||||||
char *opath;
|
char *opath;
|
||||||
|
@ -190,7 +190,6 @@ static int s_fd = -1;
|
||||||
static char *appl = NULL;
|
static char *appl = NULL;
|
||||||
static char *rootdir = NULL;
|
static char *rootdir = NULL;
|
||||||
static char *compiler = "gcc";
|
static char *compiler = "gcc";
|
||||||
static char *cppcompiler = "g++";
|
|
||||||
static struct cfile_list source_files;
|
static struct cfile_list source_files;
|
||||||
static int cfiles_count;
|
static int cfiles_count;
|
||||||
static struct cmd *command = NULL;
|
static struct cmd *command = NULL;
|
||||||
|
@ -302,9 +301,6 @@ cli_build(int argc, char **argv)
|
||||||
|
|
||||||
if ((p = getenv("CC")) != NULL)
|
if ((p = getenv("CC")) != NULL)
|
||||||
compiler = p;
|
compiler = p;
|
||||||
|
|
||||||
if ((p = getenv("CXX")) != NULL)
|
|
||||||
cppcompiler = p;
|
|
||||||
|
|
||||||
cfiles_count = 0;
|
cfiles_count = 0;
|
||||||
TAILQ_INIT(&source_files);
|
TAILQ_INIT(&source_files);
|
||||||
|
@ -674,7 +670,8 @@ cli_build_asset(char *fpath, struct dirent *dp)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
cli_add_cfile(char *name, char *fpath, char *opath, struct stat *st, int build, int cpp)
|
cli_add_cfile(char *name, char *fpath, char *opath, struct stat *st,
|
||||||
|
int build, int cpp)
|
||||||
{
|
{
|
||||||
struct cfile *cf;
|
struct cfile *cf;
|
||||||
|
|
||||||
|
@ -696,11 +693,12 @@ cli_register_cfile(char *fpath, struct dirent *dp)
|
||||||
{
|
{
|
||||||
struct stat st;
|
struct stat st;
|
||||||
char *ext, *opath;
|
char *ext, *opath;
|
||||||
int cpp;
|
int cpp;
|
||||||
|
|
||||||
if ((ext = strrchr(fpath, '.')) == NULL || !(!strcmp(ext, ".c") || !strcmp(ext, ".cpp")))
|
if ((ext = strrchr(fpath, '.')) == NULL ||
|
||||||
|
(strcmp(ext, ".c") && strcmp(ext, ".cpp")))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!strcmp(ext, ".cpp"))
|
if (!strcmp(ext, ".cpp"))
|
||||||
cpp = 1;
|
cpp = 1;
|
||||||
else
|
else
|
||||||
|
@ -714,7 +712,7 @@ cli_register_cfile(char *fpath, struct dirent *dp)
|
||||||
cli_add_cfile(dp->d_name, fpath, opath, &st, 0, cpp);
|
cli_add_cfile(dp->d_name, fpath, opath, &st, 0, cpp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
cli_add_cfile(dp->d_name, fpath, opath, &st, 1, cpp);
|
cli_add_cfile(dp->d_name, fpath, opath, &st, 1, cpp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -860,7 +858,7 @@ cli_compile_cfile(void *arg)
|
||||||
{
|
{
|
||||||
int idx;
|
int idx;
|
||||||
struct cfile *cf = arg;
|
struct cfile *cf = arg;
|
||||||
char *args[24], *ipath[2], *cppdialect;
|
char *args[24], *ipath[2], *p, *cppstandard;
|
||||||
#if defined(KORE_USE_PGSQL)
|
#if defined(KORE_USE_PGSQL)
|
||||||
char *ppath;
|
char *ppath;
|
||||||
#endif
|
#endif
|
||||||
|
@ -888,8 +886,6 @@ cli_compile_cfile(void *arg)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
args[idx++] = "-Wall";
|
args[idx++] = "-Wall";
|
||||||
args[idx++] = "-Wstrict-prototypes";
|
|
||||||
args[idx++] = "-Wmissing-prototypes";
|
|
||||||
args[idx++] = "-Wmissing-declarations";
|
args[idx++] = "-Wmissing-declarations";
|
||||||
args[idx++] = "-Wshadow";
|
args[idx++] = "-Wshadow";
|
||||||
args[idx++] = "-Wpointer-arith";
|
args[idx++] = "-Wpointer-arith";
|
||||||
|
@ -899,38 +895,35 @@ cli_compile_cfile(void *arg)
|
||||||
args[idx++] = "-g";
|
args[idx++] = "-g";
|
||||||
|
|
||||||
if (cf->cpp) {
|
if (cf->cpp) {
|
||||||
|
|
||||||
args[idx++] = "-Woverloaded-virtual";
|
args[idx++] = "-Woverloaded-virtual";
|
||||||
args[idx++] = "-Wold-style-cast";
|
args[idx++] = "-Wold-style-cast";
|
||||||
args[idx++] = "-Wnon-virtual-dtor";
|
args[idx++] = "-Wnon-virtual-dtor";
|
||||||
|
|
||||||
if ((cppdialect = getenv("CXXSTD")) != NULL) {
|
if ((p = getenv("CXXSTD")) != NULL) {
|
||||||
char *cppstandard = NULL;
|
(void)cli_vasprintf(&cppstandard, "-std=%s", p);
|
||||||
(void)cli_vasprintf(&cppstandard, "-std=%s", cppdialect);
|
|
||||||
args[idx++] = cppstandard;
|
args[idx++] = cppstandard;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
args[idx++] = "-Wstrict-prototypes";
|
||||||
|
args[idx++] = "-Wmissing-prototypes";
|
||||||
}
|
}
|
||||||
|
|
||||||
args[idx++] = "-c";
|
args[idx++] = "-c";
|
||||||
args[idx++] = cf->fpath;
|
args[idx++] = cf->fpath;
|
||||||
args[idx++] = "-o";
|
args[idx++] = "-o";
|
||||||
args[idx++] = cf->opath;
|
args[idx++] = cf->opath;
|
||||||
args[idx] = NULL;
|
args[idx] = NULL;
|
||||||
|
|
||||||
if (cf->cpp)
|
execvp(compiler, args);
|
||||||
execvp(cppcompiler, args);
|
|
||||||
else
|
|
||||||
execvp(compiler, args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
cli_link_library(void *arg)
|
cli_link_library(void *arg)
|
||||||
{
|
{
|
||||||
struct cfile *cf;
|
struct cfile *cf;
|
||||||
int idx, f, i;
|
int idx, f, i, has_cpp;
|
||||||
char *p, *libname, *flags[LD_FLAGS_MAX];
|
|
||||||
char *args[cfiles_count + 11 + LD_FLAGS_MAX];
|
char *args[cfiles_count + 11 + LD_FLAGS_MAX];
|
||||||
char *cpplib;
|
char *p, *libname, *flags[LD_FLAGS_MAX], *cpplib;
|
||||||
|
|
||||||
if ((p = getenv("LDFLAGS")) != NULL)
|
if ((p = getenv("LDFLAGS")) != NULL)
|
||||||
f = kore_split_string(p, " ", flags, LD_FLAGS_MAX);
|
f = kore_split_string(p, " ", flags, LD_FLAGS_MAX);
|
||||||
|
@ -951,17 +944,21 @@ cli_link_library(void *arg)
|
||||||
args[idx++] = "-shared";
|
args[idx++] = "-shared";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
TAILQ_FOREACH(cf, &source_files, list)
|
TAILQ_FOREACH(cf, &source_files, list) {
|
||||||
|
if (cf->cpp)
|
||||||
|
has_cpp = 1;
|
||||||
args[idx++] = cf->opath;
|
args[idx++] = cf->opath;
|
||||||
|
|
||||||
if ((cpplib = getenv("CXXLIB")) != NULL) {
|
|
||||||
char *cpplibrary = NULL;
|
|
||||||
(void)cli_vasprintf(&cpplibrary, "-l%s", cpplib);
|
|
||||||
args[idx++] = cpplibrary;
|
|
||||||
} else {
|
|
||||||
args[idx++] = "-lstdc++";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (has_cpp) {
|
||||||
|
if ((p = getenv("CXXLIB")) != NULL) {
|
||||||
|
(void)cli_vasprintf(&cpplib, "-l%s", p);
|
||||||
|
args[idx++] = cpplib;
|
||||||
|
} else {
|
||||||
|
args[idx++] = "-lstdc++";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < f; i++)
|
for (i = 0; i < f; i++)
|
||||||
args[idx++] = flags[i];
|
args[idx++] = flags[i];
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue