GEBS_CMD() convinience macro

This commit is contained in:
kamkow1
2025-05-19 11:44:52 +02:00
parent 6cbfd5ca91
commit 0087c523b5
3 changed files with 16 additions and 9 deletions

1
example/.gitignore vendored
View File

@ -1,2 +1,3 @@
gebs gebs
a.out a.out
main

View File

@ -5,14 +5,9 @@ int main(int argc, char ** argv)
{ {
gebs_rebuild_self(argc, argv, "cc", "-o", "gebs", __FILE__); gebs_rebuild_self(argc, argv, "cc", "-o", "gebs", __FILE__);
Gebs_Cmd cmd = {0}; if (GEBS_CMD("gcc", "-o", "main", "main.c") != 0) {
gebs_cmd_append(&cmd, "cc"); return 1;
gebs_cmd_append(&cmd, "main.c"); }
int ec = gebs_cmd_run(&cmd);
printf("%d\n", ec);
gebs_cmd_free(&cmd);
return 0; return 0;
} }

11
gebs.h
View File

@ -182,6 +182,17 @@ typedef Gebs_NString_List Gebs_Cmd;
int gebs_cmd_run_sync_alloc(Gebs_Allocator *alloc, Gebs_Cmd *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 // The build system
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------