forked from SPRESENSE/nuttx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsethost.sh
executable file
·223 lines (189 loc) · 5.29 KB
/
sethost.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
#!/usr/bin/env bash
# tools/sethost.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
progname=$0
host=
wenv=
MAKECMD="make"
function showusage {
echo ""
echo "USAGE: $progname [-l|m|c|g|n|B] [make-opts]"
echo " $progname -h"
echo ""
echo "Where:"
echo " -l|m|c|g|n|B selects Linux (l), macOS (m), Cygwin (c), BSD (B),"
echo " MSYS/MSYS2 (g) or Windows native (n). Default Linux"
echo " make-opts directly pass to make"
echo " -h will show this help test and terminate"
exit 1
}
# Parse command line
while [ ! -z "$1" ]; do
case $1 in
-l )
host=linux
;;
-c )
host=windows
wenv=cygwin
;;
-g )
host=windows
wenv=msys
;;
-m )
host=macos
;;
-n )
host=windows
wenv=native
;;
-B )
host=bsd
MAKECMD="gmake"
;;
-h )
showusage
;;
* )
break
;;
esac
shift
done
# If the host was not explicitly given, try to guess.
# Examples of "uname -s" outputs:
# macOS: Darwin
# Cygwin: CYGWIN_NT-10.0-WOW
# Linux: Linux
# MSYS: MINGW32_NT-6.2
# BSD: FreeBSD, OpenBSD, NetBSD, *BSD
if [ -z "$host" ]; then
case $(uname -s) in
Darwin)
host=macos
;;
*BSD)
host=bsd
MAKECMD="gmake"
;;
CYGWIN*)
host=windows
wenv=cygwin
;;
MINGW32*)
host=windows
wenv=msys
;;
*)
# Assume linux as a fallback
host=linux
;;
esac
fi
# Detect Host CPU type.
# At least MacOS and Linux can have x86_64 and arm based hosts.
if [ -z "$cpu" ]; then
case $(uname -m) in
arm64)
cpu=arm64
;;
aarch64)
cpu=arm64
;;
*)
# Assume x86_64 as default
cpu=x86_64
;;
esac
fi
WD=`test -d ${0%/*} && cd ${0%/*}; pwd`
cd $WD
if [ -x sethost.sh ]; then
cd ..
fi
if [ -x tools/sethost.sh ]; then
nuttx=$PWD
else
echo "This script must be executed in nuttx/ or nuttx/tools directories"
exit 1
fi
if [ ! -r $nuttx/.config ]; then
echo "There is no .config at $nuttx"
exit 1
fi
if [ ! -r $nuttx/Make.defs ]; then
echo "ERROR: No readable Make.defs file exists at $nuttx"
exit 1
fi
# Modify the configuration
if [ "X$host" == "Xlinux" -o "X$host" == "Xmacos" -o "X$host" == "Xbsd" ]; then
# Disable Windows (to suppress warnings from Window Environment selections)
kconfig-tweak --file $nuttx/.config --disable CONFIG_HOST_WINDOWS
# Enable Linux or macOS or BSD
if [ "X$host" == "Xlinux" ]; then
echo " Select CONFIG_HOST_LINUX=y"
kconfig-tweak --file $nuttx/.config --disable CONFIG_HOST_MACOS
kconfig-tweak --file $nuttx/.config --disable CONFIG_HOST_BSD
kconfig-tweak --file $nuttx/.config --enable CONFIG_HOST_LINUX
if [ "X$cpu" == "Xarm64" ]; then
echo " Select CONFIG_HOST_ARM64=y"
kconfig-tweak --file $nuttx/.config --enable CONFIG_HOST_ARM64
fi
elif [ "X$host" == "Xbsd" ]; then
echo " Select CONFIG_HOST_BSD=y"
kconfig-tweak --file $nuttx/.config --disable CONFIG_HOST_MACOS
kconfig-tweak --file $nuttx/.config --disable CONFIG_HOST_LINUX
kconfig-tweak --file $nuttx/.config --enable CONFIG_HOST_BSD
else
echo " Select CONFIG_HOST_MACOS=y"
kconfig-tweak --file $nuttx/.config --disable CONFIG_HOST_LINUX
kconfig-tweak --file $nuttx/.config --disable CONFIG_HOST_BSD
kconfig-tweak --file $nuttx/.config --enable CONFIG_HOST_MACOS
if [ "X$cpu" == "Xarm64" ]; then
echo " Select CONFIG_HOST_ARM64=y"
kconfig-tweak --file $nuttx/.config --enable CONFIG_HOST_ARM64
fi
fi
# Enable the System V ABI
kconfig-tweak --file $nuttx/.config --enable CONFIG_SIM_X8664_SYSTEMV
else
echo " Select CONFIG_HOST_WINDOWS=y"
kconfig-tweak --file $nuttx/.config --disable CONFIG_HOST_LINUX
kconfig-tweak --file $nuttx/.config --disable CONFIG_HOST_MACOS
kconfig-tweak --file $nuttx/.config --disable CONFIG_HOST_BSD
# Enable Windows and the Microsoft ABI
kconfig-tweak --file $nuttx/.config --enable CONFIG_HOST_WINDOWS
kconfig-tweak --file $nuttx/.config --enable CONFIG_SIM_X8664_MICROSOFT
# Enable Windows environment
if [ "X$wenv" == "Xcygwin" ]; then
echo " Select CONFIG_WINDOWS_CYGWIN=y"
kconfig-tweak --file $nuttx/.config --enable CONFIG_WINDOWS_CYGWIN
else
if [ "X$wenv" == "Xmsys" ]; then
echo " Select CONFIG_WINDOWS_MSYS=y"
kconfig-tweak --file $nuttx/.config --enable CONFIG_WINDOWS_MSYS
else
echo " Select CONFIG_WINDOWS_NATIVE=y"
kconfig-tweak --file $nuttx/.config --enable CONFIG_WINDOWS_NATIVE
fi
fi
fi
echo " Refreshing..."
${MAKECMD} olddefconfig $* || { echo "ERROR: failed to refresh"; exit 1; }