我目前正在学习如何编写makefiles。我得到了以下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我正试图在创建$(MAKE) --no-print-directory post-build文件的规则中将我的头围绕在行.elf上。
我找不到变量$(MAKE)的定义,所以我假设它是内置的。这条线到底在做什么?
发布于 2016-08-16 15:29:57
它是对make本身的递归调用,转发-t、-n和-q选项。这是有意义的:您希望嵌套的make调用也能使用这些选项运行。
发布于 2016-08-16 15:29:40
来自文档
此变量的值是调用make的文件名。
在需要调用makefile的情况下,它非常有用,但是您正在使用-t (--touch)、-n (--just-print)或-q (--question)标志进行某种尝试运行。如果使用($MAKE),则该行为将递归传播。
发布于 2019-08-30 11:09:19
请不要与前面提到的递归调用的答案混淆。$MAKE是默认变量,它被替换为"make“。
在您的场景中,$MAKE用于makefile的命令部分(食谱)。它意味着每当依赖项发生变化时,make在中执行命令,无论您在上的哪个目录。
例如,如果我有一个案例
test.o: test.c
cd /root/
$(MAKE) all它说,如果test.c中有更改,在/root目录中执行make all。
https://stackoverflow.com/questions/38978627
复制相似问题