]> Trent Huber's Code - xpmview.git/commitdiff
Upgrading to new build system
authorTrent Huber <trentmhuber@gmail.com>
Tue, 11 Feb 2025 06:55:57 +0000 (01:55 -0500)
committerTrent Huber <trentmhuber@gmail.com>
Tue, 11 Feb 2025 06:55:57 +0000 (01:55 -0500)
.gitignore
.gitmodules
README.md
bin/.gitignore [new file with mode: 0644]
build.c [new file with mode: 0644]
cbs.c [deleted file]
external/build.c [new file with mode: 0644]
external/cbs [new submodule]
external/cbs.c [deleted file]
external/cbs.d [deleted submodule]
lib/.gitignore [new file with mode: 0644]

index 5106540120c6514c96e8ff376750250dabd62c73..fd2e05803da545ce56e3003757d97d23144d43a7 100644 (file)
@@ -1,5 +1,4 @@
 *.DS_Store
 *swp
-*cbs
-bin/
+*build
 *.o
index a1b1b252e3cf387a6362ac07b59cab39a7048655..722b341d64ef87b6381b15b0d975b7bf51695e8f 100644 (file)
@@ -1,8 +1,7 @@
-[submodule "external/cbs.d"]
-   path = external/cbs.d
-   url = git@github.com:trenthuber/cbs.git
-   branch = main
 [submodule "external/raylib"]
    path = external/raylib
-   url = git@github.com:raysan5/raylib.git
+   url = https://github.com/raysan5/raylib
    branch = main
