问题描述
我有一个不太复杂的项目,我想为其建立Makefile.通过将所有对象转储到一个目录中,然后链接所有所述对象,我已使项目成功编译.经过验证可以正常工作.
现在,我希望将项目的一半转换为一个库,因为它是一种API,并且不需要对其进行源访问.我在库目录中构建了第二个makefile,并使用根makefile对其进行了调用,但是没有一个源文件在库目录中进行编译,现在我在所有"make xyz"上均出现随机错误
项目布局:
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
./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/*.o --strict \
--libpath $(SYSLIB_DIR) --userlibpath $(USERLIB_DIR) $(USERLIBS) \
--scatter ../prj/test.sct --autoat \
--info summarysizes --map --xref --callgraph --symbols \
--info sizes --info totals --info unused --info veneers \
--list ../lst/test.map -o ../bin/test.axf
@echo -e "\n done. \n"
link_noscatter : $(OBJECTS)
@echo -e "\n Linking via commands ... \n"
$(LD) --cpu Cortex-M3 ../obj/*.o --strict \
--libpath $(SYSLIB_DIR) --userlibpath $(USERLIB_DIR) $(USERLIBS) \
--ro-base 0x08000000 --rw-base 0x20000000 --first=__Vectors --entry=Reset_Handler \
--autoat --info summarysizes --map --xref --callgraph --symbols \
--info sizes --info totals --info unused --info veneers \
--list ../lst/test.map -o ../bin/test.axf
@echo -e "\n done. \n"
copy : ../bin/test.axf
@echo -e "\n Translating To Binary ... \n"
$(CP) ../bin/test.axf --bincombined --output ../bin/test.bin
@echo -e "\n done. \n"
clean :
$(MAKE) -C ../lib
@echo -e "\n Removing Old Files ... \n"
-rm ../bin/* ../lst/* ../obj/*
@echo -e "\n done. \n"
# Automaticly include all the depend files armcc.exe created
-include $(DEPENDS)
./lib/Makefile
./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/*.o
-rm $(CMSIS_DIR)/CM3/DeviceSupport/ST/STM32F10x/*.o \
-rm $(CMSIS_DIR)/CM3/CoreSupport/*.o \
-rm $(STARTUP_DIR)/*.o ./*.a
@echo -e "\n done. \n"
我的问题是:
1- ./lib/目录中的所有源文件都不会编译.我知道规则的工作方式就像我用实际名称替换%.o:%.c一样,它知道要转到该文件夹并编译该对象.但是./prj/Makefile具有非常相似的规则,并且可以正常工作.它们全部位于不同的文件夹中是否会有所不同?
2-当我什至运行任何命令时,都会得到正在创建库...",并且./lib/Makefile从不执行其清理例程.如果我从该./lib/目录中运行"make clean",则工作正常.
3-无论天气如何,总是会编译启动例程.
有人可以伸出援手吗?我已经阅读了GNU的``make''文档并阅读了教程,但是它们都是针对极其简单的项目而没有涉及宏和多文件夹编译的内容.
谢谢!
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!
推荐答案
./prj/Makefile
./prj/Makefile
# ARM-MKD toolchain setup
# -------------------------------------------------------------------------------------------------
KEIL_DIR = /home/uminded/.wine/drive_c/Keil/ARM
TOOLCHAIN_DIR =
这篇关于Makefile问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!