{
  "schemaVersion": "0.11.0",
  "canonical": "https://www.pystone.net/notes/ninja-vs-makefile/",
  "atlas": "https://www.pystone.net/?node=ninja-vs-makefile#knowledge-atlas",
  "markdown": "https://www.pystone.net/notes/ninja-vs-makefile.md",
  "context": "https://www.pystone.net/notes/ninja-vs-makefile.context.json",
  "knowledgeVersion": "224c990773de.5fa8af6e39fa",
  "build": {
    "siteCommit": "224c990773de166d23a886306577dd90379529ce",
    "notesCommit": "5fa8af6e39fa3891d1b9b4832bfa6c4e0ecaaf0a",
    "builtAt": "1970-01-01T00:00:00.000Z",
    "version": "224c990773de.5fa8af6e39fa"
  },
  "id": "note:ninja-vs-makefile",
  "slug": "ninja-vs-makefile",
  "title": "Ninja与Makefile比较",
  "type": "note",
  "visibility": "public",
  "idStability": "rename-stable",
  "author": {
    "name": "Perrin Yong",
    "profile": "https://www.pystone.net/profile/"
  },
  "publisher": {
    "name": "Perrin Yong",
    "profile": "https://www.pystone.net/profile/"
  },
  "aliases": [],
  "summary": "Ninja与Makefile比较",
  "contentRole": "unspecified",
  "isMoc": false,
  "mocRecognition": "none",
  "generated": false,
  "attribution": "unspecified",
  "domain": "10-计算机、信息技术与工程",
  "tags": [],
  "mocs": [],
  "contentHash": "9ba546ba1172f054f9c8bfcbe454be24a99532351452f0ddfc4780ae101f3851",
  "assets": [],
  "headings": [
    {
      "depth": 1,
      "text": "Ninja与Makefile比较",
      "anchor": "ninja与makefile比较",
      "citation": "https://www.pystone.net/notes/ninja-vs-makefile/#ninja%E4%B8%8Emakefile%E6%AF%94%E8%BE%83"
    },
    {
      "depth": 3,
      "text": "设计理念",
      "anchor": "设计理念",
      "citation": "https://www.pystone.net/notes/ninja-vs-makefile/#%E8%AE%BE%E8%AE%A1%E7%90%86%E5%BF%B5"
    },
    {
      "depth": 3,
      "text": "使用方式",
      "anchor": "使用方式",
      "citation": "https://www.pystone.net/notes/ninja-vs-makefile/#%E4%BD%BF%E7%94%A8%E6%96%B9%E5%BC%8F"
    },
    {
      "depth": 3,
      "text": "依赖管理",
      "anchor": "依赖管理",
      "citation": "https://www.pystone.net/notes/ninja-vs-makefile/#%E4%BE%9D%E8%B5%96%E7%AE%A1%E7%90%86"
    },
    {
      "depth": 3,
      "text": "平台支持",
      "anchor": "平台支持",
      "citation": "https://www.pystone.net/notes/ninja-vs-makefile/#%E5%B9%B3%E5%8F%B0%E6%94%AF%E6%8C%81"
    },
    {
      "depth": 3,
      "text": "具体命令比较",
      "anchor": "具体命令比较",
      "citation": "https://www.pystone.net/notes/ninja-vs-makefile/#%E5%85%B7%E4%BD%93%E5%91%BD%E4%BB%A4%E6%AF%94%E8%BE%83"
    }
  ],
  "claims": [],
  "outgoing": [],
  "incoming": [
    {
      "id": "note:programming-languages-and-runtimes",
      "title": "编程语言与运行时",
      "url": "https://www.pystone.net/notes/programming-languages-and-runtimes/",
      "atlas": "https://www.pystone.net/?node=programming-languages-and-runtimes#knowledge-atlas",
      "label": "编程语言与运行时",
      "origin": "explicit",
      "humanReviewed": true,
      "context": "本层中的“Ninja与Makefile比较”导航项",
      "citation": "https://www.pystone.net/notes/programming-languages-and-runtimes/#%E6%9C%AC%E5%B1%82"
    },
    {
      "id": "note:c-project-build-makefile-cmake",
      "title": "C语言项目构建（Makefile与CMake）",
      "url": "https://www.pystone.net/notes/c-project-build-makefile-cmake/",
      "atlas": "https://www.pystone.net/?node=c-project-build-makefile-cmake#knowledge-atlas",
      "label": "C语言项目构建（Makefile与CMake）",
      "origin": "explicit",
      "humanReviewed": true,
      "context": "生成器中的“Ninja与Makefile比较”导航项",
      "citation": "https://www.pystone.net/notes/c-project-build-makefile-cmake/#%E7%94%9F%E6%88%90%E5%99%A8"
    }
  ],
  "contentMarkdown": "# Ninja与Makefile比较\n\n﻿# Ninja与Makefile比较\n\nNinja 和 Makefile 是两个构建系统，它们各自具有不同的设计理念和使用场景。以下是它们的主要区别：\n\n### 设计理念\n\n- **Ninja**:\n\n    - **速度优化**：Ninja 是为速度而设计的。它通过高效的依赖管理和最小化磁盘 I/O 操作来加快构建速度。\n    - **简洁**：Ninja 的文件格式非常简洁和直接，目标是尽可能少地处理非必要的构建步骤。\n    - **自动化生成**：Ninja 构建文件通常不是手写的，而是通过工具（如 CMake）自动生成。\n- **Makefile**:\n\n    - **灵活性**：Makefile 提供了高度的灵活性，可以用来描述复杂的构建过程。\n    - **手动控制**：Makefile 文件通常是手写的，用户可以精细控制构建过程。\n    - **广泛支持**：Makefile 是一种老牌构建工具，几乎在所有平台上都得到广泛支持。\n\n### 使用方式\n\n- **Ninja**:\n    - 需要先通过 CMake 或其他生成工具生成 Ninja 构建文件，然后再使用 Ninja 进行构建。\n    - 示例命令：\n\n```xml\ncmake -G Ninja -S <source_dir> -B <build_dir> ninja -C <build_dir>\n```\n\n- **Makefile**:\n    - 用户需要编写 Makefile 来定义构建规则，然后直接使用 make 命令进行构建。\n    - 示例 Makefile：\n\n```makefile\nall: main.o \tgcc -o main main.o  main.o: main.c \tgcc -c main.c\n```\n\n 构建命令：\n```text\nmake\n```\n\n\n### 依赖管理\n\n- **Ninja**:\n    - 高效的依赖管理系统，能够快速检测文件变更并仅重新构建需要更新的部分。\n    - 使用基于哈希的依赖管理，避免不必要的文件检查。\n- **Makefile**:\n    - 依赖管理通过显式规则定义，用户需要手动更新依赖关系。\n    - 依赖管理相对较慢，特别是在大型项目中，容易出现重建过多的情况。\n\n### 平台支持\n\n- **Ninja**:\n    - 专为现代开发环境设计，支持跨平台构建，尤其在 Linux 和 macOS 上表现出色。\n    - 需要 CMake 等工具生成构建文件。\n- **Makefile**:\n    - 在所有主流平台上广泛使用，几乎所有 Unix-like 操作系统都内置了 make 工具。\n    - 更容易在各种不同的开发环境和工具链上使用。\n\n### 具体命令比较\n\n- **Ninja**:\n    - `ninja`: 构建目标。\n    - `ninja -t clean`: 清理构建文件。\n    - `ninja -t reconfigure`: 重新配置项目。\n- **Makefile**:\n    - `make`: 构建目标。\n    - `make clean`: 清理构建文件（根据 Makefile 定义）。\n    - `make install`: 安装目标（根据 Makefile 定义）。\n"
}
