Makefile的eval命令不会调用用户定义的函数

长史密斯

我的项目具有许多子文件夹的结构。我设法将所有C文件收集到SOURCES变量中,现在我想用相同的规则编译所有文件。由于我的C文件有很多不同的位置,所以我不能只使用像这样的简单模式规则%.o: %.c搜索显示出完全相同的问题解决方案,但是它对我不起作用。由于某种原因,我的函数define_compile_rules从未被调用过。为什么,我不知道。

TOOLCHAIN_PREFIX = arm-none-eabi
TOOLCHAIN_PATH = /home/kript0n/Applications/EmbeddedArm/gcc-arm-none-eabi/bin

CC = $(TOOLCHAIN_PATH)/$(TOOLCHAIN_PREFIX)-gcc
CXX = $(TOOLCHAIN_PATH)/$(TOOLCHAIN_PREFIX)-g++
OBJ_COPY = $(TOOLCHAIN_PATH)/$(TOOLCHAIN_PREFIX)-objcopy

PROJ_NAME = app

OBJ_NAME := $(PROJ_NAME).obj
ELF_NAME := $(PROJ_NAME).elf
BIN_NAME := $(PROJ_NAME).bin
HEX_NAME := $(PROJ_NAME).hex
BUILD_DIR := build


# Compilation flags
CC_FLAGS := -mcpu=cortex-m4 -mthumb -mfloat-abi=soft -O0 -fmessage-length=0\
    -fsigned-char -ffunction-sections -fdata-sections\
    -fno-move-loop-invariants -Wall -Wextra -g3

LD_FLAGS := -mcpu=cortex-m4 -mthumb -mfloat-abi=soft -O0 -fmessage-length=0\
    -fsigned-char -ffunction-sections -fdata-sections\
    -fno-move-loop-invariants -Wall -Wextra -g3 -T mem.ld\
    -T libs.ld -T sections.ld -nostartfiles -Xlinker --gc-sections\
    -L"../ldscripts" -Wl,-Map,"stm32f4.map" --specs=nano.specs

INC = -Isystem/include -Iinclude

PROJ_SOURCES := $(wildcard src/*.c) $(wildcard src/ble/*.c)
DRV_SOURCES := $(shell find src/Drivers -name '*.c')

################ HAL files ######################
HAL_MODULES := cortex dfsdm flash gpio iwdg pwr rcc_ex rcc spi tim_ex tim uart

HAL_PREFIX := stm32f4xx_hal_
HAL_PATH := system/src/stm32f4-hal

HAL_SOURCES := $(HAL_PATH)/stm32f4xx_hal.c
HAL_SOURCES += $(HAL_MODULES:%=$(HAL_PATH)/$(HAL_PREFIX)%.c)

################ System folder files except for HAL #######################
SYS_FULL_SOURCES := $(wildcard system/src/**/*.c)
SYS_SOURCES := $(filter-out $(HAL_PATH)/%, $(SYS_FULL_SOURCES))

################## ALL THE SOURCE FILES #################################
SOURCES := $(SYS_SOURCES) $(HAL_SOURCES) $(DRV_SOURCES) $(PROJ_SOURCES)
OBJECTS := $(addprefix $(BUILD_DIR)/,$(SOURCES:%.c=%.o))

# OBJS  :=  $(sort $(patsubst %.c,$(BUILD_DIR)/%.o,$(notdir $(SOURCES))))

#$(info SOURCES are $(SOURCES))
#$(info $(OBJECTS))
#$(info SYS_SOURCES is $(SYS_SOURCES))
#$(info PROJ_SOURCES is $(PROJ_SOURCES))
#$(info HAL_SOURCES is $(HAL_SOURCES))
#$(info DRV_SOURCE is $(DRV_SOURCES))


######################### TARGETS #############################
.PHONY: all app elf_to_bin elf_to_hex

# Compile project
all: app elf_to_bin elf_to_hex

define define_compile_rules
$(BUILD_DIR)/%.o: $(1)%.c
    @echo " + Compiling '$$<'"
    @mkdir -p $$(@D)
    $(CC) $$(CC_FLAGS) -o $$@ -c $$<
endef

$(foreach directory,$(sort $(dir $(SOURCES))),$(eval $(call define_compile_rules,$(directory))))

# Link and compile files(look at generic rule below)
app:
    @echo "Building app target ${\r\n}"
    $(shell mkdir -p $(BUILD_DIR))
    $(CC) $(LD_FLAGS) -o $(BUILD_DIR)/$(ELF_NAME) $(OBJECTS)

