blob: e04db0398dab00f81d17cdf989679b33648ef0a1 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001#!/bin/sh
2
3# OE-Core Build Environment Setup Script
4#
5# Copyright (C) 2006-2011 Linux Foundation
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 as published by
9# the Free Software Foundation; either version 2 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program; if not, write to the Free Software
19# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
21# It is assumed OEROOT is already defined when this is called
22if [ -z "$OEROOT" ]; then
23 echo >&2 "Error: OEROOT is not defined!"
24 return 1
25fi
26
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050027if [ -z "$OE_SKIP_SDK_CHECK" ] && [ -n "$OECORE_SDK_VERSION" ]; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -050028 echo >&2 "Error: The OE SDK/ADT was detected as already being present in this shell environment. Please use a clean shell when sourcing this environment script."
29 return 1
30fi
31
32# Make sure we're not using python v3.x. This check can't go into
33# sanity.bbclass because bitbake's source code doesn't even pass
34# parsing stage when used with python v3, so we catch it here so we
35# can offer a meaningful error message.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050036py_v3_check=$(/usr/bin/env python --version 2>&1 | grep "Python 3")
37if [ -n "$py_v3_check" ]; then
38 echo >&2 "Bitbake is not compatible with python v3"
39 echo >&2 "Please set up python v2 as your default python interpreter"
40 return 1
Patrick Williamsc124f4f2015-09-15 14:41:29 -050041fi
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050042unset py_v3_check
Patrick Williamsc124f4f2015-09-15 14:41:29 -050043
44# Similarly, we now have code that doesn't parse correctly with older
45# versions of Python, and rather than fixing that and being eternally
46# vigilant for any other new feature use, just check the version here.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050047py_v26_check=$(python -c 'import sys; print sys.version_info >= (2,7,3)')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050048if [ "$py_v26_check" != "True" ]; then
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050049 echo >&2 "BitBake requires Python 2.7.3 or later"
50 return 1
Patrick Williamsc124f4f2015-09-15 14:41:29 -050051fi
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050052unset py_v26_check
Patrick Williamsc124f4f2015-09-15 14:41:29 -050053
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050054if [ -z "$BDIR" ]; then
55 if [ -z "$1" ]; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -050056 BDIR="build"
57 else
58 BDIR="$1"
59 if [ "$BDIR" = "/" ]; then
60 echo >&2 "Error: / is not supported as a build directory."
61 return 1
62 fi
63
64 # Remove any possible trailing slashes. This is used to work around
65 # buggy readlink in Ubuntu 10.04 that doesn't ignore trailing slashes
66 # and hence "readlink -f new_dir_to_be_created/" returns empty.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050067 BDIR=$(echo $BDIR | sed -re 's|/+$||')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050068
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050069 BDIR=$(readlink -f "$BDIR")
Patrick Williamsc124f4f2015-09-15 14:41:29 -050070 if [ -z "$BDIR" ]; then
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050071 PARENTDIR=$(dirname "$1")
Patrick Williamsc124f4f2015-09-15 14:41:29 -050072 echo >&2 "Error: the directory $PARENTDIR does not exist?"
73 return 1
74 fi
75 fi
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050076 if [ -n "$2" ]; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -050077 BITBAKEDIR="$2"
78 fi
79fi
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050080if [ "${BDIR#/}" != "$BDIR" ]; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -050081 BUILDDIR="$BDIR"
82else
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050083 BUILDDIR="$(pwd)/$BDIR"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050084fi
85unset BDIR
86
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050087if [ -z "$BITBAKEDIR" ]; then
88 BITBAKEDIR="$OEROOT/bitbake$BBEXTRA"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050089fi
90
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050091BITBAKEDIR=$(readlink -f "$BITBAKEDIR")
92BUILDDIR=$(readlink -f "$BUILDDIR")
Patrick Williamsc124f4f2015-09-15 14:41:29 -050093
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050094if [ ! -d "$BITBAKEDIR" ]; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -050095 echo >&2 "Error: The bitbake directory ($BITBAKEDIR) does not exist! Please ensure a copy of bitbake exists at this location"
96 return 1
97fi
98
99# Make sure our paths are at the beginning of $PATH
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500100for newpath in "$BITBAKEDIR/bin" "$OEROOT/scripts"; do
101 # Remove any existences of $newpath from $PATH
102 PATH=$(echo $PATH | sed -re "s#(^|:)$newpath(:|$)#\2#g;s#^:##")
103
104 # Add $newpath to $PATH
105 PATH="$newpath:$PATH"
106done
107unset BITBAKEDIR newpath
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500108
109# Used by the runqemu script
110export BUILDDIR
111export PATH
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500112
113BB_ENV_EXTRAWHITE_OE="MACHINE DISTRO TCMODE TCLIBC HTTP_PROXY http_proxy \
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500114HTTPS_PROXY https_proxy FTP_PROXY ftp_proxy FTPS_PROXY ftps_proxy ALL_PROXY \
115all_proxy NO_PROXY no_proxy SSH_AGENT_PID SSH_AUTH_SOCK BB_SRCREV_POLICY \
116SDKMACHINE BB_NUMBER_THREADS BB_NO_NETWORK PARALLEL_MAKE GIT_PROXY_COMMAND \
117SOCKS5_PASSWD SOCKS5_USER SCREENDIR STAMPS_DIR"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500118
119BB_ENV_EXTRAWHITE="$(echo $BB_ENV_EXTRAWHITE $BB_ENV_EXTRAWHITE_OE | tr ' ' '\n' | LC_ALL=C sort --unique | tr '\n' ' ')"
120
121export BB_ENV_EXTRAWHITE