首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >makefile中的变量$(MAKE)是什么?

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

Stack Overflow用户
提问于 2016-08-16 15:17:47
回答 4查看 28.3K关注 0票数 34

我目前正在学习如何编写makefiles。我得到了以下makefile (它是为应该在ARM芯片上运行的C项目自动生成的),我正在试图理解它:

代码语言:javascript
复制
    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

我正试图在创建$(MAKE) --no-print-directory post-build文件的规则中将我的头围绕在行.elf上。

我找不到变量$(MAKE)的定义,所以我假设它是内置的。这条线到底在做什么?

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2016-08-16 15:29:57

它是对make本身的递归调用,转发-t-n-q选项。这是有意义的:您希望嵌套的make调用也能使用这些选项运行。

票数 34
EN

Stack Overflow用户

发布于 2016-08-16 15:29:40

来自文档

此变量的值是调用make的文件名。

在需要调用makefile的情况下,它非常有用,但是您正在使用-t (--touch)、-n (--just-print)或-q (--question)标志进行某种尝试运行。如果使用($MAKE),则该行为将递归传播。

票数 9
EN

Stack Overflow用户

发布于 2019-08-30 11:09:19

请不要与前面提到的递归调用的答案混淆。$MAKE是默认变量,它被替换为"make“。

在您的场景中,$MAKE用于makefile的命令部分(食谱)。它意味着每当依赖项发生变化时,make在中执行命令,无论您在上的哪个目录。

例如,如果我有一个案例

代码语言:javascript
复制
test.o: test.c
      cd /root/
      $(MAKE) all

它说,如果test.c中有更改,在/root目录中执行make all

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38978627

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档