Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # `ninja.build` reference
- Illustrative file:
- ``` ninja
- # Variables
- CXX = g++
- CXXFLAGS = -Wall -Wextra -pedantic-errors
- # Command definitions
- rule link
- command = $CXX $CXXFLAGS $in -o $out
- rule compile
- command = $CXX $CXXFLAGS -c $in -o $out
- # Targets
- build main.exe: link main.o Product.o
- build main.o: compile main.cpp
- build Product.o: compile Product.cpp | Product.h
- # the above target rule uses | to specify implicit dependencies, in this case Product.h
- # Miscellaneous rules
- default main.exe
- # Don't forget a newline at the end!
- ```
- ## Reference
- - `#`: Used at every line beginning to signify a line comment
- - `variableName = value`: how you store a string value inside a variable, used for substitution.
- > Example:
- >
- > ```
- > CXXFLAGS = -Wall -Wextra -pedantic-errors
- > ```
- >
- > could be used for defining C++ compiler flags
- - `rule`: used to define commands (note that a tab is required before the `command` keyword)
- > Example:
- > ``` ninja
- > rule compile
- > command = $CXX $CXXFLAGS -c $in -o $out
- > ```
- > could be used to define how an object file is compiled with a given `$CXX` compiler
- - `build`: used to define a build target
- > Example:
- > `build main.exe: link main.o Product.o`
- > uses the `link` command on input files `main.o` and `Product.o` to produce the output file `main.exe`.
- >
- > Note that this means `$in = main.o Product.o` and `$out = main.exe`.
- >
- > IMPORTANT: the `|` symbol can be used to signify **implicit dependencies**. Example:
- > `build Product.o: compile Product.cpp | Product.h`
- > implies that `Product.h` is indirectly involved in the production of `Product.o`, in that it is not an input file to be used for the `compile` command (`$in = Product.cpp` only), but its modification requires `Product.o` to be updated. This may happen when `Product.h` is `#include`d in `Product.cpp`.
- - `default`: used to signify a default build target, i.e. what happens when `ninja` is executed with no build target specified.
- > Example:
- > `default main.exe`
- > could be used to specify that `main.exe` is the default build target.
- - `ninja.build` only uses linefeeds, no carriage returns allowed
- - A newline is required at EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement