Add GEBS_SHIFT() macro, pass commandline arguments to self after rebuild, add build dep on gebs.h

This commit is contained in:
kamkow1
2025-05-20 23:21:09 +02:00
parent 206b1c4f0a
commit 11e3ee039a

17
gebs.h
View File

@ -25,6 +25,7 @@
#include <stdlib.h>
#include <inttypes.h>
#include <stdarg.h>
#include <string.h>
#if GEBS_PLATFORM == GEBS_PLATFORM_POSIX
# include <unistd.h>
@ -37,6 +38,16 @@
#define discard __attribute__((unused))
// ----------------------------------------------------------------------------
// Parsing commandline arguments
// ----------------------------------------------------------------------------
#define GEBS_SHIFT_CHECK(argc) \
(*(argc) <= 0 ? (GEBS_LOGE("Expected more arguments\n"), exit(EXIT_FAILURE)) : (0))
#define GEBS_SHIFT(argc, argv) \
(GEBS_SHIFT_CHECK((argc)), --(*(argc)), *(*(argv))++)
// ----------------------------------------------------------------------------
// Defer macro
// ----------------------------------------------------------------------------
@ -553,7 +564,7 @@ void gebs_rebuild_self1_alloc(Gebs_Allocator *alloc, int argc, char ** argv,
int cmd_argc, char **cmd_argv, char *source)
{
const char *binary_path = argv[0];
if (!gebs_needs_rebuild(binary_path, source)) {
if (!gebs_needs_rebuild_many(binary_path, source, __FILE__)) {
return;
}
@ -576,6 +587,10 @@ void gebs_rebuild_self1_alloc(Gebs_Allocator *alloc, int argc, char ** argv,
cmd.count = 0;
gebs_cmd_append_alloc(alloc, &cmd, (char *)binary_path);
for (size_t i = 1; i < argc; i++) {
gebs_cmd_append_alloc(alloc, &cmd, argv[i]);
}
code = gebs_cmd_run_alloc(alloc, &cmd);
if (code != EXIT_SUCCESS) {
exit(EXIT_FAILURE);