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