|
1 | | -// This is your build script. You only need to "bootstrap" it once with `cc -o nob nob.c` (you can |
2 | | -// call it whatever actually) or `cl nob.c` on MSVC and thanks to NOB_GO_REBUILD_URSELF (see below). |
3 | | -// After that every time you run the `nob` executable if it detects that you modifed nob.c it will |
4 | | -// rebuild itself automatically |
| 1 | +// This is your build script. You only need to "bootstrap" it once with `cc -o nob nob.c` |
| 2 | +// (you can call the executable whatever actually) or `cl nob.c` on MSVC. After that every |
| 3 | +// time you run the `nob` executable if it detects that you modifed nob.c it will rebuild |
| 4 | +// itself automatically thanks to NOB_GO_REBUILD_URSELF (see below) |
5 | 5 |
|
6 | 6 | // nob.h is an stb-style library https://github.com/nothings/stb/blob/master/docs/stb_howto.txt |
7 | 7 | // What that means is that it's a single file that acts both like .c and .h files, but by default |
|
14 | 14 | // and Autotools is that the codebases that use them naturally rot. That is if you do not actively update |
15 | 15 | // your build scripts, they may not work with the latest version of the build tools. Here we basically |
16 | 16 | // include the entirety of the source code of the tool along with the code base. It will never get |
17 | | -// outdated. |
| 17 | +// outdated (unless you got no standard compliant C compiler lying around, but at that point why are |
| 18 | +// you trying to build a C project?) |
18 | 19 | // |
19 | 20 | // (In these examples we actually symlinking nob.h, but this is to keep nob.h-s synced among all the |
20 | 21 | // examples) |
21 | 22 | #include "nob.h" |
22 | 23 |
|
23 | | -// TODO: add more comments in here |
24 | | - |
| 24 | +// Some folder paths that we use throughout the build process. |
25 | 25 | #define BUILD_FOLDER "build/" |
26 | 26 | #define SRC_FOLDER "src/" |
27 | 27 |
|
28 | 28 | int main(int argc, char **argv) |
29 | 29 | { |
| 30 | + // This line enables the self-rebuilding. It detects when nob.c is updated and auto rebuilds it then |
| 31 | + // runs it again. |
30 | 32 | NOB_GO_REBUILD_URSELF(argc, argv); |
31 | 33 |
|
32 | | - Nob_Cmd cmd = {0}; |
33 | | - |
| 34 | + // It's better to keep all the building artifacts in a separate build folder. Let's create it if it |
| 35 | + // does not exist yet. |
| 36 | + // |
| 37 | + // Majority of the nob command return bool which indicates whether operation has failed or not (true - |
| 38 | + // success, false - failure). If the operation returned false you don't need to log anything, the |
| 39 | + // convention is usually that the function logs what happened to itself. Just do |
| 40 | + // `if (!nob_function()) return;` |
34 | 41 | if (!nob_mkdir_if_not_exists(BUILD_FOLDER)) return 1; |
| 42 | + |
| 43 | + // The working horse of nob is the Nob_Cmd structure. It's a Dynamic Array of strings which represent |
| 44 | + // command line that you want to execute. |
| 45 | + Nob_Cmd cmd = {0}; |
| 46 | + // Let's append the command line arguments |
35 | 47 | nob_cmd_append(&cmd, "cc", "-Wall", "-Wextra", "-o", BUILD_FOLDER"main", SRC_FOLDER"main.c"); |
| 48 | + // Let's execute the command synchronously, that is it will be blocked until it's finished. |
36 | 49 | if (!nob_cmd_run_sync(cmd)) return 1; |
37 | 50 |
|
| 51 | + // TODO: add more examples in here |
| 52 | + |
38 | 53 | return 0; |
39 | 54 | } |
0 commit comments