BaseTools:Update build tool to print python version information
[mirror_edk2.git] / edksetup.sh
CommitLineData
b9e16a84 1#
445bfd92 2# Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
44f79425 3# Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>
24542fb2 4# This program and the accompanying materials
b9e16a84 5# are licensed and made available under the terms and conditions of the BSD License
6# which accompanies this distribution. The full text of the license may be found at
7# http://opensource.org/licenses/bsd-license.php
8#
9# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
2b1473c1 11#
12# In *inux environment, the build tools's source is required and need to be compiled
445bfd92 13# firstly, please reference https://github.com/tianocore/tianocore.github.io/wiki/SourceForge-to-Github-Quick-Start
2b1473c1 14# to get how to setup build tool.
15#
b9e16a84 16# Setup the environment for unix-like systems running a bash-like shell.
6dbea978 17# This file must be "sourced" not merely executed. For example: ". edksetup.sh"
2b1473c1 18#
6dbea978 19# CYGWIN users: Your path and filename related environment variables should be
20# set up in the unix style. This script will make the necessary conversions to
21# windows style.
2b1473c1 22#
445bfd92 23# Please reference edk2 user manual for more detail descriptions at https://github.com/tianocore-docs/Docs/raw/master/User_Docs/EDK_II_UserManual_0_7.pdf
2b1473c1 24#
b9e16a84 25
44f79425 26SCRIPTNAME="edksetup.sh"
c112e371 27RECONFIG=FALSE
44f79425 28
729220ea
PP
29function HelpMsg()
30{
44f79425
LL
31 echo "Usage: $SCRIPTNAME [Options]"
32 echo
33 echo "The system environment variable, WORKSPACE, is always set to the current"
34 echo "working directory."
35 echo
36 echo "Options: "
37 echo " --help, -h, -? Print this help screen and exit."
38 echo
c112e371
LL
39 echo " --reconfig Overwrite the WORKSPACE/Conf/*.txt files with the"
40 echo " template files from the BaseTools/Conf directory."
41 echo
729220ea 42 echo Please note: This script must be \'sourced\' so the environment can be changed.
44f79425
LL
43 echo ". $SCRIPTNAME"
44 echo "source $SCRIPTNAME"
729220ea
PP
45}
46
d5493449
PB
47function SetWorkspace()
48{
49 #
50 # If WORKSPACE is already set, then we can return right now
51 #
52 if [ -n "$WORKSPACE" ]
53 then
54 return 0
55 fi
56
95cc9a51 57 if [ ! ${BASH_SOURCE[0]} -ef ./edksetup.sh ] && [ -z "$PACKAGES_PATH" ]
d5493449
PB
58 then
59 echo Run this script from the base of your tree. For example:
60 echo " cd /Path/To/Edk/Root"
61 echo " . edksetup.sh"
62 return 1
63 fi
64
65 #
66 # Check for BaseTools/BuildEnv before dirtying the user's environment.
67 #
68 if [ ! -f BaseTools/BuildEnv ] && [ -z "$EDK_TOOLS_PATH" ]
69 then
70 echo BaseTools not found in your tree, and EDK_TOOLS_PATH is not set.
71 echo Please point EDK_TOOLS_PATH at the directory that contains
72 echo the EDK2 BuildEnv script.
73 return 1
74 fi
75
76 #
77 # Set $WORKSPACE
78 #
79 export WORKSPACE=`pwd`
9c2d68c0 80 export PYTHONHASHSEED=1
d5493449
PB
81 return 0
82}
83
729220ea
PP
84function SetupEnv()
85{
7bc14212
PB
86 if [ -n "$EDK_TOOLS_PATH" ]
87 then
44f79425 88 . $EDK_TOOLS_PATH/BuildEnv
d5493449 89 elif [ -f "$WORKSPACE/BaseTools/BuildEnv" ]
729220ea 90 then
44f79425 91 . $WORKSPACE/BaseTools/BuildEnv
094a6739
LG
92 elif [ -n "$PACKAGES_PATH" ]
93 then
94 PATH_LIST=$PACKAGES_PATH
95 PATH_LIST=${PATH_LIST//:/ }
96 for DIR in $PATH_LIST
97 do
98 if [ -f "$DIR/BaseTools/BuildEnv" ]
99 then
100 export EDK_TOOLS_PATH=$DIR/BaseTools
44f79425 101 . $DIR/BaseTools/BuildEnv
094a6739
LG
102 break
103 fi
104 done
7bc14212 105 else
d5493449 106 echo BaseTools not found in your tree, and EDK_TOOLS_PATH is not set.
094a6739
LG
107 echo Please check that WORKSPACE or PACKAGES_PATH is not set incorrectly
108 echo in your shell, or point EDK_TOOLS_PATH at the directory that contains
d5493449
PB
109 echo the EDK2 BuildEnv script.
110 return 1
729220ea
PP
111 fi
112}
113
9c2d68c0
ZF
114function SetupPython()
115{
116 if [ $PYTHON3_ENABLE ] && [ $PYTHON3_ENABLE == TRUE ]
117 then
118 for python in $(which python3)
119 do
120 python=$(echo $python | grep "[[:digit:]]$" || true)
121 python_version=${python##*python}
122 if [ -z "${python_version}" ];then
123 continue
124 fi
125 if [ -z $origin_version ];then
126 origin_version=$python_version
127 export PYTHON=$python
128 continue
129 fi
130 ret=`echo "$origin_version < $python_version" |bc`
131 if [ "$ret" -eq 1 ]; then
132 origin_version=$python_version
133 export PYTHON=$python
134 fi
135 done
136 fi
137
138 if [ -z $PYTHON3_ENABLE ] || [ $PYTHON3_ENABLE != TRUE ]
139 then
140 for python in $(which python2)
141 do
142 python=$(echo $python | grep "[[:digit:]]$" || true)
143 python_version=${python##*python}
144 if [ -z "${python_version}" ];then
145 continue
146 fi
147 if [ -z $origin_version ] || [ $origin_version -ge 3 ]
148 then
149 origin_version=$python_version
150 export PYTHON=$python
151 continue
152 fi
153 ret=`echo "$origin_version < $python_version" |bc`
154 if [ "$ret" -eq 1 ]; then
155 origin_version=$python_version
156 export PYTHON=$python
157 fi
158 done
159 fi
160}
161
729220ea
PP
162function SourceEnv()
163{
44f79425
LL
164 SetWorkspace &&
165 SetupEnv
9c2d68c0 166 SetupPython
729220ea 167}
ef9086c3 168
44f79425
LL
169I=$#
170while [ $I -gt 0 ]
171do
172 case "$1" in
173 BaseTools)
174 # Ignore argument for backwards compatibility
175 shift
176 ;;
c112e371
LL
177 --reconfig)
178 RECONFIG=TRUE
179 shift
180 ;;
44f79425
LL
181 -?|-h|--help|*)
182 HelpMsg
183 break
184 ;;
185 esac
186 I=$(($I - 1))
187done
1bb6bfaa 188
44f79425 189if [ $I -gt 0 ]
1bb6bfaa 190then
44f79425 191 return 1
ef9086c3
JJ
192fi
193
44f79425 194SourceEnv
b9e16a84 195
c112e371
LL
196unset SCRIPTNAME RECONFIG
197
44f79425 198return $?