From eb0aff17e824573c62e4cbac20e8cc2b5fec9a87 Mon Sep 17 00:00:00 2001 From: Trent Huber Date: Tue, 11 Feb 2025 01:55:57 -0500 Subject: [PATCH] Upgrading to new build system --- .gitignore | 3 +-- .gitmodules | 9 +++---- README.md | 4 +-- bin/.gitignore | 2 ++ build.c | 41 +++++++++++++++++++++++++++++ cbs.c | 67 ------------------------------------------------ external/build.c | 30 ++++++++++++++++++++++ external/cbs | 1 + external/cbs.c | 41 ----------------------------- external/cbs.d | 1 - lib/.gitignore | 2 ++ 11 files changed, 83 insertions(+), 118 deletions(-) create mode 100644 bin/.gitignore create mode 100644 build.c delete mode 100644 cbs.c create mode 100644 external/build.c create mode 160000 external/cbs delete mode 100644 external/cbs.c delete mode 160000 external/cbs.d create mode 100644 lib/.gitignore diff --git a/.gitignore b/.gitignore index 5106540..fd2e058 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ *.DS_Store *swp -*cbs -bin/ +*build *.o diff --git a/.gitmodules b/.gitmodules index a1b1b25..722b341 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/README.md b/README.md index d789ab1..17c52d9 100644 --- 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 index 0000000..d6b7ef3 --- /dev/null +++ b/bin/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/build.c b/build.c new file mode 100644 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 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 index 0000000..41c9f29 --- /dev/null +++ b/external/build.c @@ -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 index 0000000..5bcdae8 --- /dev/null +++ b/external/cbs @@ -0,0 +1 @@ +Subproject commit 5bcdae85d8e7f4634b6f06c1f407fb8f1f39b684 diff --git a/external/cbs.c b/external/cbs.c deleted file mode 100644 index 70c49cc..0000000 --- a/external/cbs.c +++ /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 index e7e6371..0000000 --- a/external/cbs.d +++ /dev/null @@ -1 +0,0 @@ -Subproject commit e7e6371478323f76c0ac8a7c5582973377f67ced diff --git a/lib/.gitignore b/lib/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/lib/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore -- 2.51.0