This commit is contained in:
Noah Swerhun 2024-03-06 00:03:20 -06:00
parent 338cc3c794
commit 8d835713c8

View file

@ -17,9 +17,8 @@ constantly changing.
*ngen* aims to make generating build files for these small C/C++ projects as
simple as possible by using a basic key-value configuration file using patterns
that any experienced programmer should be familiar with. In doing so, ngen
fills the gap between writing your own makefile and wrangling with
CMakeLists.txt.
that any experienced programmer should be familiar with. In doing so, ngen fills
the gap between writing your own makefile and wrangling with CMakeLists.txt.
ngen generates files for the small and modern [Ninja](https://ninja-build.org/)
build system. "Where other build systems are high-level languages Ninja aims to
@ -78,20 +77,20 @@ sources = [
**The `sources` key is a *list* of *strings*, each specifying a single source
file name.**
Now run `ngen`. This will generate a `build.ninja` file in the current
working directory. You won't ever have to touch file; thats what ngen is for. You
Now run `ngen`. This will generate a `build.ninja` file in the current working
directory. You won't ever have to touch this file; that's what ngen is for. You
also won't ever have to run `ngen` yourself again (unless your `build.ninja`
gets deleted); Ninja will take care of regenerating the build file if
`ngen.toml` changes.
With your `build.ninja` generated, run `ninja` on the command line. Thats it!
Your project is now built, you will find it in `build/main/a.out`. Remember, you
can also freely add and remove files from this list without running `ngen`
again: Ninja will regenerate the `build.ninja` for you.
With your `build.ninja` generated, run `ninja` on the command line. That's it!
Your project is now built, you will find the executable at `build/main/a.out`.
Remember, you can also freely add and remove files from the above list without
running `ngen` again: Ninja will regenerate the `build.ninja` for you.
Now, while this is functional, it isn't very useful. It is very likely that you
will want to specify a compiler (gcc/clang), pass some flags, link some
libraries into your final exectuable, and definitly name your program something
libraries into your final executable, and definitely name your program something
other than "a.out." ngen makes these things dead simple, too.
**The `outfile` key is a *string* that specifies the name of the file produced
@ -126,24 +125,24 @@ of this for you. For example, add the following to your `ngen.toml`:
compiler_flags = ["-Wall", "-Wextra -O2"]
```
**The `linker` key is a *string* that specifies the program that will be used
to combine the .o files into the final `outfile`.**
**The `linker` key is a *string* that specifies the program that will be used to
combine the .o files into the final `outfile`.**
If the `linker` key is not found, it will be set to the value of `compiler`. For
this example, we don't have to change anything here.
**The `linker_flags` key is a *list* of *strings* that contains the arguments
to be passed to the `linker` during the linking of the `outfile`.**
**The `linker_flags` key is a *list* of *strings* that contains the arguments to
be passed to the `linker` during the linking of the `outfile`.**
Library flags (`-lm`, `lyourlib`) should NOT be included here. This is for
linker options, not libraries. There is nothing we have to set here; the sytax
works the same as `compiler_flags`.
Library flags (`-lm`, `-lyourlib`) should NOT be included here. This is for
linker options, not libraries. The syntax is the same as `compiler_flags`. There
is nothing we have to set here.
**The `linker_libs` key is a *list* of *strings* that contains the link library
arguments to be linked to the `outfile`.**
THIS is where library flags (`-lm`, `lyourlib`) go. Lets say our example project
needs the math library:
THIS is where library flags (`-lm`, `-lyourlib`) go. Lets say our example
project needs the math library:
```toml
linker_libs = ["-lm"]
@ -166,8 +165,8 @@ sources = [
This is a much more realistic looking project. Once again, any changes to any of
these values will be automatically picked up by Ninja and accounted for in the
build. Running `ninja -v` should show that the options you set were recognized,
and your files were rebuilt accordingly.
build. Running `ninja -v` immediately after saving `ngen.toml` should show that
the options you set were recognized, and your files were rebuilt accordingly.
TODO: explain
- seperate targets