[ADD/WIP] Push all the Janet changes

This is still unstable(and I still need to design/document the exposed
API)! Do(n't) go and use it!
This commit is contained in:
LDA 2024-11-16 14:11:32 +01:00
commit ca87972b3a
50 changed files with 3550 additions and 92 deletions

View file

@ -367,7 +367,7 @@ write_objects(FILE *makefile, str_array_t *sources)
{
char *src = str_array_get(sources, i);
char *ofl = string_rep_ext(src, ".c", ".o");
char *obj = string_cat("build", ofl + 3);
char *obj = string_cat("build", strchr(ofl, '/'));
fprintf(makefile, " %s", obj);
free(ofl);
@ -440,7 +440,8 @@ main_build(int argc, char *argv[])
ssize_t nread;
bool with_static = false, with_lmdb = false;
int opt;
str_array_t *sources, *images, *utils, *aya;
str_array_t *sources, *janet = NULL, *images, *utils, *aya;
char *janet_dir = NULL;
if (repo)
{
@ -455,7 +456,7 @@ main_build(int argc, char *argv[])
repo = strdup("N/A");
}
while ((opt = getopt(argc, argv, "sl")) != -1)
while ((opt = getopt(argc, argv, "slJ:")) != -1)
{
switch (opt)
{
@ -466,6 +467,9 @@ main_build(int argc, char *argv[])
with_lmdb = with_static;
with_static = true;
break;
case 'J':
janet_dir = strdup(optarg);
break;
}
}
@ -484,13 +488,22 @@ main_build(int argc, char *argv[])
/* Create all objects */
sources = collect_sources("src", true, ".c");
if (janet_dir)
{
janet = collect_sources(janet_dir, true, ".c");
for (i = 0; i < str_array_len(janet); i++)
{
str_array_add(sources, str_array_get(janet, i));
}
str_array_free(janet);
}
images = collect_sources("etc/media", true, ".png");
fprintf(makefile, "binary:");
write_objects(makefile, sources);
write_images(makefile, images);
fprintf(makefile, "\n\t");
{
fprintf(makefile, "$(CC) -o $(BINARY)");
fprintf(makefile, "$(CC) -lm -o $(BINARY)");
if (with_static)
{
fprintf(makefile, " -static");
@ -503,7 +516,7 @@ main_build(int argc, char *argv[])
fprintf(makefile, " -lm -lpthread -lmbedtls -lmbedx509 -lmbedcrypto -lCytoplasm -lmbedtls -lmbedx509 -lmbedcrypto");
if (with_lmdb) fprintf(makefile, " -llmdb");
}
fprintf(makefile, " -lCytoplasm $(LDFLAGS)\n");
fprintf(makefile, " -lCytoplasm -lm $(LDFLAGS)\n");
}
/* Write rules for every source */
@ -511,7 +524,7 @@ main_build(int argc, char *argv[])
{
char *src = str_array_get(sources, i);
char *ofl = string_rep_ext(src, ".c", ".o");
char *obj = string_cat("build", ofl + 3);
char *obj = string_cat("build", strchr(ofl, '/'));
fprintf(makefile, "%s: %s\n", obj, src);
{
@ -527,6 +540,10 @@ main_build(int argc, char *argv[])
str_array_free(s);
fprintf(makefile, "\t$(CC) -c -Isrc -Isrc/include -I$(CYTO_INC) ");
if (janet_dir)
{
fprintf(makefile, "-DJANET -I %s ", janet_dir);
}
fprintf(makefile, "-DVERSION=\"\\\"$(VERSION)\\\"\" ");
fprintf(makefile, "-DNAME=\"\\\"$(NAME)\\\"\" ");
fprintf(makefile, "-DCODE=\"\\\"$(CODE)\\\"\" ");
@ -597,7 +614,7 @@ main_build(int argc, char *argv[])
fprintf(makefile, " -lCytoplasm -lmbedtls -lmbedx509 -lmbedcrypto");
if (with_lmdb) fprintf(makefile, " -llmdb");
}
fprintf(makefile, " -lCytoplasm $(CFLAGS)\n");
fprintf(makefile, " -lCytoplasm -lm $(CFLAGS)\n");
}
free(ofl);
@ -685,6 +702,7 @@ main_build(int argc, char *argv[])
str_array_free(aya);
fflush(makefile);
fclose(makefile);
free(janet_dir);
free(repo);
return EXIT_SUCCESS;
}