[ADD/MOD] CFLAGS/LDFLAGS and version checks

This commit is contained in:
LDA 2024-09-07 14:49:30 +02:00
commit 0ec028d458
7 changed files with 222 additions and 80 deletions

View file

@ -19,8 +19,8 @@ PREFIX ?=/usr/local
AYAS=ayaya
ETC=etc
CFLAGS=-I$(SOURCE) -I$(INCLUDES) -I$(CYTO_INC) -DNAME="\"$(NAME)\"" -DVERSION="\"$(VERSION)\"" -DREPOSITORY=\"$(REPOSITORY)\" -DCODE=\"$(CODE)\" -O2 -g -Wall -Werror
LDFLAGS=-L $(CYTO_LIB) -lCytoplasm -O2 -g
FCFLAGS=-I$(SOURCE) -I$(INCLUDES) -I$(CYTO_INC) -DNAME="\"$(NAME)\"" -DVERSION="\"$(VERSION)\"" -DREPOSITORY=\"$(REPOSITORY)\" -DCODE=\"$(CODE)\" $(CFLAGS)
FLDFLAGS=-L $(CYTO_LIB) -lCytoplasm $(LDFLAGS)
AFLAGS=-C "$(ETC)/ayadoc/style.css" -p "$(NAME)"
# ============================ Compilation =================================
SRC_FILES:=$(shell find $(SOURCE) -name '*.c') $(shell find $(ETC)/media -name '*.png')
@ -32,7 +32,7 @@ AYA_FILES:=${subst $(INCLUDES)/,$(AYAS)/,$(patsubst %.h, %.html, $(CPP_FILES))}
all: utils binary
binary: $(OBJ_FILES)
$(CC) $(LDFLAGS) $(OBJ_FILES) -o $(BINARY)
$(CC) $(FLDFLAGS) $(OBJ_FILES) -o $(BINARY)
tags: $(SRC_FILES)
@ctags --recurse $(SOURCE)/
@ -45,10 +45,10 @@ $(OBJECT)/%.o: $(ETC)/media/%.png
@base64 $< | \
sed -e 's/^\(.*\)$$/ "\1"/' | \
sed -e '$$ s/^\(.*\)$$/\1;/' >> $@.c
$(CC) -c $(CFLAGS) $@.c -o $@
$(CC) -c $(FCFLAGS) $@.c -o $@
$(OBJECT)/%.o: $(SOURCE)/%.c
@mkdir -p $(shell dirname "$@")
$(CC) -c $(CFLAGS) $< -o $@
$(CC) -c $(FCFLAGS) $< -o $@
utils:
(cd tools && make)

196
build.c
View file

