lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # -*- mode: shell-script; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
| 3 | # |
| 4 | # Copyright (C) 2012, 2013, 2016 O.S. Systems Software LTDA. |
| 5 | # Authored-by: Otavio Salvador <otavio@ossystems.com.br> |
| 6 | # |
| 7 | # This program is free software; you can redistribute it and/or modify |
| 8 | # it under the terms of the GNU General Public License version 2 as |
| 9 | # published by the Free Software Foundation. |
| 10 | # |
| 11 | # This program is distributed in the hope that it will be useful, |
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | # GNU General Public License for more details. |
| 15 | # |
| 16 | # You should have received a copy of the GNU General Public License along |
| 17 | # with this program; if not, write to the Free Software Foundation, Inc., |
| 18 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | # |
| 20 | # Add options for the script |
| 21 | # Copyright (C) 2013 Freescale Semiconductor, Inc. |
| 22 | |
| 23 | CWD=`pwd` |
| 24 | PROGNAME="setup-environment" |
| 25 | |
| 26 | usage() |
| 27 | { |
| 28 | echo -e " |
| 29 | Usage: MACHINE=<machine> DISTRO=<distro> source $PROGNAME <build-dir> |
| 30 | Usage: source $PROGNAME <build-dir> |
| 31 | <machine> machine name |
| 32 | <distro> distro name |
| 33 | <build-dir> build directory |
| 34 | |
| 35 | The first usage is for creating a new build directory. In this case, the |
| 36 | script creates the build directory <build-dir>, configures it for the |
| 37 | specified <machine> and <distro>, and prepares the calling shell for running |
| 38 | bitbake on the build directory. |
| 39 | |
| 40 | The second usage is for using an existing build directory. In this case, |
| 41 | the script prepares the calling shell for running bitbake on the build |
| 42 | directory <build-dir>. The build directory configuration is unchanged. |
| 43 | " |
| 44 | |
| 45 | ls sources/*/conf/machine/*.conf > /dev/null 2>&1 |
| 46 | ls sources/meta-zxic-custom/conf/distro/cpe.conf > /dev/null 2>&1 |
| 47 | if [ $? -eq 0 ]; then |
| 48 | echo -e " |
| 49 | Supported machines: `echo; ls sources/*/conf/machine/*.conf \ |
| 50 | | sed s/\.conf//g | sed -r 's/^.+\///' | xargs -I% echo -e "\t%"` |
| 51 | |
| 52 | Supported Freescale's distros: `echo; ls sources/meta-zxic-custom/conf/distro/*.conf \ |
| 53 | | sed s/\.conf//g | sed -r 's/^.+\///' | xargs -I% echo -e "\t%"` |
| 54 | |
| 55 | Available Poky's distros: `echo; ls sources/poky/meta-poky/conf/distro/*.conf \ |
| 56 | | sed s/\.conf//g | sed -r 's/^.+\///' | xargs -I% echo -e "\t%"` |
| 57 | |
| 58 | Examples: |
| 59 | |
| 60 | - To create a new Yocto build directory: |
| 61 | $ MACHINE=zx297520v3 DISTRO=vehicle source $PROGNAME build |
| 62 | |
| 63 | - To use an existing Yocto build directory: |
| 64 | $ source $PROGNAME build |
| 65 | " |
| 66 | fi |
| 67 | } |
| 68 | |
| 69 | clean_up() |
| 70 | { |
| 71 | unset EULA LIST_MACHINES VALID_MACHINE |
| 72 | unset CWD TEMPLATES SHORTOPTS LONGOPTS ARGS PROGNAME |
| 73 | unset generated_config updated |
| 74 | unset MACHINE SDKMACHINE DISTRO OEROOT |
| 75 | } |
| 76 | |
| 77 | # get command line options |
| 78 | SHORTOPTS="h" |
| 79 | LONGOPTS="help" |
| 80 | |
| 81 | ARGS=$(getopt --options $SHORTOPTS \ |
| 82 | --longoptions $LONGOPTS --name $PROGNAME -- "$@" ) |
| 83 | # Print the usage menu if invalid options are specified |
| 84 | if [ $? != 0 -o $# -lt 1 ]; then |
| 85 | usage && clean_up |
| 86 | return 1 |
| 87 | fi |
| 88 | |
| 89 | eval set -- "$ARGS" |
| 90 | while true; |
| 91 | do |
| 92 | case $1 in |
| 93 | -h|--help) |
| 94 | usage |
| 95 | clean_up |
| 96 | return 0 |
| 97 | ;; |
| 98 | --) |
| 99 | shift |
| 100 | break |
| 101 | ;; |
| 102 | esac |
| 103 | done |
| 104 | |
| 105 | if [ "$(whoami)" = "root" ]; then |
| 106 | echo "ERROR: do not use the BSP as root. Exiting..." |
| 107 | fi |
| 108 | |
| 109 | if [ ! -e $1/conf/local.conf.sample ]; then |
| 110 | build_dir_setup_enabled="true" |
| 111 | else |
| 112 | build_dir_setup_enabled="false" |
| 113 | fi |
| 114 | |
| 115 | if [ "$build_dir_setup_enabled" = "true" ] && [ -z "$MACHINE" ]; then |
| 116 | usage |
| 117 | echo -e "ERROR: You must set MACHINE when creating a new build directory." |
| 118 | clean_up |
| 119 | return 1 |
| 120 | fi |
| 121 | |
| 122 | if [ -z "$SDKMACHINE" ]; then |
| 123 | SDKMACHINE='i686' |
| 124 | fi |
| 125 | |
| 126 | if [ "$build_dir_setup_enabled" = "true" ] && [ -z "$DISTRO" ]; then |
| 127 | usage |
| 128 | echo -e "ERROR: You must set DISTRO when creating a new build directory." |
| 129 | clean_up |
| 130 | return 1 |
| 131 | fi |
| 132 | |
| 133 | OEROOT=$PWD/sources/poky |
| 134 | if [ -e $PWD/sources/oe-core ]; then |
| 135 | OEROOT=$PWD/sources/oe-core |
| 136 | fi |
| 137 | |
| 138 | . $OEROOT/oe-init-build-env $CWD/$1 > /dev/null |
| 139 | |
| 140 | # if conf/local.conf not generated, no need to go further |
| 141 | if [ ! -e conf/local.conf ]; then |
| 142 | clean_up && return 1 |
| 143 | fi |
| 144 | |
| 145 | # Clean up PATH, because if it includes tokens to current directories somehow, |
| 146 | # wrong binaries can be used instead of the expected ones during task execution |
| 147 | export PATH="`echo $PATH | sed 's/\(:.\|:\)*:/:/g;s/^.\?://;s/:.\?$//'`" |
| 148 | |
| 149 | generated_config= |
| 150 | if [ "$build_dir_setup_enabled" = "true" ]; then |
| 151 | mv conf/local.conf conf/local.conf.sample |
| 152 | |
| 153 | # Generate the local.conf based on the Yocto defaults |
| 154 | TEMPLATES=$CWD/sources/base/conf |
| 155 | grep -v '^#\|^$' conf/local.conf.sample > conf/local.conf |
| 156 | cat >> conf/local.conf <<EOF |
| 157 | |
| 158 | DL_DIR ?= "\${BSPDIR}/downloads/" |
| 159 | EOF |
| 160 | # Change settings according environment |
| 161 | sed -e "s,MACHINE ??=.*,MACHINE ??= '$MACHINE',g" \ |
| 162 | -e "s,SDKMACHINE ??=.*,SDKMACHINE ??= '$SDKMACHINE',g" \ |
| 163 | -e "s,DISTRO ?=.*,DISTRO ?= '$DISTRO',g" \ |
| 164 | -i conf/local.conf |
| 165 | |
| 166 | echo "MK_SDK_VERSION ?= '$MK_SDK_VERSION'" >> conf/local.conf |
| 167 | echo "BOOT_CTL ?= '$BOOT_CTL'" >> conf/local.conf |
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame] | 168 | echo "BB_HASH_IGNORE_MISMATCH ?= '1'" >> conf/local.conf |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 169 | echo "STRORAGE_CONF ?= '$STRORAGE_CONF'" >> conf/local.conf |
| 170 | sed -e "s,PACKAGE_CLASSES ?=.*,PACKAGE_CLASSES ?= 'package_ipk',g" \ |
| 171 | -i conf/local.conf |
| 172 | |
| 173 | cp $TEMPLATES/* conf/ |
| 174 | |
| 175 | for s in $HOME/.oe $HOME/.yocto; do |
| 176 | if [ -e $s/site.conf ]; then |
| 177 | echo "Linking $s/site.conf to conf/site.conf" |
| 178 | ln -s $s/site.conf conf |
| 179 | fi |
| 180 | done |
| 181 | |
| 182 | generated_config=1 |
| 183 | fi |
| 184 | |
| 185 | cat <<EOF |
| 186 | |
| 187 | |
| 188 | The Yocto Project has extensive documentation about OE including a |
| 189 | reference manual which can be found at: |
| 190 | http://yoctoproject.org/documentation |
| 191 | |
| 192 | For more information about OpenEmbedded see their website: |
| 193 | http://www.openembedded.org/ |
| 194 | |
| 195 | You can now run 'bitbake <target>' |
| 196 | |
| 197 | Common targets are: |
| 198 | core-image-minimal |
| 199 | meta-toolchain |
| 200 | meta-ide-support |
| 201 | zxic-image |
| 202 | EOF |
| 203 | |
| 204 | if [ -n "$generated_config" ]; then |
| 205 | cat <<EOF |
| 206 | Your build environment has been configured with: |
| 207 | MACHINE=$MACHINE |
| 208 | DISTRO=$DISTRO |
| 209 | SDK=$MK_SDK_VERSION |
| 210 | BOOT_CTL=$BOOT_CTL |
| 211 | STRORAGE_CONF=$STRORAGE_CONF |
| 212 | EOF |
| 213 | else |
| 214 | echo "Your configuration files at $1 have not been touched." |
| 215 | fi |
| 216 | |
| 217 | clean_up |