-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
109 lines (88 loc) · 2.75 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
# Makefile - build script
# Copyright (C) 2014 Nicolas Benes
#
# 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/>.
CC := avr-gcc
OBJDUMP := avr-objdump
OBJCOPY := avr-objcopy
MV := mv
RM := rm
MKDIR := mkdir
DOXYGEN := doxygen
SIZE := avr-size
ECHO := echo
EXPAND := expand -t 2
INDENT := indent
TARGET := rxsms
MCU := atxmega32a4u
# cpu clk frq w/o 'UL'
F_CPU := 32000000
DOCDIR := doc
GCC_VERSION:=$(shell $(CC) -dumpversion)
SRC := $(wildcard *.c)
HDR := $(wildcard *.h)
OBJ := $(patsubst %.c, %.o, $(SRC))
override CFLAGS+=-mmcu=$(MCU) -DF_CPU=$(F_CPU)UL -O3 \
-fdata-sections -ffunction-sections -fshort-enums -Wall -Wextra \
-Werror-implicit-function-declaration -Wmissing-prototypes \
-Wpointer-arith -Wstrict-prototypes -Wswitch-enum \
-mrelax -std=gnu11 -g3
# -pedantic
# commented because it's too verbose
# -save-temps
ifeq ($(GCC_VERSION),4.9.2)
override CFLAGS+=-fdiagnostics-color
SIZE+=--target=elf32-avr
else
SIZE+=--mcu=$(MCU) --format=avr
endif
LFLAGS += -mmcu=$(MCU) -O3
LFLAGS += -Wl,-Map,$(TARGET).map
# preserve intermediate files
.SECONDARY:
all: $(TARGET).elf $(TARGET).hex $(TARGET).lss $(patsubst %.o, %.lss, $(OBJ)) $(TARGET).eep
$(SIZE) $<
@echo DONE
%.hex: %.elf
$(OBJCOPY) -O ihex -R .eeprom -R .fuse -R .lock $< $@
%.eep: %.elf
$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
--change-section-lma .eeprom=0 --no-change-warnings -O ihex $< $@
$(TARGET).lss: $(TARGET).elf
$(MV) $@ $@-prev || true
$(MV) $@-dense $@-dense-prev || true
$(OBJDUMP) -S $< | $(EXPAND) > $@
$(OBJDUMP) -d $< | $(EXPAND) > $@-dense
%.lss: %.o
$(MV) $@ $@-prev 2>/dev/null || true
$(OBJDUMP) -r -d $< | $(EXPAND) > $@
%.elf: $(OBJ)
@$(ECHO) Link $@
@$(CC) $(LFLAGS) -o $@ $^
%.o: %.c $(HDR) Makefile
@$(ECHO) Compile $<
@$(CC) $(CFLAGS) -o $@ -c $<
doxy: | $(DOCDIR)
$(RM) -rf $(wildcard $(DOCDIR)/*)
$(DOXYGEN) Doxyfile
indent:
$(INDENT) -kr -psl -nut $(SRC) $(HDR)
program: $(TARGET).elf
avrdude -P usb -p x32a4u -c jtag2pdi -e -U flash:w:$<
clean:
$(RM) -rf $(DOCDIR) $(TARGET).elf $(TARGET).hex \
$(wildcard *.lss*) \
$(TARGET).eep $(TARGET).map $(OBJ) \
$(wildcard *.i) $(wildcard *.s)
.PHONY: all clean doxy indent program