makefile中的变量$(MAKE)是什么?

K.M*_*ier 12 makefile build

我目前正在学习如何编写makefile.我有以下makefile(它是为一个应该在ARM芯片上运行的C项目自动生成的),我正在尝试理解它:

    RM := rm -rf

    # All of the sources participating in the build are defined here
    -include sources.mk
    -include FreeRTOS/Supp_Components/subdir.mk
    -include FreeRTOS/MemMang/subdir.mk
    -...
    -include subdir.mk
    -include objects.mk

    ifneq ($(MAKECMDGOALS),clean)
    ifneq ($(strip $(S_UPPER_DEPS)),)
    -include $(S_UPPER_DEPS)
    endif
    ifneq ($(strip $(C_DEPS)),)
    -include $(C_DEPS)
    endif
    endif

    -include ../makefile.defs

    # Add inputs and outputs from these tool invocations to the build variables 

    # All Target
    all: FreeRTOS_T02.elf

    # Tool invocations
    FreeRTOS_T02.elf: $(OBJS) $(USER_OBJS)
        @echo 'Building target: $@'
        @echo 'Invoking: MCU GCC Linker'
        arm-none-eabi-gcc -mcpu=cortex-m7 -mthumb -mfloat-abi=hard -mfpu=fpv5-sp-d16 -specs=nosys.specs -specs=nano.specs -T LinkerScript.ld -Wl,-Map=output.map -Wl,--gc-sections -lm -o "FreeRTOS_T02.elf" @"objects.list" $(USER_OBJS) $(LIBS)
        @echo 'Finished building target: $@'
        @echo ' '
        $(MAKE) --no-print-directory post-build

    # Other Targets
    clean:
        -$(RM) *
        -@echo ' '

    post-build:
        -@echo 'Generating binary and Printing size information:'
        arm-none-eabi-objcopy -O binary "FreeRTOS_T02.elf" "FreeRTOS_T02.bin"
        arm-none-eabi-size "FreeRTOS_T02.elf"
        -@echo ' '

    .PHONY: all clean dependents
    .SECONDARY: post-build

    -include ../makefile.targets
Run Code Online (Sandbox Code Playgroud)

我正试图围绕$(MAKE) --no-print-directory post-build制作.elf文件的规则中的线条.

我找不到变量的定义$(MAKE),所以我认为它是内置的东西.这条线实际上在做什么?

MSa*_*ers 11

这是一个递归调用make自身,转发-t,-n和-q选项.这是有道理的:您希望嵌套make调用也可以使用这些选项运行.

  • @K.Mulier,“-”用于在命令失败(具有非零退出状态)时忽略错误。有关详细信息,请参阅[这篇文章](/sf/ask/243410471/)。但是,我不太明白为什么它会出现在“@echo”中。 (2认同)

Dae*_*ndt 8

从文档:

这个变量的值是调用 make 的文件名

如果要创建某个目标必须调用其makefile,但您正在使用-t( --touch)、-n( --just-print) 或-q( --question) 标志进行某种试运行,则它很有用。如果($MAKE)使用,该行为将递归传播。

  • “调用 make 的文件名”究竟是什么? (3认同)
  • 文档中的剩余段落:*如果此文件名为 /bin/make,则执行的配方为 'cd subdir && /bin/make'。如果您使用特殊版本的 make 来运行顶级 makefile,则递归调用将执行相同的特殊版本。* (3认同)
  • > *如果我通过双击文件来启动 GNU make 程序* 是的,它应该是。您可以尝试编写一个简单的 makefile 来执行 `echo $(MAKE)` 或类似的操作。 (3认同)