From: fennecdjay Date: Sat, 21 Jan 2023 00:17:17 +0000 (+0100) Subject: :art: Add ability to embed gw files X-Git-Tag: nightly~206^2~21 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=52062ca3ef4a298fdc10faf8740ec4a9042fc4a5;p=gwion.git :art: Add ability to embed gw files --- diff --git a/Makefile b/Makefile index a2d0a4cc..d2ea3145 100644 --- a/Makefile +++ b/Makefile @@ -79,6 +79,11 @@ options-show: @$(call _options) @$(info libs: ${GWLIBS}) +embed_gw: + bash scripts/gw_embed.sh ${GWION_EMBED_GW} > src/embed.c + CFLAGS="-DGWION_EMBED_GW -Iembed $(eval ${CFLAGS})" ${MAKE} + rm src/embed.c + almost_gwion: ${almost_obj} ${ALMOST_LIBS} lto: diff --git a/fmt b/fmt index bee2f7b0..c026b026 160000 --- a/fmt +++ b/fmt @@ -1 +1 @@ -Subproject commit bee2f7b0dc9942e804aa12d2cf3c29914c38b834 +Subproject commit c026b026ff0a93b1fe4790f0918e315ff045a9f6 diff --git a/scripts/gw_embed.sh b/scripts/gw_embed.sh new file mode 100644 index 00000000..391bf039 --- /dev/null +++ b/scripts/gw_embed.sh @@ -0,0 +1,46 @@ +#!/bin/sh +header_name() { + echo "$1" | sed 's/\./_/' | sed 's#/#_#g' +} + +cat << EOF +#include "gwion_util.h" +#include "gwion_ast.h" +#include "gwion_env.h" +#include "vm.h" +#include "instr.h" +#include "emit.h" +#include "compile.h" +#include "gwion.h" + +static void compile_embed_gw(const Gwion gwion, const m_str filename, + const m_str content, const size_t sz) { + const m_str str = mp_malloc2(gwion->mp, sz + 1); + memcpy(str, content, sz); + str[sz] = 0; + compile_string(gwion, filename, str); + mp_free2(gwion->mp, sz + 1, str); +} + +EOF + +for file in $GWION_EMBED_GW +do + name=$(header_name "$file") + xxd -i "$file" > embed/"${name}.h" + echo "#include \"${name}.h\"" +done + + + +echo "void embed_gw(const Gwion gwion) {" + +for file in $GWION_EMBED_GW +do + name=$(header_name "$file") + xxd -i "$file" > "${name}.h" + echo " compile_embed_gw(gwion, \"$file\", ${name}, ${name}_len);" + +done + +echo "}" diff --git a/src/main.c b/src/main.c index d8abd6ef..ccd94559 100644 --- a/src/main.c +++ b/src/main.c @@ -43,12 +43,19 @@ int main(int argc, char **argv) { #else +#ifdef GWION_EMBED_GW +void embed_gw(const Gwion); +#endif + int main(int argc, char **argv) { CliArg arg = {.arg = {.argc = argc, .argv = argv}, .loop = false}; signal(SIGINT, sig); signal(SIGTERM, sig); const m_bool ini = gwion_ini(&gwion, &arg); arg_release(&arg); +#ifdef GWION_EMBED_GW + embed_gw(&gwion); +#endif if (ini > 0) gwion_run(&gwion); gwion_end(&gwion); gwion.vm = NULL;