Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. # `ninja.build` reference
  2.  
  3. Illustrative file:
  4.  
  5. ``` ninja
  6. # Variables
  7. CXX = g++
  8. CXXFLAGS = -Wall -Wextra -pedantic-errors
  9.  
  10. # Command definitions
  11. rule link
  12. command = $CXX $CXXFLAGS $in -o $out
  13.  
  14. rule compile
  15. command = $CXX $CXXFLAGS -c $in -o $out
  16.  
  17. # Targets
  18. build main.exe: link main.o Product.o
  19.  
  20. build main.o: compile main.cpp
  21.  
  22. build Product.o: compile Product.cpp | Product.h
  23. # the above target rule uses | to specify implicit dependencies, in this case Product.h
  24.  
  25. # Miscellaneous rules
  26. default main.exe
  27. # Don't forget a newline at the end!
  28.  
  29. ```
  30.  
  31. ## Reference
  32.  
  33. - `#`: Used at every line beginning to signify a line comment
  34.  
  35. - `variableName = value`: how you store a string value inside a variable, used for substitution.
  36.  
  37. > Example:
  38. >
  39. > ```
  40. > CXXFLAGS = -Wall -Wextra -pedantic-errors
  41. > ```
  42. >
  43. > could be used for defining C++ compiler flags
  44.  
  45. - `rule`: used to define commands (note that a tab is required before the `command` keyword)
  46.  
  47. > Example:
  48. > ``` ninja
  49. > rule compile
  50. > command = $CXX $CXXFLAGS -c $in -o $out
  51. > ```
  52. > could be used to define how an object file is compiled with a given `$CXX` compiler
  53.  
  54. - `build`: used to define a build target
  55.  
  56. > Example:
  57. > `build main.exe: link main.o Product.o`
  58. > uses the `link` command on input files `main.o` and `Product.o` to produce the output file `main.exe`.
  59. >
  60. > Note that this means `$in = main.o Product.o` and `$out = main.exe`.
  61. >
  62. > IMPORTANT: the `|` symbol can be used to signify **implicit dependencies**. Example:
  63. > `build Product.o: compile Product.cpp | Product.h`
  64. > 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`.
  65.  
  66. - `default`: used to signify a default build target, i.e. what happens when `ninja` is executed with no build target specified.
  67.  
  68. > Example:
  69. > `default main.exe`
  70. > could be used to specify that `main.exe` is the default build target.
  71.  
  72. - `ninja.build` only uses linefeeds, no carriage returns allowed
  73.  
  74. - A newline is required at EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement