Quantcast
Channel: more advanced makefile (part 2) - Stack Overflow
Viewing all articles
Browse latest Browse all 4

more advanced makefile (part 2)

$
0
0

after my last post i have fixed several issues with my makefile. currently it looks that way:

RM := rm -rfOBJSDIR := \    ./objs# compiler flagsCFLAGS := \    -mcpu=cortex-m4           \    -mthumb -mlittle-endian   \    -mfloat-abi=softfp        \    -mfpu=fpv4-sp-d16         \    -O0                       \    -fmessage-length=0        \    -fsigned-char             \    -ffunction-sections       \    -fdata-sections           \    -ffreestanding            \    -fno-move-loop-invariants \    -Wall                     \    -g3                       \    -std=gnu11                \    -DSTM32F429xx             \    -DDEBUG                   \    -DUSE_FULL_ASSERT         \    -DTRACE                   \    -DOS_USE_TRACE_ITM        \    -DUSE_HAL_DRIVER          \    -DHSE_VALUE=8000000# assembler flagsASMFLAGS := \    -mcpu=cortex-m4             \    -mthumb -mlittle-endian     \    -mfloat-abi=softfp          \    -mfpu=fpv4-sp-d16           \    -O0                         \    -fmessage-length=0          \    -fsigned-char               \    -ffunction-sections         \    -fdata-sections             \    -ffreestanding              \    -fno-move-loop-invariants   \    -Wall                       \    -g3                         \    -x assembler                \    -DSTM32F429xx               \    -DDEBUG                     \    -DUSE_FULL_ASSERT           \    -DTRACE                     \    -DOS_USE_TRACE_ITM          \    -DUSE_HAL_DRIVER            \    -DHSE_VALUE=8000000# include dirsINCDIRS := \    -I"./src/application"                              \    -I"./src/application/config"                       \    -I"./src/application/task"                         \    -I"./src/module/adc"                               \    -I"./src/module/can"                               \    -I"./src/module/com"                               \    -I"./src/module/config"                            \    -I"./src/module/contactor"                         \    -I"./src/module/cpuload"                           \    -I"./src/module/io"                                \    -I"./src/module/ltc"                               \    -I"./src/module/spi"                               \    -I"./src/module/uart"                              \    -I"./src/engine/config"                            \    -I"./src/engine/database"                          \    -I"./src/engine/diag"                              \    -I"./src/engine/isoguard"                          \    -I"./src/engine/soc"                               \    -I"./src/engine/sof"                               \    -I"./src/engine/sysctrl"                           \    -I"./src/engine/task"                              \    -I"./src/general"                                  \    -I"./src/general/config"                           \    -I"./src/general/includes"                         \    -I"./src/hal/CMSIS/Device/ST/STM32F4xx/Include"    \    -I"./src/hal/CMSIS/Include"                        \    -I"./src/hal/STM32F4xx_HAL_Driver/Inc"             \    -I"./src/os"                                       \    -I"./src/os/FreeRTOS"                              \    -I"./src/os/FreeRTOS/Source"                       \    -I"./src/os/FreeRTOS/Source/include"               \    -I"./src/os/FreeRTOS/Source/CMSIS_RTOS"            \    -I"./src/os/FreeRTOS/Source/portable/GCC/ARM_CM4F" \    -I"./src/test"                                     \    -I"./src/module/cpu"                               \    -I"./src/module/dma"                               \    -I"./src/module/irq"                               \    -I"./src/module/rcc"                               \    -I"./src/test/usb_cdc_lolevel"S_UPPER_SRCS := \    ./src/general/config/startup_stm32f429xx.SS_UPPER_DEPS := \    ./src/general/config/startup_stm32f429xx.d# recursive search subfolders matching patternrwildcard = $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d))# All of the sources participating in the build are defined hereC_SRCS := \    $(call rwildcard, , *.c)#   $(foreach d,$(SUBDIRS),$(call rwildcard, , *.c)) # bug, needs d passed as param to the wildcard func# exclude STM templates from buildC_SRCS := $(filter-out src/hal/CMSIS/Device/ST/STM32F4xx/Source/Templates/system_stm32f4xx.c, $(C_SRCS))C_SRCS := $(filter-out src/hal/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_msp_template.c, $(C_SRCS))#$(info C_SRCS='$(C_SRCS)')OBJS := \    $(patsubst %.c, $(OBJSDIR)/%.o,$(C_SRCS))# add linker scriptOBJS += \    $(OBJSDIR)/src/general/config/startup_stm32f429xx.oC_DEPS := \    $(patsubst %.c,$(OBJSDIR)/%.d,$(C_SRCS))#$(info C_DEPS='$(C_DEPS)')# compile src files$(OBJSDIR)/%.o: %.c    @echo 'Building file: $<'    @echo 'Invoking: Cross ARM C Compiler'    arm-none-eabi-gcc $(CFLAGS) $(INCDIRS) -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" -c -o "$@""$<"    @echo 'Finished building: $<'    @echo ''# assemble linker script src/general/config/startup_stm32f429xx.o: src/general/config/startup_stm32f429xx.S    @echo 'Building file: $<'    @echo 'Invoking: Cross ARM GNU Assembler'    arm-none-eabi-gcc $(ASMFLAGS) -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" -c -o "$@""$<"    @echo 'Finished building: $<'    @echo ''ifneq ($(MAKECMDGOALS),clean)ifneq ($(strip $(CC_DEPS)),)-include $(CC_DEPS)endififneq ($(strip $(C++_DEPS)),)-include $(C++_DEPS)endififneq ($(strip $(C_UPPER_DEPS)),)-include $(C_UPPER_DEPS)endififneq ($(strip $(CXX_DEPS)),)-include $(CXX_DEPS)endififneq ($(strip $(ASM_DEPS)),)-include $(ASM_DEPS)endififneq ($(strip $(S_UPPER_DEPS)),)-include $(S_UPPER_DEPS)endififneq ($(strip $(C_DEPS)),)-include $(C_DEPS)endififneq ($(strip $(CPP_DEPS)),)-include $(CPP_DEPS)endifendif# Add inputs and outputs from these tool invocations to the build variablesSECONDARY_FLASH := \    foxbms.hex \SECONDARY_LIST := \    foxbms.lst \SECONDARY_SIZE := \    foxbms.siz \# All Targetall: foxbms.elf secondary-outputs# Tool invocationsfoxbms.elf: $(OBJS) $(USER_OBJS)    @echo 'Building target: $@'    @echo 'Invoking: Cross ARM C++ Linker'    arm-none-eabi-g++ -mcpu=cortex-m4 -mthumb -mlittle-endian -mfloat-abi=softfp -mfpu=fpv4-sp-d16 -O0 -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -ffreestanding -fno-move-loop-invariants -Wall -g3 -T "src/STM32F429ZIT6_FLASH.ld" -Xlinker --gc-sections -Wl,-Map,"foxbms.map" --specs=nano.specs -o "foxbms.elf" $(OBJS) $(USER_OBJS) $(LIBS)    @echo 'Finished building target: $@'    @echo ''    $(MAKE) --no-print-directory post-buildfoxbms.hex: foxbms.elf    @echo 'Invoking: Cross ARM GNU Create Flash Image'    arm-none-eabi-objcopy -O ihex "foxbms.elf""foxbms.hex"    @echo 'Finished building: $@'    @echo ''foxbms.lst: foxbms.elf    @echo 'Invoking: Cross ARM GNU Create Listing'    arm-none-eabi-objdump --source --all-headers --demangle --line-numbers --wide "foxbms.elf"> "foxbms.lst"    @echo 'Finished building: $@'    @echo ''foxbms.siz: foxbms.elf    @echo 'Invoking: Cross ARM GNU Print Size'    arm-none-eabi-size --format=berkeley $(OBJS) "foxbms.elf"    @echo 'Finished building: $@'    @echo ''# Other Targetsclean:    -$(RM) \        $(CC_DEPS)         \        $(C++_DEPS)        \        $(OBJS)            \        $(C_UPPER_DEPS)    \        $(CXX_DEPS)        \        $(SECONDARY_FLASH) \        $(SECONDARY_LIST)  \        $(SECONDARY_SIZE)  \        $(ASM_DEPS)        \        $(S_UPPER_DEPS)    \        $(C_DEPS)          \        $(CPP_DEPS)        \        foxbms.elf    -@echo ''post-build:    -@echo 'Create binary'    -arm-none-eabi-objcopy -O binary "foxbms.elf""foxbms.bin"    -@echo ''secondary-outputs: $(SECONDARY_FLASH) $(SECONDARY_LIST) $(SECONDARY_SIZE).PHONY: all clean dependents x.SECONDARY: post-build

