-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
118 lines (88 loc) · 4 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# This file is part of the UVic Formula Motorsports PDU project.
#
# Copyright (c) 2015 UVic Formula Motorsports
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
################################################################################
# Project
################################################################################
PROJECT = canwheel
F_CPU = 16000000L
################################################################################
# Compiler Options
################################################################################
TARGET = atmega16m1
OPTIMIZATION = s
STANDARD = c11
################################################################################
# Programmer Options
################################################################################
PROGRAMMER = arduino
PROGRAMMER_PART = m16m1
PROGRAMMER_PORT = /dev/cu.usbmodem*
PROGRAMMER_OPTIONS = -b 19200
################################################################################
# Directories
################################################################################
INCLUDE_DIR = ./include
SOURCE_DIR = ./src
################################################################################
# Tools
################################################################################
CC = avr-gcc
AR = avr-ar
LD = avr-gcc
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
SIZE = avr-size
AVRDUDE = avrdude
REMOVE = rm
################################################################################
# Source Files
################################################################################
GCC_SOURCES = $(shell find $(SOURCE_DIR) -type f -name '*.c')
OBJECTS = $(GCC_SOURCES:.c=.o)
################################################################################
# Tool Flags
################################################################################
GCC_FLAGS = -g -std=$(STANDARD) -mmcu=$(TARGET) -O$(OPTIMIZATION) -DF_CPU=$(F_CPU) -fpack-struct -fshort-enums -funsigned-bitfields -funsigned-char -Wall -Wstrict-prototypes
GCC_FLAGS += $(patsubst %,-I%,$(INCLUDE_DIR)) -I. $(CFLAGS)
LD_FLAGS = -mmcu=$(TARGET) -DF_CPU=$(F_CPU)
LD_FLAGS += $(patsubst %,-I%,$(INCLUDE_DIR)) -I. $(CFLAGS)
AVRDUDE_FLAGS = -p $(PROGRAMMER_PART) -c $(PROGRAMMER) -P $(PROGRAMMER_PORT) $(PROGRAMMER_OPTIONS)
################################################################################
# Targets: Actions
################################################################################
.SUFFIXES: .c .eep .h .hex .o .out .s .S
.PHONY: all disasm fuse hex upload clean
all: $(PROJECT).out
disasm: $(PROJECT).out
$(OBJDUMP) -D -S $< > $(PROJECT).s
fuse:
$(AVRDUDE) $(AVRDUDE_FLAGS) # -U lfuse:w:0xff:m -U hfuse:w:0xd9:m -U efuse:w:0xfe:m
hex: all $(PROJECT).hex $(PROJECT).eep
upload: hex
$(AVRDUDE) $(AVRDUDE_FLAGS) -U flash:w:$(PROJECT).hex # -U eeprom:w:$(PROJECT).eep
clean:
find . \( -type f -name '*.o' -o -name '*.s' -o -name '*.out' -o -name '*.hex' \) -exec $(REMOVE) {} \;
################################################################################
# Targets: Output
################################################################################
$(PROJECT).out: $(OBJECTS)
$(LD) -o $@ $(OBJECTS) $(LD_FLAGS)
%.o: %.c
$(CC) $(GCC_FLAGS) -c $< -o $@
%.hex: %.out
$(OBJCOPY) -O ihex -R .eeprom $< $@
%.eep: %.out
$(OBJCOPY) -O ihex -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 $< $@