summaryrefslogtreecommitdiff
path: root/bsp/maxim/libraries/MAX32660PeriphDriver/CMSIS/Device/Maxim/MAX32660/Source/GCC/gcc.mk
blob: 9732a102885f668a18067ae5d810b06ce5ac7ced (plain)
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
################################################################################
 # Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
 #
 # Permission is hereby granted, free of charge, to any person obtaining a
 # copy of this software and associated documentation files (the "Software"),
 # to deal in the Software without restriction, including without limitation
 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
 # and/or sell copies of the Software, and to permit persons to whom the
 # Software is furnished to do so, subject to the following conditions:
 #
 # The above copyright notice and this permission notice shall be included
 # in all copies or substantial portions of the Software.
 #
 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 # IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
 # OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 # OTHER DEALINGS IN THE SOFTWARE.
 #
 # Except as contained in this notice, the name of Maxim Integrated
 # Products, Inc. shall not be used except as stated in the Maxim Integrated
 # Products, Inc. Branding Policy.
 #
 # The mere transfer of this software does not imply any licenses
 # of trade secrets, proprietary technology, copyrights, patents,
 # trademarks, maskwork rights, or any other form of intellectual
 # property whatsoever. Maxim Integrated Products, Inc. retains all
 # ownership rights.
 #
 # $Date: 2018-12-18 15:37:22 -0600 (Tue, 18 Dec 2018) $ 
 # $Revision: 40072 $
 #
 ###############################################################################

# The build directory
ifeq "$(BUILD_DIR)" ""
BUILD_DIR=$(CURDIR)/build
endif

# Create output object file names
SRCS_NOPATH := $(foreach NAME,$(SRCS),$(basename $(notdir $(NAME))).c)
OBJS_NOPATH := $(SRCS_NOPATH:.c=.o)
OBJS        := $(OBJS_NOPATH:%.o=$(BUILD_DIR)/%.o)

################################################################################
# Goals

# The default goal, which causes the example to be built.
.DEFAULT_GOAL :=
.PHONY: all
all: mkbuildir
all: ${BUILD_DIR}/${PROJECT}.elf

# Goal to build for release without debug
.PHONY: release
release: mkbuildir
release: ${BUILD_DIR}/${PROJECT}.elf
release: ${BUILD_DIR}/${PROJECT}.srec
release: ${BUILD_DIR}/${PROJECT}.hex
release: ${BUILD_DIR}/${PROJECT}.bin
release: ${BUILD_DIR}/${PROJECT}.dasm

# The goal to build as a library
.PHONY: lib
lib: mkbuildir
lib: ${BUILD_DIR}/${PROJECT}.a

# The goal to create the target directory.
.PHONY: mkbuildir
mkbuildir:
	@mkdir -p ${BUILD_DIR}

# The goal to clean out all the build products.
.PHONY: clean
clean:
	@rm -rf ${BUILD_DIR} ${wildcard *~}

${BUILD_DIR}/${PROJECT}.elf: ${LIBS} ${OBJS} ${LINKERFILE}
${BUILD_DIR}/${PROJECT}.a: ${OBJS}

# Create a goal to exercise the library build dependencies
.PHONY: FORCE
FORCE:

