2016-07-22 11 views
0

プロジェクトのコードをコンパイルするための簡単なmakefileを作成します。私は、コマンドを使用する場合:"cc drone.c hex1 clean -o drone"この行はありません

$ make drone 

を出力ファイルは正しいですが、makeユーティリティは、私が(14行目にライン10から)理解していない結果が得られます。

1: avr-gcc -g -Os -mmcu=atmega328p -DF_CPU=16000000UL -c drone.c 
2: drone.c:1:0: warning: "F_CPU" redefined 
3: #define F_CPU 16000000 
4:^
5: <command-line>:0:0: note: this is the location of the previous definition 
6: avr-gcc -g -Os -mmcu=atmega328p -DF_CPU=16000000UL -c ./lib/lib_uart.c 
7: avr-gcc -g -mmcu=atmega328p -o drone.elf drone.o lib_uart.o 
8: avr-objcopy -j .text -j .data -O ihex drone.elf drone.hex 
9: rm *.o *.elf 
10: cc  drone.c hex1 clean -o drone 
11: cc: error: hex1: No such file or directory 
12: cc: error: clean: No such file or directory 
13: <builtin>: recipe for target 'drone' failed 
14: make: *** [drone] Error 1 

メークファイルのテキストは:

CPU=atmega328p 
CLK=16000000UL 
PRG=avrisp 
BRATE=-b 19200 
PORT=ttyACM0 
libs_comando=lib_uart.o 
libs_drone=lib_uart.o 

drone: hex1 clean 
comando: hex2 clean 

# drone 

hex1: elf1 
    avr-objcopy -j .text -j .data -O ihex drone.elf drone.hex 

elf1: obj1 $(libs_drone) 
    avr-gcc -g -mmcu=$(CPU) -o drone.elf drone.o $(libs_drone) 

obj1: 
    avr-gcc -g -Os -mmcu=$(CPU) -DF_CPU=$(CLK) -c drone.c 

#-------------------------------------------------------------------------------- 

# comando 

hex2: elf2 
    avr-objcopy -j .text -j .data -O ihex comando.elf comando.hex 

elf2: obj2 $(libs_comando) 
    avr-gcc -g -mmcu=$(CPU) -o comando.elf comando.o $(libs_comando) 

obj2: 
    avr-gcc -g -Os -mmcu=$(CPU) -DF_CPU=$(CLK) -c comando.c 

#-------------------------------------------------------------------------------- 

# library 

lib_uart.o: 
    avr-gcc -g -Os -mmcu=$(CPU) -DF_CPU=$(CLK) -c ./lib/lib_uart.c 

#-------------------------------------------------------------------------------- 

clean: 
    rm *.o *.elf 

flash_drone: drone.hex 
    avrdude -c $(PRG) -p $(CPU) $(BRATE) -P /dev/$(PORT) -U flash:w:drone.hex:i 

flash_comando: comando.hex 
    avrdude -c $(PRG) -p $(CPU) $(BRATE) -P /dev/$(PORT) -U flash:w:comando.hex:i 

答えて

1

です。問題はdrone: hex1 cleanです。現在のディレクトリにdrone.cというファイルがあるので、暗黙のルール%: %.cが一致します。これを修正する最も簡単な方法は、暗黙的なルールを無効にするか、droneの名前を変更するか、drone.cファイルを別のディレクトリ(たとえばsrc)に移動することです。

もっと良い解決策は、暗黙のルールと戦うのではなく、それらをベースにすることです。ここにはスニペットがあります。

# Programs 
CC  := avr-gcc 
OBJCOPY := avr-objcopy 

# Flags 
CFLAGS  := -g -Os 
TARGET_ARCH := -mmcu=atmega328p -DF_CPU=16000000UL 
OBJFLAGS := -j .text -j .data -O ihex 

# Libraray file location 
vpath lib_%.c lib 

all: drone.hex 

drone: lib_uart.o 

%.hex: % 
    $(OBJCOPY) $(OBJFLAGS) $< [email protected] 

が生成されます。

avr-gcc -g -Os -mmcu=atmega328p -DF_CPU=16000000UL -c -o lib_uart.o lib/lib_uart.c 
avr-gcc -g -Os -mmcu=atmega328p -DF_CPU=16000000UL drone.c lib_uart.o -o drone 
avr-objcopy -j .text -j .data -O ihex drone drone.hex 
関連する問題