blob: 0f2818c4599e5216429b6682b155ea37df04dda4 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001#!/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
23CWD=`pwd`
24PROGNAME="setup-environment"
25
26usage()
27{
28 echo -e "
29Usage: MACHINE=<machine> DISTRO=<distro> source $PROGNAME <build-dir>
30Usage: source $PROGNAME <build-dir>
31 <machine> machine name
32 <distro> distro name
33 <build-dir> build directory
34
35The first usage is for creating a new build directory. In this case, the
36script creates the build directory <build-dir>, configures it for the
37specified <machine> and <distro>, and prepares the calling shell for running
38bitbake on the build directory.
39
40The second usage is for using an existing build directory. In this case,
41the script prepares the calling shell for running bitbake on the build
42directory <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 "
49Supported machines: `echo; ls sources/*/conf/machine/*.conf \
50| sed s/\.conf//g | sed -r 's/^.+\///' | xargs -I% echo -e "\t%"`
51
52Supported 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
55Available 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
58Examples:
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
69clean_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
78SHORTOPTS="h"
79LONGOPTS="help"
80
81ARGS=$(getopt --options $SHORTOPTS \
82 --longoptions $LONGOPTS --name $PROGNAME -- "$@" )
83# Print the usage menu if invalid options are specified
84if [ $? != 0 -o $# -lt 1 ]; then
85 usage && clean_up
86 return 1
87fi
88
89eval set -- "$ARGS"
90while true;
91do
92 case $1 in
93 -h|--help)
94 usage
95 clean_up
96 return 0
97 ;;
98 --)
99 shift
100 break
101 ;;
102 esac
103done
104
105if [ "$(whoami)" = "root" ]; then
106 echo "ERROR: do not use the BSP as root. Exiting..."
107fi
108
109if [ ! -e $1/conf/local.conf.sample ]; then
110 build_dir_setup_enabled="true"
111else
112 build_dir_setup_enabled="false"
113fi
114
115if [ "$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
120fi
121
122if [ -z "$SDKMACHINE" ]; then
123 SDKMACHINE='i686'
124fi
125
126if [ "$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
131fi
132
133OEROOT=$PWD/sources/poky
134if [ -e $PWD/sources/oe-core ]; then
135 OEROOT=$PWD/sources/oe-core
136fi
137
138. $OEROOT/oe-init-build-env $CWD/$1 > /dev/null
139
140# if conf/local.conf not generated, no need to go further
141if [ ! -e conf/local.conf ]; then
142 clean_up && return 1
143fi
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
147export PATH="`echo $PATH | sed 's/\(:.\|:\)*:/:/g;s/^.\?://;s/:.\?$//'`"
148
149generated_config=
150if [ "$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
158DL_DIR ?= "\${BSPDIR}/downloads/"
159EOF
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
lh758261d2023-07-13 05:52:04 -0700168 echo "BB_HASH_IGNORE_MISMATCH ?= '1'" >> conf/local.conf
lh9ed821d2023-04-07 01:36:19 -0700169 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
183fi
184
185cat <<EOF
186
187
188The Yocto Project has extensive documentation about OE including a
189reference manual which can be found at:
190 http://yoctoproject.org/documentation
191
192For more information about OpenEmbedded see their website:
193 http://www.openembedded.org/
194
195You can now run 'bitbake <target>'
196
197Common targets are:
198 core-image-minimal
199 meta-toolchain
200 meta-ide-support
201 zxic-image
202EOF
203
204if [ -n "$generated_config" ]; then
205 cat <<EOF
206Your 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
212EOF
213else
214 echo "Your configuration files at $1 have not been touched."
215fi
216
217clean_up