build指定了編譯的依賴關係等shell
rule指定了編譯的規則也就是編譯命令等,就是指定從依賴的文件如何造成目標文件的。app
ninja中一樣有一些變量,經過$來引用不用加任何括號的ide
注意,在rule中一樣也是定義一些變量,可是這些變量是ninja內部指定的。下面是這些特殊變量的文檔ui
A rule block contains a list of key = value declarations that affect the processing of the rule. Here is a full list of special keys. command (required) the command line to run. This string (after $variables are expanded) is passed directly to sh -c without interpretation by Ninja. Each rule may have only one command declaration. To specify multiple commands use && (or similar) to concatenate operations. depfile path to an optional Makefile that contains extra implicit dependencies (see the reference on dependency types). This is explicitly to support C/C++ header dependencies; see the full discussion. deps (Available since Ninja 1.3.) if present, must be one of gcc or msvc to specify special dependency processing. See the full discussion. The generated database is stored as .ninja_deps in the builddir, see the discussion of builddir. msvc_deps_prefix (Available since Ninja 1.5.) defines the string which should be stripped from msvc’s /showIncludes output. Only needed when deps = msvc and no English Visual Studio version is used. description a short description of the command, used to pretty-print the command as it’s running. The -v flag controls whether to print the full command or its description; if a command fails, the full command line will always be printed before the command’s output. generator if present, specifies that this rule is used to re-invoke the generator program. Files built using generator rules are treated specially in two ways: firstly, they will not be rebuilt if the command line changes; and secondly, they are not cleaned by default. in the space-separated list of files provided as inputs to the build line referencing this rule, shell-quoted if it appears in commands. ($in is provided solely for convenience; if you need some subset or variant of this list of files, just construct a new variable with that list and use that instead.) in_newline the same as $in except that multiple inputs are separated by newlines rather than spaces. (For use with $rspfile_content; this works around a bug in the MSVC linker where it uses a fixed-size buffer for processing input.) out the space-separated list of files provided as outputs to the build line referencing this rule, shell-quoted if it appears in commands. restat if present, causes Ninja to re-stat the command’s outputs after execution of the command. Each output whose modification time the command did not change will be treated as though it had never needed to be built. This may cause the output’s reverse dependencies to be removed from the list of pending build actions. rspfile, rspfile_content if present (both), Ninja will use a response file for the given command, i.e. write the selected string (rspfile_content) to the given file (rspfile) before calling the command and delete the file after successful execution of the command. This is particularly useful on Windows OS, where the maximal length of a command line is limited and response files must be used instead. Use it like in the following example: rule link command = link.exe /OUT$out [usual link flags here] @$out.rsp rspfile = $out.rsp rspfile_content = $in build myapp.exe: link a.obj b.obj [possibly many other .obj files]
一樣只要是變量就須要賦值。注意rule的內容須要另起一行,而且必需要空格而不是tab按鍵。this
編譯語句的格式爲spa
build 輸出文件: 規則名 輸入文件。注意這個語句中的輸出文件和輸入文件將會成爲rule中的對應的$in,$outrest
能夠在build語句的後面換行提供相似於key=value這樣的鍵值對在當前的這個build中來臨時shadow掉在當前的編譯文件中的那些變量。也就是說這樣指定的鍵值對本次會輸入到對應的rule中去。
code