aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: 3c1580092fd718ba51625e0cf806a859ec92ab7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
CC ?= avr-gcc
OBJCOPY ?= avr-objcopy
AVRDUDE ?= avrdude
QEMU_AVR ?= qemu-system-avr

MCU ?= atmega32u4
SIM_MCU ?= atmega2560
CFLAGS += -Wall -Wextra -DF_CPU=16000000UL -mmcu=$(MCU) -O3
SIM_CFLAGS += -Wall -Wextra -DF_CPU=16000000UL -mmcu=$(SIM_MCU) -g3 -gdwarf-2 -DWDT_DISABLE

$(shell mkdir -p build/{real,sim})

all: build/altimeter_sim.elf build/altimeter.hex

emu: build/altimeter_sim.elf
	$(QEMU_AVR) -s -S -nographic -machine mega2560 -bios $<

flash: build/altimeter.hex
	$(AVRDUDE) -F -V -c avr109 -p $(MCU) -P $(PORT) -b 115200 -U flash:w:$<

clean:
	rm -rf build/

build/altimeter.elf: \
	build/real/barometer_sim.o \
	build/real/display_sim.o \
	build/real/altimeter.o \
	build/real/util.o
	$(CC) -o $@ $^ $(CFLAGS)

build/altimeter_sim.elf: \
	build/sim/barometer_sim.o \
	build/sim/display_sim.o \
	build/sim/altimeter.o \
	build/sim/util.o
	$(CC) -o $@ $^ $(SIM_CFLAGS)

include config.mk


build/sim/%.o: %.c
	$(CC) -c -o $@ $^ $(SIM_CFLAGS)

build/real/%.o: %.c
	$(CC) -c -o $@ $^ $(CFLAGS)

build/%.hex: build/%.elf
	$(OBJCOPY) -O ihex -R .eeprom $< $@

build/%.elf:
	$(CC) -o $@ $^ $(CFLAGS)


.PHONY: all emu flash clean