diff --git a/example/.gitignore b/example/.gitignore index d174a82..f8a94ff 100644 --- a/example/.gitignore +++ b/example/.gitignore @@ -1,2 +1,3 @@ gebs a.out +main diff --git a/example/gebs.c b/example/gebs.c index 963ad35..ba944d9 100644 --- a/example/gebs.c +++ b/example/gebs.c @@ -5,14 +5,9 @@ int main(int argc, char ** argv) { gebs_rebuild_self(argc, argv, "cc", "-o", "gebs", __FILE__); - Gebs_Cmd cmd = {0}; - gebs_cmd_append(&cmd, "cc"); - gebs_cmd_append(&cmd, "main.c"); - - int ec = gebs_cmd_run(&cmd); - printf("%d\n", ec); - - gebs_cmd_free(&cmd); - + if (GEBS_CMD("gcc", "-o", "main", "main.c") != 0) { + return 1; + } + return 0; } diff --git a/gebs.h b/gebs.h index ce62f7a..a70f9a0 100644 --- a/gebs.h +++ b/gebs.h @@ -182,6 +182,17 @@ typedef Gebs_NString_List Gebs_Cmd; int gebs_cmd_run_sync_alloc(Gebs_Allocator *alloc, Gebs_Cmd *cmd); +#define GEBS_CMD(...) \ +({ \ + char *__args[] = { __VA_ARGS__ }; \ + Gebs_Cmd __cmd = {0}; \ + defer { gebs_cmd_free(&__cmd); } \ + for (size_t __i = 0; __i < sizeof(__args)/sizeof(__args[0]); __i++) { \ + gebs_cmd_append(&__cmd, __args[__i]); \ + } \ + gebs_cmd_run(&__cmd); \ +}) + // ---------------------------------------------------------------------------- // The build system // ----------------------------------------------------------------------------