File indexing completed on 2021-12-21 13:58:15

0001 #!/bin/sh
0002 # -*- mode: shell-script; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
0003 #
0004 # Copyright (C) 2012, 2013 O.S. Systems Software LTDA.
0005 # Authored-by:  Otavio Salvador <otavio@ossystems.com.br>
0006 #
0007 # This program is free software; you can redistribute it and/or modify
0008 # it under the terms of the GNU General Public License version 2 as
0009 # published by the Free Software Foundation.
0010 #
0011 # This program is distributed in the hope that it will be useful,
0012 # but WITHOUT ANY WARRANTY; without even the implied warranty of
0013 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014 # GNU General Public License for more details.
0015 #
0016 # You should have received a copy of the GNU General Public License along
0017 # with this program; if not, write to the Free Software Foundation, Inc.,
0018 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
0019 #
0020 # Add options for the script
0021 # Copyright (C) 2013 Freescale Semiconductor, Inc.
0022 
0023 CWD=`pwd`
0024 PROGNAME="setup-environment"
0025 
0026 usage()
0027 {
0028     echo -e "\nUsage: . $PROGNAME <build-dir>
0029     <build-dir>: specifies the build directory location (required)
0030 
0031 If undefined, this script will set \$MACHINE to 'raspberrypi'.
0032 
0033 Supported machines: `echo; ls */conf/machine/*.conf */*/conf/machine/*.conf \
0034 | sed s/\.conf//g | sed -r 's/^.+\///' | xargs -I% echo -e "\t%"`
0035 
0036 To build for a machine listed above, run this script as:
0037 MACHINE=<machine> . $PROGNAME <build-dir>
0038 "
0039 }
0040 
0041 clean_up()
0042 {
0043    unset LIST_MACHINES VALID_MACHINE
0044    unset CWD TEMPLATES SHORTOPTS LONGOPTS ARGS PROGNAME
0045    unset generated_config updated
0046    unset MACHINE SDKMACHINE DISTRO OEROOT
0047 }
0048 
0049 # get command line options
0050 SHORTOPTS="h"
0051 LONGOPTS="help"
0052 
0053 ARGS=$(getopt --options $SHORTOPTS  \
0054   --longoptions $LONGOPTS --name $PROGNAME -- "$@" )
0055 # Print the usage menu if invalid options are specified
0056 if [ $? != 0 -o $# -lt 1 ]; then
0057    usage && clean_up
0058    return 1
0059 fi
0060 
0061 eval set -- "$ARGS"
0062 while true;
0063 do
0064     case $1 in
0065         -h|--help)
0066            usage
0067            clean_up
0068            return 0
0069            ;;
0070         --)
0071            shift
0072            break
0073            ;;
0074     esac
0075 done
0076 
0077 if [ "$(whoami)" = "root" ]; then
0078     echo "ERROR: do not use the BSP as root. Exiting..."
0079 fi
0080 
0081 if [ -z "$MACHINE" ]; then
0082     MACHINE='raspberrypi'
0083 fi
0084 
0085 # Check the machine type specified
0086 LIST_MACHINES=`ls -1 $CWD/*/conf/machine $CWD/*/*/conf/machine`
0087 VALID_MACHINE=`echo -e "$LIST_MACHINES" | grep ${MACHINE}.conf$ | wc -l`
0088 if [ "x$MACHINE" = "x" ] || [ "$VALID_MACHINE" = "0" ]; then
0089     echo -e "\nThe \$MACHINE you have specified ($MACHINE) is not supported by this build setup"
0090     usage && clean_up
0091     return 1
0092 else
0093     if [ ! -e $1/conf/local.conf.sample ]; then
0094         echo "Configuring for ${MACHINE}"
0095     fi
0096 fi
0097 
0098 if [ -z "$SDKMACHINE" ]; then
0099     SDKMACHINE='x86_64'
0100 fi
0101 
0102 if [ -z "$DISTRO" ]; then
0103     DISTRO='kde-linux'
0104 fi
0105 
0106 OEROOT=`readlink -f poky`
0107 
0108 # Ensure all files in base are kept in sync with project root
0109 # updated=
0110 # for f in $CWD/base/*; do
0111 #     file="$(basename $f)"
0112 #     if [ "$file" = "conf" ] || echo $file | grep -q '~$'; then
0113 #         continue
0114 #     fi
0115 #
0116 #     if ! cmp -s "$file" "$f"; then
0117 #         updated="true"
0118 #         [ -e $file ] && chmod u+w $file
0119 #         cp $f $file
0120 #     fi
0121 # done
0122 # if [ "$updated" = "true" ]; then
0123 #     echo "The project root content has been updated. Please run '$PROGNAME' again."
0124 #     return
0125 # fi
0126 
0127 cd $OEROOT
0128 
0129 . ./oe-init-build-env $CWD/$1 > /dev/null
0130 
0131 # Clean up PATH, because if it includes tokens to current directories somehow,
0132 # wrong binaries can be used instead of the expected ones during task execution
0133 export PATH="`echo $PATH | sed 's/\(:.\|:\)*:/:/g;s/^.\?://;s/:.\?$//'`"
0134 
0135 generated_config=
0136 if [ ! -e conf/local.conf.sample ]; then
0137     mv conf/local.conf conf/local.conf.sample
0138 
0139     # Generate the local.conf based on the Yocto defaults
0140     TEMPLATES=$CWD/yocto-meta-kde-demo/setup
0141     grep -v '^#\|^$' conf/local.conf.sample > conf/local.conf
0142 
0143     # Change settings according environment
0144     sed -e "s,MACHINE ??=.*,MACHINE ??= '$MACHINE',g" \
0145         -e "s,SDKMACHINE ??=.*,SDKMACHINE ??= '$SDKMACHINE',g" \
0146         -e "s,DISTRO ?=.*,DISTRO ?= '$DISTRO',g" \
0147         -i conf/local.conf
0148 
0149     cp $TEMPLATES/* conf/
0150 
0151     for s in $HOME/.oe $HOME/.yocto; do
0152         if [ -e $s/site.conf ]; then
0153             echo "Linking $s/site.conf to conf/site.conf"
0154             ln -s $s/site.conf conf
0155         fi
0156     done
0157 
0158     generated_config=1
0159 fi
0160 
0161 cat <<EOF
0162 
0163 Welcome to KDE Demo BSP
0164 
0165 The Yocto Project has extensive documentation about OE including a
0166 reference manual which can be found at:
0167     http://yoctoproject.org/documentation
0168 
0169 For more information about OpenEmbedded see their website:
0170     http://www.openembedded.org/
0171 
0172 You can now run 'bitbake <target>'
0173 
0174 Common targets are:
0175     kde-demo-image
0176 
0177 EOF
0178 
0179 if [ -n "$generated_config" ]; then
0180     cat <<EOF
0181 Your build environment has been configured with:
0182 
0183     MACHINE=$MACHINE
0184     SDKMACHINE=$SDKMACHINE
0185     DISTRO=$DISTRO
0186 EOF
0187 else
0188     echo "Your configuration files at $1 have not been touched."
0189 fi
0190 
0191 clean_up