]> git.tdb.fi Git - model-railway-devices.git/blob - common/build.mk
Reorganize the directory structure
[model-railway-devices.git] / common / build.mk
1 MCU := atmega328p
2 CLOCK := 16000000
3 CC := avr-gcc
4 CFLAGS := -Wall -Os -ffunction-sections -fdata-sections -mmcu=$(MCU) -DF_CPU=$(CLOCK) $(patsubst %,-D%,$(FEATURES)) -I../common
5 LDFLAGS := -Os -Wl,--gc-sections -mmcu=$(MCU)
6 AVRDUDE := avrdude
7 OBJCOPY := avr-objcopy
8 ifeq ($(MCU),atmega168)
9 BAUD := 19200
10 else
11 BAUD := 57600
12 endif
13
14 VPATH := ../common
15
16 help:
17         @echo "Targets:"
18         @echo "  %.hex:    Build firmware from %.c"
19         @echo "  upload-%: Upload firmware to AVR"
20         @echo "  clean:    Clean all built files"
21         @echo
22         @echo "Variables:"
23         @echo "  MCU:      Microcontroller type"
24         @echo "            Arduino Duemilanove = atmega328p (default)"
25         @echo "            Arduino Mini = atmega168"
26
27 %.hex: %.elf
28         $(OBJCOPY) -O ihex $< $@
29
30 %.elf: %.o
31         $(CC) $(LDFLAGS) -o $@ $^
32
33 %.o: %.c
34         $(CC) -c $(CFLAGS) -o $@ $<
35
36 upload-%: %.hex
37         $(AVRDUDE) -p$(MCU) -carduino -P/dev/ttyUSB0 -b$(BAUD) -D -Uflash:w:$<:i
38
39 clean:
40         $(RM) *.hex
41         $(RM) *.elf
42         $(RM) *.o