#!/bin/bash # configure.sh # # Copyright (C) 2007, 2008, 2011, 2015, 2017 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # 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=`test -d ${0%/*} && cd ${0%/*}; pwd` TOPDIR="${WD}/.." USAGE=" USAGE: ${0} [-d] [-l|c|u|n] [-a ] / Where: -l selects the Linux (l) host environment. The [-c|u|n] options select one of the Windows environments. Default: Use host setup in the defconfig file [-c|u|n] selects the Windows host and a Windows environment: Cygwin (c), Ubuntu under Windows 10 (u), or Windows native (n). Default Cygwin is the name of the board in the configs directory is the name of the board configuration sub-directory is the path to the apps/ directory, relative to the nuttx directory " # A list of optional files that may be installed OPTFILES="\ .gdbinit\ .cproject\ .project\ " # Parse command arguments unset boardconfig unset appdir unset host unset wenv while [ ! -z "$1" ]; do case "$1" in -a ) shift appdir=$1 ;; -c ) host=windows wenv=cygwin ;; -d ) set -x ;; -h ) echo "$USAGE" exit 0 ;; -l ) host=linux ;; -n ) host=windows wenv=native ;; -u ) host=windows wenv=ubuntu ;; *) if [ ! -z "${boardconfig}" ]; then echo "" echo " defined twice" echo "$USAGE" exit 1 fi boardconfig=$1 ;; esac shift done # Sanity checking if [ -z "${boardconfig}" ]; then echo "" echo "Missing argument" echo "$USAGE" exit 2 fi configpath=${TOPDIR}/configs/${boardconfig} if [ ! -d "${configpath}" ]; then # Try direct path for convenience. configpath=${TOPDIR}/${boardconfig} if [ ! -d "${configpath}" ]; then echo "Directory ${configpath} does not exist. Options are:" echo "" echo "Select one of the following options for :" configlist=`find ${TOPDIR}/configs -name defconfig` for defconfig in ${configlist}; do config=`dirname ${defconfig} | sed -e "s,${TOPDIR}/configs/,,g"` echo " ${config}" done echo "" echo "$USAGE" exit 3 fi fi src_makedefs="${configpath}/Make.defs" dest_makedefs="${TOPDIR}/Make.defs" if [ ! -r "${src_makedefs}" ]; then boardpath=`dirname $configpath` src_makedefs="${boardpath}/scripts/Make.defs" if [ ! -r "${src_makedefs}" ]; then echo "File Make.defs could not be found" exit 4 fi fi src_config="${configpath}/defconfig" dest_config="${TOPDIR}/.config" if [ ! -r "${src_config}" ]; then echo "File \"${src_config}\" does not exist" exit 6 fi if [ -r ${dest_config} ]; then echo "Already configured!" echo "Do 'make distclean' and try again." exit 7 fi # Extract values needed from the defconfig file. We need: # (1) The CONFIG_WINDOWS_NATIVE setting to know it this is target for a # native Windows # (2) The CONFIG_APPS_DIR setting to see if there is a configured location for the # application directory. This can be overridden from the command line. winnative=`grep CONFIG_WINDOWS_NATIVE= "${src_config}" | cut -d'=' -f2` defappdir=y if [ -z "${appdir}" ]; then quoted=`grep "^CONFIG_APPS_DIR=" "${src_config}" | cut -d'=' -f2` if [ ! -z "${quoted}" ]; then appdir=`echo ${quoted} | sed -e "s/\"//g"` defappdir=n fi fi # Check for the apps/ directory in the usual place if appdir was not provided if [ -z "${appdir}" ]; then # Check for a version file unset CONFIG_VERSION_STRING if [ -x "${TOPDIR}/.version" ]; then . "${TOPDIR}/.version" fi # Check for an unversioned apps/ directory if [ -d "${TOPDIR}/../apps" ]; then appdir="../apps" else # Check for a versioned apps/ directory if [ -d "${TOPDIR}/../apps-${CONFIG_VERSION_STRING}" ]; then appdir="../apps-${CONFIG_VERSION_STRING}" fi fi fi # For checking the apps dir path, we need a POSIX version of the relative path. posappdir=`echo "${appdir}" | sed -e 's/\\\\/\\//g'` winappdir=`echo "${appdir}" | sed -e 's/\\//\\\\/g'` # If appsdir was provided (or discovered) then make sure that the apps/ # directory exists if [ ! -z "${appdir}" -a ! -d "${TOPDIR}/${posappdir}" ]; then echo "Directory \"${TOPDIR}/${posappdir}\" does not exist" exit 7 fi # Okay... Everything looks good. Setup the configuration echo " Copy files" install -m 644 "${src_makedefs}" "${dest_makedefs}" || \ { echo "Failed to copy \"${src_makedefs}\"" ; exit 7 ; } install -m 644 "${src_config}" "${dest_config}" || \ { echo "Failed to copy \"${src_config}\"" ; exit 9 ; } # Install any optional files for opt in ${OPTFILES}; do test -f "${configpath}/${opt}" && install "${configpath}/${opt}" "${TOPDIR}/" done # 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 # 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}" if [ "X${winnative}" = "Xy" ]; then echo "CONFIG_APPS_DIR=\"$winappdir\"" >> "${dest_config}" else echo "CONFIG_APPS_DIR=\"$posappdir\"" >> "${dest_config}" fi fi if [ ! -z "$host" ]; then sed -i -e "/CONFIG_HOST_OSX/d" ${dest_config} sed -i -e "/CONFIG_HOST_OTHER/d" ${dest_config} if [ "$host" == "linux" ]; then echo " Select CONFIG_HOST_LINUX=y" sed -i -e "/CONFIG_HOST_WINDOWS/d" ${dest_config} sed -i -e "/CONFIG_SIM_X8664_MICROSOFT/d" ${dest_config} sed -i -e "/CONFIG_SIM_M32/d" ${dest_config} echo "CONFIG_HOST_LINUX=y" >> "${dest_config}" echo "CONFIG_SIM_X8664_SYSTEMV=y" >> "${dest_config}" else echo " Select CONFIG_HOST_WINDOWS=y" sed -i -e "/CONFIG_HOST_LINUX/d" ${dest_config} sed -i -e "/CONFIG_WINDOWS_MSYS/d" ${dest_config} sed -i -e "/CONFIG_WINDOWS_OTHER/d" ${dest_config} sed -i -e "/CONFIG_SIM_X8664_SYSTEMV/d" ${dest_config} echo "CONFIG_HOST_WINDOWS=y" >> "${dest_config}" echo "CONFIG_SIM_X8664_MICROSOFT=y" >> "${dest_config}" if [ "X$wenv" == "Xcygwin" ]; then echo " Select CONFIG_WINDOWS_CYGWIN=y" sed -i -e "/CONFIG_WINDOWS_UBUNTU/d" ${dest_config} sed -i -e "/CONFIG_WINDOWS_NATIVE/d" ${dest_config} echo "CONFIG_WINDOWS_CYGWIN=y" >> "${dest_config}" else sed -i -e "/CONFIG_WINDOWS_CYGWIN/d" ${dest_config} if [ "X$wenv" == "Xubuntu" ]; then echo " Select CONFIG_WINDOWS_UBUNTU=y" sed -i -e "/CONFIG_WINDOWS_UBUNTU/d" ${dest_config} echo "CONFIG_WINDOWS_UBUNTU=y" >> "${dest_config}" else echo " Select CONFIG_WINDOWS_NATIVE=y" sed -i -e "/CONFIG_WINDOWS_NATIVE/d" ${dest_config} echo "CONFIG_WINDOWS_NATIVE=y" >> "${dest_config}" fi fi fi fi # The saved defconfig files are all in compressed format and must be # reconstitued before they can be used. echo " Refreshing..." cd ${TOPDIR} || { echo "Failed to cd to ${TOPDIR}"; exit 1; } make olddefconfig 1>/dev/null 2>&1