From: fennecdjay Date: Fri, 27 Jan 2023 11:34:46 +0000 (+0100) Subject: :art: add arguments, cflags, ldflags, improve X-Git-Tag: nightly~206^2~9 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=e6016ef30939a6dba378015f9bbf84d0aa4ca673;p=gwion.git :art: add arguments, cflags, ldflags, improve --- diff --git a/scripts/embed.bash b/scripts/embed.bash index 0701c385..bad1b1b2 100644 --- a/scripts/embed.bash +++ b/scripts/embed.bash @@ -80,8 +80,9 @@ ANN static void compile_script(const Gwion gwion, const m_str filename, EOF +libraries=$(jq -rc '.libraries' <<< "$json") echo "ANN void gwion_embed(const Gwion gwion) {" >> embed/embed_foot -jq -rc '.libraries|.[]' <<< "$json" | +jq -rc '.[]' <<< "$libraries" | while read -r lib do path=$(jq -c '.path' <<< "$lib" | sed -e 's/^"//' -e 's/"$//') @@ -105,9 +106,10 @@ handle_script() { echo " compile_script(gwion, \"$name\", ${name}, ${name}_len);" } +scripts=$(jq -r '.scripts' <<< "$json") handle_scripts() { i=0 - jq -r '.scripts|.[]' <<< "$json" | + jq -r '.[]' <<< "$scripts" | while read -r name; do handle_script "$name" "$i"; i=$((i+1)); done @@ -123,10 +125,60 @@ audio=$(jq -rc '.audio' <<< "$json") in=$(jq -rc '.in' <<< "$audio") out=$(jq -rc '.out' <<< "$audio") samplerate=$(jq -rc '.samplerate' <<< "$audio") -# check is truthy + { [ "$in" != "null" ] && echo "CFLAGS += -DGWION_DEFAULT_NIN=$in" [ "$out" != "null" ] && echo "CFLAGS += -DGWION_DEFAULT_NOUT=$out" [ "$samplerate" != "null" ] && echo "CFLAGS += -DGWION_DEFAULT_SAMPLERATE=$samplerate" } >> embed/embed.mk +args=$(jq -rc '.args' <<< "$json") +[ "$args" != "null" ] && { + count=0 + echo "CFLAGS += -DGWION_CONFIG_ARGS" >> embed/embed.mk + echo "static const char *config_argv[] = {" + jq -rc '.[]' <<< "$args" | + while read -r arg + do + echo " \"$arg\", " + done + echo "};" + count=$((count+1)) + echo "static const int config_argc = $count;" +cat << EOF +ANN const char** config_args(int *argc, char **const argv) { + const int nargs = config_argc + *argc; + const char ** args = malloc(nargs * SZ_INT); + for(int i = 0; i < config_argc; i++) { + args[i] = config_argv[i]; + } + for(int i = 0; i < *argc; i++) { + puts(argv[i]); + args[i + config_argc] = argv[i]; + } + *argc = nargs; + return args; +} +EOF +} >> embed/embed.c + +[ "$libraries" != "null" ] || [ "$scripts" != "null" ] && { + echo "CFLAGS += -DGWION_EMBED" +} >> embed/embed.mk + +cflags=$(jq -rc '.cflags' <<< "$json") +[ "$cflags" != "null" ] && { + jq -rc '.[]' <<< "$cflags" | + while read -r cflag + do + echo "CFLAGS += $cflag " + done +} >> embed/embed.mk +ldflags=$(jq -rc '.ldflags' <<< "$json") +[ "$ldflags" != "null" ] && { + jq -rc '.[]' <<< "$ldflags" | + while read -r ldflag + do + echo "LDFLAGS += $ldflag " + done +} >> embed/embed.mk diff --git a/src/main.c b/src/main.c index 9959c8c0..b2d1be35 100644 --- a/src/main.c +++ b/src/main.c @@ -43,20 +43,31 @@ int main(int argc, char **argv) { #else -#ifdef GWION_EMBED_GW -void gwion_embed(const Gwion); +#ifdef GWION_CONFIG_ARGS +ANN char **config_args(int *, char **const); +#endif +#ifdef GWION_EMBED +ANN void gwion_embed(const Gwion); #endif int main(int argc, char **argv) { +#ifndef GWION_CONFIG_ARGS CliArg arg = {.arg = {.argc = argc, .argv = argv}, .loop = false}; +#else + char **config_argv = config_args(&argc, argv); + CliArg arg = {.arg = {.argc = argc, .argv = config_argv}, .loop = false}; +#endif signal(SIGINT, sig); signal(SIGTERM, sig); const m_bool ini = gwion_ini(&gwion, &arg); -#ifdef GWION_EMBED_GW +#ifdef GWION_EMBED gwion_embed(&gwion); #endif arg_compile(&gwion, &arg); arg_release(&arg); +#ifdef GWION_CONFIG_ARGS + free(config_argv); +#endif if (ini > 0) gwion_run(&gwion); gwion_end(&gwion); gwion.vm = NULL;