2019-08-10 17:57:26 +02:00
|
|
|
#!/usr/bin/env bash
|
2018-06-02 19:05:54 +02:00
|
|
|
# tools/configure.sh
|
2007-02-18 00:21:28 +01:00
|
|
|
#
|
2019-08-05 17:03:12 +02:00
|
|
|
# Copyright (C) 2007, 2008, 2011, 2015, 2017-2019 Gregory Nutt. All rights
|
2018-04-25 16:28:49 +02:00
|
|
|
# reserved.
|
2012-09-01 17:33:33 +02:00
|
|
|
# Author: Gregory Nutt <gnutt@nuttx.org>
|
2007-02-18 00:21:28 +01:00
|
|
|
#
|
|
|
|
# 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.
|
2008-08-29 17:36:02 +02:00
|
|
|
# 3. Neither the name NuttX nor the names of its contributors may be
|
2007-02-18 00:21:28 +01:00
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
|
2020-09-17 03:24:23 +02:00
|
|
|
set -e
|
|
|
|
|
2017-06-15 14:12:56 +02:00
|
|
|
WD=`test -d ${0%/*} && cd ${0%/*}; pwd`
|
2008-01-08 00:13:12 +01:00
|
|
|
TOPDIR="${WD}/.."
|
2011-03-19 14:28:07 +01:00
|
|
|
USAGE="
|
|
|
|
|
2020-10-18 15:28:35 +02:00
|
|
|
USAGE: ${0} [-E] [-e] [-l|m|c|g|n] [L] [-a <app-dir>] <board-name>:<config-name> [make-opts]
|
2011-03-19 14:28:07 +01:00
|
|
|
|
|
|
|
Where:
|
2020-08-20 18:30:03 +02:00
|
|
|
-E enforces distclean if already configured.
|
2020-08-20 14:37:10 +02:00
|
|
|
-e performs distclean if configuration changed.
|
2017-11-10 00:11:59 +01:00
|
|
|
-l selects the Linux (l) host environment.
|
|
|
|
-m selects the macOS (m) host environment.
|
|
|
|
-c selects the Windows host and Cygwin (c) environment.
|
2018-05-31 19:53:09 +02:00
|
|
|
-g selects the Windows host and MinGW/MSYS environment.
|
2017-11-10 00:11:59 +01:00
|
|
|
-n selects the Windows host and Windows native (n) environment.
|
|
|
|
Default: Use host setup in the defconfig file
|
|
|
|
Default Windows: Cygwin
|
2020-09-02 20:04:33 +02:00
|
|
|
-L Lists all available configurations.
|
2020-01-19 18:22:36 +01:00
|
|
|
-a <app-dir> is the path to the apps/ directory, relative to the nuttx
|
|
|
|
directory
|
2019-08-05 14:04:14 +02:00
|
|
|
<board-name> is the name of the board in the boards directory
|
2019-08-05 16:30:34 +02:00
|
|
|
configs/<config-name> is the name of the board configuration sub-directory
|
2020-03-20 05:08:27 +01:00
|
|
|
make-opts directly pass to make
|
2011-03-19 14:28:07 +01:00
|
|
|
|
|
|
|
"
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2017-06-15 16:24:28 +02:00
|
|
|
# A list of optional files that may be installed
|
|
|
|
|
|
|
|
OPTFILES="\
|
2017-06-15 17:59:32 +02:00
|
|
|
.gdbinit\
|
|
|
|
.cproject\
|
|
|
|
.project\
|
2017-06-15 16:24:28 +02:00
|
|
|
"
|
|
|
|
|
2011-03-18 18:22:50 +01:00
|
|
|
# Parse command arguments
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2011-03-18 18:22:50 +01:00
|
|
|
unset boardconfig
|
2020-01-19 18:29:34 +01:00
|
|
|
unset winnative
|
2011-03-18 18:22:50 +01:00
|
|
|
unset appdir
|
2017-07-10 17:38:45 +02:00
|
|
|
unset host
|
2020-08-20 14:37:10 +02:00
|
|
|
unset enforce_distclean
|
|
|
|
unset distclean
|
2011-03-18 18:22:50 +01:00
|
|
|
|
2020-09-02 20:04:33 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2011-03-18 18:22:50 +01:00
|
|
|
while [ ! -z "$1" ]; do
|
|
|
|
case "$1" in
|
2020-01-05 17:29:59 +01:00
|
|
|
-a )
|
|
|
|
shift
|
|
|
|
appdir=$1
|
|
|
|
;;
|
2020-10-18 15:28:35 +02:00
|
|
|
-c | -g | -l | -m )
|
2020-01-19 18:29:34 +01:00
|
|
|
winnative=n
|
|
|
|
host+=" $1"
|
|
|
|
;;
|
|
|
|
-n )
|
|
|
|
winnative=y
|
|
|
|
host+=" $1"
|
2020-01-05 17:29:59 +01:00
|
|
|
;;
|
2020-08-20 14:37:10 +02:00
|
|
|
-E )
|
|
|
|
enforce_distclean=y
|
|
|
|
;;
|
2020-03-19 19:09:45 +01:00
|
|
|
-e )
|
2020-08-20 14:37:10 +02:00
|
|
|
distclean=y
|
2020-01-05 17:29:59 +01:00
|
|
|
;;
|
|
|
|
-h )
|
|
|
|
echo "$USAGE"
|
|
|
|
exit 0
|
|
|
|
;;
|
2020-09-02 20:04:33 +02:00
|
|
|
-L )
|
|
|
|
dumpcfgs
|
|
|
|
exit 0
|
|
|
|
;;
|
2020-01-05 17:29:59 +01:00
|
|
|
*)
|
|
|
|
boardconfig=$1
|
2020-03-20 05:08:27 +01:00
|
|
|
shift
|
|
|
|
break
|
2020-01-05 17:29:59 +01:00
|
|
|
;;
|
2011-03-18 18:22:50 +01:00
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
|
|
|
# Sanity checking
|
|
|
|
|
|
|
|
if [ -z "${boardconfig}" ]; then
|
|
|
|
echo ""
|
2019-08-05 17:03:12 +02:00
|
|
|
echo "Missing <board/config> argument"
|
2011-03-18 18:22:50 +01:00
|
|
|
echo "$USAGE"
|
|
|
|
exit 2
|
2007-02-18 00:21:28 +01:00
|
|
|
fi
|
|
|
|
|
2019-08-06 00:53:39 +02:00
|
|
|
configdir=`echo ${boardconfig} | cut -s -d':' -f2`
|
|
|
|
if [ -z "${configdir}" ]; then
|
2019-08-06 16:36:40 +02:00
|
|
|
boarddir=`echo ${boardconfig} | cut -d'/' -f1`
|
|
|
|
configdir=`echo ${boardconfig} | cut -d'/' -f2`
|
2019-08-06 00:53:39 +02:00
|
|
|
else
|
|
|
|
boarddir=`echo ${boardconfig} | cut -d':' -f1`
|
|
|
|
fi
|
2019-08-05 17:03:12 +02:00
|
|
|
|
2020-01-16 02:16:14 +01:00
|
|
|
configpath=${TOPDIR}/boards/*/*/${boarddir}/configs/${configdir}
|
|
|
|
if [ ! -d ${configpath} ]; then
|
2019-08-06 18:39:12 +02:00
|
|
|
# Try direct path used with custom configurations.
|
2017-06-15 16:24:28 +02:00
|
|
|
|
2017-06-15 14:12:56 +02:00
|
|
|
configpath=${TOPDIR}/${boardconfig}
|
2020-01-16 02:16:14 +01:00
|
|
|
if [ ! -d ${configpath} ]; then
|
2020-09-02 20:04:33 +02:00
|
|
|
echo "Directory for ${boardconfig} does not exist."
|
2017-06-15 14:12:56 +02:00
|
|
|
echo ""
|
2020-09-02 20:04:33 +02:00
|
|
|
echo "Run tools/configure.sh -L to list available configurations."
|
2017-06-15 14:12:56 +02:00
|
|
|
echo "$USAGE"
|
2019-08-06 16:36:40 +02:00
|
|
|
exit 3
|
2017-06-15 14:12:56 +02:00
|
|
|
fi
|
2011-03-18 18:22:50 +01:00
|
|
|
fi
|
|
|
|
|
2020-01-16 02:16:14 +01:00
|
|
|
src_makedefs=${TOPDIR}/boards/*/*/${boarddir}/configs/${configdir}/Make.defs
|
2012-11-09 23:37:52 +01:00
|
|
|
dest_makedefs="${TOPDIR}/Make.defs"
|
|
|
|
|
2020-01-16 02:16:14 +01:00
|
|
|
if [ ! -r ${src_makedefs} ]; then
|
|
|
|
src_makedefs=${TOPDIR}/boards/*/*/${boarddir}/scripts/Make.defs
|
2017-07-11 01:00:54 +02:00
|
|
|
|
2020-01-16 02:16:14 +01:00
|
|
|
if [ ! -r ${src_makedefs} ]; then
|
|
|
|
src_makedefs=${TOPDIR}/${boardconfig}/Make.defs
|
|
|
|
if [ ! -r ${src_makedefs} ]; then
|
2020-10-21 09:34:15 +02:00
|
|
|
src_makedefs=${TOPDIR}/${boardconfig}/../../scripts/Make.defs
|
|
|
|
|
|
|
|
if [ ! -r ${src_makedefs} ]; then
|
|
|
|
echo "File Make.defs could not be found"
|
|
|
|
exit 4
|
|
|
|
fi
|
2019-08-06 16:36:40 +02:00
|
|
|
fi
|
2017-07-11 01:00:54 +02:00
|
|
|
fi
|
2007-02-18 00:21:28 +01:00
|
|
|
fi
|
|
|
|
|
2020-01-16 02:16:14 +01:00
|
|
|
src_config=${configpath}/defconfig
|
2012-11-09 23:37:52 +01:00
|
|
|
dest_config="${TOPDIR}/.config"
|
2020-03-19 19:09:45 +01:00
|
|
|
backup_config="${TOPDIR}/defconfig"
|
2012-11-09 23:37:52 +01:00
|
|
|
|
2020-01-16 02:16:14 +01:00
|
|
|
if [ ! -r ${src_config} ]; then
|
|
|
|
echo "File ${src_config} does not exist"
|
2019-08-06 16:36:40 +02:00
|
|
|
exit 5
|
2007-02-18 00:21:28 +01:00
|
|
|
fi
|
|
|
|
|
2020-03-19 18:35:04 +01:00
|
|
|
if [ -r ${dest_config} ]; then
|
2020-08-20 18:30:03 +02:00
|
|
|
if [ "X${enforce_distclean}" = "Xy" ]; then
|
2020-03-20 05:08:27 +01:00
|
|
|
make -C ${TOPDIR} distclean $*
|
2020-03-19 19:09:45 +01:00
|
|
|
else
|
2020-08-20 18:30:03 +02:00
|
|
|
if cmp -s ${src_config} ${backup_config}; then
|
|
|
|
echo "No configuration change."
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "X${distclean}" = "Xy" ]; then
|
|
|
|
make -C ${TOPDIR} distclean $*
|
|
|
|
else
|
|
|
|
echo "Already configured!"
|
2020-08-20 20:32:42 +02:00
|
|
|
echo "Please 'make distclean' and try again."
|
2020-08-20 18:30:03 +02:00
|
|
|
exit 6
|
|
|
|
fi
|
2020-03-19 19:09:45 +01:00
|
|
|
fi
|
2017-07-10 17:38:45 +02:00
|
|
|
fi
|
|
|
|
|
2012-09-03 17:16:32 +02:00
|
|
|
# Extract values needed from the defconfig file. We need:
|
2014-03-06 20:00:50 +01:00
|
|
|
# (1) The CONFIG_WINDOWS_NATIVE setting to know it this is target for a
|
2017-04-26 18:28:37 +02:00
|
|
|
# native Windows
|
2014-03-06 20:00:50 +01:00
|
|
|
# (2) The CONFIG_APPS_DIR setting to see if there is a configured location for the
|
2012-11-21 18:44:14 +01:00
|
|
|
# application directory. This can be overridden from the command line.
|
2012-09-03 17:16:32 +02:00
|
|
|
|
2020-04-08 14:45:35 +02:00
|
|
|
# If we are going to some host other than windows native or to a windows
|
2017-10-01 19:49:17 +02:00
|
|
|
# native host, then don't even check what is in the defconfig file.
|
|
|
|
|
2020-01-16 02:16:14 +01:00
|
|
|
oldnative=`grep CONFIG_WINDOWS_NATIVE= ${src_config} | cut -d'=' -f2`
|
2020-01-19 18:29:34 +01:00
|
|
|
if [ -z "${oldnative}" ]; then
|
|
|
|
oldnative=n
|
|
|
|
fi
|
|
|
|
if [ -z "${winnative}" ]; then
|
|
|
|
winnative=$oldnative
|
2017-10-01 19:49:17 +02:00
|
|
|
fi
|
|
|
|
|
2017-10-01 20:45:29 +02:00
|
|
|
# If no application directory was provided on the command line and we are
|
2017-10-01 19:49:17 +02:00
|
|
|
# switching between a windows native host and some other host then ignore the
|
2017-10-01 20:45:29 +02:00
|
|
|
# path to the apps/ directory in the defconfig file. It will most certainly
|
|
|
|
# not be in a usable form.
|
2012-09-03 17:16:32 +02:00
|
|
|
|
2012-09-06 03:19:05 +02:00
|
|
|
defappdir=y
|
2017-10-01 19:49:17 +02:00
|
|
|
if [ -z "${appdir}" -a "X$oldnative" = "$winnative" ]; then
|
2020-01-16 02:16:14 +01:00
|
|
|
quoted=`grep "^CONFIG_APPS_DIR=" ${src_config} | cut -d'=' -f2`
|
2015-08-11 16:33:14 +02:00
|
|
|
if [ ! -z "${quoted}" ]; then
|
2012-09-08 18:40:12 +02:00
|
|
|
appdir=`echo ${quoted} | sed -e "s/\"//g"`
|
2012-09-06 03:19:05 +02:00
|
|
|
defappdir=n
|
|
|
|
fi
|
2012-09-03 17:16:32 +02:00
|
|
|
fi
|
|
|
|
|
2012-09-04 02:54:09 +02:00
|
|
|
# Check for the apps/ directory in the usual place if appdir was not provided
|
2011-03-18 18:22:50 +01:00
|
|
|
|
|
|
|
if [ -z "${appdir}" ]; then
|
2011-03-20 23:07:56 +01:00
|
|
|
|
|
|
|
# Check for a version file
|
|
|
|
|
2011-04-14 19:28:21 +02:00
|
|
|
unset CONFIG_VERSION_STRING
|
2011-03-20 23:07:56 +01:00
|
|
|
if [ -x "${TOPDIR}/.version" ]; then
|
2011-08-28 14:32:14 +02:00
|
|
|
. "${TOPDIR}/.version"
|
2011-03-20 23:07:56 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Check for an unversioned apps/ directory
|
2014-04-14 00:22:22 +02:00
|
|
|
|
2011-03-18 18:22:50 +01:00
|
|
|
if [ -d "${TOPDIR}/../apps" ]; then
|
2011-03-19 14:28:07 +01:00
|
|
|
appdir="../apps"
|
2011-03-20 23:07:56 +01:00
|
|
|
else
|
|
|
|
# Check for a versioned apps/ directory
|
|
|
|
|
2011-04-14 19:28:21 +02:00
|
|
|
if [ -d "${TOPDIR}/../apps-${CONFIG_VERSION_STRING}" ]; then
|
|
|
|
appdir="../apps-${CONFIG_VERSION_STRING}"
|
2014-04-14 00:22:22 +02:00
|
|
|
fi
|
2011-03-18 18:22:50 +01:00
|
|
|
fi
|
2007-02-18 00:21:28 +01:00
|
|
|
fi
|
|
|
|
|
2012-11-21 18:44:14 +01:00
|
|
|
# For checking the apps dir path, we need a POSIX version of the relative path.
|
|
|
|
|
2012-11-21 20:54:44 +01:00
|
|
|
posappdir=`echo "${appdir}" | sed -e 's/\\\\/\\//g'`
|
2018-11-05 23:35:28 +01:00
|
|
|
winappdir=`echo "${appdir}" | sed -e 's/\\//\\\\\\\/g'`
|
2012-11-21 18:44:14 +01:00
|
|
|
|
2012-09-04 02:54:09 +02:00
|
|
|
# If appsdir was provided (or discovered) then make sure that the apps/
|
|
|
|
# directory exists
|
|
|
|
|
2012-11-21 18:44:14 +01:00
|
|
|
if [ ! -z "${appdir}" -a ! -d "${TOPDIR}/${posappdir}" ]; then
|
|
|
|
echo "Directory \"${TOPDIR}/${posappdir}\" does not exist"
|
2019-08-06 16:36:40 +02:00
|
|
|
exit 7
|
2012-09-04 02:54:09 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Okay... Everything looks good. Setup the configuration
|
2011-03-18 18:22:50 +01:00
|
|
|
|
2017-07-10 17:38:45 +02:00
|
|
|
echo " Copy files"
|
2020-01-16 02:16:14 +01:00
|
|
|
install -m 644 ${src_makedefs} "${dest_makedefs}" || \
|
|
|
|
{ echo "Failed to copy ${src_makedefs}" ; exit 8 ; }
|
|
|
|
install -m 644 ${src_config} "${dest_config}" || \
|
|
|
|
{ echo "Failed to copy ${src_config}" ; exit 9 ; }
|
2020-03-19 19:09:45 +01:00
|
|
|
install -m 644 ${src_config} "${backup_config}" || \
|
|
|
|
{ echo "Failed to backup ${src_config}" ; exit 10 ; }
|
2017-06-15 16:24:28 +02:00
|
|
|
|
|
|
|
# Install any optional files
|
|
|
|
|
|
|
|
for opt in ${OPTFILES}; do
|
2020-01-16 02:16:14 +01:00
|
|
|
test -f ${configpath}/${opt} && install ${configpath}/${opt} "${TOPDIR}/"
|
2017-06-15 16:24:28 +02:00
|
|
|
done
|
2011-03-18 18:22:50 +01:00
|
|
|
|
2012-09-08 18:40:12 +02:00
|
|
|
# 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
|
2014-05-25 15:38:32 +02:00
|
|
|
# In-place edit can mess up permissions on Windows
|
|
|
|
# sed -i -e "/^CONFIG_APPS_DIR/d" "${dest_config}"
|
|
|
|
sed -e "/^CONFIG_APPS_DIR/d" "${dest_config}" > "${dest_config}-temp"
|
|
|
|
mv "${dest_config}-temp" "${dest_config}"
|
|
|
|
|
2012-11-21 20:54:44 +01:00
|
|
|
if [ "X${winnative}" = "Xy" ]; then
|
2013-01-05 14:19:53 +01:00
|
|
|
echo "CONFIG_APPS_DIR=\"$winappdir\"" >> "${dest_config}"
|
2012-11-21 18:44:14 +01:00
|
|
|
else
|
2013-01-05 14:19:53 +01:00
|
|
|
echo "CONFIG_APPS_DIR=\"$posappdir\"" >> "${dest_config}"
|
2012-11-21 18:44:14 +01:00
|
|
|
fi
|
2014-04-14 00:22:22 +02:00
|
|
|
fi
|
2017-07-10 17:38:45 +02:00
|
|
|
|
|
|
|
# The saved defconfig files are all in compressed format and must be
|
|
|
|
# reconstitued before they can be used.
|
|
|
|
|
2020-03-21 11:14:41 +01:00
|
|
|
${TOPDIR}/tools/sethost.sh $host $*
|