# Include the automatically generated dependency files.
ifneq (${MAKECMDGOALS},clean)
-include ${wildcard ${BUILD_DIR}/*.d} __dummy__
endif

################################################################################
# Get the operating system name.  If this is Cygwin, the .d files will be
# munged to convert c: into /cygdrive/c so that "make" will be happy with the
# auto-generated dependencies. Also if this is Cygwin, file paths for ARM GCC
# will be converted from /cygdrive/c to C:.
################################################################################
ifneq ($(findstring CYGWIN, ${shell uname -s}), )
CYGWIN=True
endif

# Get the prefix for the tools to use.
ifeq "$(TOOL_DIR)" ""
PREFIX=arm-none-eabi
else
PREFIX=$(TOOL_DIR)/arm-none-eabi
endif

# The command for calling the compiler.
CC=${PREFIX}-gcc
CXX=${PREFIX}-g++

# Discover if we are using GCC > 4.8.0
GCCVERSIONGTEQ4 := $(shell expr `gcc -dumpversion | cut -f1 -d.` \> 4)
ifeq "$(GCCVERSIONGTEQ4)" "0"
GCCVERSIONGTEQ4 := $(shell expr `gcc -dumpversion | cut -f1 -d.` \>= 4)
ifeq "$(GCCVERSIONGTEQ4)" "1"
GCCVERSIONGTEQ4 := $(shell expr `gcc -dumpversion | cut -f2 -d.` \>= 8)
endif

endif

# The flags passed to the assembler.
AFLAGS=-mthumb         \
       -mcpu=cortex-m4 \
       -MD
ifneq "$(HEAP_SIZE)" ""
AFLAGS+=-D__HEAP_SIZE=$(HEAP_SIZE)
endif
ifneq "$(STACK_SIZE)" ""
AFLAGS+=-D__STACK_SIZE=$(STACK_SIZE)
endif
AFLAGS+=$(PROJ_AFLAGS)

ifeq "$(MXC_OPTIMIZE_CFLAGS)" ""
# Default is optimize for size
MXC_OPTIMIZE_CFLAGS = -Os   
endif

# The flags passed to the compiler.
# fno-isolate-erroneous-paths-dereference disables the check for pointers with the value of 0
#  add this below when arm-none-eabi-gcc version is past 4.8 -fno-isolate-erroneous-paths-dereference                                \

CFLAGS=-mthumb                                                                 \
       -mcpu=cortex-m4                                                         \
       -mfloat-abi=hard                                                        \
       -mfpu=fpv4-sp-d16                                                       \
       -Wa,-mimplicit-it=thumb                                                 \
       $(MXC_OPTIMIZE_CFLAGS)                                                  \
       -fsingle-precision-constant                                             \
       -ffunction-sections                                                     \
       -fdata-sections                                                         \
       -MD                                                                     \
       -Wall                                                                   \
       -Wdouble-promotion													   \
       -Wno-format                                                             \
       -c

# The flags passed to the C++ compiler.
CXXFLAGS= \
	-mthumb					\
	-mcpu=cortex-m4				\
	-mfloat-abi=hard			\
	-mfpu=fpv4-sp-d16			\
	-Wa,-mimplicit-it=thumb			\
	$(MXC_OPTIMIZE_CFLAGS)			\
	-ffunction-sections			\
	-fdata-sections				\
	-MD					\
	-Wall					\
	-Wno-format				\
	-fno-rtti				\
	-fno-exceptions				\
	-std=c++11				\
	-c

# On GCC version > 4.8.0 use the -fno-isolate-erroneous-paths-dereference flag
ifeq "$(GCCVERSIONGTEQ4)" "1"
CFLAGS += -fno-isolate-erroneous-paths-dereference
endif

ifneq "$(TARGET)" ""
# Turn TARGET into a number for use within source files (e.g. MAX32650 -> 32650)
CFLAGS+=-DTARGET=$(shell echo $(TARGET) | tr -d '[:alpha:]')
CXXFLAGS+=-DTARGET=$(shell echo $(TARGET) | tr -d '[:alpha:]')
endif

ifneq "$(TARGET_REV)" ""
CFLAGS+=-DTARGET_REV=$(TARGET_REV)
CXXFLAGS+=-DTARGET_REV=$(TARGET_REV)
endif

# Exclude debug for 'release' builds
ifneq (${MAKECMDGOALS},release)
ifneq (${DEBUG},0)
CFLAGS+=-g3 -ggdb -DDEBUG
endif
endif

CFLAGS+=$(PROJ_CFLAGS)
CXXFLAGS+=$(PROJ_CFLAGS)

# The command for calling the library archiver.
AR=${PREFIX}-ar

# The command for calling the linker.
LD=${PREFIX}-gcc

# The flags passed to the linker.
LDFLAGS=-mthumb                                                                \
        -mcpu=cortex-m4                                                        \
        -mfloat-abi=hard                                                       \
        -mfpu=fpv4-sp-d16                                                      \
        -Xlinker --gc-sections                                                 \
	-Xlinker -Map -Xlinker ${BUILD_DIR}/$(PROJECT).map
LDFLAGS+=$(PROJ_LDFLAGS)

# Include math library
STD_LIBS=-lc -lm

# Determine if any C++ files are in the project sources, and add libraries as appropriate
ifneq "$(findstring cpp, ${SRCS})" ""
STD_LIBS+=-lsupc++ -lstdc++
endif

# Finally, resolve any newlib system calls with libnosys
STD_LIBS+=-lnosys

PROJ_LIBS:=$(addprefix -l, $(PROJ_LIBS))

# The command for extracting images from the linked executables.
OBJCOPY=${PREFIX}-objcopy
OBJDUMP=${PREFIX}-objdump

ifeq "$(CYGWIN)" "True"
fixpath=$(shell echo $(1) | sed -r 's/\/cygdrive\/([A-Na-n])/\U\1:/g' )
else
fixpath=$(1)
endif

# Add the include file paths to AFLAGS and CFLAGS.
AFLAGS+=${patsubst %,-I%,$(call fixpath,$(IPATH))}
CFLAGS+=${patsubst %,-I%,$(call fixpath,$(IPATH))}
CXXFLAGS+=${patsubst %,-I%,$(call fixpath,$(IPATH))}
LDFLAGS+=${patsubst %,-L%,$(call fixpath,$(LIBPATH))}

################################################################################
# The rule for building the object file from each C source file.
${BUILD_DIR}/%.o: %.c
	@if [ 'x${ECLIPSE}' != x ]; 																			\
	then 																									\
		echo ${CC} ${CFLAGS} -o $(call fixpath,${@}) $(call fixpath,${<}) | sed 's/-I\/\(.\)\//-I\1:\//g' ; \
	elif [ 'x${VERBOSE}' != x ];                                               								\
	then 																									\
	    echo ${CC} ${CFLAGS} -o $(call fixpath,${@}) $(call fixpath,${<});     								\
	else                                                                       								\
	    echo "  CC    ${<}";                                                   								\
	fi
	@${CC} ${CFLAGS} -o $(call fixpath,${@}) $(call fixpath,${<})
ifeq "$(CYGWIN)" "True"
	@sed -i -r -e 's/([A-Na-n]):/\/cygdrive\/\L\1/g' -e 's/\\([A-Za-z])/\/\1/g' ${@:.o=.d}
endif

# The rule to build an object file from a C++ source file
${BUILD_DIR}/%.o: %.cpp
	@if [ 'x${ECLIPSE}' != x ]; 																			\
	then 																									\
		echo ${CXX} ${CXXFLAGS} -o $(call fixpath,${@}) $(call fixpath,${<}) | sed 's/-I\/\(.\)\//-I\1:\//g' ; \
	elif [ 'x${VERBOSE}' != x ];                                               								\
	then 																									\
	    echo ${CXX} ${CXXFLAGS} -o $(call fixpath,${@}) $(call fixpath,${<});     								\
	else                                                                       								\
	    echo "  CXX    ${<}";                                                   								\
	fi
	@${CXX} ${CXXFLAGS} -o $(call fixpath,${@}) $(call fixpath,${<})
ifeq "$(CYGWIN)" "True"
	@sed -i -r -e 's/([A-Na-n]):/\/cygdrive\/\L\1/g' -e 's/\\([A-Za-z])/\/\1/g' ${@:.o=.d}
endif

# The rule for building the object file from each assembly source file.
${BUILD_DIR}/%.o: %.S
	@if [ 'x${VERBOSE}' = x ];                                                   \
	 then                                                                        \
	     echo "  AS    ${<}";                                                    \
	 else                                                                        \
	     echo ${CC} ${AFLAGS} -o $(call fixpath,${@}) -c $(call fixpath,${<});   \
	 fi
	@${CC} ${AFLAGS} -o $(call fixpath,${@}) -c $(call fixpath,${<})
ifeq "$(CYGWIN)" "True"
	@sed -i -r -e 's/([A-Na-n]):/\/cygdrive\/\L\1/g' -e 's/\\([A-Za-z])/\/\1/g' ${@:.o=.d}
endif

# The rule for creating an object library.
${BUILD_DIR}/%.a:
	@if [ 'x${VERBOSE}' = x ];                                                   \
	 then                                                                        \
	     echo "  AR    ${@}";                                                    \
	 else                                                                        \
	     echo ${AR} -cr $(call fixpath,${@}) $(call fixpath,${^});               \
	 fi
	@${AR} -cr $(call fixpath,${@}) $(call fixpath,${^})

# The rule for linking the application.
${BUILD_DIR}/%.elf:
	@if [ 'x${VERBOSE}' = x ];                                                   \
	 then                                                                        \
	     echo "  LD    ${@} ${LNK_SCP}";                                         \
	 else                                                                        \
	     echo ${LD} -T $(call fixpath,${LINKERFILE})                             \
	          --entry ${ENTRY}                                                   \
	          $(call fixpath,${LDFLAGS})                                         \
	          -o $(call fixpath,${@})                                            \
	          $(call fixpath,$(filter %.o, ${^}))                                \
	          -Xlinker --start-group                                             \
	          $(call fixpath,$(filter %.a, ${^}))                                \
	          ${PROJ_LIBS}                                                       \
	          ${STD_LIBS}                                                        \
	          -Xlinker --end-group;                                              \
	 fi;                                                                         \
	${LD} -T $(call fixpath,${LINKERFILE})                                       \
	      --entry ${ENTRY}                                                       \
	      $(call fixpath,${LDFLAGS})                                             \
	      -o $(call fixpath,${@})                                                \
	      $(call fixpath,$(filter %.o, ${^}))                                    \
	      -Xlinker --start-group                                                 \
	      $(call fixpath,$(filter %.a, ${^}))                                    \
	      ${PROJ_LIBS}                                                           \
	      ${STD_LIBS}                                                            \
	      -Xlinker --end-group

# Create S-Record output file
%.srec: %.elf
	@if [ 'x${VERBOSE}' = x ];                                                   \
	 then                                                                        \
	     echo "Creating ${@}";                                                   \
	 else                                                                        \
	     echo ${OBJCOPY} -O srec $(call fixpath,${<}) $(call fixpath,${@});      \
	 fi
	@$(OBJCOPY) -O srec $< $(call fixpath,${@})

# Create Intex Hex output file
%.hex: %.elf
	@if [ 'x${VERBOSE}' = x ];                                                   \
	 then                                                                        \
	     echo "Creating ${@}";                                                   \
	 else                                                                        \
	     echo ${OBJCOPY} -O ihex $(call fixpath,${<}) $(call fixpath,${@});      \
	 fi
	@$(OBJCOPY) -O ihex $< $(call fixpath,${@})

# Create binary output file
%.bin: %.elf
	@if [ 'x${VERBOSE}' = x ];                                                   \
	 then                                                                        \
	     echo "Creating ${@}";                                                   \
	 else                                                                        \
	     echo ${OBJCOPY} -O binary $(call fixpath,${<}) $(call fixpath,${@});    \
	 fi
	@$(OBJCOPY) -O binary $< $(call fixpath,${@})

# Create disassembly file
%.dasm: %.elf
	@if [ 'x${VERBOSE}' = x ];                                                   \
	 then                                                                        \
	     echo "Creating ${@}";                                                   \
	 else                                                                        \
	     echo $(OBJDUMP) -S $(call fixpath,${<}) $(call fixpath,${@});        \
	 fi
	@$(OBJDUMP) -S $< > $(call fixpath,${@})

################################################################################
.PHONY: debug
debug:
	@echo CYGWIN = ${CYGWIN}
	@echo
	@echo BUILD_DIR = ${BUILD_DIR}
	@echo
	@echo SRCS = ${SRCS}
	@echo
	@echo SRCS_NOPATH = ${SRCS_NOPATH}
	@echo
	@echo OBJS_NOPATH = ${OBJS_NOPATH}
	@echo
	@echo OBJS = ${OBJS}
	@echo
	@echo LIBS = ${LIBS}
	@echo
	@echo VPATH = ${VPATH}
	@echo
	@echo IPATH = ${IPATH}