This repository has been archived by the owner on Mar 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmakefile.iarcc
242 lines (192 loc) · 6.59 KB
/
makefile.iarcc
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
#**********************************************************#
#file makefile
#author Rajmund Szymanski
#date 27.02.2021
#brief LM4F120H5QR makefile.
#**********************************************************#
IARCC :=
GNUCC :=
OPENOCD := openocd
LMFLASH := lmflash -q ek-lm4f232
QEMU := qemu-system-gnuarmeclipse -semihosting -board EK-LM4F120XL
#----------------------------------------------------------#
PROJECT ?= $(notdir $(CURDIR))
DEFS ?=
DIRS ?=
INCS ?= ./.
LIBS ?=
KEYS ?=
OPTF ?= h # hz
SCRIPT ?=
#----------------------------------------------------------#
DEFS += ewarm TARGET_IS_BLIZZARD_RA2 PART_LM4F120H5QR __ARM__
KEYS += .iarcc .cortexm .lm4f *
#----------------------------------------------------------#
AS := $(IARCC)iasmarm
CC := $(IARCC)iccarm
CXX := $(IARCC)iccarm
COPY := $(IARCC)ielftool
DUMP := $(GNUCC)arm-none-eabi-objdump
#DUMP := $(IARCC)ielfdumparm
SIZE := $(GNUCC)arm-none-eabi-size
LD := $(IARCC)ilinkarm
AR := $(IARCC)iarchive
GDB := $(GNUCC)arm-none-eabi-gdb
RM ?= rm -f
#----------------------------------------------------------#
DTREE = $(foreach d,$(foreach k,$(KEYS),$(wildcard $1$k)),$(dir $d) $(call DTREE,$d/))
VPATH := $(sort $(call DTREE,) $(foreach d,$(DIRS),$(call DTREE,$d/)))
#----------------------------------------------------------#
AS_EXT := .s
C_EXT := .c
CXX_EXT := .cpp
INC_DIRS := $(sort $(dir $(foreach d,$(VPATH),$(wildcard $d*.h $d*.hpp))))
LIB_DIRS := $(sort $(dir $(foreach d,$(VPATH),$(wildcard $dlib*.a $d*.icf))))
OBJ_SRCS := $(foreach d,$(VPATH),$(wildcard $d*.o))
AS_SRCS := $(foreach d,$(VPATH),$(wildcard $d*$(AS_EXT)))
C_SRCS := $(foreach d,$(VPATH),$(wildcard $d*$(C_EXT)))
CXX_SRCS := $(foreach d,$(VPATH),$(wildcard $d*$(CXX_EXT)))
LIB_SRCS := $(notdir $(foreach d,$(VPATH),$(wildcard $dlib*.a)))
ifeq ($(strip $(SCRIPT)),)
SCRIPT := $(firstword $(foreach d,$(VPATH),$(wildcard $d*.icf)))
else
SCRIPT := $(firstword $(foreach d,$(VPATH),$(wildcard $d$(SCRIPT))))
endif
ifeq ($(strip $(PROJECT)),)
PROJECT := $(notdir $(CURDIR))
endif
AS_SRCS := $(AS_SRCS:%.S=)
#----------------------------------------------------------#
BIN := $(PROJECT).bin
ELF := $(PROJECT).elf
HEX := $(PROJECT).hex
LIB := lib$(PROJECT).a
LSS := $(PROJECT).lss
MAP := $(PROJECT).map
OBJS := $(AS_SRCS:%$(AS_EXT)=%.o)
OBJS += $(C_SRCS:%$(C_EXT)=%.o)
OBJS += $(CXX_SRCS:%$(CXX_EXT)=%.o)
DEPS := $(OBJS:.o=.d)
LSTS := $(OBJS:.o=.lst)
#----------------------------------------------------------#
CORE_F := --cpu Cortex-M4
ifneq ($(MAKECMDGOALS),qemu)
CORE_F += --fpu VFPv4_sp
endif
COMMON_F = --thumb -O$(OPTF) -e --dependencies=m $*.d
AS_FLAGS = -S -s+ -w+
C_FLAGS = --silent
CXX_FLAGS = --silent --enable_restrict --c++ --no_rtti --no_exceptions
LD_FLAGS = --silent --config $(SCRIPT) --map $(MAP) --no_exceptions
ifneq ($(filter USE_SEMIHOST,$(DEFS)),)
LD_FLAGS += --semihosting
endif
ifneq ($(filter main_stack_size%,$(DEFS)),)
LD_FLAGS += --config_def $(filter main_stack_size%,$(DEFS))
endif
ifneq ($(filter proc_stack_size%,$(DEFS)),)
LD_FLAGS += --config_def $(filter proc_stack_size%,$(DEFS))
endif
#----------------------------------------------------------#
DEFS_F := $(DEFS:%=-D%)
LIBS += $(LIB_SRCS:lib%.a=%)
LIBS_F := $(LIBS:%=-l%)
OBJS_ALL := $(sort $(OBJ_SRCS) $(OBJS))
INC_DIRS += $(INCS:%=%/)
INC_DIRS_F := $(INC_DIRS:%=-I%)
LIB_DIRS_F := $(LIB_DIRS:%=-L%)
AS_FLAGS += $(CORE_F) $(DEFS_F) $(INC_DIRS_F)
C_FLAGS += $(CORE_F) $(COMMON_F) $(DEFS_F) $(INC_DIRS_F)
CXX_FLAGS += $(CORE_F) $(COMMON_F) $(DEFS_F) $(INC_DIRS_F)
LD_FLAGS += $(CORE_F)
#----------------------------------------------------------#
#openocd command-line
#interface and board/target settings (using the OOCD target-library here)
OOCD_INIT := -f board/ek-lm4f120xl.cfg
OOCD_INIT += -c init
OOCD_INIT += -c targets
#commands to enable semihosting
OOCD_DEBG := -c "arm semihosting enable"
#commands to prepare flash-write
OOCD_SAVE := -c "reset halt"
#flash-write and -verify
OOCD_SAVE += -c "flash write_image erase $(ELF)"
OOCD_SAVE += -c "verify_image $(ELF)"
#reset target
OOCD_EXEC := -c "reset run"
#terminate OOCD after programming
OOCD_EXIT := -c shutdown
#gdb command line
DEBUG_CMD := -ex "target remote localhost:3333"
DEBUG_CMD += -ex "mon reset halt"
DEBUG_CMD += -ex "tbreak main"
DEBUG_CMD += -ex "c"
#----------------------------------------------------------#
all : $(LSS) print_elf_size
lib : $(LIB) print_size
$(ELF) : $(OBJS_ALL) $(SCRIPT)
$(info Linking target: $(ELF))
ifeq ($(strip $(SCRIPT)),)
$(error No linker script in project)
endif
$(LD) $(LD_FLAGS) $(OBJS_ALL) $(LIBS_F) $(LIB_DIRS_F) -o $@
$(LIB) : $(OBJS_ALL)
$(info Building library: $(LIB))
$(AR) --create $@ $?
$(OBJS) : $(MAKEFILE_LIST)
%.o : %$(AS_EXT)
$(info Assembling file: $<)
$(AS) $(AS_FLAGS) -c $< -o $@
%.o : %$(C_EXT)
$(info Compiling file: $<)
$(CC) $(C_FLAGS) -c $< -o $@
%.o : %$(CXX_EXT)
$(info Compiling file: $<)
$(CXX) $(CXX_FLAGS) -c $< -o $@
$(BIN) : $(ELF)
$(info Creating BIN image: $(BIN))
# $(COPY) -O binary $< $@
$(COPY) --silent --strip --bin $^ $@
$(HEX) : $(ELF)
$(info Creating HEX image: $(HEX))
# $(COPY) -O ihex $< $@
$(COPY) --silent --strip --ihex $^ $@
$(LSS) : $(ELF)
$(info Creating extended listing: $(LSS))
$(DUMP) --demangle -S $< > $@
# $(DUMP) --all $< -o $@
print_size :
$(info Size of modules:)
$(SIZE) -B -t --common $(OBJS_ALL)
print_elf_size : # print_size
$(info Size of target file:)
$(SIZE) -B $(ELF)
GENERATED = $(BIN) $(ELF) $(HEX) $(LIB) $(LSS) $(MAP) $(DEPS) $(LSTS) $(OBJS)
clean :
$(info Removing all generated output files)
$(RM) $(BIN) $(ELF) $(HEX) $(LIB) $(LSS) $(MAP)
$(RM) $(DEPS)
$(RM) $(LSTS)
$(RM) $(OBJS)
flash : all $(BIN)
$(info Programing device...)
$(OPENOCD) $(OOCD_INIT) $(OOCD_SAVE) $(OOCD_EXEC) $(OOCD_EXIT)
# $(LMFLASH) -v -r $(BIN)
server : all
$(info Starting server...)
$(OPENOCD) $(OOCD_INIT) $(OOCD_SAVE)
debug : all
$(info Debugging device...)
$(GDB) --nx $(DEBUG_CMD) $(ELF)
monitor : all
$(info Monitoring device...)
$(OPENOCD) $(OOCD_INIT) $(OOCD_SAVE) $(OOCD_DEBG) $(OOCD_EXEC)
qemu : all
$(info Emulating device...)
$(QEMU) -image $(ELF)
reset :
$(info Reseting device...)
$(OPENOCD) $(OOCD_INIT) $(OOCD_EXEC) $(OOCD_EXIT)
# $(LMFLASH) --hreset
.PHONY : all lib clean flash server debug monitor qemu reset
-include $(DEPS)