I have a not to complex project that I wish to set up makefiles for. I have got the project to successfully compile by dumping all the object into one directory and then linking all said objects. Verified to work correctly.
I now wish to convert half the project into a library as it is an API and I do not need source access to it. I built a second makefile in the library directory and call it with the root makefile however none of the source files compile in the library directory and now I have random errors on all "make xyz"
The project layout:
uminded@phenom9550 $ ls -aR
.:
bin lib lst obj prj src
./bin:
./lib:
Makefile STM32F10x_StdPeriph_Lib_V3.4.0
./lib/STM32F10x_StdPeriph_Lib_V3.4.0:
Libraries
./lib/STM32F10x_StdPeriph_Lib_V3.4.0/Libraries:
CMSIS.2 STM32F10x_StdPeriph_Driver
./lib/STM32F10x_StdPeriph_Lib_V3.4.0/Libraries/CMSIS.2:
CM3
./lib/STM32F10x_StdPeriph_Lib_V3.4.0/Libraries/CMSIS.2/CM3:
CoreSupport DeviceSupport
./lib/STM32F10x_StdPeriph_Lib_V3.4.0/Libraries/CMSIS.2/CM3/CoreSupport:
core_cm3.c core_cm3.h
./lib/STM32F10x_StdPeriph_Lib_V3.4.0/Libraries/CMSIS.2/CM3/DeviceSupport:
ST
./lib/STM32F10x_StdPeriph_Lib_V3.4.0/Libraries/CMSIS.2/CM3/DeviceSupport/ST:
STM32F10x
./lib/STM32F10x_StdPeriph_Lib_V3.4.0/Libraries/CMSIS.2/CM3/DeviceSupport/ST/STM32F10x:
startup stm32f10x.h system_stm32f10x.c system_stm32f10x.h
./lib/STM32F10x_StdPeriph_Lib_V3.4.0/Libraries/CMSIS.2/CM3/DeviceSupport/ST/STM32F10x/startup:
arm
./lib/STM32F10x_StdPeriph_Lib_V3.4.0/Libraries/CMSIS.2/CM3/DeviceSupport/ST/STM32F10x/startup/arm:
startup_stm32f10x_md.s
./lib/STM32F10x_StdPeriph_Lib_V3.4.0/Libraries/STM32F10x_StdPeriph_Driver:
inc src
./lib/STM32F10x_StdPeriph_Lib_V3.4.0/Libraries/STM32F10x_StdPeriph_Driver/inc:
misc.h stm32f10x_can.h stm32f10x_dac.h stm32f10x_exti.h stm32f10x_gpio.h stm32f10x_pwr.h stm32f10x_sdio.h stm32f10x_usart.h
stm32f10x_adc.h stm32f10x_cec.h stm32f10x_dbgmcu.h stm32f10x_flash.h stm32f10x_i2c.h stm32f10x_rcc.h stm32f10x_spi.h stm32f10x_wwdg.h
stm32f10x_bkp.h stm32f10x_crc.h stm32f10x_dma.h stm32f10x_fsmc.h stm32f10x_iwdg.h stm32f10x_rtc.h stm32f10x_tim.h
./lib/STM32F10x_StdPeriph_Lib_V3.4.0/Libraries/STM32F10x_StdPeriph_Driver/src:
misc.c stm32f10x_can.c stm32f10x_dac.c stm32f10x_exti.c stm32f10x_gpio.c stm32f10x_pwr.c stm32f10x_sdio.c stm32f10x_usart.c
stm32f10x_adc.c stm32f10x_cec.c stm32f10x_dbgmcu.c stm32f10x_flash.c stm32f10x_i2c.c stm32f10x_rcc.c stm32f10x_spi.c stm32f10x_wwdg.c
stm32f10x_bkp.c stm32f10x_crc.c stm32f10x_dma.c stm32f10x_fsmc.c stm32f10x_iwdg.c stm32f10x_rtc.c stm32f10x_tim.c
./lst:
./obj:
./prj:
Makefile openocd.cfg test.sct
./src:
main.c startup_stm32f10x_md.s stm32f10x_conf.h stm32f10x_it.c stm32f10x_it.h
./prj/Makefile
# ARM-MKD toolchain setup
# -------------------------------------------------------------------------------------------------
KEIL_DIR = /home/uminded/.wine/drive_c/Keil/ARM
TOOLCHAIN_DIR = $(KEIL_DIR)/BIN40
INCLUDES = -I $(KEIL_DIR)/RV31/INC
SYSLIB_DIR = $(KEIL_DIR)/RV31/LIB
CC = $(TOOLCHAIN_DIR)/armcc.exe
AS = $(TOOLCHAIN_DIR)/armasm.exe
LD = $(TOOLCHAIN_DIR)/armlink.exe
CP = $(TOOLCHAIN_DIR)/fromelf.exe
# -------------------------------------------------------------------------------------------------
# CMSIS & Standard Firmware Library directories
# -------------------------------------------------------------------------------------------------
CMSIS_DIR = ../lib/STM32F10x_StdPeriph_Lib_V3.4.0/Libraries/CMSIS.2
STDPERIPH_DIR = ../lib/STM32F10x_StdPeriph_Lib_V3.4.0/Libraries/STM32F10x_StdPeriph_Driver
INCLUDES += -I $(CMSIS_DIR)/CM3/CoreSupport
INCLUDES += -I $(CMSIS_DIR)/CM3/DeviceSupport/ST/STM32F10x
INCLUDES += -I $(STDPERIPH_DIR)/inc
USERLIB_DIR = ../lib
USERLIBS = libstm32f10x.a
# -------------------------------------------------------------------------------------------------
# Use sources list to locate compile directories automaticly
# -------------------------------------------------------------------------------------------------
VPATH = $(dir $(SOURCES))
# -------------------------------------------------------------------------------------------------
# Project setup
# -------------------------------------------------------------------------------------------------
DEFINES = -D STM32F10X_MD
DEFINES += -D USE_STDPERIPH_DRIVER
INCLUDES += -I ../src
SOURCES = ../src/main.c
SOURCES += ../src/stm32f10x_it.c
STARTUP = ../src/startup_stm32f10x_md.s
STARTUP_OBJ = $(addprefix ../obj/, $(notdir $(STARTUP:.s=.o)))
STARTUP_DEP = $(addprefix ../obj/, $(notdir $(STARTUP:.s=.d)))
OBJECTS = $(addprefix ../obj/, $(notdir $(SOURCES:.c=.o)))
OBJECTS += $(STARTUP_OBJ)
DEPENDS = $(OBJECTS:.o=.d)
# -------------------------------------------------------------------------------------------------
# Make directives, recipies, whatever you like to call them...
# -------------------------------------------------------------------------------------------------
.PHONY : all libs scatter noscatter startup link_scatter link_noscatter copy tada clean
scatter : libs startup link_scatter copy
noscatter : libs startup link_noscatter copy
../obj/%.o : %.c
@echo -e "\n Compiling $@ ... \n"
$(CC) --cpu Cortex-M3 -g -O0 --apcs=interwork --split_sections \
$(INCLUDES) $(DEFINES) --depend ../obj/$*.d -o $@ -c $<
@echo -e "\n done. \n"
libs :
$(MAKE) -C ../lib
startup : $(STARTUP)
@echo -e "\n Assembling $@ ... \n"
$(AS) --cpu Cortex-M3 -g --16 --apcs=interwork $(INCLUDES) --xref \
--depend $(STARTUP_DEP) -o $(STARTUP_OBJ) $(STARTUP)
@echo -e "\n done. \n"
link_scatter : $(OBJECTS)
@echo -e "\n Linking via scatter file ... \n"
$(LD) --cpu Cortex-M3 ../obj
./lib/Makefile
# ARM-MKD toolchain setup
# -------------------------------------------------------------------------------------------------
KEIL_DIR = /home/uminded/.wine/drive_c/Keil/ARM
TOOLCHAIN_DIR = $(KEIL_DIR)/BIN40
INCLUDES = -I $(KEIL_DIR)/RV31/INC
LIBRARIES = $(KEIL_DIR)/RV31/LIB
CC = $(TOOLCHAIN_DIR)/armcc.exe
AS = $(TOOLCHAIN_DIR)/armasm.exe
LD = $(TOOLCHAIN_DIR)/armlink.exe
CP = $(TOOLCHAIN_DIR)/fromelf.exe
# -------------------------------------------------------------------------------------------------
# CMSIS & Standard Firmware Library directories
# -------------------------------------------------------------------------------------------------
CMSIS_DIR = ./STM32F10x_StdPeriph_Lib_V3.4.0/Libraries/CMSIS.2
STDPERIPH_DIR = ./STM32F10x_StdPeriph_Lib_V3.4.0/Libraries/STM32F10x_StdPeriph_Driver
# -------------------------------------------------------------------------------------------------
# Use sources list to locate compile directories automaticly
# -------------------------------------------------------------------------------------------------
VPATH = $(dir $(LIB_SRC))
# -------------------------------------------------------------------------------------------------
# Library setup
# -------------------------------------------------------------------------------------------------
LIB_DEF = -D STM32F10X_MD
LIB_DEF += -D USE_STDPERIPH_DRIVER
LIB_INC = -I $(CMSIS_DIR)/CM3/CoreSupport
LIB_INC += -I $(CMSIS_DIR)/CM3/DeviceSupport/ST/STM32F10x
LIB_INC += -I $(STDPERIPH_DIR)/inc
LIB_SRC = $(CMSIS_DIR)/CM3/CoreSupport/core_cm3.c
LIB_SRC += $(CMSIS_DIR)/CM3/DeviceSupport/ST/STM32F10x/system_stm32f10x.c
LIB_SRC += $(STDPERIPH_DIR)/src/misc.c
LIB_SRC += $(STDPERIPH_DIR)/src/stm32f10x_adc.c
LIB_SRC += $(STDPERIPH_DIR)/src/stm32f10x_bkp.c
LIB_SRC += $(STDPERIPH_DIR)/src/stm32f10x_can.c
LIB_SRC += $(STDPERIPH_DIR)/src/stm32f10x_cec.c
LIB_SRC += $(STDPERIPH_DIR)/src/stm32f10x_crc.c
LIB_SRC += $(STDPERIPH_DIR)/src/stm32f10x_dat.c
LIB_SRC += $(STDPERIPH_DIR)/src/stm32f10x_dbgmcu.c
LIB_SRC += $(STDPERIPH_DIR)/src/stm32f10x_dma.c
LIB_SRC += $(STDPERIPH_DIR)/src/stm32f10x_exti.c
LIB_SRC += $(STDPERIPH_DIR)/src/stm32f10x_flash.c
LIB_SRC += $(STDPERIPH_DIR)/src/stm32f10x_fsmc.c
LIB_SRC += $(STDPERIPH_DIR)/src/stm32f10x_gpio.c
LIB_SRC += $(STDPERIPH_DIR)/src/stm32f10x_i2c.c
LIB_SRC += $(STDPERIPH_DIR)/src/stm32f10x_iwdg.c
LIB_SRC += $(STDPERIPH_DIR)/src/stm32f10x_pwr.c
LIB_SRC += $(STDPERIPH_DIR)/src/stm32f10x_rcc.c
LIB_SRC += $(STDPERIPH_DIR)/src/stm32f10x_rtc.c
LIB_SRC += $(STDPERIPH_DIR)/src/stm32f10x_sdio.c
LIB_SRC += $(STDPERIPH_DIR)/src/stm32f10x_spi.c
LIB_SRC += $(STDPERIPH_DIR)/src/stm32f10x_tim.c
LIB_SRC += $(STDPERIPH_DIR)/src/stm32f10x_usart.c
LIB_SRC += $(STDPERIPH_DIR)/src/stm32f10x_wwdg.c
LIB_OBJ = $(LIB_SRC:.c=.o)
# -------------------------------------------------------------------------------------------------
.PHONY : all libs clean
%.o : %.c
$(eval OBJ_PATH = $(dir $<))
@echo -e "\n Compiling $@ ... \n"
$(CC) --cpu Cortex-M3 -g -O0 --apcs=interwork --split_sections \
$(LIB_INC) $(INCLUDES) $(LIB_DEF) -o $@ -c $<
@echo -e "\n done. \n"
libs :
@echo -e "\n Creating library ... \n"
-$(AR) -cr $(LIB_OBJ) -o libstm32f10x.a
@echo -e "\n done. \n"
clean :
@echo -e "\n Removing Old Files ... \n"
-rm $(STDPERIPH_DIR)/src
My Problems Are:
1- None of the source files in the ./lib/ directories will compile. I know the rule works as if I replace %.o : %.c with an actual name it knows that folder to go to and compile that object. However the ./prj/Makefile has a very similar rule and it works correctly. Does the fact they are all in different folders make a difference??
2- When I run any command even clean I get "Creating library ..." and the ./lib/Makefile never executes its clean routine. If i run "make clean" from within that ./lib/ directory it works perfectly fine.
3- The startup routine is always compiled, regardless of weather it is up to date.
Can anybody lend a hand? I have read the GNU 'make' documentation and read tutorials but they are all for extremely simple projects and none deal with macros and multi folder compiling.
Thanks!