1

我正在为 STM32F4 构建一个程序,使用GNU-ARM-GccEclipse_make.exe 来构建项目。一切正常,但编译时终端上显示的诊断消息太长而且很难看到。当每个 *.c 文件被编译时,终端会给我一个诊断消息(见下面的段落)任何人都可以给我建议只显示一个文件名 [删除 gcc 目录路径、依赖项、头文件路径]。makefile 由 CubeMX 生成。这是makefile:https ://github.com/loiefy/STM32-makefile/blob/main/Makefile

示例诊断消息:

C:/Program Files (x86)/GNU Arm Embedded Toolchain/9 2020-q2-update/bin/arm-none-eabi-gcc -c -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -DUSE_HAL_DRIVER -DSTM32F407xx -IEngine/Src/website_c -IEngine/Inc -ILWIP/Target -IMiddlewares/Third_Party/LwIP/src/include -IMiddlewares/Third_Party/LwIP/system -IDrivers/STM32F4xx_HAL_Driver/Inc -IDrivers/STM32F4xx_HAL_Driver/Inc/Legacy -IMiddlewares/Third_Party/LwIP/src/include/netif/ppp -IMiddlewares/Third_Party/LwIP/src/apps/httpd -IDrivers/CMSIS/Device/ST/STM32F4xx/Include -IMiddlewares/Third_Party/LwIP/src/include/lwip -IMiddlewares/Third_Party/LwIP/src/include/lwip/apps -IMiddlewares/Third_Party/LwIP/src/include/lwip/priv -IMiddlewares/Third_Party/LwIP/src/include/lwip/prot -IMiddlewares/Third_Party/LwIP/src/include/netif -IMiddlewares/Third_Party/LwIP/src/include/posix -IMiddlewares/Third_Party/LwIP/src/include/posix/sys -IMiddlewares/Third_Party/LwIP/system/arch -IDrivers/CMSIS/Include -IDrivers/CMSIS/Include -IEngine/Inc -ILWIP/Target  -Og -Wall -fdata-sections -ffunction-sections -fdiagnostics-show-location=every-line -g -gdwarf-2 -MMD -MP -MF"build/mqtt.d"  -Wa,-a,-ad,-alms=build/mqtt.lst Middlewares/Third_Party/LwIP/src/apps/mqtt/mqtt.c -o build/mqtt.o

我要显示的消息:Middlewares/Third_Party/LwIP/src/apps/mqtt/mqtt.c已编译

我花了一天时间找到 echo 命令或另一个命令具有相同目的来显示 makefile 中的消息。但我什么也没找到。
感谢您的帮助

4

1 回答 1

2

因此,默认情况下会回显它运行的每一行 - 您在 makefile 中的编译器行:

$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR) 
    $(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@

将输出执行行你可以做的是:

$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR) 
    @echo "compiling $<"
    @$(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@

注意:@make 中的前缀表示不打印正在执行的命令。因此,即使 echo 行也需要 @ 否则你会得到echo comping...打印以及compiling ...

您可能希望也可能不希望对所有输出执行类似操作。我有时会根据可以传入的详细程度标志有条件地做一个或另一个,这样当你真的想看到实际的编译行时,你可以......

于 2020-10-12T10:02:15.170 回答