2019-08-10 23:57:26 +08:00
|
|
|
#!/usr/bin/env bash
|
2016-08-04 06:31:35 +08:00
|
|
|
# tools/sethost.sh
|
|
|
|
#
|
2020-04-28 01:22:40 +08:00
|
|
|
# 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
|
2016-08-04 06:31:35 +08:00
|
|
|
#
|
2020-04-28 01:22:40 +08:00
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
2016-08-04 06:31:35 +08:00
|
|
|
#
|
2020-04-28 01:22:40 +08:00
|
|
|
# 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.
|
2016-08-04 06:31:35 +08:00
|
|
|
#
|
|
|
|
|
2020-09-17 09:24:23 +08:00
|
|
|
set -e
|
|
|
|
|
2016-08-04 06:31:35 +08:00
|
|
|
progname=$0
|
2020-02-06 15:16:53 +08:00
|
|
|
host=
|
|
|
|
wenv=
|
2021-10-17 00:30:54 +08:00
|
|
|
MAKECMD="make"
|
2016-08-04 06:31:35 +08:00
|
|
|
|
|
|
|
function showusage {
|
2020-01-06 00:29:59 +08:00
|
|
|
echo ""
|
2021-10-17 00:30:54 +08:00
|
|
|
echo "USAGE: $progname [-l|m|c|g|n|B] [make-opts]"
|
2020-01-06 00:29:59 +08:00
|
|
|
echo " $progname -h"
|
|
|
|
echo ""
|
|
|
|
echo "Where:"
|
2021-10-17 00:30:54 +08:00
|
|
|
echo " -l|m|c|g|n|B selects Linux (l), macOS (m), Cygwin (c), BSD (B),"
|
2020-10-18 21:28:35 +08:00
|
|
|
echo " MSYS/MSYS2 (g) or Windows native (n). Default Linux"
|
2020-03-20 12:08:27 +08:00
|
|
|
echo " make-opts directly pass to make"
|
2020-01-06 00:29:59 +08:00
|
|
|
echo " -h will show this help test and terminate"
|
|
|
|
exit 1
|
2016-08-04 06:31:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
# Parse command line
|
|
|
|
|
|
|
|
while [ ! -z "$1" ]; do
|
2020-01-06 00:29:59 +08:00
|
|
|
case $1 in
|
|
|
|
-l )
|
|
|
|
host=linux
|
|
|
|
;;
|
|
|
|
-c )
|
|
|
|
host=windows
|
|
|
|
wenv=cygwin
|
|
|
|
;;
|
|
|
|
-g )
|
|
|
|
host=windows
|
|
|
|
wenv=msys
|
|
|
|
;;
|
|
|
|
-m )
|
|
|
|
host=macos
|
|
|
|
;;
|
|
|
|
-n )
|
|
|
|
host=windows
|
|
|
|
wenv=native
|
|
|
|
;;
|
2021-10-17 00:30:54 +08:00
|
|
|
-B )
|
|
|
|
host=bsd
|
|
|
|
MAKECMD="gmake"
|
|
|
|
;;
|
2020-01-06 00:29:59 +08:00
|
|
|
-h )
|
|
|
|
showusage
|
|
|
|
;;
|
|
|
|
* )
|
2020-03-20 12:08:27 +08:00
|
|
|
break
|
2020-01-06 00:29:59 +08:00
|
|
|
;;
|
2016-08-04 06:31:35 +08:00
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2020-02-06 15:16:53 +08:00
|
|
|
# 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
|
2023-10-24 18:29:05 +08:00
|
|
|
# MSYS2: MSYS_NT-6.3-9600
|
2021-10-17 00:30:54 +08:00
|
|
|
# BSD: FreeBSD, OpenBSD, NetBSD, *BSD
|
2020-03-29 01:04:23 +08:00
|
|
|
|
2020-02-06 15:16:53 +08:00
|
|
|
if [ -z "$host" ]; then
|
|
|
|
case $(uname -s) in
|
|
|
|
Darwin)
|
|
|
|
host=macos
|
|
|
|
;;
|
2021-10-17 00:30:54 +08:00
|
|
|
*BSD)
|
|
|
|
host=bsd
|
|
|
|
MAKECMD="gmake"
|
|
|
|
;;
|
2020-02-06 15:16:53 +08:00
|
|
|
CYGWIN*)
|
|
|
|
host=windows
|
|
|
|
wenv=cygwin
|
|
|
|
;;
|
|
|
|
MINGW32*)
|
|
|
|
host=windows
|
|
|
|
wenv=msys
|
|
|
|
;;
|
2023-10-24 18:29:05 +08:00
|
|
|
MSYS*)
|
|
|
|
host=windows
|
|
|
|
wenv=msys
|
|
|
|
;;
|
2020-02-06 15:16:53 +08:00
|
|
|
*)
|
|
|
|
# Assume linux as a fallback
|
2020-03-29 01:04:23 +08:00
|
|
|
|
2020-02-06 15:16:53 +08:00
|
|
|
host=linux
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
|
2022-01-30 04:20:10 +08:00
|
|
|
# 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)
|
2022-02-03 06:36:23 +08:00
|
|
|
cpu=arm64
|
2022-01-30 04:20:10 +08:00
|
|
|
;;
|
|
|
|
aarch64)
|
2022-02-03 06:36:23 +08:00
|
|
|
cpu=arm64
|
2022-01-30 04:20:10 +08:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
# Assume x86_64 as default
|
|
|
|
cpu=x86_64
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
|
2020-03-19 10:41:36 +08:00
|
|
|
WD=`test -d ${0%/*} && cd ${0%/*}; pwd`
|
|
|
|
cd $WD
|
|
|
|
|
2016-08-04 06:31:35 +08:00
|
|
|
if [ -x sethost.sh ]; then
|
2020-03-20 12:08:27 +08:00
|
|
|
cd ..
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -x tools/sethost.sh ]; then
|
|
|
|
nuttx=$PWD
|
2016-08-04 06:31:35 +08:00
|
|
|
else
|
2020-03-29 01:04:23 +08:00
|
|
|
echo "This script must be executed in nuttx/ or nuttx/tools directories"
|
2020-03-20 12:08:27 +08:00
|
|
|
exit 1
|
2016-08-04 06:31:35 +08:00
|
|
|
fi
|
|
|
|
|
2020-03-19 11:47:34 +08:00
|
|
|
if [ ! -r $nuttx/.config ]; then
|
|
|
|
echo "There is no .config at $nuttx"
|
|
|
|
exit 1
|
2016-08-04 06:31:35 +08:00
|
|
|
fi
|
|
|
|
|
2020-03-19 11:47:34 +08:00
|
|
|
if [ ! -r $nuttx/Make.defs ]; then
|
|
|
|
echo "ERROR: No readable Make.defs file exists at $nuttx"
|
|
|
|
exit 1
|
2016-08-04 06:31:35 +08:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Modify the configuration
|
|
|
|
|
2021-10-17 00:30:54 +08:00
|
|
|
if [ "X$host" == "Xlinux" -o "X$host" == "Xmacos" -o "X$host" == "Xbsd" ]; then
|
2016-08-04 06:31:35 +08:00
|
|
|
|
2020-04-28 01:22:40 +08:00
|
|
|
# Disable Windows (to suppress warnings from Window Environment selections)
|
|
|
|
|
|
|
|
kconfig-tweak --file $nuttx/.config --disable CONFIG_HOST_WINDOWS
|
|
|
|
|
2021-10-17 00:30:54 +08:00
|
|
|
# Enable Linux or macOS or BSD
|
2018-06-02 04:21:04 +08:00
|
|
|
|
2020-01-06 00:29:59 +08:00
|
|
|
if [ "X$host" == "Xlinux" ]; then
|
|
|
|
echo " Select CONFIG_HOST_LINUX=y"
|
2020-04-28 01:22:40 +08:00
|
|
|
kconfig-tweak --file $nuttx/.config --disable CONFIG_HOST_MACOS
|
2021-10-17 00:30:54 +08:00
|
|
|
kconfig-tweak --file $nuttx/.config --disable CONFIG_HOST_BSD
|
2020-04-28 01:22:40 +08:00
|
|
|
kconfig-tweak --file $nuttx/.config --enable CONFIG_HOST_LINUX
|
2021-10-17 00:30:54 +08:00
|
|
|
|
2022-02-03 06:36:23 +08:00
|
|
|
if [ "X$cpu" == "Xarm64" ]; then
|
|
|
|
echo " Select CONFIG_HOST_ARM64=y"
|
|
|
|
kconfig-tweak --file $nuttx/.config --enable CONFIG_HOST_ARM64
|
2022-01-30 04:20:10 +08:00
|
|
|
fi
|
|
|
|
|
2021-10-17 00:30:54 +08:00
|
|
|
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
|
|
|
|
|
2020-01-06 00:29:59 +08:00
|
|
|
else
|
|
|
|
echo " Select CONFIG_HOST_MACOS=y"
|
2020-04-28 01:22:40 +08:00
|
|
|
kconfig-tweak --file $nuttx/.config --disable CONFIG_HOST_LINUX
|
2021-10-17 00:30:54 +08:00
|
|
|
kconfig-tweak --file $nuttx/.config --disable CONFIG_HOST_BSD
|
2020-04-28 01:22:40 +08:00
|
|
|
kconfig-tweak --file $nuttx/.config --enable CONFIG_HOST_MACOS
|
2022-01-30 04:20:10 +08:00
|
|
|
|
2022-02-03 06:36:23 +08:00
|
|
|
if [ "X$cpu" == "Xarm64" ]; then
|
|
|
|
echo " Select CONFIG_HOST_ARM64=y"
|
|
|
|
kconfig-tweak --file $nuttx/.config --enable CONFIG_HOST_ARM64
|
2022-01-30 04:20:10 +08:00
|
|
|
fi
|
2020-01-06 00:29:59 +08:00
|
|
|
fi
|
2016-08-04 06:31:35 +08:00
|
|
|
|
2020-04-28 01:22:40 +08:00
|
|
|
# Enable the System V ABI
|
2018-06-02 04:21:04 +08:00
|
|
|
|
2020-04-28 01:22:40 +08:00
|
|
|
kconfig-tweak --file $nuttx/.config --enable CONFIG_SIM_X8664_SYSTEMV
|
2016-08-04 06:31:35 +08:00
|
|
|
else
|
2020-01-06 00:29:59 +08:00
|
|
|
echo " Select CONFIG_HOST_WINDOWS=y"
|
2018-06-02 04:21:04 +08:00
|
|
|
|
2020-04-28 01:22:40 +08:00
|
|
|
kconfig-tweak --file $nuttx/.config --disable CONFIG_HOST_LINUX
|
|
|
|
kconfig-tweak --file $nuttx/.config --disable CONFIG_HOST_MACOS
|
2021-10-17 00:30:54 +08:00
|
|
|
kconfig-tweak --file $nuttx/.config --disable CONFIG_HOST_BSD
|
2018-06-02 04:21:04 +08:00
|
|
|
|
2020-04-28 01:22:40 +08:00
|
|
|
# Enable Windows and the Microsoft ABI
|
2016-08-04 06:31:35 +08:00
|
|
|
|
2020-04-28 01:22:40 +08:00
|
|
|
kconfig-tweak --file $nuttx/.config --enable CONFIG_HOST_WINDOWS
|
|
|
|
kconfig-tweak --file $nuttx/.config --enable CONFIG_SIM_X8664_MICROSOFT
|
2018-06-01 01:53:09 +08:00
|
|
|
|
2020-01-06 00:29:59 +08:00
|
|
|
# Enable Windows environment
|
2018-06-02 04:21:04 +08:00
|
|
|
|
2020-01-06 00:29:59 +08:00
|
|
|
if [ "X$wenv" == "Xcygwin" ]; then
|
|
|
|
echo " Select CONFIG_WINDOWS_CYGWIN=y"
|
2020-04-28 01:22:40 +08:00
|
|
|
kconfig-tweak --file $nuttx/.config --enable CONFIG_WINDOWS_CYGWIN
|
2020-01-06 00:29:59 +08:00
|
|
|
else
|
|
|
|
if [ "X$wenv" == "Xmsys" ]; then
|
|
|
|
echo " Select CONFIG_WINDOWS_MSYS=y"
|
2020-04-28 01:22:40 +08:00
|
|
|
kconfig-tweak --file $nuttx/.config --enable CONFIG_WINDOWS_MSYS
|
2016-08-04 06:31:35 +08:00
|
|
|
else
|
2020-10-18 21:28:35 +08:00
|
|
|
echo " Select CONFIG_WINDOWS_NATIVE=y"
|
2023-10-24 20:27:15 +08:00
|
|
|
kconfig-tweak --file $nuttx/.config --enable CONFIG_EXPERIMENTAL
|
2020-10-18 21:28:35 +08:00
|
|
|
kconfig-tweak --file $nuttx/.config --enable CONFIG_WINDOWS_NATIVE
|
2016-08-04 06:31:35 +08:00
|
|
|
fi
|
2020-01-06 00:29:59 +08:00
|
|
|
fi
|
2016-08-04 06:31:35 +08:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo " Refreshing..."
|
2020-03-24 03:15:18 +08:00
|
|
|
|
2021-10-17 00:30:54 +08:00
|
|
|
${MAKECMD} olddefconfig $* || { echo "ERROR: failed to refresh"; exit 1; }
|