2019-08-10 17:57:26 +02:00
|
|
|
#!/usr/bin/env bash
|
2016-08-04 00:31:35 +02:00
|
|
|
# tools/sethost.sh
|
|
|
|
#
|
2017-01-01 22:34:23 +01:00
|
|
|
# Copyright (C) 2016-2017 Gregory Nutt. All rights reserved.
|
2016-08-04 00:31:35 +02:00
|
|
|
# Author: Gregory Nutt <gnutt@nuttx.org>
|
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions
|
|
|
|
# are met:
|
|
|
|
#
|
|
|
|
# 1. Redistributions of source code must retain the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer.
|
|
|
|
# 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer in
|
|
|
|
# the documentation and/or other materials provided with the
|
|
|
|
# distribution.
|
|
|
|
# 3. Neither the name NuttX nor the names of its contributors may be
|
|
|
|
# used to endorse or promote products derived from this software
|
|
|
|
# without specific prior written permission.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
# POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
#
|
|
|
|
|
|
|
|
WD=$PWD
|
|
|
|
|
|
|
|
progname=$0
|
|
|
|
host=linux
|
|
|
|
wenv=cygwin
|
|
|
|
hsize=64
|
|
|
|
unset configfile
|
|
|
|
|
|
|
|
function showusage {
|
|
|
|
echo ""
|
2018-06-01 22:21:04 +02:00
|
|
|
echo "USAGE: $progname [-w|l|m] [-c|u|g|n] [-32|64] [<config>]"
|
2016-08-04 00:31:35 +02:00
|
|
|
echo " $progname -h"
|
|
|
|
echo ""
|
|
|
|
echo "Where:"
|
2018-06-01 22:21:04 +02:00
|
|
|
echo " -w|l|m selects Windows (w), Linux (l), or macOS (m). Default: Linux"
|
2018-05-31 19:53:09 +02:00
|
|
|
echo " -c|u|g|n selects Windows environment option: Cygwin (c), Ubuntu under"
|
|
|
|
echo " Windows 10 (u), MSYS/MSYS2 (g) or Windows native (n). Default Cygwin"
|
2017-01-01 22:34:23 +01:00
|
|
|
echo " -32|64 selects 32- or 64-bit host. Default 64"
|
2016-08-04 00:31:35 +02:00
|
|
|
echo " -h will show this help test and terminate"
|
|
|
|
echo " <config> selects configuration file. Default: .config"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
# Parse command line
|
|
|
|
|
|
|
|
while [ ! -z "$1" ]; do
|
|
|
|
case $1 in
|
|
|
|
-w )
|
2018-06-01 22:21:04 +02:00
|
|
|
host=windows
|
|
|
|
;;
|
2016-08-04 00:31:35 +02:00
|
|
|
-l )
|
2018-06-01 22:21:04 +02:00
|
|
|
host=linux
|
|
|
|
;;
|
2016-08-04 00:31:35 +02:00
|
|
|
-c )
|
2018-06-01 22:21:04 +02:00
|
|
|
host=windows
|
|
|
|
wenv=cygwin
|
|
|
|
;;
|
|
|
|
-g )
|
|
|
|
host=windows
|
|
|
|
wenv=msys
|
|
|
|
;;
|
2017-01-01 22:34:23 +01:00
|
|
|
-u )
|
2018-06-01 22:21:04 +02:00
|
|
|
host=windows
|
|
|
|
wenv=ubuntu
|
|
|
|
;;
|
|
|
|
-m )
|
|
|
|
host=macos
|
|
|
|
;;
|
2016-08-04 00:31:35 +02:00
|
|
|
-n )
|
2018-06-01 22:21:04 +02:00
|
|
|
host=windows
|
|
|
|
wenv=native
|
|
|
|
;;
|
2016-08-04 00:31:35 +02:00
|
|
|
-32 )
|
2018-06-01 22:21:04 +02:00
|
|
|
hsize=32
|
|
|
|
;;
|
2016-08-04 00:31:35 +02:00
|
|
|
-64 )
|
2018-06-01 22:21:04 +02:00
|
|
|
hsize=32
|
|
|
|
;;
|
2016-08-04 00:31:35 +02:00
|
|
|
-h )
|
2018-06-01 22:21:04 +02:00
|
|
|
showusage
|
|
|
|
;;
|
2016-08-04 00:31:35 +02:00
|
|
|
* )
|
2018-06-01 22:21:04 +02:00
|
|
|
configfile="$1"
|
|
|
|
shift
|
|
|
|
break;
|
|
|
|
;;
|
2016-08-04 00:31:35 +02:00
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ ! -z "$1" ]; then
|
|
|
|
echo "ERROR: Garbage at the end of line"
|
|
|
|
showusage
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -x sethost.sh ]; then
|
|
|
|
nuttx=$PWD/..
|
|
|
|
else
|
|
|
|
if [ -x tools/sethost.sh ]; then
|
|
|
|
nuttx=$PWD
|
|
|
|
else
|
|
|
|
echo "This script must be execute in nuttx/ or nutts/tools directories"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
rm -f $nuttx/SAVEconfig
|
|
|
|
rm -f $nuttx/SAVEMake.defs
|
|
|
|
|
|
|
|
unset dotconfig
|
|
|
|
if [ -z "$configfile" ]; then
|
|
|
|
dotconfig=y
|
|
|
|
else
|
2016-08-09 21:20:20 +02:00
|
|
|
if [ "X$configfile" = "X.config" ]; then
|
2016-08-04 00:31:35 +02:00
|
|
|
dotconfig=y
|
|
|
|
else
|
2016-08-09 21:20:20 +02:00
|
|
|
if [ "X$configfile" = "X$nuttx/.config" ]; then
|
2016-08-04 00:31:35 +02:00
|
|
|
dotconfig=y
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "X$dotconfig" = "Xy" ]; then
|
|
|
|
unset configfile
|
|
|
|
if [ -r $nuttx/.config ]; then
|
|
|
|
configfile=$nuttx/.config
|
|
|
|
else
|
|
|
|
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
|
|
|
|
else
|
|
|
|
if [ ! -r "$configfile" ]; then
|
|
|
|
echo "ERROR: No readable configuration file exists at $configfile"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
configdir=`dirname $configfile`
|
|
|
|
makedefs=$configdir/Make.defs
|
|
|
|
|
2016-08-09 21:20:20 +02:00
|
|
|
if [ ! -r $makedefs ]; then
|
2016-08-04 00:31:35 +02:00
|
|
|
echo "ERROR: No readable Make.defs file exists at $configdir"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2016-08-09 21:20:20 +02:00
|
|
|
if [ -f $nuttx/.config ]; then
|
2016-08-04 00:31:35 +02:00
|
|
|
mv $nuttx/.config $nuttx/SAVEconfig
|
|
|
|
fi
|
|
|
|
cp $configfile $nuttx/.config || \
|
|
|
|
{ echo "ERROR: cp to $nuttx/.config failed"; exit 1; }
|
|
|
|
|
2016-08-09 21:20:20 +02:00
|
|
|
if [ -f $nuttx/Make.defs ]; then
|
2016-08-04 00:31:35 +02:00
|
|
|
mv $nuttx/Make.defs $nuttx/SAVEMake.defs
|
|
|
|
fi
|
|
|
|
cp $makedefs $nuttx/Make.defs || \
|
|
|
|
{ echo "ERROR: cp to $nuttx/Make.defs failed"; exit 1; }
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Modify the configuration
|
|
|
|
|
2018-06-01 22:21:04 +02:00
|
|
|
if [ "X$host" == "Xlinux" -o "X$host" == "Xmacos" ]; then
|
2016-08-04 00:31:35 +02:00
|
|
|
|
2018-06-01 22:21:04 +02:00
|
|
|
# Enable Linux or macOS
|
|
|
|
|
|
|
|
if [ "X$host" == "Xlinux" ]; then
|
|
|
|
echo " Select CONFIG_HOST_LINUX=y"
|
|
|
|
|
|
|
|
kconfig-tweak --file $nuttx/.config --enable CONFIG_HOST_LINUX
|
|
|
|
kconfig-tweak --file $nuttx/.config --disable CONFIG_HOST_MACOS
|
|
|
|
else
|
|
|
|
echo " Select CONFIG_HOST_MACOS=y"
|
|
|
|
|
|
|
|
kconfig-tweak --file $nuttx/.config --disable CONFIG_HOST_LINUX
|
|
|
|
kconfig-tweak --file $nuttx/.config --enable CONFIG_HOST_MACOS
|
|
|
|
fi
|
2016-08-04 00:31:35 +02:00
|
|
|
|
2018-06-01 22:21:04 +02:00
|
|
|
# Disable all Windows options
|
|
|
|
|
|
|
|
kconfig-tweak --file $nuttx/.config --disable CONFIG_HOST_WINDOWS
|
2018-05-31 19:53:09 +02:00
|
|
|
kconfig-tweak --file $nuttx/.config --disable CONFIG_SIM_X8664_MICROSOFT
|
|
|
|
kconfig-tweak --file $nuttx/.config --enable CONFIG_SIM_X8664_SYSTEMV
|
|
|
|
|
2016-08-04 00:31:35 +02:00
|
|
|
kconfig-tweak --file $nuttx/.config --disable CONFIG_WINDOWS_NATIVE
|
|
|
|
kconfig-tweak --file $nuttx/.config --disable CONFIG_WINDOWS_CYGWIN
|
2017-01-01 22:34:23 +01:00
|
|
|
kconfig-tweak --file $nuttx/.config --disable CONFIG_WINDOWS_UBUNTU
|
2016-08-04 00:31:35 +02:00
|
|
|
kconfig-tweak --file $nuttx/.config --disable CONFIG_WINDOWS_MSYS
|
|
|
|
kconfig-tweak --file $nuttx/.config --disable CONFIG_WINDOWS_OTHER
|
|
|
|
|
|
|
|
kconfig-tweak --file $nuttx/.config --enable CONFIG_SIM_X8664_SYSTEMV
|
|
|
|
kconfig-tweak --file $nuttx/.config --disable CONFIG_SIM_X8664_MICROSOFT
|
|
|
|
kconfig-tweak --file $nuttx/.config --disable CONFIG_SIM_M32
|
|
|
|
else
|
|
|
|
echo " Select CONFIG_HOST_WINDOWS=y"
|
2018-06-01 22:21:04 +02:00
|
|
|
|
|
|
|
# Enable Windows
|
|
|
|
|
2016-08-04 00:31:35 +02:00
|
|
|
kconfig-tweak --file $nuttx/.config --enable CONFIG_HOST_WINDOWS
|
|
|
|
kconfig-tweak --file $nuttx/.config --disable CONFIG_HOST_LINUX
|
2018-06-01 22:21:04 +02:00
|
|
|
kconfig-tweak --file $nuttx/.config --disable CONFIG_HOST_MACOS
|
2016-08-04 00:31:35 +02:00
|
|
|
|
2018-05-31 19:53:09 +02:00
|
|
|
kconfig-tweak --file $nuttx/.config --enable CONFIG_SIM_X8664_MICROSOFT
|
|
|
|
kconfig-tweak --file $nuttx/.config --disable CONFIG_SIM_X8664_SYSTEMV
|
|
|
|
|
2018-06-01 22:21:04 +02:00
|
|
|
# Enable Windows environment
|
|
|
|
|
2018-05-31 19:53:09 +02:00
|
|
|
kconfig-tweak --file $nuttx/.config --disable CONFIG_WINDOWS_OTHER
|
2016-08-04 00:31:35 +02:00
|
|
|
if [ "X$wenv" == "Xcygwin" ]; then
|
|
|
|
echo " Select CONFIG_WINDOWS_CYGWIN=y"
|
|
|
|
kconfig-tweak --file $nuttx/.config --enable CONFIG_WINDOWS_CYGWIN
|
2018-05-31 19:53:09 +02:00
|
|
|
kconfig-tweak --file $nuttx/.config --disable CONFIG_WINDOWS_MSYS
|
2017-01-01 22:34:23 +01:00
|
|
|
kconfig-tweak --file $nuttx/.config --disable CONFIG_WINDOWS_UBUNTU
|
2016-08-04 00:31:35 +02:00
|
|
|
kconfig-tweak --file $nuttx/.config --disable CONFIG_WINDOWS_NATIVE
|
|
|
|
else
|
|
|
|
kconfig-tweak --file $nuttx/.config --disable CONFIG_WINDOWS_CYGWIN
|
2018-05-31 19:53:09 +02:00
|
|
|
if [ "X$wenv" == "Xmsys" ]; then
|
|
|
|
echo " Select CONFIG_WINDOWS_MSYS=y"
|
|
|
|
kconfig-tweak --file $nuttx/.config --enable CONFIG_WINDOWS_MSYS
|
|
|
|
kconfig-tweak --file $nuttx/.config --disable CONFIG_WINDOWS_UBUNTU
|
2017-01-01 22:34:23 +01:00
|
|
|
kconfig-tweak --file $nuttx/.config --disable CONFIG_WINDOWS_NATIVE
|
|
|
|
else
|
2018-05-31 19:53:09 +02:00
|
|
|
kconfig-tweak --file $nuttx/.config --disable CONFIG_WINDOWS_MSYS
|
|
|
|
if [ "X$wenv" == "Xubuntu" ]; then
|
|
|
|
echo " Select CONFIG_WINDOWS_UBUNTU=y"
|
|
|
|
kconfig-tweak --file $nuttx/.config --enable CONFIG_WINDOWS_UBUNTU
|
|
|
|
kconfig-tweak --file $nuttx/.config --disable CONFIG_WINDOWS_NATIVE
|
|
|
|
else
|
|
|
|
echo " Select CONFIG_WINDOWS_NATIVE=y"
|
|
|
|
kconfig-tweak --file $nuttx/.config --disable CONFIG_WINDOWS_UBUNTU
|
|
|
|
kconfig-tweak --file $nuttx/.config --enable CONFIG_WINDOWS_NATIVE
|
|
|
|
fi
|
2017-01-01 22:34:23 +01:00
|
|
|
fi
|
2016-08-04 00:31:35 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "X$hsize" == "X32" ]; then
|
|
|
|
kconfig-tweak --file $nuttx/.config --enable CONFIG_SIM_M32
|
|
|
|
else
|
|
|
|
kconfig-tweak --file $nuttx/.config --disable CONFIG_SIM_M32
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2018-06-01 21:25:50 +02:00
|
|
|
kconfig-tweak --file $nuttx/.config --disable CONFIG_HOST_MACOS
|
2016-08-04 00:31:35 +02:00
|
|
|
kconfig-tweak --file $nuttx/.config --disable CONFIG_HOST_OTHER
|
|
|
|
|
|
|
|
echo " Refreshing..."
|
|
|
|
cd $nuttx || { echo "ERROR: failed to cd to $nuttx"; exit 1; }
|
|
|
|
make clean_context 1>/dev/null 2>&1
|
|
|
|
make olddefconfig 1>/dev/null 2>&1
|
|
|
|
|
2016-08-04 20:59:33 +02:00
|
|
|
# Move config file to correct location and restore any previous .config
|
|
|
|
# and Make.defs files
|
2016-08-04 00:31:35 +02:00
|
|
|
|
|
|
|
if [ "X$dotconfig" != "Xy" ]; then
|
|
|
|
sed -i -e "s/^CONFIG_APPS_DIR/# CONFIG_APPS_DIR/g" .config
|
|
|
|
|
|
|
|
mv .config $configfile || \
|
|
|
|
{ echo "ERROR: Failed to move .conig to $configfile"; exit 1; }
|
|
|
|
|
|
|
|
if [ -e SAVEconfig ]; then
|
|
|
|
mv SAVEconfig .config || \
|
|
|
|
{ echo "ERROR: Failed to move SAVEconfig to .config"; exit 1; }
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -e SAVEMake.defs ]; then
|
|
|
|
mv SAVEMake.defs Make.defs || \
|
|
|
|
{ echo "ERROR: Failed to move SAVEMake.defs to Make.defs"; exit 1; }
|
|
|
|
fi
|
2016-08-09 21:20:20 +02:00
|
|
|
fi
|