build-makefile

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

构建 Makefile 工程

Build Makefile Projects

适用场景

Applicable Scenarios

  • Project Profile
    中标明
    build_system: makefile
  • 工作区存在
    Makefile
    /
    makefile
    /
    GNUmakefile
    ,但没有
    CMakeLists.txt
    platformio.ini
    .uvprojx
    .ewp
  • 用户希望对裸 Makefile MCU 工程执行编译或确认固件产物。
  • 烧录或调试流程需要新的
    ELF
    HEX
    BIN
  • Project Profile
    specifies
    build_system: makefile
    .
  • The workspace contains
    Makefile
    /
    makefile
    /
    GNUmakefile
    , but no
    CMakeLists.txt
    ,
    platformio.ini
    ,
    .uvprojx
    or
    .ewp
    .
  • Users want to compile or confirm firmware artifacts for bare Makefile MCU projects.
  • New
    ELF
    ,
    HEX
    or
    BIN
    files are required for flashing or debugging processes.

必要输入

Required Inputs

  • 工作区路径,或一份已有的
    Project Profile
  • 可选的 make 目标名、额外变量(如
    CROSS_COMPILE
    MCU
    )、make 标志和并行任务数。
  • Workspace path, or an existing
    Project Profile
    .
  • Optional make target name, additional variables (e.g.,
    CROSS_COMPILE
    ,
    MCU
    ), make flags, and number of parallel tasks.

自动探测

Automatic Detection

  • 若工作区根目录存在
    Makefile
    /
    makefile
    /
    GNUmakefile
    ,脚本自动识别。
  • 解析 Makefile 变量:
    CROSS_COMPILE
    CC
    TARGET
    MCU
    BOARD
    CFLAGS
    LDFLAGS
    等。
  • CROSS_COMPILE
    前缀推断工具链家族(
    arm-none-eabi-
    gnu-arm
    riscv32-unknown-elf-
    gnu-riscv
    xtensa-esp32-elf-
    gnu-esp
    )。
  • MCU
    变量、
    -mcpu=
    标志或链接脚本名推断目标芯片。
  • 检测
    make
    /
    gmake
    /
    mingw32-make
    是否可用。
  • 若 Makefile 包含
    # Generated by CMake
    ,提示用户使用
    build-cmake
    skill。
  • If
    Makefile
    /
    makefile
    /
    GNUmakefile
    exists in the workspace root directory, the script automatically identifies it.
  • Parse Makefile variables:
    CROSS_COMPILE
    ,
    CC
    ,
    TARGET
    ,
    MCU
    ,
    BOARD
    ,
    CFLAGS
    ,
    LDFLAGS
    , etc.
  • Infer toolchain family from
    CROSS_COMPILE
    prefix (
    arm-none-eabi-
    gnu-arm
    ,
    riscv32-unknown-elf-
    gnu-riscv
    ,
    xtensa-esp32-elf-
    gnu-esp
    ).
  • Infer target chip from
    MCU
    variable,
    -mcpu=
    flag or linker script name.
  • Detect if
    make
    /
    gmake
    /
    mingw32-make
    is available.
  • If the Makefile contains
    # Generated by CMake
    , prompt the user to use the
    build-cmake
    skill.

执行步骤

Execution Steps

  1. 先阅读 references/usage.md,确认本次是环境探测、解析 Makefile、列出目标、执行构建,还是仅扫描产物。
  2. 若不确定环境是否就绪,先运行自带脚本 scripts/makefile_builder.py
    --detect
    模式确认。
  3. 运行
    --parse-makefile
    检查解析出的变量和工具链信息,确认目标芯片和编译器。
  4. 若需查看可用目标,运行
    --list-targets
  5. 使用
    --source
    运行构建,按需指定
    --target
    --clean
    --extra-args
    -j
  6. 读取脚本输出的构建结果和产物扫描报告,将产物路径写回
    Project Profile
    并交给下游 skill。
  1. First read references/usage.md to confirm whether this time is for environment detection, Makefile parsing, target listing, build execution, or just artifact scanning.
  2. If you are not sure whether the environment is ready, first run the
    --detect
    mode of the built-in script scripts/makefile_builder.py to confirm.
  3. Run
    --parse-makefile
    to check the parsed variables and toolchain information, and confirm the target chip and compiler.
  4. To view available targets, run
    --list-targets
    .
  5. Use
    --source
    to run the build, specifying
    --target
    ,
    --clean
    ,
    --extra-args
    and
    -j
    as needed.
  6. Read the build results and artifact scan report output by the script, write the artifact path back to
    Project Profile
    and pass it to downstream skills.

失败分流

Failure Diversion

  • 当缺少
    make
    或交叉编译器时,返回
    environment-missing
  • 当 Makefile 语法错误、链接失败或目标名无效时,返回
    project-config-error
  • 当构建成功但未在源目录及
    build/
    output/
    out/
    中找到可烧录产物时,返回
    artifact-missing
  • 当工作区存在多个顶层 Makefile 且意图不明确时,返回
    ambiguous-context
  • Return
    environment-missing
    when
    make
    or cross-compiler is missing.
  • Return
    project-config-error
    when there are Makefile syntax errors, link failures or invalid target names.
  • Return
    artifact-missing
    when the build is successful but no flashable artifacts are found in the source directory and
    build/
    ,
    output/
    ,
    out/
    .
  • Return
    ambiguous-context
    when multiple top-level Makefiles exist in the workspace and the intent is unclear.

平台说明

Platform Notes

  • Linux / macOS 上
    make
    通常已预装。
  • Windows 上需要 MSYS2、MinGW 或 WSL 提供
    make
    。脚本会依次尝试
    make
    gmake
    mingw32-make
  • 输出中的构建目录应保持为绝对路径,方便下游烧录和调试 skill 直接复用。
  • make
    is usually pre-installed on Linux / macOS.
  • On Windows,
    make
    is provided by MSYS2, MinGW or WSL. The script will try
    make
    ,
    gmake
    ,
    mingw32-make
    in sequence.
  • The build directory in the output should remain an absolute path for direct reuse by downstream flashing and debugging skills.

输出约定

Output Conventions

  • 输出构建命令、构建目录、解析的工具链信息和首选产物路径。
  • artifact_path
    artifact_kind
    toolchain
    target_mcu
    更新
    Project Profile
  • 成功后推荐
    flash-openocd
    flash-jlink
    debug-gdb-openocd
  • Output build commands, build directories, parsed toolchain information and preferred artifact paths.
  • Update
    Project Profile
    with
    artifact_path
    ,
    artifact_kind
    ,
    toolchain
    and
    target_mcu
    .
  • Recommend
    flash-openocd
    ,
    flash-jlink
    or
    debug-gdb-openocd
    after success.

交接关系

Handover Relationships

  • 当下一步意图是给硬件烧录程序时,将成功构建结果交给
    flash-openocd
    flash-jlink
  • 当下一步需要符号信息或调试会话时,将成功构建结果交给
    debug-gdb-openocd
    debug-jlink
  • When the next step is to flash the program to hardware, pass the successful build result to
    flash-openocd
    or
    flash-jlink
    .
  • When symbol information or a debugging session is needed for the next step, pass the successful build result to
    debug-gdb-openocd
    or
    debug-jlink
    .