1#******************************************************************************
2#
3# makedefs - Definitions common to all makefiles.
4#
5# Copyright (c) 2005-2012 Texas Instruments Incorporated.  All rights reserved.
6# Software License Agreement
7#
8#   Redistribution and use in source and binary forms, with or without
9#   modification, are permitted provided that the following conditions
10#   are met:
11#
12#   Redistributions of source code must retain the above copyright
13#   notice, this list of conditions and the following disclaimer.
14#
15#   Redistributions in binary form must reproduce the above copyright
16#   notice, this list of conditions and the following disclaimer in the
17#   documentation and/or other materials provided with the
18#   distribution.
19#
20#   Neither the name of Texas Instruments Incorporated nor the names of
21#   its contributors may be used to endorse or promote products derived
22#   from this software without specific prior written permission.
23#
24# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35#
36# This is part of revision 9453 of the Stellaris Firmware Development Package.
37#
38#******************************************************************************
39
40#******************************************************************************
41#
42# Get the operating system name.  If this is Cygwin, the .d files will be
43# munged to convert c: into /cygdrive/c so that "make" will be happy with the
44# auto-generated dependencies.
45#
46#******************************************************************************
47os:=${shell uname -s}
48
49#******************************************************************************
50#
51# The compiler to be used.
52#
53#******************************************************************************
54ifndef COMPILER
55COMPILER=gcc
56endif
57
58#******************************************************************************
59#
60# Definitions for using GCC.
61#
62#******************************************************************************
63ifeq (${COMPILER}, gcc)
64
65#
66# Get the prefix for the tools to use.  Use arm-stellaris-eabi if it exists,
67# otherwise fall back to arm-none-eabi.
68#
69PREFIX=${shell type arm-stellaris-eabi-gcc > /dev/null 2>&1 && \
70         echo arm-stellaris-eabi || echo arm-none-eabi}
71
72#
73# The command for calling the compiler.
74#
75CC=${PREFIX}-gcc
76
77#
78# The location of the C compiler
79# ARMGCC_ROOT is used by some makefiles that need to know where the compiler
80# is installed.  It is not used further for normal stellarisware apps
81#
82ARMGCC_ROOT:=${shell dirname '${shell sh -c "which ${CC}"}'}/..
83
84#
85# Determine the compiler CPU/FPU options based on the processor variant.
86#
87ifndef VARIANT
88CPU=-mcpu=cortex-m3
89FPU=
90else
91ifeq (${VARIANT}, cm3)
92CPU=-mcpu=cortex-m3
93FPU=
94else
95ifeq (${VARIANT}, cm4f)
96CPU=-mcpu=cortex-m4
97FPU=-mfpu=fpv4-sp-d16 -mfloat-abi=softfp
98else
99$(error Unknown processor variant ${VARIANT}!)
100endif
101endif
102endif
103
104#
105# The flags passed to the assembler.
106#
107AFLAGS=-mthumb \
108       ${CPU}  \
109       ${FPU}  \
110       -MD
111
112#
113# The flags passed to the compiler.
114#
115CFLAGS=-mthumb             \
116       ${CPU}              \
117       ${FPU}              \
118       -Os                 \
119       -ffunction-sections \
120       -fdata-sections     \
121       -MD                 \
122       -std=c99            \
123       -Wall               \
124       -pedantic           \
125       -DPART_${PART}      \
126       -c
127
128#
129# The command for calling the library archiver.
130#
131AR=${PREFIX}-ar
132
133#
134# The command for calling the linker.
135#
136LD=${PREFIX}-ld
137
138#
139# The flags passed to the linker.
140#
141LDFLAGS=--gc-sections
142
143#
144# Get the location of libgcc.a from the GCC front-end.
145#
146LIBGCC=${shell ${CC} ${CFLAGS} -print-libgcc-file-name}
147
148#
149# Get the location of libc.a from the GCC front-end.
150#
151LIBC=${shell ${CC} ${CFLAGS} -print-file-name=libc.a}
152
153#
154# Get the location of libm.a from the GCC front-end.
155#
156LIBM=${shell ${CC} ${CFLAGS} -print-file-name=libm.a}
157
158#
159# The command for extracting images from the linked executables.
160#
161OBJCOPY=${PREFIX}-objcopy
162
163#
164# Tell the compiler to include debugging information if the DEBUG environment
165# variable is set.
166#
167ifdef DEBUG
168CFLAGS+=-g -D DEBUG
169endif
170
171#
172# Add the tool specific CFLAGS.
173#
174CFLAGS+=${CFLAGSgcc}
175
176#
177# Add the include file paths to AFLAGS and CFLAGS.
178#
179AFLAGS+=${patsubst %,-I%,${subst :, ,${IPATH}}}
180CFLAGS+=${patsubst %,-I%,${subst :, ,${IPATH}}}
181
182#
183# The rule for building the object file from each C source file.
184#
185${COMPILER}${SUFFIX}/%.o: %.c
186	@if [ 'x${VERBOSE}' = x ];                            \
187	 then                                                 \
188	     echo "  CC    ${<}";                             \
189	 else                                                 \
190	     echo ${CC} ${CFLAGS} -D${COMPILER} -o ${@} ${<}; \
191	 fi
192	@${CC} ${CFLAGS} -D${COMPILER} -o ${@} ${<}
193ifneq ($(findstring CYGWIN, ${os}), )
194	@sed -i -r 's/ ([A-Za-z]):/ \/cygdrive\/\1/g' ${@:.o=.d}
195endif
196
197#
198# The rule for building the object file from each assembly source file.
199#
200${COMPILER}${SUFFIX}/%.o: %.S
201	@if [ 'x${VERBOSE}' = x ];                               \
202	 then                                                    \
203	     echo "  AS    ${<}";                                \
204	 else                                                    \
205	     echo ${CC} ${AFLAGS} -D${COMPILER} -o ${@} -c ${<}; \
206	 fi
207	@${CC} ${AFLAGS} -D${COMPILER} -o ${@} -c ${<}
208ifneq ($(findstring CYGWIN, ${os}), )
209	@sed -i -r 's/ ([A-Za-z]):/ \/cygdrive\/\1/g' ${@:.o=.d}
210endif
211
212#
213# The rule for creating an object library.
214#
215${COMPILER}${SUFFIX}/%.a:
216	@if [ 'x${VERBOSE}' = x ];     \
217	 then                          \
218	     echo "  AR    ${@}";      \
219	 else                          \
220	     echo ${AR} -cr ${@} ${^}; \
221	 fi
222	@${AR} -cr ${@} ${^}
223
224#
225# The rule for linking the application.
226#
227${COMPILER}${SUFFIX}/%.axf:
228	@if [ 'x${SCATTERgcc_${notdir ${@:.axf=}}}' = x ];                    \
229	 then                                                                 \
230	     ldname="${ROOT}/gcc/standalone.ld";                              \
231	 else                                                                 \
232	     ldname="${SCATTERgcc_${notdir ${@:.axf=}}}";                     \
233	 fi;                                                                  \
234	 if [ 'x${VERBOSE}' = x ];                                            \
235	 then                                                                 \
236	     echo "  LD    ${@} ${LNK_SCP}";                                  \
237	 else                                                                 \
238	     echo ${LD} -T $${ldname}                                         \
239	          --entry ${ENTRY_${notdir ${@:.axf=}}}                       \
240	          ${LDFLAGSgcc_${notdir ${@:.axf=}}}                          \
241	          ${LDFLAGS} -o ${@} $(filter %.o %.a, ${^})                  \
242	          '${LIBM}' '${LIBC}' '${LIBGCC}';                            \
243	 fi;                                                                  \
244	${LD} -T $${ldname}                                                   \
245	      --entry ${ENTRY_${notdir ${@:.axf=}}}                           \
246	      ${LDFLAGSgcc_${notdir ${@:.axf=}}}                              \
247	      ${LDFLAGS} -o ${@} $(filter %.o %.a, ${^})                      \
248	      '${LIBM}' '${LIBC}' '${LIBGCC}'
249	@${OBJCOPY} -O binary ${@} ${@:.axf=.bin}
250endif
251
252