-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
70 lines (55 loc) · 1.28 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# this Makefile builds avr-midi-footswitch.
#
# "make program" to program the chip using AVRDUDE.
#
# author: Philippe Proulx <eepp.ca>
# sources
C_SRC = main.c config.c
H_SRC = config.h
# target MCU
MCU = atmega88p
F_CPU = 8000000UL
# targets
TARGET = avr-midi-footswitch
TARGET_OUT = $(TARGET).out
TARGET_HEX = $(TARGET).hex
TARGET_MAP = $(TARGET).map
# configuration
HEXFORMAT = ihex
OPTLEVEL = s
# tools
CC = avr-gcc
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
SIZE = avr-size
PROG = avrdude
PROGFLAGS = -c usbasp -p $(MCU) -e
RM = rm -f
AR = avr-ar
# shorts
O_FILES = $(subst .c,.o,$(C_SRC))
# C flags
CFLAGS = -mmcu=$(MCU) -O$(OPTLEVEL) -fshort-enums \
-funsigned-bitfields -funsigned-char -Wall -DF_CPU=$(F_CPU)
# linker flags
LDFLAGS = -Wl,-Map,$(TARGET_MAP) -mmcu=$(MCU)
# phony targets
.PHONY: clean all program
# main target
all: $(TARGET_OUT)
# make output
$(TARGET_OUT): $(O_FILES)
$(CC) $(LDFLAGS) -o $@ $(O_FILES) && \
$(SIZE) $(TARGET_OUT)
# make binary image
$(TARGET_HEX): $(TARGET_OUT)
$(OBJCOPY) -j .text -j .data -O $(HEXFORMAT) $< $@
# program target
program: $(TARGET_HEX)
$(PROG) $(PROGFLAGS) -U flash:w:$(TARGET_HEX)
# objects from C files
%.o : %.c $(H_SRC)
$(CC) $(CFLAGS) -o $@ -c $<
# clean target
clean:
$(RM) $(TARGET_OUT) $(TARGET_HEX) $(TARGET_MAP) $(O_FILES)