]> Trent Huber's Code - xpmview.git/commitdiff
Bug fix in main.c, src/build.c bootstraps itself
authorTrent Huber <trentmhuber@gmail.com>
Wed, 6 Aug 2025 18:43:00 +0000 (14:43 -0400)
committerTrent Huber <trentmhuber@gmail.com>
Wed, 6 Aug 2025 18:43:00 +0000 (14:43 -0400)
external/build.c
external/cbs
src/.gitignore
src/build.c
src/buildfont.c [deleted file]
src/main.c

index 15141c5f0ca020daa643faa49bf0f9634550bef9..d0eec79c9c62f541b5edb656d45c2681e1bb48dc 100644 (file)
 #define RLSRC "raylib/src/"
 
 void buildcbs(void) {
-   char **c, **l;
-
-   c = cflags;
-   l = lflags;
-
    cflags = CLPIC;
    compile("cbs/cbs");
 
-   lflags = NONE;
    load(LIBTYPE, "cbs/cbs", LIST("cbs/cbs"));
-
-   cflags = c;
-   lflags = l;
 }
 
 void buildraylib(void) {
index 4711a83fafa0282fadeaba701a25539b3e73d073..5499560c6a497c72aa1bd5c5dd770795d789d4d5 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 4711a83fafa0282fadeaba701a25539b3e73d073
+Subproject commit 5499560c6a497c72aa1bd5c5dd770795d789d4d5
index d605eed07d81455c6a9be17e5a0dd0d1dbab540e..96ac906d3eaf56ff638479ff19dfd48e464cf5e6 100644 (file)
@@ -1,3 +1,2 @@
 colors.c
 font.c
-buildfont
index b7d3afdf42cf39b54efd1dcfcb863fecb487d800..59e3b38e3d832cc467674da24ef2b070a42e8b2d 100644 (file)
@@ -4,7 +4,14 @@
 #include "../external/cbs/cbs.c"
 #include "../external/cbsfile.c"
 
-#define CLRAYLIB LIST("-I../external/raylib/src/")
+#ifdef FONT
+#include <err.h>
+#include <stdlib.h>
+
+#include "raylib.h"
+#endif
+
+#define CFRAYLIB "-I../external/raylib/src/"
 #ifdef DYNAMICLIBS
 #define LIBEXT DYEXT
 #define LLRAYLIB NONE
@@ -16,6 +23,7 @@
 #define RLLIB "../external/raylib/raylib" LIBEXT
 #define CBSLIB "../external/cbs/cbs" LIBEXT
 
+#ifdef FONT
 static void buildcolors(void) {
    int quit, txtfd, codefd;
    char *txt, *code, *p;
@@ -88,28 +96,34 @@ closetxt:
 }
 
 static void buildfont(void) {
-   char **c, **l;
-   pid_t cpid;
+   char *ttf, *code;
+   Font font;
 
-   c = cflags;
-   l = lflags;
+   ttf = "../assets/font.ttf";
+   code = "font.c";
 
-   cflags = CLRAYLIB;
-   compile("buildfont");
+   SetTraceLogLevel(LOG_WARNING);
+   InitWindow(0, 0, "");
 
-   lflags = LLRAYLIB;
-   load('x', "buildfont", LIST("buildfont", RLLIB));
-
-   if ((cpid = fork()) == -1) err(EXIT_FAILURE, "Unable to fork");
-   else if (cpid == 0) run("buildfont", LIST("buildfont"), "run", "buildfont");
-   await(cpid, "run", "buildfont");
+   if (!ExportFontAsCode(font = LoadFontEx(ttf, 48, NULL, 95), code))
+       errx(EXIT_FAILURE, "Unable to generate `%s' from `%s'", code, ttf);
 
-   cflags = c;
-   lflags = l;
+   UnloadFont(font);
 }
+#endif
 
 int main(void) {
-   build("./");
+#ifndef FONT
+   cflags = LIST("-DFONT", CFRAYLIB);
+   compile("build");
+
+   lflags = LLRAYLIB;
+   load('x', "build", LIST("build", RLLIB));
+
+   run("!build", LIST("build"), "run", "build");
+#else
+   compile("build");
+   load('x', "build", LIST("build"));
 
    buildcolors();
    buildfont();
@@ -117,14 +131,15 @@ int main(void) {
    buildfiles((struct cbsfile []){{"../bin/simplexpm", LLRAYLIB, 'x'},
 
                                   {"colors", NONE},
-                                  {"main", CLRAYLIB},
+                                  {"main", LIST(CFRAYLIB)},
                                   {"options", NONE},
-                                  {"xpm", CLRAYLIB},
+                                  {"xpm", LIST(CFRAYLIB)},
 
                                   {CBSLIB},
                                   {RLLIB},
 
                                   {NULL}});
+#endif
 
    return EXIT_SUCCESS;
 }
diff --git a/src/buildfont.c b/src/buildfont.c
deleted file mode 100644 (file)
index a123e51..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-#include <err.h>
-#include <stdlib.h>
-
-#include "raylib.h"
-
-int main(void) {
-   char *ttf, *code;
-   Font font;
-
-   ttf = "../assets/font.ttf";
-   code = "font.c";
-
-   SetTraceLogLevel(LOG_WARNING);
-   InitWindow(0, 0, "");
-
-   if (!ExportFontAsCode(font = LoadFontEx(ttf, 48, NULL, 95), code))
-       errx(EXIT_FAILURE, "Unable to generate `%s' from `%s'", code, ttf);
-
-   UnloadFont(font);
-
-   return EXIT_SUCCESS;
-}
index 17173e77c9129d126c02a74ce4922805382983ef..e649fb78a8a1388cedae3b855ebb87516b05f153 100644 (file)
@@ -20,7 +20,7 @@ static void handleinput(void) {
 
    if (IsFileDropped()) {
        files = LoadDroppedFiles();
-       if (xpm) RL_FREE(xpm);
+       if (xpm) free(xpm);
        xpm = allocate(FILENAME_MAX);
        strcpy(xpm, files.paths[0]);
        UnloadDroppedFiles(files);
@@ -104,8 +104,7 @@ int main(int argc, char **argv) {
    }
 
    if (xpm) free(xpm);
-
-   UnloadTexture(*texture);
+   if (texture) UnloadTexture(*texture);
    CloseWindow();
 
    return EXIT_SUCCESS;