我有一个非常引渡的问题。makefile,编译源文件列表卡在第一个文件
我正在使用makefile和Eclipse来编译AVR微控制器的程序。基本的想法是创建一个由makefile处理的项目,并且如果我只有一个源文件,那么一切运行良好,但是如果我添加多个源文件,只需将第一个文件编译为对象的时间( .o文件)我想创建。
我认为是与下面的例子更好: 这是我的makefile的snipet:
PROJ_DIR = /home/namontoy/workspace-AVR/exampleBitCloudMakefile
SDK_ROOT = /opt/cross/avr
LIST_PATH = $(CONFIG_NAME)/List
EXE_PATH = $(CONFIG_NAME)/Exe
OBJ_PATH = $(CONFIG_NAME)/Obj
# Create list of sources and list objects
SRCS := $(shell find . -type f -name '*.c')
OBJECTS := $(SRCS:.c=.o)
# Second for to create list of sources and objects
#SOURCES=$(wildcard $(SRCS)/*.c)
#OBJECTS_AUX=$(patsubst %.c, %.o, $(SOURCES))
#OBJECTS = $(subst $(PROJ_DIR),$(OBJ_PATH), $(OBJECTS_AUX))
directories:
@echo
@echo $(MSG_MKDIR) [email protected]
@"mkdir" -p $(LIST_PATH)
@"mkdir" -p $(EXE_PATH)
@"mkdir" -p $(OBJ_PATH)
# Compile: create object files from C source files.
$(OBJECTS) : $(SRCS) directories
@echo
@echo $(MSG_BUILDING) $< # print message of begining build
@echo srcs: $(SRCS) # print list of sources
@echo objects: $(OBJECTS) # print list of objects
@echo '$$< is "$<"' # print file to be compiled
@echo '[email protected] is "[email protected]"' # print name of object file
$(CC) $(CFLAGS) $< -o [email protected]
@echo $(MSG_FINISH_BUILDING) $< # print message of finished build
在终端上,使打印:
Building file: dummyFile.c
srcs: ./dummyFile.c ./LearningInterrupt_Main.c
objects: ./dummyFile.o ./LearningInterrupt_Main.o
$< is "dummyFile.c"
[email protected] is "dummyFile.o"
avr-gcc -g -c -O1 -std=gnu99 -Wall -mmcu=atmega328p -fshort-enums -funsigned-char -funsigned-bitfields -fpack-struct -Wstrict-prototypes -Wa,-adhlns=dummyFile.lst -I/opt/cross/avr/avr/include -I/opt/cross/avr/lib/gcc/avr/4.8.3/include -I/opt/cross/avr/lib/gcc/avr/4.8.3/include-fixed -I/home/namontoy/workspace-AVR/exampleBitCloudMakefile/headers -I/home/namontoy/workspace-AVR/exampleBitCloudMakefile/ dummyFile.c -o dummyFile.o
Finished building: dummyFile.c
Building file: dummyFile.c
srcs: ./dummyFile.c ./LearningInterrupt_Main.c
objects: ./dummyFile.o ./LearningInterrupt_Main.o
$< is "dummyFile.c"
[email protected] is "LearningInterrupt_Main.o"
avr-gcc -g -c -O1 -std=gnu99 -Wall -mmcu=atmega328p -fshort-enums -funsigned-char -funsigned-bitfields -fpack-struct -Wstrict-prototypes -Wa,-adhlns=dummyFile.lst -I/opt/cross/avr/avr/include -I/opt/cross/avr/lib/gcc/avr/4.8.3/include -I/opt/cross/avr/lib/gcc/avr/4.8.3/include-fixed -I/home/namontoy/workspace-AVR/exampleBitCloudMakefile/headers -I/home/namontoy/workspace-AVR/exampleBitCloudMakefile/ dummyFile.c -o LearningInterrupt_Main.o
Finished building: dummyFile.c
所以,你可以看到,使读取所有源文件和对象,但是当第二个目标文件将被创建时,make不会在源列表上运行,它会在第一个源文件上进行搜索。
任何想法或建议吗?
在此先感谢,
namontoy。
从[生成文件文档](https://www.gnu.org/software/make/manual/html_node/Automatic-Variables.html):“$ <的**第一**先决条件的名称。“ – kaylum
关于这一行:'SRCS:= $(shell find。-type f -name'* .c')'你在makefile的顶部附近有一个声明,它定义了要使用哪个shell?建议使用如下代码:'SRCS:= $(通配符* .c)' – user3629249
这一行:'$(OBJECTS):$(SRCS)directories'会更好地写成:'%.o:%。c'只有得到第一个文件,因为这一行反复编译:'$(CC)$(CFLAGS)$ <-o $ @',如果使用建议的行,这将会很好 – user3629249