aboutsummaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile54
1 files changed, 54 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..879452f
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,54 @@
+CC ?= avr-gcc
+OBJCOPY ?= avr-objcopy
+AVRDUDE ?= avrdude
+QEMU_AVR ?= qemu-system-avr
+
+MCU ?= atmega32u4
+SIM_MCU ?= atmega2560
+CFLAGS += -DF_CPU=16000000UL -mmcu=$(MCU) -O3
+SIM_CFLAGS += -DF_CPU=16000000UL -mmcu=$(SIM_MCU) -g3 -gdwarf-2
+
+$(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