Реальный пример
Исходники размещены в подкаталоге lwIP/netif/. Эклипс генерирует основной мейкфайл Debug/makefile и мейкфайл для подкаталога Debug/lwIP/netif/subdir.mk. Вот так выглядит этот мейкфайл:
Код
C_SRCS += \
../lwIP/netif/etharp.c \
../lwIP/netif/ethernetif.c \
../lwIP/netif/lpc17xx_emac.c \
../lwIP/netif/sys_arch.c
OBJS += \
./lwIP/netif/etharp.o \
./lwIP/netif/ethernetif.o \
./lwIP/netif/lpc17xx_emac.o \
./lwIP/netif/sys_arch.o
C_DEPS += \
./lwIP/netif/etharp.d \
./lwIP/netif/ethernetif.d \
./lwIP/netif/lpc17xx_emac.d \
./lwIP/netif/sys_arch.d
# Each subdirectory must supply rules for building sources it contributes
lwIP/netif/%.o: ../lwIP/netif/%.c
@echo 'Building file: $<'
@echo 'Invoking: MCU C Compiler'
arm-none-eabi-gcc -D__NEWLIB__ -D__USE_CMSIS -DDEBUG -D__CODE_RED -I"../Applications" -I"../FreeRTOS_portable" -I"../lwIP/include" -I"../lwIP/include/ipv4" -I"../lwIP/netif/include" -I"../FreeRTOS_include" -I"../CMSIS_LPC177x_8x/inc" -I"../lpc177x.lpc178x.cmsis.driver.library/inc" -I"../FreeRTOS-Plus-CLI" -O0 -g3 -Wall -c -fmessage-length=0 -fno-builtin -ffunction-sections -fdata-sections -mcpu=cortex-m3 -mthumb -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o"$@" "$<"
@echo 'Finished building: $<'
@echo ' '
../lwIP/netif/etharp.c \
../lwIP/netif/ethernetif.c \
../lwIP/netif/lpc17xx_emac.c \
../lwIP/netif/sys_arch.c
OBJS += \
./lwIP/netif/etharp.o \
./lwIP/netif/ethernetif.o \
./lwIP/netif/lpc17xx_emac.o \
./lwIP/netif/sys_arch.o
C_DEPS += \
./lwIP/netif/etharp.d \
./lwIP/netif/ethernetif.d \
./lwIP/netif/lpc17xx_emac.d \
./lwIP/netif/sys_arch.d
# Each subdirectory must supply rules for building sources it contributes
lwIP/netif/%.o: ../lwIP/netif/%.c
@echo 'Building file: $<'
@echo 'Invoking: MCU C Compiler'
arm-none-eabi-gcc -D__NEWLIB__ -D__USE_CMSIS -DDEBUG -D__CODE_RED -I"../Applications" -I"../FreeRTOS_portable" -I"../lwIP/include" -I"../lwIP/include/ipv4" -I"../lwIP/netif/include" -I"../FreeRTOS_include" -I"../CMSIS_LPC177x_8x/inc" -I"../lpc177x.lpc178x.cmsis.driver.library/inc" -I"../FreeRTOS-Plus-CLI" -O0 -g3 -Wall -c -fmessage-length=0 -fno-builtin -ffunction-sections -fdata-sections -mcpu=cortex-m3 -mthumb -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o"$@" "$<"
@echo 'Finished building: $<'
@echo ' '
В таком виде всё работает. Теперь я переношу Debug/lwIP/netif/subdir.mk в каталог с исходниками, т.е. lwIP/netif/subdir.mk и вместе с этим основной мейкфайл. В основном мейкфайле ничего не трогаю. В мейкфайле подкаталога (lwIP/netif/subdir.mk) исправляю так:
Код
C_SRCS += \
etharp.c \
ethernetif.c \
lpc17xx_emac.c \
sys_arch.c
OBJS += \
etharp.o \
ethernetif.o \
lpc17xx_emac.o \
sys_arch.o
C_DEPS += \
etharp.d \
ethernetif.d \
lpc17xx_emac.d \
sys_arch.d
# Each subdirectory must supply rules for building sources it contributes
%.o: %.c
@echo 'Building file: $<'
@echo 'Invoking: MCU C Compiler'
arm-none-eabi-gcc -D__NEWLIB__ -D__USE_CMSIS -DDEBUG -D__CODE_RED -I"../Applications" -I"../FreeRTOS_portable" -I"../lwIP/include" -I"../lwIP/include/ipv4" -I"../lwIP/netif/include" -I"../FreeRTOS_include" -I"../CMSIS_LPC177x_8x/inc" -I"../lpc177x.lpc178x.cmsis.driver.library/inc" -I"../FreeRTOS-Plus-CLI" -O0 -g3 -Wall -c -fmessage-length=0 -fno-builtin -ffunction-sections -fdata-sections -mcpu=cortex-m3 -mthumb -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o"$@" "$<"
@echo 'Finished building: $<'
@echo ' '
etharp.c \
ethernetif.c \
lpc17xx_emac.c \
sys_arch.c
OBJS += \
etharp.o \
ethernetif.o \
lpc17xx_emac.o \
sys_arch.o
C_DEPS += \
etharp.d \
ethernetif.d \
lpc17xx_emac.d \
sys_arch.d
# Each subdirectory must supply rules for building sources it contributes
%.o: %.c
@echo 'Building file: $<'
@echo 'Invoking: MCU C Compiler'
arm-none-eabi-gcc -D__NEWLIB__ -D__USE_CMSIS -DDEBUG -D__CODE_RED -I"../Applications" -I"../FreeRTOS_portable" -I"../lwIP/include" -I"../lwIP/include/ipv4" -I"../lwIP/netif/include" -I"../FreeRTOS_include" -I"../CMSIS_LPC177x_8x/inc" -I"../lpc177x.lpc178x.cmsis.driver.library/inc" -I"../FreeRTOS-Plus-CLI" -O0 -g3 -Wall -c -fmessage-length=0 -fno-builtin -ffunction-sections -fdata-sections -mcpu=cortex-m3 -mthumb -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o"$@" "$<"
@echo 'Finished building: $<'
@echo ' '
Рассчитывая что теперь все объектные файлы будут генерироваться там же где исходники. Но при попытке сборки проекта получаю:
Код
make: *** No rule to make target `etharp.o', needed by ,,,,
Моих скудных знаний мейкфайлов не хватает чтобы понять что не так.