forked from SPRESENSE/nuttx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure.sh
executable file
·304 lines (255 loc) · 8.04 KB
/
configure.sh
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
#!/usr/bin/env bash
# tools/configure.sh
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
set -e
WD=`test -d ${0%/*} && cd ${0%/*}; pwd`
TOPDIR="${WD}/.."
MAKECMD="make"
USAGE="
USAGE: ${0} [-E] [-e] [-l|m|c|g|n|B] [L] [-a <app-dir>] <board-name>:<config-name> [make-opts]
Where:
-E enforces distclean if already configured.
-e performs distclean if configuration changed.
-l selects the Linux (l) host environment.
-m selects the macOS (m) host environment.
-c selects the Windows host and Cygwin (c) environment.
-g selects the Windows host and MinGW/MSYS environment.
-n selects the Windows host and Windows native (n) environment.
-B selects the *BSD (B) host environment.
Default: Use host setup in the defconfig file
Default Windows: Cygwin
-L Lists all available configurations.
-a <app-dir> is the path to the apps/ directory, relative to the nuttx
directory
<board-name> is the name of the board in the boards directory
configs/<config-name> is the name of the board configuration sub-directory
make-opts directly pass to make
"
# A list of optional files that may be installed
OPTFILES="\
.gdbinit\
.cproject\
.project\
"
# Parse command arguments
unset boardconfig
unset winnative
unset appdir
unset host
unset enforce_distclean
unset distclean
function dumpcfgs
{
configlist=`find ${TOPDIR}/boards -name defconfig`
for defconfig in ${configlist}; do
config=`dirname ${defconfig} | sed -e "s,${TOPDIR}/boards/,,g"`
boardname=`echo ${config} | cut -d'/' -f3`
configname=`echo ${config} | cut -d'/' -f5`
echo " ${boardname}:${configname}"
done
}
while [ ! -z "$1" ]; do
case "$1" in
-a )
shift
appdir=$1
;;
-c | -g | -l | -m )
winnative=n
host+=" $1"
;;
-n )
winnative=y
host+=" $1"
;;
-B )
winnative=n
host+=" $1"
MAKECMD="gmake"
;;
-E )
enforce_distclean=y
;;
-e )
distclean=y
;;
-h )
echo "$USAGE"
exit 0
;;
-L )
dumpcfgs
exit 0
;;
*)
boardconfig=$1
shift
break
;;
esac
shift
done
# Sanity checking
if [ -z "${boardconfig}" ]; then
echo "" 1>&2
echo "Missing <board/config> argument" 1>&2
echo "$USAGE" 1>&2
exit 2
fi
configdir=`echo ${boardconfig} | cut -s -d':' -f2`
if [ -z "${configdir}" ]; then
boarddir=`echo ${boardconfig} | cut -d'/' -f1`
configdir=`echo ${boardconfig} | cut -d'/' -f2`
else
boarddir=`echo ${boardconfig} | cut -d':' -f1`
fi
configpath=${TOPDIR}/boards/*/*/${boarddir}/configs/${configdir}
if [ ! -d ${configpath} ]; then
# Try direct path used with custom configurations.
configpath=${TOPDIR}/${boardconfig}
if [ ! -d ${configpath} ]; then
configpath=${boardconfig}
if [ ! -d ${configpath} ]; then
echo "Directory for ${boardconfig} does not exist." 1>&2
echo "" 1>&2
echo "Run tools/configure.sh -L to list available configurations." 1>&2
echo "$USAGE" 1>&2
exit 3
fi
fi
fi
src_makedefs=${TOPDIR}/boards/*/*/${boarddir}/configs/${configdir}/Make.defs
dest_makedefs="${TOPDIR}/Make.defs"
if [ ! -r ${src_makedefs} ]; then
src_makedefs=${TOPDIR}/boards/*/*/${boarddir}/scripts/Make.defs
if [ ! -r ${src_makedefs} ]; then
src_makedefs=${configpath}/Make.defs
if [ ! -r ${src_makedefs} ]; then
src_makedefs=${configpath}/../../scripts/Make.defs
if [ ! -r ${src_makedefs} ]; then
echo "File Make.defs could not be found"
exit 4
fi
fi
fi
fi
src_config=${configpath}/defconfig
dest_config="${TOPDIR}/.config"
backup_config="${TOPDIR}/defconfig"
if [ ! -r ${src_config} ]; then
echo "File ${src_config} does not exist"
exit 5
fi
if [ -r ${dest_config} ]; then
if [ "X${enforce_distclean}" = "Xy" ]; then
${MAKECMD} -C ${TOPDIR} distclean
else
if cmp -s ${src_config} ${backup_config}; then
echo "No configuration change."
exit 0
fi
if [ "X${distclean}" = "Xy" ]; then
${MAKECMD} -C ${TOPDIR} distclean
else
echo "Already configured!"
echo "Please 'make distclean' and try again."
exit 6
fi
fi
fi
# Extract values needed from the defconfig file. We need:
# (1) The CONFIG_WINDOWS_NATIVE setting to know it this is target for a
# native Windows
# (2) The CONFIG_APPS_DIR setting to see if there is a configured location for the
# application directory. This can be overridden from the command line.
# If we are going to some host other than windows native or to a windows
# native host, then don't even check what is in the defconfig file.
oldnative=`grep CONFIG_WINDOWS_NATIVE= ${src_config} | cut -d'=' -f2`
if [ -z "${oldnative}" ]; then
oldnative=n
fi
if [ -z "${winnative}" ]; then
winnative=$oldnative
fi
# If no application directory was provided on the command line and we are
# switching between a windows native host and some other host then ignore the
# path to the apps/ directory in the defconfig file. It will most certainly
# not be in a usable form.
defappdir=y
if [ -z "${appdir}" -a "X$oldnative" = "X$winnative" ]; then
quoted=`grep "^CONFIG_APPS_DIR=" ${src_config} | cut -d'=' -f2`
if [ ! -z "${quoted}" ]; then
appdir=`echo ${quoted} | sed -e "s/\"//g"`
defappdir=n
fi
fi
# Check for the apps/ directory in the usual place if appdir was not provided
if [ -z "${appdir}" ]; then
# Check for a version file
unset CONFIG_VERSION_STRING
if [ -x "${TOPDIR}/.version" ]; then
. "${TOPDIR}/.version"
fi
# Check for an unversioned apps/ directory
if [ -d "${TOPDIR}/../apps" ]; then
appdir="../apps"
else
# Check for a versioned apps/ directory
if [ -d "${TOPDIR}/../apps-${CONFIG_VERSION_STRING}" ]; then
appdir="../apps-${CONFIG_VERSION_STRING}"
fi
fi
fi
# For checking the apps dir path, we need a POSIX version of the relative path.
posappdir=`echo "${appdir}" | sed -e 's/\\\\/\\//g'`
winappdir=`echo "${appdir}" | sed -e 's/\\//\\\\\\\/g'`
# If appsdir was provided (or discovered) then make sure that the apps/
# directory exists
if [ ! -z "${appdir}" -a ! -d "${TOPDIR}/${posappdir}" ]; then
echo "Directory \"${TOPDIR}/${posappdir}\" does not exist"
exit 7
fi
# Okay... Everything looks good. Setup the configuration
echo " Copy files"
ln -sf ${src_makedefs} ${dest_makedefs} || \
{ echo "Failed to symlink ${src_makedefs}" ; exit 8 ; }
install -m 644 ${src_config} "${dest_config}" || \
{ echo "Failed to copy ${src_config}" ; exit 9 ; }
install -m 644 ${src_config} "${backup_config}" || \
{ echo "Failed to backup ${src_config}" ; exit 10 ; }
# Install any optional files
for opt in ${OPTFILES}; do
test -f ${configpath}/${opt} && install ${configpath}/${opt} "${TOPDIR}/"
done
# If we did not use the CONFIG_APPS_DIR that was in the defconfig config file,
# then append the correct application information to the tail of the .config
# file
if [ "X${defappdir}" = "Xy" ]; then
# In-place edit can mess up permissions on Windows
# sed -i.bak -e "/^CONFIG_APPS_DIR/d" "${dest_config}"
sed -e "/^CONFIG_APPS_DIR/d" "${dest_config}" > "${dest_config}-temp"
mv "${dest_config}-temp" "${dest_config}"
if [ "X${winnative}" = "Xy" ]; then
echo "CONFIG_APPS_DIR=\"$winappdir\"" >> "${dest_config}"
else
echo "CONFIG_APPS_DIR=\"$posappdir\"" >> "${dest_config}"
fi
fi
# The saved defconfig files are all in compressed format and must be
# reconstitued before they can be used.
${TOPDIR}/tools/sethost.sh $host $*