elf_to_bin:
    $(OBJ_COPY) -S -O binary $(BUILD_DIR)/$(ELF_NAME) $(BUILD_DIR)/$(BIN_NAME)

elf_to_hex:
    $(OBJ_COPY) -S -O ihex $(BUILD_DIR)/$(ELF_NAME) $(BUILD_DIR)/$(HEX_NAME)

clean:
    rm -r $(BUILD_DIR)/

立即执行make即可开始构建app目标,而无需将C文件编译为对象文件。

这是make输出:

Building app target 
/home/kript0n/Applications/EmbeddedArm/gcc-arm-none-eabi/bin/arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -mfloat-abi=soft -O0 -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -fno-move-loop-invariants -Wall -Wextra -g3 -T mem.ld -T libs.ld -T sections.ld -nostartfiles -Xlinker --gc-sections -L"../ldscripts" -Wl,-Map,"stm32f4.map" --specs=nano.specs -o build/app.elf build/system/src/cortexm/exception_handlers.o build/system/src/cortexm/_initialize_hardware.o build/system/src/cortexm/_reset_hardware.o build/system/src/newlib/_startup.o build/system/src/newlib/syscalls.o build/system/src/newlib/_exit.o build/system/src/newlib/_sbrk.o build/system/src/newlib/assert.o build/system/src/cmsis/system_stm32f4xx.o build/system/src/cmsis/vectors_stm32f401xe.o build/system/src/stm32f4-hal/stm32f4xx_hal.o build/system/src/stm32f4-hal/stm32f4xx_hal_cortex.o build/system/src/stm32f4-hal/stm32f4xx_hal_dfsdm.o build/system/src/stm32f4-hal/stm32f4xx_hal_flash.o build/system/src/stm32f4-hal/stm32f4xx_hal_gpio.o build/system/src/stm32f4-hal/stm32f4xx_hal_iwdg.o build/system/src/stm32f4-hal/stm32f4xx_hal_pwr.o build/system/src/stm32f4-hal/stm32f4xx_hal_rcc_ex.o build/system/src/stm32f4-hal/stm32f4xx_hal_rcc.o build/system/src/stm32f4-hal/stm32f4xx_hal_spi.o build/system/src/stm32f4-hal/stm32f4xx_hal_tim_ex.o build/system/src/stm32f4-hal/stm32f4xx_hal_tim.o build/system/src/stm32f4-hal/stm32f4xx_hal_uart.o build/src/Drivers/Middlewares/STM32_BlueNRG/SimpleBlueNRG_HCI/utils/ble_list.o build/src/Drivers/Middlewares/STM32_BlueNRG/SimpleBlueNRG_HCI/utils/gp_timer.o build/src/Drivers/Middlewares/STM32_BlueNRG/SimpleBlueNRG_HCI/utils/osal.o build/src/Drivers/Middlewares/STM32_BlueNRG/SimpleBlueNRG_HCI/hci/hci_dma_lp.o build/src/Drivers/Middlewares/STM32_BlueNRG/SimpleBlueNRG_HCI/hci/controller/bluenrg_gatt_aci.o build/src/Drivers/Middlewares/STM32_BlueNRG/SimpleBlueNRG_HCI/hci/controller/bluenrg_utils_small.o build/src/Drivers/Middlewares/STM32_BlueNRG/SimpleBlueNRG_HCI/hci/controller/bluenrg_hal_aci.o build/src/Drivers/Middlewares/STM32_BlueNRG/SimpleBlueNRG_HCI/hci/controller/bluenrg_utils.o build/src/Drivers/Middlewares/STM32_BlueNRG/SimpleBlueNRG_HCI/hci/controller/bluenrg_updater_aci.o build/src/Drivers/Middlewares/STM32_BlueNRG/SimpleBlueNRG_HCI/hci/controller/bluenrg_IFR.o build/src/Drivers/Middlewares/STM32_BlueNRG/SimpleBlueNRG_HCI/hci/controller/bluenrg_gap_aci.o build/src/Drivers/Middlewares/STM32_BlueNRG/SimpleBlueNRG_HCI/hci/controller/bluenrg_l2cap_aci.o build/src/Drivers/Middlewares/STM32_BlueNRG/SimpleBlueNRG_HCI/hci/hci.o build/src/Drivers/Middlewares/STM32_BlueNRG/SimpleBlueNRG_HCI/hci/hci_le.o build/src/Drivers/Middlewares/STM32_BlueNRG/LibProfPeriph/timer.o build/src/Drivers/Middlewares/STM32_BlueNRG/STM32F4xx_HAL_BlueNRG_Drivers/stm32f4xx_hal_bluenrg_syscfg.o build/src/Drivers/Middlewares/STM32_BlueNRG/STM32F4xx_HAL_BlueNRG_Drivers/stm32f4xx_hal_bluenrg_gpio.o build/src/Drivers/Middlewares/STM32_BlueNRG/Interface/bluenrg_itf.o build/src/Drivers/Middlewares/LowPowerManager/stm32xx_lpm.o build/src/Drivers/Middlewares/TimerServer/src/stm32xx_timerserver.o build/src/Drivers/BSP/Components/L6470/L6470.o build/src/Drivers/BSP/STM32F4xx-Nucleo/stm32f4xx_nucleo.o build/src/Drivers/BSP/motor_params.o build/src/Drivers/BSP/X-NUCLEO-IHM02A1/xnucleoihm02a1.o build/src/Drivers/BSP/X-NUCLEO-IHM02A1/NUCLEO-F401RE/xnucleoihm02a1_interface.o build/src/Drivers/BSP/X-NUCLEO-IDB0xA1/stm32_bluenrg_ble_dma_lp.o build/src/Drivers/BSP/X-NUCLEO-IDB0xA1/stm32_bluenrg_ble.o build/src/stepper.o build/src/coil.o build/src/servo.o build/src/boxy.o build/src/stm32f4xx_hal_msp.o build/src/stm32f4xx_it.o build/src/synchronizer.o build/src/main.o build/src/_initialize_hardware.o build/src/BlinkLed.o build/src/sys.o build/src/controller.o build/src/buttons.o build/src/utils.o build/src/ble/sensor_service.o build/src/ble/ble.o build/src/ble/bluenrg_interface.o
arm-none-eabi-gcc: error: build/system/src/cortexm/exception_handlers.o: No such file or directory
arm-none-eabi-gcc: error: build/system/src/cortexm/_initialize_hardware.o: No such file or directory
arm-none-eabi-gcc: error: build/system/src/cortexm/_reset_hardware.o: No such file or directory
arm-none-eabi-gcc: error: build/system/src/newlib/_startup.o: No such file or directory
arm-none-eabi-gcc: error: build/system/src/newlib/syscalls.o: No such file or directory
arm-none-eabi-gcc: error: build/system/src/newlib/_exit.o: No such file or directory
arm-none-eabi-gcc: error: build/system/src/newlib/_sbrk.o: No such file or directory
arm-none-eabi-gcc: error: build/system/src/newlib/assert.o: No such file or directory
arm-none-eabi-gcc: error: build/system/src/cmsis/system_stm32f4xx.o: No such file or directory
arm-none-eabi-gcc: error: build/system/src/cmsis/vectors_stm32f401xe.o: No such file or directory
arm-none-eabi-gcc: error: build/system/src/stm32f4-hal/stm32f4xx_hal.o: No such file or directory
arm-none-eabi-gcc: error: build/system/src/stm32f4-hal/stm32f4xx_hal_cortex.o: No such file or directory
arm-none-eabi-gcc: error: build/system/src/stm32f4-hal/stm32f4xx_hal_dfsdm.o: No such file or directory
arm-none-eabi-gcc: error: build/system/src/stm32f4-hal/stm32f4xx_hal_flash.o: No such file or directory
arm-none-eabi-gcc: error: build/system/src/stm32f4-hal/stm32f4xx_hal_gpio.o: No such file or directory
arm-none-eabi-gcc: error: build/system/src/stm32f4-hal/stm32f4xx_hal_iwdg.o: No such file or directory
arm-none-eabi-gcc: error: build/system/src/stm32f4-hal/stm32f4xx_hal_pwr.o: No such file or directory
arm-none-eabi-gcc: error: build/system/src/stm32f4-hal/stm32f4xx_hal_rcc_ex.o: No such file or directory
arm-none-eabi-gcc: error: build/system/src/stm32f4-hal/stm32f4xx_hal_rcc.o: No such file or directory
arm-none-eabi-gcc: error: build/system/src/stm32f4-hal/stm32f4xx_hal_spi.o: No such file or directory
arm-none-eabi-gcc: error: build/system/src/stm32f4-hal/stm32f4xx_hal_tim_ex.o: No such file or directory
arm-none-eabi-gcc: error: build/system/src/stm32f4-hal/stm32f4xx_hal_tim.o: No such file or directory
arm-none-eabi-gcc: error: build/system/src/stm32f4-hal/stm32f4xx_hal_uart.o: No such file or directory
arm-none-eabi-gcc: error: build/src/Drivers/Middlewares/STM32_BlueNRG/SimpleBlueNRG_HCI/utils/ble_list.o: No such file or directory
arm-none-eabi-gcc: error: build/src/Drivers/Middlewares/STM32_BlueNRG/SimpleBlueNRG_HCI/utils/gp_timer.o: No such file or directory
arm-none-eabi-gcc: error: build/src/Drivers/Middlewares/STM32_BlueNRG/SimpleBlueNRG_HCI/utils/osal.o: No such file or directory
arm-none-eabi-gcc: error: build/src/Drivers/Middlewares/STM32_BlueNRG/SimpleBlueNRG_HCI/hci/hci_dma_lp.o: No such file or directory
arm-none-eabi-gcc: error: build/src/Drivers/Middlewares/STM32_BlueNRG/SimpleBlueNRG_HCI/hci/controller/bluenrg_gatt_aci.o: No such file or directory
arm-none-eabi-gcc: error: build/src/Drivers/Middlewares/STM32_BlueNRG/SimpleBlueNRG_HCI/hci/controller/bluenrg_utils_small.o: No such file or directory
arm-none-eabi-gcc: error: build/src/Drivers/Middlewares/STM32_BlueNRG/SimpleBlueNRG_HCI/hci/controller/bluenrg_hal_aci.o: No such file or directory
arm-none-eabi-gcc: error: build/src/Drivers/Middlewares/STM32_BlueNRG/SimpleBlueNRG_HCI/hci/controller/bluenrg_utils.o: No such file or directory
arm-none-eabi-gcc: error: build/src/Drivers/Middlewares/STM32_BlueNRG/SimpleBlueNRG_HCI/hci/controller/bluenrg_updater_aci.o: No such file or directory
arm-none-eabi-gcc: error: build/src/Drivers/Middlewares/STM32_BlueNRG/SimpleBlueNRG_HCI/hci/controller/bluenrg_IFR.o: No such file or directory
arm-none-eabi-gcc: error: build/src/Drivers/Middlewares/STM32_BlueNRG/SimpleBlueNRG_HCI/hci/controller/bluenrg_gap_aci.o: No such file or directory
arm-none-eabi-gcc: error: build/src/Drivers/Middlewares/STM32_BlueNRG/SimpleBlueNRG_HCI/hci/controller/bluenrg_l2cap_aci.o: No such file or directory
arm-none-eabi-gcc: error: build/src/Drivers/Middlewares/STM32_BlueNRG/SimpleBlueNRG_HCI/hci/hci.o: No such file or directory
arm-none-eabi-gcc: error: build/src/Drivers/Middlewares/STM32_BlueNRG/SimpleBlueNRG_HCI/hci/hci_le.o: No such file or directory
arm-none-eabi-gcc: error: build/src/Drivers/Middlewares/STM32_BlueNRG/LibProfPeriph/timer.o: No such file or directory
arm-none-eabi-gcc: error: build/src/Drivers/Middlewares/STM32_BlueNRG/STM32F4xx_HAL_BlueNRG_Drivers/stm32f4xx_hal_bluenrg_syscfg.o: No such file or directory
arm-none-eabi-gcc: error: build/src/Drivers/Middlewares/STM32_BlueNRG/STM32F4xx_HAL_BlueNRG_Drivers/stm32f4xx_hal_bluenrg_gpio.o: No such file or directory
arm-none-eabi-gcc: error: build/src/Drivers/Middlewares/STM32_BlueNRG/Interface/bluenrg_itf.o: No such file or directory
arm-none-eabi-gcc: error: build/src/Drivers/Middlewares/LowPowerManager/stm32xx_lpm.o: No such file or directory
arm-none-eabi-gcc: error: build/src/Drivers/Middlewares/TimerServer/src/stm32xx_timerserver.o: No such file or directory
arm-none-eabi-gcc: error: build/src/Drivers/BSP/Components/L6470/L6470.o: No such file or directory
arm-none-eabi-gcc: error: build/src/Drivers/BSP/STM32F4xx-Nucleo/stm32f4xx_nucleo.o: No such file or directory
arm-none-eabi-gcc: error: build/src/Drivers/BSP/motor_params.o: No such file or directory
arm-none-eabi-gcc: error: build/src/Drivers/BSP/X-NUCLEO-IHM02A1/xnucleoihm02a1.o: No such file or directory
arm-none-eabi-gcc: error: build/src/Drivers/BSP/X-NUCLEO-IHM02A1/NUCLEO-F401RE/xnucleoihm02a1_interface.o: No such file or directory
arm-none-eabi-gcc: error: build/src/Drivers/BSP/X-NUCLEO-IDB0xA1/stm32_bluenrg_ble_dma_lp.o: No such file or directory
arm-none-eabi-gcc: error: build/src/Drivers/BSP/X-NUCLEO-IDB0xA1/stm32_bluenrg_ble.o: No such file or directory
arm-none-eabi-gcc: error: build/src/stepper.o: No such file or directory
arm-none-eabi-gcc: error: build/src/coil.o: No such file or directory
arm-none-eabi-gcc: error: build/src/servo.o: No such file or directory
arm-none-eabi-gcc: error: build/src/boxy.o: No such file or directory
arm-none-eabi-gcc: error: build/src/stm32f4xx_hal_msp.o: No such file or directory
arm-none-eabi-gcc: error: build/src/stm32f4xx_it.o: No such file or directory
arm-none-eabi-gcc: error: build/src/synchronizer.o: No such file or directory
arm-none-eabi-gcc: error: build/src/main.o: No such file or directory
arm-none-eabi-gcc: error: build/src/_initialize_hardware.o: No such file or directory
arm-none-eabi-gcc: error: build/src/BlinkLed.o: No such file or directory
arm-none-eabi-gcc: error: build/src/sys.o: No such file or directory
arm-none-eabi-gcc: error: build/src/controller.o: No such file or directory
arm-none-eabi-gcc: error: build/src/buttons.o: No such file or directory
arm-none-eabi-gcc: error: build/src/utils.o: No such file or directory
arm-none-eabi-gcc: error: build/src/ble/sensor_service.o: No such file or directory
arm-none-eabi-gcc: error: build/src/ble/ble.o: No such file or directory
arm-none-eabi-gcc: error: build/src/ble/bluenrg_interface.o: No such file or directory
Makefile:77: recipe for target 'app' failed
make: *** [app] Error 1

