2017-02-13 4 views
0

私は非常に奇妙な問題があります。makefile、最初のファイルにスタックされたソースのリストをコンパイル

私はmakefileとEclipseを使用して、AVRマイクロコントローラ用のプログラムをコンパイルしています。基本的な考え方は、makefileで扱われるプロジェクトを作成することです。ソースファイルが1つだけの場合はすべてうまくいきますが、複数のソースファイルを追加すると、最初のファイルだけがオブジェクトとしてコンパイルされます( .oファイル)作成したい。これは私のメイクファイルの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 

だから、あなたが見ることができるよう、すべてのソースファイルとオブジェクトを読み込みますが、2番目のオブジェクトファイルが作成されるとき、makeはソースリストを超えて実行されず、最初のソースファイルに貼り付けられます。

アイデアや提案はありますか?

ありがとうございます。

namontoyここで

+1

[メイクファイルのドキュメント](https://www.gnu.org/software/make/manual/html_node/Automatic-Variables.html)から:「$ < **最初の**前提条件の名前。 'SRCS:= $(shell find。-type f -name '* .c')' makefileの先頭近くに、どのシェルを使用するかを定義したステートメントがありますか?この行に関しては – kaylum

+0

です。 'SRCS:= $(wildcard * .c)' – user3629249

+0

この行に '$(OBJECTS):$(SRCS)directories'を'%.o:%.c'と書いたほうが良いでしょう。 '$(CC)$(CFLAGS)$ <-o $ @'のように、この行のために何度も最初にコンパイルされたファイルを取得するだけです。 – user3629249

答えて

0

$(OBJECTS) : $(SRCS) directories 
    ... 
    $(CC) $(CFLAGS) $< -o [email protected] 

あなたはすべてのオブジェクトを作るには、すべてのソースに依存します。自動変数$<は、作成しようとしているものに関係なく、リストの最初のソースファイルになる最初の前提条件をとります。

pattern ruleをお試しください:

%.o : %.c directories 
    @echo compiling $< to produce [email protected] 
    $(CC) $(CFLAGS) $< -o [email protected] 
+0

こんにちは!すべての回答とコメントに感謝します。 @betaと@ user3629249で2つの変更を加えましたが、すべてがうまくいきますが、1つの副作用があります。 '$(OBJECTS):$(SRCS)directories'で特定のフォルダにオブジェクトファイルを生成しようとしましたが、'%.o:%。cディレクトリ 'ビルドプロセスは、オブジェクトファイルをソース(.c)ファイルの隣のメインフォルダに置きます。また、私は '$(OBJ_PATH)/%.O:%.c'と' $(OBJ_PATH)/%.O:$(PROJ_DIR)/%.c'を試しても動作しません。 – namontoy

+0

@namontoy:なぜ '$(OBJ_PATH)/%。o:%.c'が動作していないのか(それがどうして失敗するのか)を知っていますが、それは別の質問です。 – Beta

関連する問題