From 3f59e2fa436ef5d7e527fd39e52a050536669db7 Mon Sep 17 00:00:00 2001 From: Trent Huber Date: Thu, 17 Apr 2025 02:59:54 -0400 Subject: [PATCH] Finishing touches --- README.md | 8 ++++---- cbs.c | 3 +-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index e027b35..e35ff3a 100644 --- a/README.md +++ b/README.md @@ -92,9 +92,9 @@ The rest of the arguments are the names of the files you want to link together. In a similar way as compiling, the predefined `lflags` variable can be used to define flags for the linker. -The `DYEXT` macro has been defined which represents the platform-dependent file extension for dyanmic libraries, `".dylib"` for macOS and `".so"` for anything else. This can be used to allow portability of build files. +The `DYEXT` macro has been defined which represents the platform-dependent file extension for dynamic libraries, `".dylib"` for macOS and `".so"` for anything else. This can be used to allow portability of build files. -An example of linking `liba.dylib` (or `liba.so`), `b.o`, `libc.a`, and the system math library as a statically linked library `libmain.a`. +An example of linking `liba.dylib` (or `liba.so`), `b.o`, `libc.a`, and the system math library into a statically linked library `libmain.a`. ```c lflags = (char *[]){"-lm", NULL}; @@ -107,9 +107,9 @@ load('s', "main", "a" DYEXT, "b", "c.a", NULL); void build(char *path); ``` -It is often adventagous to compartmentalize projects into a number of subdirectories both for organizational purposes and for rebuilding parts at a time without needing to rebuild the whole thing. The usual way this is done is by placing build scripts in any subdirectory you want to rebuild on its own. These scripts double as both being able to be ran by the programmer from the shell as well as being able to be run by the build system itself from some parent directory. The `build()` function performs the latter function of the build system. +It is often advantageous to compartmentalize projects into a number of subdirectories both for organizational purposes and for rebuilding parts at a time without needing to rebuild the whole thing. The usual way this is done is by placing build scripts in any subdirectory you want to rebuild on its own. These scripts double as both being able to be ran by the programmer from the shell as well as being able to be run by the build system itself from some parent directory. The `build()` function performs the latter function of the build system. -`build()` gets passed the name of the subdirectory you want to build, either as an absolute or relative path. Another philosophy taken by cbs is that **relative paths in a build file are always assumed to be with respect to the directory that that build file is in**. The directory you pass `build()` must have a `build.c` file in it which will be compiled and run (of course being recompiled and rerun if needed). If `path` is a null pointer, this has the effect of staying in the current directory and (again, if necessary) recompiling the build file and rerunning the build executable therein. In other words, in addition to orchestrating recursive builds, this function is also used to automate build executables rebuilding themselves and is thus why we generally include the `build(NULL);` statement at the start of build files. +`build()` gets passed the name of the subdirectory you want to build, either as an absolute or relative path. Another philosophy taken by cbs is that **relative paths in a build file are always assumed to be with respect to the directory that that build file is in**. The directory you pass `build()` must have a `build.c` file in it which will be (re)compiled and (re)run. If `path` is a null pointer, this has the effect of staying in the current directory and (again, if necessary) recompiling the build file and rerunning the build executable therein. Putting `build(NULL);` at the start of build files is what allows a build executable to recompile itself in the event its corresponding build file gets changed. In essence, this function is what allows cbs to be truly automated. An example of building the contents of the directories `abc/src/` and `/usr/local/proj/src/`. diff --git a/cbs.c b/cbs.c index 18a0b39..e6a77f9 100644 --- a/cbs.c +++ b/cbs.c @@ -48,8 +48,6 @@ char *extend(char *path, char *ext) { d = bp - dp; b = (e = strrchr(bp, '.')) ? e - bp : (e = ext, strlen(bp)); if (*ext == '!') e = ++ext; - l = strcmp(e, ".a") == 0 || strcmp(e, DYEXT) == 0 ? 3 : 0; - if (strcmp(e, DYEXT) == 0) { path = d ? strndup(dp, d) : strdup("."); if (!(dp = realpath(path, NULL))) @@ -58,6 +56,7 @@ char *extend(char *path, char *ext) { dp[(d = strlen(dp))] = '/'; ++d; } + l = strcmp(e, ".a") == 0 || strcmp(e, DYEXT) == 0 ? 3 : 0; r = allocate(d + l + b + strlen(e) + 1); strncat(r, dp, d); -- 2.51.0