@ -203,6 +203,8 @@ typedef struct buildinfo {
char *inc;
char *obj;
char *cflags, *ldflags;
char *cc;
} basic;
@ -216,52 +218,26 @@ destroy_buildinfo(buildinfo_t *info)
return;
}
if (info->basic.codename)
{
free(info->basic.codename);
info->basic.codename = NULL;
}
if (info->basic.version)
{
free(info->basic.version);
info->basic.version = NULL;
}
if (info->basic.name)
{
free(info->basic.name);
info->basic.name = NULL;
}
if (info->basic.binary)
{
free(info->basic.binary);
info->basic.binary = NULL;
}
if (info->basic.src)
{
free(info->basic.src);
info->basic.src = NULL;
}
if (info->basic.inc)
{
free(info->basic.inc);
info->basic.inc = NULL;
}
if (info->basic.obj)
{
free(info->basic.obj);
info->basic.obj = NULL;
}
if (info->basic.cc)
{
free(info->basic.cc);
info->basic.cc = NULL;
}
#define FreeIfExistent(v) do \
{ \
if (v) \
{ \
free(v); \
v = NULL; \
} \
} while (0)
if (info->repo)
{
free(info->repo);
info->repo = NULL;
}
FreeIfExistent(info->basic.codename);
FreeIfExistent(info->basic.version);
FreeIfExistent(info->basic.ldflags);
FreeIfExistent(info->basic.binary);
FreeIfExistent(info->basic.cflags);
FreeIfExistent(info->basic.name);
FreeIfExistent(info->basic.src);
FreeIfExistent(info->basic.inc);
FreeIfExistent(info->basic.obj);
FreeIfExistent(info->basic.cc);
FreeIfExistent(info->repo);
}
static char *
@ -309,8 +285,10 @@ exec_code(char *program, char *argv[])
}
return status;
}
}
/* We're not meant to ever be there, but TCC is stupid. */
return -1;
}
static char *
strchrn(char *s, char c)
@ -358,6 +336,32 @@ mkdir_rec(char *dir)
}
}
}
static str_array_t *
split(char *dir)
{
str_array_t *ret;
char *start;
if (!dir || strlen(dir) >= PATH_MAX - 1)
{
return NULL;
}
ret = str_array_create();
for (start = dir; start; start = strchrn(start, ' '))
{
char subtmp[PATH_MAX];
char *next = strchr(start, ' ');
if (!next)
{
next = start + strlen(start);
}
memcpy(subtmp, start, next - start);
subtmp[next - start] = '\0';
str_array_add(ret, subtmp);
}
return ret;
}
static time_t
mod_date(char *file)
{
@ -371,7 +375,7 @@ mod_date(char *file)
static bool
build_file(char *cSource, buildinfo_t info, bool isTool)
{
char *args[16] = { 0 };
str_array_t *args, *cflags;
char *oFileName, *objPath, *oFile;
int ret, i = 0;
int srclen;
@ -408,30 +412,44 @@ build_file(char *cSource, buildinfo_t info, bool isTool)
return true;
}
args[i++] = Compiler(info);
args = str_array_create();
if (!isTool)
{
printf("\tCC %s...\n", cSource);
}
str_array_add(args, Compiler(info));
if (isTool)
{
args[i++] = "-lCytoplasm";
args[i++] = "-I.";
str_array_add(args, "-lCytoplasm");
str_array_add(args, "-I.");
}
else
{
args[i++] = "-c";
str_array_add(args, "-c");
}
args[i++] = cSource;
args[i++] = "-o";
args[i++] = oFileName;
str_array_add(args, cSource);
args[i++] = "-I";
args[i++] = info.basic.inc;
args[i++] = "-I";
args[i++] = info.basic.src;
cflags = split(info.basic.cflags);
for (i = 0; i < str_array_len(cflags); i++)
{
str_array_add(args, str_array_get(cflags, i));
}
str_array_free(cflags);
str_array_add(args, "-o");
str_array_add(args, oFileName);
str_array_add(args, "-I");
str_array_add(args, info.basic.inc);
str_array_add(args, "-I");
str_array_add(args, info.basic.src);
{
char *pre = string_cat("\"", info.basic.version);
char *pos = string_cat(pre, "\"");
vers = string_cat("-DVERSION=", pos);
args[i++] = vers;
str_array_add(args, vers);
free(pos);
free(pre);
@ -440,7 +458,7 @@ build_file(char *cSource, buildinfo_t info, bool isTool)
char *pre = string_cat("\"", info.basic.name);
char *pos = string_cat(pre, "\"");
name = string_cat("-DNAME=", pos);
args[i++] = name;
str_array_add(args, name);
free(pos);
free(pre);
@ -449,7 +467,7 @@ build_file(char *cSource, buildinfo_t info, bool isTool)
char *pre = string_cat("\"", info.basic.codename);
char *pos = string_cat(pre, "\"");
code = string_cat("-DCODE=", pos);
args[i++] = code;
str_array_add(args, code);
free(pos);
free(pre);
@ -458,15 +476,17 @@ build_file(char *cSource, buildinfo_t info, bool isTool)
char *pre = string_cat("\"", info.repo);
char *pos = string_cat(pre, "\"");
repo = string_cat("-DREPOSITORY=", pos);
args[i++] = repo;
str_array_add(args, repo);
free(pos);
free(pre);
}
args[i++] = NULL;
str_array_add(args, NULL);
ret = exec_code(Compiler(info), args);
ret = exec_code(Compiler(info), args->values);
str_array_free(args);
free(objPath);
free(oFileName);
free(oFile);
@ -479,7 +499,7 @@ build_file(char *cSource, buildinfo_t info, bool isTool)
static bool
finalise_file(str_array_t *arr, buildinfo_t info)
{
str_array_t *flags;
str_array_t *flags, *ldflags;
size_t i;
bool ret = true;
if (!arr)
@ -490,6 +510,13 @@ finalise_file(str_array_t *arr, buildinfo_t info)
flags = str_array_create();
str_array_add(flags, Compiler(info));
ldflags = split(info.basic.cflags);
for (i = 0; i < str_array_len(ldflags); i++)
{
str_array_add(flags, str_array_get(ldflags, i));
}
str_array_free(ldflags);
str_array_add(flags, "-lCytoplasm");
for (i = 0; i < str_array_len(arr); i++)
@ -709,6 +736,9 @@ main_build(int argc, char *argv[])
If("VERSION", basic.version, "Version");
If("BINARY", basic.binary, "Binary name");
If("CFLAGS", basic.cflags, "C compiler arguments");
If("LDFLAGS", basic.ldflags, "Linker arguments");
If("INCLUDES", basic.inc, "Include path");
If("SOURCE", basic.src, "Source path");
If("OBJECT", basic.obj, "Object path");
@ -731,6 +761,20 @@ main_build(int argc, char *argv[])
}
info.repo = trim_nl(info.repo);
if (argc >= 2 && !strcmp(argv[1], "clean"))
{
char *args[8];
size_t i;
unlink(info.basic.binary);
args[i++] = "rm";
args[i++] = "-r";
args[i++] = info.basic.obj;
args[i++] = NULL;
exec_code(args[0], args);
goto end;
}
/* Step 3: Build all utilities. */
sources = collect_sources("tools", true, ".c");
@ -771,7 +815,6 @@ main_build(int argc, char *argv[])
for (i = 0; i < str_array_len(sources); i++)
{
char *file = str_array_get(sources, i);
printf("\tCC %s...\n", file);
if (!build_file(file, info, false))
{
str_array_free(sources);
@ -785,10 +828,8 @@ main_build(int argc, char *argv[])
goto fail;
}
str_array_free(sources);
/* Step 6: Build every Ayadoc */
/* Step 7: Good! */
/* TODO: Step 6: Build every Ayadoc */
end:
destroy_buildinfo(&info);
return EXIT_SUCCESS;
fail:
@ -802,8 +843,21 @@ fail:
}
int
main(int argc, char* argv[])
main(int argc, char *argv[])
{
/* TODO: Multiple flags(build/install/ayadoc/...) */
if ((argc - 1) < 1)
{
/* No arguments, let's just build. */
return main_build(argc, argv);
}
if (!strcmp(argv[1], "build") ||
!strcmp(argv[1], "clean"))
{
return main_build(argc, argv);
}
printf("%s: unknown verb: %s\n", argv[0], argv[1]);
return EXIT_FAILURE;
}

View file

@ -211,6 +211,10 @@ Main(Array *args, HashMap *env)
conf.maxConnections = conf.threads << 2;
conf.handlerArgs = ParseeInitData(jabber);
conf.handler = ParseeRequest;
if (!conf.handlerArgs)
{
goto end;
}
Log(LOG_DEBUG, "Verbosity level: %d", verbose);
((ParseeData *) conf.handlerArgs)->verbosity = verbose;

View file

@ -14,6 +14,7 @@
ParseeData *
ParseeInitData(XMPPComponent *comp)
{
char *version;
ParseeData *data;
DbRef *ref;
if (!ParseeConfigGet())
@ -37,7 +38,10 @@ ParseeInitData(XMPPComponent *comp)
if (!data->db)
{
Log(LOG_WARNING, "LMDB doesn't seem to be setup.");
if (data->config->db_size)
{
Log(LOG_WARNING, "Falling back to flat-file.");
}
data->db = DbOpen(data->config->db_path, 0);
}
@ -49,6 +53,27 @@ ParseeInitData(XMPPComponent *comp)
Free(id);
}
version = GrabString(DbJson(ref), 1, "version");
if (!ParseeIsCompatible(VERSION, version))
{
Log(LOG_WARNING, "Version mismatch(curr=%s db=%s).", VERSION, version);
Log(LOG_WARNING, "Yeah. You may want to _not_ do that.");
DbUnlock(data->db, ref);
DbClose(data->db);
HashMapFree(data->oid_servers);
pthread_mutex_destroy(&data->oidl);
XMPPEndCompStream(data->jabber);
HttpRouterFree(data->router);
CommandFreeRouter(data->handler);
Free(data);
return NULL;
}
data->id = StrDuplicate(GrabString(DbJson(ref), 1, "identifier"));
DbUnlock(data->db, ref);

53
src/Parsee/Versions.c Normal file
View file

@ -0,0 +1,53 @@
#include <Parsee.h>
#include <Cytoplasm/Memory.h>
#include <Cytoplasm/Str.h>
bool
ParseeIsCompatible(char *ver1, char *ver2)
{
char *major1 = NULL;
char *major2 = NULL;
char *tmp;
if (!ver1 || !ver2)
{
return false;
}
/* Check if one of them is a "flipped"(joke) version. If so,
* then the user should definitely NOT try funny things with
* their data. */
if (*ver1 == '-' || *ver2 == '-')
{
return false;
}
#define GetMajor(v) do \
{ \
while (*ver##v != '.') \
{ \
char cb[2]; \
cb[0] = *ver##v; \
cb[1] = '\0'; \
tmp = major##v; \
major##v = StrConcat(2, major##v, cb); \
Free(tmp); \
ver##v++; \
} \
} \
while (0)
GetMajor(1);
GetMajor(2);
if (!StrEquals(major1, major2))
{
Free(major1);
Free(major2);
return false;
}
Free(major1);
Free(major2);
return true;
}

View file

@ -303,9 +303,9 @@ end_error:
args->config, mroom_id, encoded,
"m.room.message", content
);
Free(mime);
Free(mxc);
}
Free(mime);
}
}
else if (reactions)

View file

@ -110,6 +110,12 @@ extern const char *parsee_ascii[PARSEE_ASCII_LINES];
* Modifies: the logger output */
extern void ParseePrintASCII(void);
/**
* Checks if two versions of Parsee can be considered "compatible".
* ---------------
* Modifies: NOTHING */
extern bool ParseeIsCompatible(char *ver1, char *ver2);
/** Generates a valid, getopt-style argument list from a end-terminated
* argument list.
* ------------