-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
92 lines (74 loc) · 2.15 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
# Copyright (C) 2020 Martin Ribelotta.
#
# This file is part of tdebug.
#
# This library 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.
#
# It 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, write to the Free Software
# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
# MA 02110-1301, USA.
#
TARGET:=tdebug
OUT:=build
INCLUDES:=inc
LIB_PATH:=lib
SPECS:=nano rdimon
LDSCRIPTS:=lib/cmx-generic.ld
ARCH_FLAGS:=-mcpu=cortex-m3 -mthumb
CFLAGS:=$(ARCH_FLAGS)
CFLAGS+=-Og -g3
CFLAGS+=$(foreach i, $(INCLUDES), -I$(i))
CFLAGS+=$(foreach d, $(DEFINES), -D$(d))
CFLAGS+=-fdata-sections -ffunction-sections
LDFLAGS:=$(ARCH_FLAGS)
LDFLAGS+=$(foreach L, $(LIB_PATH), -L$(L))
LDFLAGS+=$(foreach l, $(LIBRARIES), -l$(l))
LDFLAGS+=$(foreach s, $(SPECS), --specs=$(s).specs)
LDFLAGS+=$(foreach t, $(LDSCRIPTS), -T$(t))
LDFLAGS+=-Wl,--gc-sections
LDFLAGS+=-Wl,--print-memory-usage
CROSS:=arm-none-eabi-
CC:=$(CROSS)gcc
LD:=$(CROSS)gcc
OD:=$(CROSS)objdump -dsxS
OCP:=$(CROSS)objcopy -O binary -S
MD:=mkdir -p
RM:=rm -fr
ifeq ($(VERBOSE),y)
Q:=
else
Q:=@
endif
SOURCES:=$(wildcard src/*.c)
OBJECTS:=$(addprefix $(OUT)/, $(patsubst src/%.c, %.o, $(SOURCES)))
ELF:=$(addprefix $(OUT)/, $(addsuffix .elf, $(TARGET)))
LST:=$(patsubst %.elf, %.lst, $(ELF))
BIN:=$(patsubst %.elf, %.bin, $(ELF))
all: $(ELF) $(LST) $(BIN)
$(OUT)/:
@echo mkdir $@
$(Q)$(MD) $@
$(OUT)/%.o: src/%.c | $(OUT)/
@echo CC $(notdir $<)
$(Q)$(CC) -c $(CFLAGS) -o $@ $<
$(ELF): $(OBJECTS) $(LDSCRIPTS) | $(OUT)/
@echo LD $(notdir $@)
$(Q)$(LD) -o $@ $(LDFLAGS) $(OBJECTS)
$(LST): $(ELF) | $(OUT)/
@echo GEN $(notdir $@)
$(Q)$(OD) $< > $@
$(BIN): $(ELF) | $(OUT)/
@echo GEN $(notdir $@)
$(Q)$(OCP) $< $@
clean:
@echo CLEAN
$(Q)$(RM) $(OUT)/