rgb-led-string: Christmas tree mod after real-world testing
[tinyboard.git] / projects / step-up / Makefile
1
2 PROGRAM=lights
3 SRC=version.c main.c logging.c pwm.c adc.c pwmled.c pattern.c buttons.c \
4         control.c battery.c wdt.c
5 OBJ=$(SRC:.c=.o)
6
7
8 MCU=attiny45
9 AVRDUDE_MCU=$(MCU)
10 AVRDUDE_PROGRAMMER=usbasp
11
12 CFLAGS=-Wall -Os -mmcu=$(MCU) -DUSE_LOGGING=1 -DF_CPU=1000000UL -std=gnu99
13 LDFLAGS=
14 AVRDUDE_FLAGS= -p$(AVRDUDE_MCU) -c $(AVRDUDE_PROGRAMMER)
15
16 FORMAT=ihex
17
18 CC=avr-gcc
19 OBJCOPY=avr-objcopy
20 OBJDUMP=avr-objdump
21 AVRDUDE=avrdude
22
23 all: $(PROGRAM).hex $(PROGRAM).eep
24
25 program: $(PROGRAM).hex $(PROGRAM).eep
26         $(AVRDUDE) $(AVRDUDE_FLAGS) -U flash:w:$(PROGRAM).hex:i -U eeprom:w:$(PROGRAM).eep:i
27
28 program_flash: $(PROGRAM).hex
29         $(AVRDUDE) $(AVRDUDE_FLAGS) -U flash:w:$(PROGRAM).hex:i
30
31 program_eeprom: $(PROGRAM).eep
32         $(AVRDUDE) $(AVRDUDE_FLAGS) eeprom:w:$(PROGRAM).eep:i
33
34 dump_eeprom:
35         $(AVRDUDE) $(AVRDUDE_FLAGS) -U eeprom:r:eeprom.raw:r
36         od -tx1 eeprom.raw
37
38 objdump: $(PROGRAM).elf
39         $(OBJDUMP) --disassemble $<
40
41 .PRECIOUS : $(OBJ) $(PROGRAM).elf
42
43 %.hex: %.elf
44         $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
45
46 %.eep: %.elf
47         $(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
48                 --change-section-lma .eeprom=0 -O $(FORMAT) $< $@
49
50 %.elf: $(OBJ)
51         $(CC) $(CFLAGS) $(OBJ) -o $@ $(LDFLAGS)
52
53 %.o: %.c lights.h Makefile
54         $(CC) -c $(CFLAGS) $< -o $@
55
56 %.s: %.c lights.h Makefile
57         $(CC) -S -c $(CFLAGS) $< -o $@
58
59 %.o: %.S
60         $(CC) -c $(CFLAGS) $< -o $@
61
62 clean:
63         rm -f $(PROGRAM).hex $(PROGRAM).eep $(PROGRAM).elf *.o *.s eeprom.raw
64
65 version.c:
66         ./version.pl > version.c
67
68 .PHONY: all clean dump_eeprom program program_flash program_eeprom objdump version.c
69