]> git.tdb.fi Git - model-railway-devices.git/blobdiff - common/build.mk
Reorganize the directory structure
[model-railway-devices.git] / common / build.mk
diff --git a/common/build.mk b/common/build.mk
new file mode 100644 (file)
index 0000000..96d0f93
--- /dev/null
@@ -0,0 +1,42 @@
+MCU := atmega328p
+CLOCK := 16000000
+CC := avr-gcc
+CFLAGS := -Wall -Os -ffunction-sections -fdata-sections -mmcu=$(MCU) -DF_CPU=$(CLOCK) $(patsubst %,-D%,$(FEATURES)) -I../common
+LDFLAGS := -Os -Wl,--gc-sections -mmcu=$(MCU)
+AVRDUDE := avrdude
+OBJCOPY := avr-objcopy
+ifeq ($(MCU),atmega168)
+BAUD := 19200
+else
+BAUD := 57600
+endif
+
+VPATH := ../common
+
+help:
+       @echo "Targets:"
+       @echo "  %.hex:    Build firmware from %.c"
+       @echo "  upload-%: Upload firmware to AVR"
+       @echo "  clean:    Clean all built files"
+       @echo
+       @echo "Variables:"
+       @echo "  MCU:      Microcontroller type"
+       @echo "            Arduino Duemilanove = atmega328p (default)"
+       @echo "            Arduino Mini = atmega168"
+
+%.hex: %.elf
+       $(OBJCOPY) -O ihex $< $@
+
+%.elf: %.o
+       $(CC) $(LDFLAGS) -o $@ $^
+
+%.o: %.c
+       $(CC) -c $(CFLAGS) -o $@ $<
+
+upload-%: %.hex
+       $(AVRDUDE) -p$(MCU) -carduino -P/dev/ttyUSB0 -b$(BAUD) -D -Uflash:w:$<:i
+
+clean:
+       $(RM) *.hex
+       $(RM) *.elf
+       $(RM) *.o