Restructure project, add gebs_exists() and gebs_mkdir()
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
build
|
||||||
|
gebs
|
3
example/.gitignore
vendored
3
example/.gitignore
vendored
@ -1,3 +0,0 @@
|
|||||||
gebs
|
|
||||||
a.out
|
|
||||||
main
|
|
@ -1,7 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
printf("Hello world\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
11
example/self_rebuild.c
Normal file
11
example/self_rebuild.c
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#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;
|
||||||
|
}
|
@ -1,13 +1,16 @@
|
|||||||
#define GEBS_IMPLEMENTATION
|
#define GEBS_IMPLEMENTATION
|
||||||
#include "../gebs.h"
|
#include "gebs.h"
|
||||||
|
|
||||||
int main(int argc, char ** argv)
|
int main(int argc, char ** argv)
|
||||||
{
|
{
|
||||||
gebs_rebuild_self(argc, argv, "cc", "-o", "gebs", __FILE__);
|
gebs_rebuild_self(argc, argv, "cc", "-o", "gebs", __FILE__);
|
||||||
|
|
||||||
if (GEBS_CMD("gcc", "-o", "main", "main.c") != 0) {
|
if (!gebs_exists("build")) {
|
||||||
return 1;
|
gebs_mkdir("build");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (GEBS_CMD("gcc", "-o", "build/self_rebuild", "example/self_rebuild.c") != 0)
|
||||||
|
return 1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
25
gebs.h
25
gebs.h
@ -164,6 +164,8 @@ typedef struct {
|
|||||||
|
|
||||||
bool gebs_rename(const char *a, const char *b);
|
bool gebs_rename(const char *a, const char *b);
|
||||||
bool gebs_remove(const char *p);
|
bool gebs_remove(const char *p);
|
||||||
|
bool gebs_mkdir(const char *p);
|
||||||
|
bool gebs_exists(const char *p);
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// Commands
|
// 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)
|
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
|
#if GEBS_PLATFORM == GEBS_PLATFORM_POSIX
|
||||||
// Clone the list
|
// Clone the list
|
||||||
Gebs_Cmd new_cmd = {0};
|
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
|
// 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)
|
bool gebs_rename(const char *a, const char *b)
|
||||||
{
|
{
|
||||||
GEBS_LOGO("rename %s -> %s\n", a, b);
|
GEBS_LOGO("rename %s -> %s\n", a, b);
|
||||||
|
Reference in New Issue
Block a user