]> git.tdb.fi Git - model-railway-devices.git/blob - common/build.mk
Drop the pretense of C89, put declarations where they make sense
[model-railway-devices.git] / common / build.mk
1 MCU := atmega328p
2 CLOCK := 16000000
3 CC := avr-gcc
4 CFLAGS := -Wall -std=c99 -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 DEVICE := /dev/ttyUSB0
9 ifeq ($(MCU),atmega168)
10 BAUD := 19200
11 else
12 BAUD := 57600
13 endif
14
15 VPATH := ../common
16
17 help:
18         @echo "Targets:"
19         @echo "  %.hex:    Build firmware from %.c"
20         @echo "  upload-%: Upload firmware to AVR"
21         @echo "  clean:    Clean all built files"
22         @echo
23         @echo "Variables:"
24         @echo "  MCU:      Microcontroller type"
25         @echo "            Arduino Duemilanove = atmega328p (default)"
26         @echo "            Arduino Mini = atmega168"
27
28 %.hex: %.elf
29         $(OBJCOPY) -O ihex $< $@
30
31 %.elf: %.o
32         $(CC) $(LDFLAGS) -o $@ $^
33
34 %.o: %.c
35         $(CC) -c $(CFLAGS) -o $@ $<
36
37 upload-%: %.hex
38         $(AVRDUDE) -p$(MCU) -carduino -P$(DEVICE) -b$(BAUD) -D -Uflash:w:$<:i
39
40 clean:
41         $(RM) *.hex
42         $(RM) *.elf
43         $(RM) *.o