我有一個非常引渡的問題。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