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/"$//')
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
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
#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;