with_config:
@bash scripts/embed.bash gwion.config.json
- @touch src/main.c src/arg.c
+ @touch src/main.c
@${MAKE} USE_CONFIG=1
- @touch src/main.c src/arg.c
+ @touch src/main.c
almost_gwion: ${almost_obj} ${ALMOST_LIBS}
struct Vector_ lib;
struct Vector_ config;
struct SoundInfo_ *si;
+ char** (*config_args)(int*, char**);
+ void (*embed_libs)(Gwion);
+ void (*embed_scripts)(Gwion);
bool loop;
bool quit;
+ bool urc;
+ bool ulib;
+ bool uargs;
enum COLOR color;
} CliArg;
echo "$1" >> embed/embed.mk
}
+cflag() {
+ config "CFLAGS += $1"
+}
+
has_func() {
nm "$2" | grep "${1}_${3}" > /dev/null
}
return 1
}
+lenght() {
+ jq -rc "length" <<< "$1"
+}
array_is_ok() {
not_null "$1" || return 1
length=$(jq -rc "length" <<< "$1")
names=$(jq -c '.names' <<< "$lib")
cflags=$(jq -c '.cflags' <<< "$lib")
if [ "$cflags" != "null" ]
- then config "CFLAGS += $cflags"
+ then cflag "$cflags"
fi
config "LDFLAGS += $path"
if [ "$names" != "null" ]
}
scripts=$(jq -r '.scripts' <<< "$json")
+
handle_scripts() {
- array_is_ok "$scripts" || return
script_helper
i=0
jq -r '.[]' <<< "$scripts" |
done
}
embed() {
- array_is_ok "$scripts" || array_is_ok "$libraries" || return
- echo "ANN void gwion_embed(const Gwion gwion) {" >> embed/embed_foot
- handle_libs
- handle_scripts >> embed/embed_foot
- echo "}" >> embed/embed_foot
+ array_is_ok "$libraries" && {
+ echo "ANN void gwion_embed_libs(const Gwion gwion) {" >> embed/embed_foot
+ handle_libs
+ echo "}" >> embed/embed_foot
+ cflag "-DGWION_EMBED_LIBS"
+ }
+ array_is_ok "$scripts" && {
+ echo "ANN void gwion_embed_scripts(const Gwion gwion) {" >> embed/embed_foot
+ handle_scripts >> embed/embed_foot
+ echo "}" >> embed/embed_foot
+ cflag "-DGWION_EMBED_SCRIPTS"
+ }
}
embed
touch embed/embed_body
out=$(jq -rc '.out' <<< "$audio")
samplerate=$(jq -rc '.samplerate' <<< "$audio")
-not_null "$in" && config "CFLAGS += -DGWION_DEFAULT_NIN=$in"
-not_null "$out" && config "CFLAGS += -DGWION_DEFAULT_NOUT=$out"
-not_null "$samplerate" && config "CFLAGS += -DGWION_DEFAULT_SAMPLERATE=$samplerate"
+not_null "$in" && cflag "-DGWION_DEFAULT_NIN=$in"
+not_null "$out" && cflag "-DGWION_DEFAULT_NOUT=$out"
+not_null "$samplerate" && cflag "-DGWION_DEFAULT_SAMPLERATE=$samplerate"
args=$(jq -rc '.args' <<< "$json")
{
- count=0
- config "CFLAGS += -DGWION_CONFIG_ARGS"
+ cflag "-DGWION_CONFIG_ARGS"
echo "static const char *config_argv[] = {"
array_is_ok "$args" && {
jq -rc '.[]' <<< "$args" |
while read -r arg
do echo " \"$arg\", "
done
- count=$((count+1))
}
echo "};"
- echo "static const int config_argc = $count;"
+ echo "static const int config_argc = $(lenght "$args");"
cat << EOF
-ANN const char** config_args(int *argc, char **const argv) {
-#ifdef GWION_NO_UARGS
- *argc = 0;
-#endif
+ANN const char** gwion_config_args(int *argc, char **const argv) {
const int nargs = config_argc + *argc;
const char ** args = malloc(nargs * SZ_INT);
+ args[0] = *argv;
for(int i = 0; i < config_argc; i++) {
- args[i] = config_argv[i];
+ args[i + 1] = config_argv[i];
}
- for(int i = 0; i < *argc; i++) {
+ for(int i = 1; i < *argc; i++) {
args[i + config_argc] = argv[i];
}
*argc = nargs;
EOF
} >> embed/embed.c
-not_null "$libraries" || not_null "$scripts" &&
- config "CFLAGS += -DGWION_EMBED"
-
cflags=$(jq -rc '.cflags' <<< "$json")
array_is_ok "$cflags" && {
jq -rc '.[]' <<< "$cflags" |
while read -r cflag
- do config "CFLAGS += $cflag "
+ do cflag "$cflag"
done
}
ldflags=$(jq -rc '.ldflags' <<< "$json")
}
rc=$(jq -rc '.urc' <<< "$json")
-[ "$rc" = "false" ] && config "CFLAGS += -DGWION_NO_URC"
+[ "$rc" = "false" ] && cflag "-DGWION_HAS_URC=false"
ulib=$(jq -rc '.ulib' <<< "$json")
-[ "$ulib" = "false" ] && config "CFLAGS += -DGWION_NO_ULIB"
+[ "$ulib" = "false" ] && cflag "-DGWION_HAS_ULIB=false"
uargs=$(jq -rc '.uargs' <<< "$json")
-[ "$uargs" = "false" ] && config "CFLAGS += -DGWION_NO_UARGS"
+[ "$uargs" = "false" ] && cflag "-DGWION_HAS_UARGS=false"
+name=$(jq -rc '.name' <<< "$json")
+not_null "$name" && config "PRG := $name"
:
#include "soundinfo.h"
#include "vm.h"
#include "gwion.h"
-#include "arg.h"
#include "pass.h"
#include "compile.h"
#include "cmdapp.h"
}
}
-#ifndef GWION_NO_ULIB
ANN static m_str plug_dir(void) {
const m_str home = getenv("HOME");
const size_t sz = strlen(home);
strcpy(plug_dir + sz, pdir);
return plug_dir;
}
-#endif
enum arg_type {
ARG_FILE,
vector_init(&arg->add);
vector_init(&arg->lib);
vector_init(&arg->config);
-#ifndef GWION_NO_ULIB
- vector_add(&arg->lib, (vtype)plug_dir());
-#endif
+ if(arg->ulib)vector_add(&arg->lib, (vtype)plug_dir());
arg->color = COLOR_AUTO;
}
return GW_OK;
}
-#ifndef GWION_NO_URC
ANN static void config_default(struct ArgInternal *arg) {
char *home = getenv("HOME");
char c[strlen(home) + strlen(GWIONRC) + 2];
sprintf(c, "%s/%s", home, GWIONRC);
config_parse(arg, c);
}
-#endif
ANN m_bool arg_parse(const Gwion gwion, CliArg *a) {
+ if(!a->uargs) a->arg.argc = 1;
+ if(a->config_args) a->arg.argv = a->config_args(&a->arg.argc, a->arg.argv);
struct ArgInternal arg = {.gwion = gwion, .arg = a};
arg_init(a);
#ifdef __FUZZING
return;
#endif
-#ifndef GWION_NO_URC
- config_default(&arg);
-#endif
+ if(a->urc) config_default(&arg);
return _arg_parse(&arg);
}
ANN static m_bool gwion_ok(const Gwion gwion, CliArg *arg) {
CHECK_BB(plug_ini(gwion, &arg->lib));
shreduler_set_loop(gwion->vm->shreduler, arg->loop);
+ if(arg->embed_libs) arg->embed_libs(gwion);
if (gwion_audio(gwion) > 0) {
CHECK_BB(plug_run(gwion, &arg->mod));
if (type_engine_init(gwion)) {
vector_add(&gwion->data->plugs->vec, (m_uint)gwion->env->global_nspc);
gwion->vm->cleaner_shred = gwion_cleaner(gwion);
gwion->emit->locale = gwion_locale(gwion);
+ if(arg->embed_scripts) arg->embed_scripts(gwion);
+ arg_compile(gwion, arg);
return GW_OK;
}
}
#include "gwion_util.h"
#include "gwion_ast.h"
#include "gwion_env.h"
-#include "plug.h"
#include "gwiondata.h"
#include "vm.h"
#include "instr.h"
#include "emit.h"
#include "gwion.h"
+#include "plug.h"
#include "specialid.h"
#include "pass.h"
#else
#ifdef GWION_CONFIG_ARGS
-ANN char **config_args(int *, char **const);
+ANN char **gwion_config_args(int *, char **const);
+#else
+#define gwion_config_args NULL
#endif
-#ifdef GWION_EMBED
-ANN void gwion_embed(const Gwion);
+
+#ifdef GWION_EMBED_LIBS
+ANN void gwion_embed_libs(Gwion);
+#else
+#define gwion_embed_libs NULL
#endif
-int main(int argc, char **argv) {
-#ifndef GWION_CONFIG_ARGS
- CliArg arg = {.arg = {.argc = argc, .argv = argv} };
+#ifdef GWION_EMBED_SCRIPTS
+ANN void gwion_embed_scripts(Gwion);
#else
- char **config_argv = config_args(&argc, argv);
- CliArg arg = {.arg = {.argc = argc, .argv = config_argv} };
+#define gwion_embed_scripts NULL
+#endif
+
+#ifndef GWION_HAS_URC
+#define GWION_HAS_URC true
+#endif
+
+#ifndef GWION_HAS_ULIB
+#define GWION_HAS_ULIB true
#endif
+
+#ifndef GWION_HAS_UARGS
+#define GWION_HAS_UARGS true
+#endif
+
+int main(int argc, char **argv) {
signal(SIGINT, sig);
signal(SIGTERM, sig);
- const m_bool ini = gwion_ini(&gwion, &arg);
-#ifdef GWION_EMBED
- gwion_embed(&gwion);
-#endif
- if(ini > 0) arg_compile(&gwion, &arg);
+ CliArg arg = {
+ .arg = {.argc = argc, .argv = argv},
+ .urc = GWION_HAS_URC,
+ .ulib = GWION_HAS_ULIB,
+ .uargs = GWION_HAS_UARGS,
+ .config_args = gwion_config_args,
+ .embed_libs = gwion_embed_libs,
+ .embed_scripts = gwion_embed_scripts,
+ };
+ const m_bool ini = gwion_ini(&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;
exit(EXIT_SUCCESS);
}
-
#endif
ANN gwdriver_t driver_ini(const struct Gwion_ *gwion, struct SoundInfo_ *si) {
const Map map = &gwion->data->plugs->map;
- m_str dname = si->arg;
+ m_str dname = strdup(si->arg);
m_str opt = strchr(dname, '=');
- const char c = opt ? *opt : '\0';
if (opt) *opt = '\0';
for (m_uint i = 0; i < map_size(map); ++i) {
const m_str name = (m_str)VKEY(map, i);
if (!strcmp(name, dname)) {
const Plug plug = (Plug)VVAL(map, i);
const gwdriver_t drv = plug->driver;
- if (opt) *opt = c;
+ free(dname);
return drv;
}
}
- if (opt) *opt = c;
gw_err("can't find driver '%s'\n", dname);
+ free(dname);
return NULL;
}