# Ninja

{% embed url="<https://github.com/ninja-build/ninja>" %}

Ninja представляет собой улучшенную и доработанную версию утилиты Make. Главная цель которой – автоматизация сборки и её ускорение, а также ускорение последующих пересборок, на основе сгенерированных утилитой файлов и решение типовых проблем при кроссплатформенной разработке.

Пример базового файла build.ninja:

```log
cflags = -Wall

rule cc
  command = gcc $cflags -c $in -o $out

build hello.o: cc hello.c
```

Используемые понятия:

* Узел (Node) – это просто файл. Входной (исходники), выходной (объектные файлы) – это все узлы или вершины графа.
* Правило (Rule) – по сути это просто команда с шаблоном аргументов. Например, вызов gcc – правило, а его аргументы – $FLAGS $INCLUDES $DEFINES и еще какие-то общие аргументы.
* Ребро (Edge) – соединяет несколько входных узлов и один выходной узлов, посредством Правила. Вся система сборки основана на том, что последовательно обходит граф, выполняя команды для ребер. Как только все ребра обработаны, проект собран.
* Состояние (State) – это контейнер со всем вышеперечисленным, который система сборки и использует.

{% code title="cmake\_generated\_build.ninja" overflow="wrap" lineNumbers="true" %}

```cmake
# CMAKE generated file: DO NOT EDIT!
# Generated by "Ninja" Generator, CMake Version 3.24
# =============================================================================
# Project: DebuggingExample
# Configurations: Debug
# =============================================================================
ninja_required_version = 1.5
CONFIGURATION = Debug
include CMakeFiles/rules.ninja
cmake_ninja_workdir = .../cmake-build-debug/
...

build CMakeFiles/DebuggingExample.dir/main.c.obj: C_COMPILER__DebuggingExample_Debug .../main.c || cmake_object_order_depends_target_DebuggingExample
  DEP_FILE = CMakeFiles\DebuggingExample.dir\main.c.obj.d
  FLAGS = -g -fdiagnostics-color=always -std=gnu2x
  INCLUDES = -I.../DebuggingExample/.
  OBJECT_DIR = CMakeFiles\DebuggingExample.dir
  OBJECT_FILE_DIR = CMakeFiles\DebuggingExample.dir

build DebuggingExample.exe: C_EXECUTABLE_LINKER__DebuggingExample_Debug CMakeFiles/DebuggingExample.dir/main.c.obj
  FLAGS = -g
  LINK_LIBRARIES = -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32
  OBJECT_DIR = CMakeFiles\DebuggingExample.dir
  POST_BUILD = cd .
  PRE_LINK = cd .
  TARGET_FILE = DebuggingExample.exe
  TARGET_IMPLIB = libDebuggingExample.dll.a
  TARGET_PDB = DebuggingExample.exe.dbg

build DebuggingExample: phony DebuggingExample.exe

build all: phony DebuggingExample.exe

default all
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://skkv-itmo.gitbook.io/c-cpp-cookies/build/build-systems/ninja.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
