aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2023-12-28 19:57:02 +0100
committerThomas Voss <mail@thomasvoss.com> 2023-12-28 19:57:02 +0100
commit44c74f36336a62dd0e2aeeefbc53ac4ea2a5d200 (patch)
treed631e6c4a5a9ba270e657a5a2c44aaa92a6976a4
parent3d3ed71d3e9930810015bcebf02b562892e251c0 (diff)
Add an example to the README
-rw-r--r--README.md47
1 files changed, 47 insertions, 0 deletions
diff --git a/README.md b/README.md
index d65ff49..e256438 100644
--- a/README.md
+++ b/README.md
@@ -15,4 +15,51 @@ simply aims to be a set of potentially useful functions and macros to
make writing a build script in C a bit easier. If there is functionality
you are missing, then add it. You’re a programmer aren’t you?
+All functions and macros are documented in cbs.h.
+
CBS is very much inspired by Tsoding’s ‘Nob’.
+
+
+## Example
+
+Assuming you have a source file `my-file.c` — you can compile this build
+script (called `build.c` for example) with `cc build.c` to bootstrap —
+and then run `./a.out` to build the `my-file` binary linked against the
+liblux library.
+
+If you make any modifications to the build script *or* to the cbs.h
+header, there is no need to manually recompile — the script will rebuild
+itself.
+
+```c
+#include "cbs.h"
+
+#define needs_rebuild(dst, src) (!fexists(dst) || fmdolder(dst, src))
+
+#define CC "cc"
+#define CFLAGS "-Wall", "-Wextra", "-Werror", "-O3"
+#define TARGET "my-file"
+
+int
+main(int argc, char **argv)
+{
+ int ec;
+ struct cmd cmd = {0};
+
+ cbsinit(argc, argv);
+ rebuild();
+
+ if (!needs_rebuild(TARGET, TARGET ".c"))
+ return EXIT_SUCCESS;
+
+ cmdadd(&cmd, "cc");
+ if (!pcquery(&cmd, "liblux", PKGC_LIBS | PKGC_CFLAGS))
+ cmdadd(&cmd, "-llux");
+ cmdadd(&cmd, CFLAGS, "-o", TARGET, TARGET ".c");
+ cmdput(cmd);
+ if ((ec = cmdexec(cmd)) != EXIT_SUCCESS)
+ diex("%s failed with exit-code %d", *cmd.argv, ec);
+
+ return EXIT_SUCCESS;
+}
+```