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