last thing i want to to do is placing all .o and .d files into a /objs subfolder, outside the /src folder. i have edited the makefile but it gives me following error:

make all Building file: src/general/nvic.cInvoking: Cross ARM C Compilerarm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -mlittle-endian -mfloat-abi=softfp -mfpu=fpv4-sp-d16 -O0 -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -ffreestanding -fno-move-loop-invariants -Wall -g3 -std=gnu11 -DSTM32F429xx -DDEBUG -DUSE_FULL_ASSERT -DTRACE -DOS_USE_TRACE_ITM -DUSE_HAL_DRIVER -DHSE_VALUE=8000000 -I"./src/application" -I"./src/application/config" -I"./src/application/task" -I"./src/module/adc" -I"./src/module/can" -I"./src/module/com" -I"./src/module/config" -I"./src/module/contactor" -I"./src/module/cpuload" -I"./src/module/io" -I"./src/module/ltc" -I"./src/module/spi" -I"./src/module/uart" -I"./src/engine/config" -I"./src/engine/database" -I"./src/engine/diag" -I"./src/engine/isoguard" -I"./src/engine/soc" -I"./src/engine/sof" -I"./src/engine/sysctrl" -I"./src/engine/task" -I"./src/general" -I"./src/general/config" -I"./src/general/includes" -I"./src/hal/CMSIS/Device/ST/STM32F4xx/Include" -I"./src/hal/CMSIS/Include" -I"./src/hal/STM32F4xx_HAL_Driver/Inc" -I"./src/os" -I"./src/os/FreeRTOS" -I"./src/os/FreeRTOS/Source" -I"./src/os/FreeRTOS/Source/include" -I"./src/os/FreeRTOS/Source/CMSIS_RTOS" -I"./src/os/FreeRTOS/Source/portable/GCC/ARM_CM4F" -I"./src/test" -I"./src/module/cpu" -I"./src/module/dma" -I"./src/module/irq" -I"./src/module/rcc" -I"./src/test/usb_cdc_lolevel" -MMD -MP -MF"objs/src/general/nvic.d" -MT"objs/src/general/nvic.o" -c -o "objs/src/general/nvic.o""src/general/nvic.c"src/general/nvic.c:108:1: fatal error: opening dependency file objs/src/general/nvic.d: No such file or directory } ^compilation terminated.makefile:131: recipe for target 'objs/src/general/nvic.o' failedmake: *** [objs/src/general/nvic.o] Error 1

any hints what i am doing wrong here?

what do i have to do to generate those folders? in some makefile examples i saw people creating a rule with mkdir, others just didn't do that, what is correct?


Viewing all articles
Browse latest Browse all 4

Trending Articles