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
|
|
|
#
|
2021-02-18 13:48:10 +01: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
|
2007-02-18 00:21:28 +01:00
|
|
|
#
|
2021-02-18 13:48:10 +01:00
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
2007-02-18 00:21:28 +01:00
|
|
|
#
|
2021-02-18 13:48:10 +01: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.
|
2007-02-18 00:21:28 +01:00
|
|
|
#
|
|
|
|
|
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}/.."
|
2021-10-16 18:30:54 +02:00
|
|
|
MAKECMD="make"
|
2011-03-19 14:28:07 +01:00
|
|
|
USAGE="
|
|
|
|
|
2024-04-14 04:07:08 +02:00
|
|
|
USAGE: ${0} [-E] [-e] [-l|m|c|g|n|B] [-L [boardname]] [-a <app-dir>] <board-selection> [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.
|
2021-10-16 18:30:54 +02:00
|
|
|
-B selects the *BSD (B) host environment.
|
2017-11-10 00:11:59 +01:00
|
|
|
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
|
2022-09-15 19:53:22 +02:00
|
|
|
<board-selection> is either:
|
|
|
|
For in-tree boards: a <board-name>:<config-name> pair where <board-name> is
|
|
|
|
the name of the board in the boards directory and <config-name> is the name
|
|
|
|
of the board configuration sub-directory (e.g. boardname:nsh), or: For
|
|
|
|
out-of-tree custom boards: a path to the board's configuration directory,
|
|
|
|
either relative to TOPDIR (e.g. ../mycustomboards/myboardname/config/nsh)
|
|
|
|
or an absolute path.
|
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
|
|
|
|
{
|
2024-04-14 04:07:08 +02:00
|
|
|
if [ -n "$1" ]; then
|
|
|
|
local boards=$(find ${TOPDIR}/boards -mindepth 3 -maxdepth 3 -type d -name "*$1*")
|
|
|
|
[ -z "$boards" ] && { echo board "$1" not found; return ;}
|
|
|
|
configlist=$(find $boards -name defconfig -type f)
|
|
|
|
else
|
|
|
|
configlist=$(find ${TOPDIR}/boards -name defconfig -type f)
|
|
|
|
fi
|
2020-09-02 20:04:33 +02:00
|
|
|
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
|
|
|
;;
|
2021-10-16 18:30:54 +02:00
|
|
|
-B )
|
|
|
|
winnative=n
|
|
|
|
host+=" $1"
|
|
|
|
MAKECMD="gmake"
|
|
|
|
;;
|
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 )
|
2024-04-14 04:07:08 +02:00
|
|
|
shift
|
|
|
|
dumpcfgs $1
|
2020-09-02 20:04:33 +02:00
|
|
|
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
|
2021-10-06 11:15:13 +02:00
|
|
|
echo "" 1>&2
|
|
|
|
echo "Missing <board/config> argument" 1>&2
|
|
|
|
echo "$USAGE" 1>&2
|
2011-03-18 18:22:50 +01:00
|
|
|
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-11-23 10:17:18 +01:00
|
|
|
configpath=${boardconfig}
|
|
|
|
if [ ! -d ${configpath} ]; then
|
2021-10-06 11:15:13 +02:00
|
|
|
echo "Directory for ${boardconfig} does not exist." 1>&2
|
|
|
|
echo "" 1>&2
|
|
|
|
echo "Run tools/configure.sh -L to list available configurations." 1>&2
|
|
|
|
echo "$USAGE" 1>&2
|
2020-11-23 10:17:18 +01:00
|
|
|
exit 3
|
|
|
|
fi
|
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
|
2020-11-23 10:17:18 +01:00
|
|
|
src_makedefs=${configpath}/Make.defs
|
2020-01-16 02:16:14 +01:00
|
|
|
if [ ! -r ${src_makedefs} ]; then
|
2020-11-23 10:17:18 +01:00
|
|
|
src_makedefs=${configpath}/../../scripts/Make.defs
|
2020-10-21 09:34:15 +02:00
|
|
|
|
|
|
|
if [ ! -r ${src_makedefs} ]; then
|
2023-11-24 09:38:10 +01:00
|
|
|
src_makedefs=${configpath}/../../../common/scripts/Make.defs
|
|
|
|
|
|
|
|
if [ ! -r ${src_makedefs} ]; then
|
|
|
|
echo "File Make.defs could not be found"
|
|
|
|
exit 4
|
|
|
|
fi
|
2020-10-21 09:34:15 +02:00
|
|
|
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"
|
2023-06-01 23:43:48 +02:00
|
|
|
original_config="${TOPDIR}/.config.orig"
|
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
|
2021-10-16 18:30:54 +02:00
|
|
|
${MAKECMD} -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
|
2021-10-16 18:30:54 +02:00
|
|
|
${MAKECMD} -C ${TOPDIR} distclean
|
2020-08-20 18:30:03 +02:00
|
|
|
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
|
|
|
|
|
2023-09-11 11:18:06 +02:00
|
|
|
# Okay... Everything looks good. Setup the configuration
|
|
|
|
|
|
|
|
echo " Copy files"
|
|
|
|
ln -sf ${src_makedefs} ${dest_makedefs} || \
|
|
|
|
{ echo "Failed to symlink ${src_makedefs}" ; exit 8 ; }
|
|
|
|
${TOPDIR}/tools/process_config.sh -I ${configpath}/../../common/configs \
|
|
|
|
-I ${configpath}/../common -o ${dest_config} ${src_config}
|
|
|
|
install -m 644 ${src_config} "${backup_config}" || \
|
|
|
|
{ echo "Failed to backup ${src_config}" ; exit 10 ; }
|
|
|
|
|
|
|
|
# Install any optional files
|
|
|
|
|
|
|
|
for opt in ${OPTFILES}; do
|
|
|
|
test -f ${configpath}/${opt} && install ${configpath}/${opt} "${TOPDIR}/"
|
|
|
|
done
|
|
|
|
|
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
|
2022-02-14 12:33:40 +01:00
|
|
|
if [ -z "${appdir}" -a "X$oldnative" = "X$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}"
|
2023-09-22 10:37:11 +02:00
|
|
|
else
|
|
|
|
echo "ERROR: Could not find the path to the appdir"
|
|
|
|
exit 7
|
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
|
|
|
|
|
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
|
2021-01-05 05:29:08 +01:00
|
|
|
# sed -i.bak -e "/^CONFIG_APPS_DIR/d" "${dest_config}"
|
2014-05-25 15:38:32 +02:00
|
|
|
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
|
|
|
|
2023-06-01 23:43:48 +02:00
|
|
|
# Update the CONFIG_BASE_DEFCONFIG setting
|
|
|
|
|
|
|
|
posboardconfig=`echo "${boardconfig}" | sed -e 's/\\\\/\\//g'`
|
|
|
|
echo "CONFIG_BASE_DEFCONFIG=\"$posboardconfig\"" >> "${dest_config}"
|
|
|
|
|
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 $*
|
2023-06-01 23:43:48 +02:00
|
|
|
|
|
|
|
# Save the original configuration file without CONFIG_BASE_DEFCONFIG
|
|
|
|
# for later comparison
|
|
|
|
|
|
|
|
grep -v "CONFIG_BASE_DEFCONFIG" "${dest_config}" > "${original_config}"
|