diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c0060cc --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +build +gebs diff --git a/example/.gitignore b/example/.gitignore deleted file mode 100644 index f8a94ff..0000000 --- a/example/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -gebs -a.out -main diff --git a/example/main.c b/example/main.c deleted file mode 100644 index 8cefa26..0000000 --- a/example/main.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -int main(void) -{ - printf("Hello world\n"); - return 0; -} diff --git a/example/self_rebuild.c b/example/self_rebuild.c new file mode 100644 index 0000000..af31a30 --- /dev/null +++ b/example/self_rebuild.c @@ -0,0 +1,11 @@ +#include +#define GEBS_IMPLEMENTATION +#include "../gebs.h" + +int main(int argc, char ** argv) +{ + gebs_rebuild_self(argc, argv, "cc", "-o", "self_rebuild", __FILE__); + + printf("Hello world\n"); + return 0; +} diff --git a/example/gebs.c b/gebs.c similarity index 50% rename from example/gebs.c rename to gebs.c index ba944d9..509859f 100644 --- a/example/gebs.c +++ b/gebs.c @@ -1,13 +1,16 @@ #define GEBS_IMPLEMENTATION -#include "../gebs.h" +#include "gebs.h" int main(int argc, char ** argv) { gebs_rebuild_self(argc, argv, "cc", "-o", "gebs", __FILE__); - if (GEBS_CMD("gcc", "-o", "main", "main.c") != 0) { - return 1; + if (!gebs_exists("build")) { + gebs_mkdir("build"); } - + + if (GEBS_CMD("gcc", "-o", "build/self_rebuild", "example/self_rebuild.c") != 0) + return 1; + return 0; } diff --git a/gebs.h b/gebs.h index a70f9a0..82c8a7d 100644 --- a/gebs.h +++ b/gebs.h @@ -164,6 +164,8 @@ typedef struct { bool gebs_rename(const char *a, const char *b); bool gebs_remove(const char *p); +bool gebs_mkdir(const char *p); +bool gebs_exists(const char *p); // ---------------------------------------------------------------------------- // Commands @@ -216,6 +218,10 @@ void gebs_rebuild_self1_alloc(Gebs_Allocator *alloc, int argc, char ** argv, int gebs_cmd_run_sync_alloc(Gebs_Allocator *alloc, Gebs_Cmd *cmd) { + Gebs_String_Builder sb = {0}; + gebs_nsl_join_alloc(alloc, cmd, &sb, " "); + GEBS_LOGI("cmd `%s`\n", sb.items); + #if GEBS_PLATFORM == GEBS_PLATFORM_POSIX // Clone the list Gebs_Cmd new_cmd = {0}; @@ -287,6 +293,25 @@ void *gebs_default_allocator_realloc(void *memory, size_t prev_size, size_t new_ // Filesystem operations // ---------------------------------------------------------------------------- +bool gebs_mkdir(const char *p) +{ +#if GEBS_PLATFORM == GEBS_PLATFORM_POSIX + return mkdir(p, 0777) == 0; +#else +# error "gebs_mkdir unknown platform" +#endif +} + +bool gebs_exists(const char *p) +{ +#if GEBS_PLATFORM == GEBS_PLATFORM_POSIX + struct stat st; + return stat(p, &st) == 0; +#else +# error "gebs_exists unknown platform" +#endif +} + bool gebs_rename(const char *a, const char *b) { GEBS_LOGO("rename %s -> %s\n", a, b);