Makefile
author Tero Marttila <terom@paivola.fi>
Sat, 05 Apr 2014 01:50:26 +0300
changeset 59 7090f61e5e17
parent 58 a445e08b63e0
child 62 2d68a76322cb
permissions -rw-r--r--
hello-lkm: buttons
PROG = hello-lkm

ELF = build/src/$(PROG).elf
HEX = build/src/$(PROG).hex

all: $(HEX)

build:
	mkdir -p build/src

## Compiler
MCU = atmega328p

# CPU clock frequency
CPU = 16000000

CC = avr-gcc
CPPFLAGS = -DF_CPU=$(CPU)UL
CFLAGS = -g -mmcu=$(MCU) -Os

build/%.elf: %.c
	$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ $*.c
	$(CC) -MM $(CPPFLAGS) -MT $@ -MF build/$*.d $*.c

# existing .d files for rebuilding existing .o's
-include $(wildcard build/*/*.d)

build/%.hex: build/%.elf
	avr-objcopy -O ihex -R .eeprom $< $@

.PRECIOUS: build/%.elf

dump: $(ELF)
	avr-objdump -d $(ELF)

## Assembler
AS = avra
ASFLAGS = 

matrix.hex: spi.inc matrix.inc timer.inc delay.inc macros.inc font.inc font.def
led7seg.hex: spi.inc led7seg.inc adc.inc timer.inc delay.inc macros.inc
timer.hex: timer.inc macros.inc

%.hex: %.s
	$(AS) $(ASFLAGS) $<
	mv $<.hex $@

# fonts
font.inc: font.def

font.def: font.txt font-compile.py
	python font-compile.py $< $@ > /dev/null


## Flashing
# Arduino Duemilanove
AD_PART = m328p
AD_PROG = arduino
AD_BAUD = 57600
AD_PORT = /dev/arduino

AD = avrdude
ADFLAGS = -p $(AD_PART) -c $(AD_PROG) -b $(AD_BAUD) -P $(AD_PORT)

upload: $(HEX)
	$(AD) $(ADFLAGS) -U flash:w:$<

## Console
SERIAL_BAUD = 9600
SERIAL_FLOW = n
SERIAL_PARITY = n
SERIAL_BITS = 8
SERIAL_PORT = $(AD_PORT)

SERIAL_TERM = picocom
SERIAL_FLAGS = -b $(SERIAL_BAUD) -f $(SERIAL_FLOW) -p $(SERIAL_PARITY) -d $(SERIAL_BITS)

console:
	$(SERIAL_TERM) $(SERIAL_FLAGS) $(SERIAL_PORT)