+[submodule "external/cbs"]
+   path = external/cbs
+   url = https://github.com/trenthuber/cbs
index d789ab19b2ed5dbfd7dabcba38bc6e6e422a3be4..17c52d9a0b0d69f72e53eb3166de8be0533ac016 100644 (file)
--- a/README.md
+++ b/README.md
@@ -10,7 +10,7 @@ To build the program, all you need is `git` (which you obviously have if you're
 $ git clone https://github.com/trenthuber/simplexpm.git
 $ cd simplexpm
 $ git submodule update --init
-$ cc -o cbs cbs.c && ./cbs
+$ cc -o build build.c && ./build
 ```
 
 This will update all submodules (I use [Raylib](https://www.raylib.com) and my own C build system [cbs](https://github.com/trenthuber/cbs.git)) and then build and run the program.
@@ -21,7 +21,7 @@ To run the program after it's been built, just run the executable found in the `
 
 Simply drag and drop XPM files into the window to view them. The window can be resized and the image will scale accordingly.
 
-To reload the current image press R. To save the current image as a PNG, press S. PNG files are saved to the same folder as the XPM file.
+To reload the current image press `R`. To save the current image as a PNG, press `S`. PNG files are saved to the same folder as the XPM file.
 
 ## Unimplemented features
 - Not tested for Linux (built on macOS)
diff --git a/bin/.gitignore b/bin/.gitignore
new file mode 100644 (file)
index 0000000..d6b7ef3
--- /dev/null
@@ -0,0 +1,2 @@
+*
+!.gitignore
diff --git a/build.c b/build.c
new file mode 100644 (file)
index 0000000..29456b6
--- /dev/null
+++ b/build.c
@@ -0,0 +1,41 @@
+#define SRCPATH "src/"
+#define FONTPATH "fonts/"
+
+#define CFLAGS "-Wall", "-Wextra", "-Wpedantic", "-Iexternal/raylib/src/", "-Ifonts/"
+#define LDFLAGS "-framework", "CoreVideo", \
+                "-framework", "IOKit", \
+                "-framework", "Cocoa", \
+                "-framework", "GLUT", \
+                "-framework", "OpenGL"
+
+#include "external/cbs/cbs.c"
+
+#define HDRS \
+   SRCPATH "parser", \
+   SRCPATH "tokenizer", \
+   SRCPATH "utils", \
+   SRCPATH "xpm_mode" \
+
+#define SRCS SRCPATH "main", HDRS
+
+#define FONTS FONTPATH "source_code_pro_font"
+
+int main(void) {
+   char **srcs, **fonts;
+   int i;
+
+   build(NULL);
+
+   build("external/");
+
+   srcs = CARRAY(SRCS);
+   fonts = CARRAY(FONTS);
+
+   for (i = 0; srcs[i]; ++i) CC(srcs[i], HDRS);
+   for (i = 0; fonts[i]; ++i) CC(fonts[i], fonts[i]);
+
+   // LD('x', "bin/simplexpm", SRCS, FONTS);
+   LD('x', "bin/simplexpm", "lib/libraylib.a", SRCS, FONTS);
+
+   return 0;
+}
diff --git a/cbs.c b/cbs.c
deleted file mode 100644 (file)
index 9e8cb63..0000000
--- a/cbs.c
+++ /dev/null
@@ -1,67 +0,0 @@
-#define CBS_IMPLEMENTATION
-#define CBS_LIBRARY_PATH "./external/cbs.d/cbs.h"
-#include CBS_LIBRARY_PATH
-
-// TODO: Support for Linux
-
-#define CC "cc"
-#define CFLAGS "-Wall", "-Wextra", "-Wpedantic", "-I./external/raylib/src", "-I./fonts"
-#ifdef __MACH__
-#define LDFLAGS "-L./external/raylib/lib", "-lraylib", \
-                "-framework", "CoreVideo", \
-                "-framework", "IOKit", \
-                "-framework", "Cocoa", \
-                "-framework", "GLUT", \
-                "-framework", "OpenGL"
-#else
-#define LDFLAGS "-L./external/raylib/lib", "-lraylib"
-#endif // __MACH__
-
-int main(int argc, char **argv) {
-   cbs_rebuild_self(argv);
-   cbs_shift_args(&argc, &argv);
-
-   const char *subcommand = cbs_shift_args(&argc, &argv);
-   if (subcommand && cbs_string_eq(subcommand, "clean")) {
-       Cbs_Cmd cmd = {0};
-       cbs_cmd_build(&cmd, "rm", "-rf", "./bin");
-       Cbs_File_Paths obj_files = {0};
-       cbs_file_paths_build_file_ext(&obj_files, "./src", ".o");
-       cbs_cmd_build_file_paths(&cmd, obj_files);
-       cbs_cmd_run(&cmd);
-       return 0;
-   }
-
-   cbs_subbuild("./external");
-
-   // Generate font data as a C style array
-   const char *font_src = "./fonts/source_code_pro_font.c",
-              *font_obj = cbs_string_build(cbs_strip_file_ext(font_src), ".o");
-   if (cbs_needs_rebuild(font_obj, font_src))
-       cbs_run(CC, CFLAGS, "-c", "-o", font_obj, font_src);
-
-   cbs_run("mkdir", "-p", "./bin");
-   Cbs_File_Paths src_files = {0};
-   cbs_file_paths_build_file_ext(&src_files, "./src", ".c");
-   cbs_file_paths_for_each (src_file, src_files) {
-       const char *obj_file = cbs_string_build(cbs_strip_file_ext(src_file), ".o");
-       if (cbs_needs_rebuild(obj_file, src_file, "./src/utils.h"))
-           cbs_run(CC, CFLAGS, "-c", "-o", obj_file, src_file);
-   }
-
-   Cbs_File_Paths obj_files = {0};
-   cbs_file_paths_build_file_ext(&obj_files, "./src", ".o");
-   cbs_file_paths_build_file_ext(&obj_files, "./fonts", ".o");
-   const char *bin_file = "./bin/simplexpm";
-   if (cbs_needs_rebuild_file_paths(bin_file, obj_files)) {
-       Cbs_Cmd cmd = {0};
-       cbs_cmd_build(&cmd, CC, "-o", bin_file);
-       cbs_cmd_build_file_paths(&cmd, obj_files);
-       cbs_cmd_build(&cmd, LDFLAGS);
-       cbs_cmd_run(&cmd);
-   }
-
-   cbs_run(bin_file);
-
-   return 0;
-}
diff --git a/external/build.c b/external/build.c
new file mode 100644 (file)
index 0000000..41c9f29
--- /dev/null
@@ -0,0 +1,30 @@
+#define SRCPATH "raylib/src/"
+
+#define CFLAGS \
+   "-x", "objective-c", \
+   "-DPLATFORM_DESKTOP", \
+   "-I" SRCPATH "external/glfw/include/"
+#define LDFLAGS ""
+
+#include "cbs/cbs.c"
+
+#define SRCS \
+   SRCPATH "raudio", SRCPATH "rcore", \
+   SRCPATH "rglfw", SRCPATH "rmodels", \
+   SRCPATH "rshapes", SRCPATH "rtext", \
+   SRCPATH "rtextures", SRCPATH "utils"
+
+int main(void) {
+   char **srcs;
+   int i;
+
+   build(NULL);
+
+   srcs = CARRAY(SRCS);
+
+   for (i = 0; srcs[i]; ++i) CC(srcs[i]);
+
+   LD('s', "../lib/raylib", SRCS);
+
+   return 0;
+}
diff --git a/external/cbs b/external/cbs
new file mode 160000 (submodule)
index 0000000..5bcdae8
--- /dev/null
@@ -0,0 +1 @@
+Subproject commit 5bcdae85d8e7f4634b6f06c1f407fb8f1f39b684
diff --git a/external/cbs.c b/external/cbs.c
deleted file mode 100644 (file)
index 70c49cc..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-#define CBS_IMPLEMENTATION
-#define CBS_LIBRARY_PATH "./cbs.d/cbs.h"
-#include CBS_LIBRARY_PATH
-
-#define CC "cc"
-
-int main(int argc, char **argv) {
-   cbs_rebuild_self(argv);
-   cbs_shift_args(&argc, &argv);
-
-   const char *raylib_src_dir = "./raylib/src";
-   Cbs_File_Paths raylib_src_files = {0}, raylib_obj_files = {0};
-   cbs_file_paths_build_file_ext(&raylib_src_files, raylib_src_dir, ".c");
-   Cbs_Async_Procs procs = {0};
-   Cbs_Cmd cmd = {0};
-   cbs_file_paths_for_each(src_file, raylib_src_files) {
-       char *obj_file = cbs_string_build(cbs_strip_file_ext(src_file), ".o");
-       cbs_file_paths_build(&raylib_obj_files, obj_file);
-       if (cbs_needs_rebuild(obj_file, src_file)) {
-           cbs_cmd_build(&cmd, CC, "-c");
-           if (cbs_string_eq(src_file, cbs_string_build(raylib_src_dir, "/rglfw.c")))
-               cbs_cmd_build(&cmd, "-x", "objective-c");
-           cbs_cmd_build(&cmd, "-DPLATFORM_DESKTOP",
-                         cbs_string_build("-I", raylib_src_dir,
-                                          "/external/glfw/include"));
-           cbs_cmd_build(&cmd, "-o", obj_file, src_file);
-           cbs_cmd_async_run(&procs, &cmd);
-       }
-   }
-   cbs_async_wait(&procs);
-
-   cbs_run("mkdir", "-p", "./raylib/lib");
-   const char *output_file = "./raylib/lib/libraylib.a";
-   if (cbs_needs_rebuild_file_paths(output_file, raylib_obj_files)) {
-       cbs_cmd_build(&cmd, "ar", "-r", output_file);
-       cbs_cmd_build_file_paths(&cmd, raylib_obj_files);
-       cbs_cmd_run(&cmd);
-   }
-
-   return 0;
-}
diff --git a/external/cbs.d b/external/cbs.d
deleted file mode 160000 (submodule)
index e7e6371..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit e7e6371478323f76c0ac8a7c5582973377f67ced
diff --git a/lib/.gitignore b/lib/.gitignore
new file mode 100644 (file)
index 0000000..d6b7ef3
--- /dev/null
@@ -0,0 +1,2 @@
+*
+!.gitignore