-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
87 lines (74 loc) · 2.08 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# AVR Makefile
# #####################################
#
# Part of the uCtools project
# uctools.github.com
#
#######################################
# user configuration:
#######################################
# TARGET: name of the output file
TARGET = $(FILE)
# MCU: part number to build for
MCU = atmega16m1
# SOURCES: list of input source sources
SOURCES = $(FILE).c uart.c
# INC: list of build dependencies
INC = -Isrc/
# OUTDIR: directory to use for output
OUTDIR = build
# PROGRAMMER: name of programmer
PROGRAMMER = avrispmkII
#PROGRAMMER = dragon_isp
# PORT: location of programmer
PORT = usb
# define flags
CFLAGS = -mmcu=$(MCU) -g -Os -Wall -Wunused $(INC)
ASFLAGS = -mmcu=$(MCU) -x assembler-with-cpp -Wa,-gstabs
LDFLAGS = -mmcu=$(MCU) -Wl,-Map=$(OUTDIR)/$(TARGET).map
AVRDUDE_FLAGS = -p $(MCU) -v -c $(PROGRAMMER) -P $(PORT)
#######################################
# end of user configuration
#######################################
#
#######################################
# binaries
#######################################
CC = avr-gcc
LD = avr-ld
AR = avr-ar
AS = avr-gcc
GASP = avr-gasp
NM = avr-nm
OBJCOPY = avr-objcopy
RM = rm -f
MKDIR = mkdir -p
AVRDUDE = avrdude
#######################################
# file that includes all dependancies
DEPEND = $(SOURCES:.c=.d)
# list all object files
OBJECTS = $(addprefix $(OUTDIR)/,$(SOURCES:.c=.o))
# default: build all
all: $(OUTDIR)/$(TARGET).elf $(OUTDIR)/$(TARGET).hex $(OUTDIR)/$(TARGET).srec
$(OUTDIR)/%.srec: $(OUTDIR)/%.elf
$(OBJCOPY) -j .text -j .data -O srec $< $@
$(OUTDIR)/%.elf: $(OBJECTS)
$(CC) $(OBJECTS) $(LDFLAGS) $(LIBS) -o $@
$(OUTDIR)/%.hex: $(OUTDIR)/%.elf
$(OBJCOPY) -O ihex -R .eeprom $< $@
$(OUTDIR)/%.o: src/%.c | $(OUTDIR)
$(CC) -c $(CFLAGS) -o $@ $<
%.lst: %.c
$(CC) -c $(ASFLAGS) -Wa,-anlhd $< > $@
# create the output directory
$(OUTDIR):
$(MKDIR) $(OUTDIR)
# download to mcu flash
flash: $(OUTDIR)/$(TARGET).hex
$(AVRDUDE) $(AVRDUDE_FLAGS) -U flash:w:$<
# verify mcu flash
verify: $(OUTDIR)/$(TARGET).hex
$(AVRDUDE) $(AVRDUDE_FLAGS) -U flash:v:$<
clean:
-$(RM) -r $(OUTDIR)/*