PS我使用GNU Make 4.1。

烤肉串

“主要”规则app(即构建所有需要构建的规则)必须具有所需文件(目标文件)的依赖关系。这种方式make将首先通过调用适当的规则来构建它们。

因此,您的规则必须是:

# Link and compile files(look at generic rule below)
app: $(OBJECTS)
    @echo "Building app target ${\r\n}"
    $(shell mkdir -p $(BUILD_DIR))
    $(CC) $(LD_FLAGS) -o $(BUILD_DIR)/$(ELF_NAME) $(OBJECTS)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Pandas eval-在列上调用用户定义的函数

在Sqlite的Insert命令中调用用户定义的函数

从dplyr :: mutate调用用户定义的函数

调用用户定义的jQuery函数

Julia模块调用用户定义函数

调用用户定义的函数时,不会触发输入type = file onchange事件

禁用用户交互的 UITableViewCell 和 UITextField 不会调用 didSelectRow

不会调用Javascript函数

使用Rcpp从C ++调用用户定义的R函数

调用用户定义的数据库函数

如何在Java中调用用户定义的Lambda函数

如何在C ++中调用用户定义的函数?

如何在VBA代码中调用用户定义的函数

从Qt在Excel中调用用户定义的VBA函数

如何在代码中调用用户定义函数?

使用$(this)选择器调用用户定义的Jquery函数

在Sub VBA中调用用户定义的函数

从WPF C#中的For循环调用用户定义的函数

如何从 PHP 中的另一个用户定义函数调用用户定义函数

如何从bash中的另一个用户定义函数调用用户定义函数?

按钮onclick不会调用javascript函数

UIButton 按下不会调用函数

反应js onclick函数不会调用

我的自定义django-admin命令不会调用celery任务

用户定义的指针包装器和 nullptr 比较不会调用我提供的运算符

如果用户拒绝在firefox中共享地理位置,则函数永远不会调用失败

如何多次调用用户命令

Scala:像成员函数一样调用用户定义函数

在另一个用户定义的函数中调用用户定义的函数时发生Nameerror