]> git.proxmox.com Git - mirror_edk2.git/blame - edksetup.sh
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[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>
9ca2b9b9 4# SPDX-License-Identifier: BSD-2-Clause-Patent
2b1473c1 5#
6# In *inux environment, the build tools's source is required and need to be compiled
445bfd92 7# firstly, please reference https://github.com/tianocore/tianocore.github.io/wiki/SourceForge-to-Github-Quick-Start
2b1473c1 8# to get how to setup build tool.
9#
b9e16a84 10# Setup the environment for unix-like systems running a bash-like shell.
6dbea978 11# This file must be "sourced" not merely executed. For example: ". edksetup.sh"
2b1473c1 12#
6dbea978 13# CYGWIN users: Your path and filename related environment variables should be
14# set up in the unix style. This script will make the necessary conversions to
15# windows style.
2b1473c1 16#
445bfd92 17# 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 18#
b9e16a84 19
44f79425 20SCRIPTNAME="edksetup.sh"
c112e371 21RECONFIG=FALSE
44f79425 22
729220ea
PP
23function HelpMsg()
24{
44f79425
LL
25 echo "Usage: $SCRIPTNAME [Options]"
26 echo
27 echo "The system environment variable, WORKSPACE, is always set to the current"
28 echo "working directory."
29 echo
30 echo "Options: "
31 echo " --help, -h, -? Print this help screen and exit."
32 echo
c112e371
LL
33 echo " --reconfig Overwrite the WORKSPACE/Conf/*.txt files with the"
34 echo " template files from the BaseTools/Conf directory."
35 echo
729220ea 36 echo Please note: This script must be \'sourced\' so the environment can be changed.
44f79425
LL
37 echo ". $SCRIPTNAME"
38 echo "source $SCRIPTNAME"
729220ea
PP
39}
40
d5493449
PB
41function SetWorkspace()
42{
43 #
44 # If WORKSPACE is already set, then we can return right now
45 #
95083f7d 46 export PYTHONHASHSEED=1
d5493449
PB
47 if [ -n "$WORKSPACE" ]
48 then
49 return 0
50 fi
51
07d80d35 52 if [ ! ${BASH_SOURCE[0]} -ef ./$SCRIPTNAME ] && [ -z "$PACKAGES_PATH" ]
d5493449
PB
53 then
54 echo Run this script from the base of your tree. For example:
55 echo " cd /Path/To/Edk/Root"
07d80d35 56 echo " . $SCRIPTNAME"
d5493449
PB
57 return 1
58 fi
59
60 #
61 # Check for BaseTools/BuildEnv before dirtying the user's environment.
62 #
63 if [ ! -f BaseTools/BuildEnv ] && [ -z "$EDK_TOOLS_PATH" ]
64 then
65 echo BaseTools not found in your tree, and EDK_TOOLS_PATH is not set.
66 echo Please point EDK_TOOLS_PATH at the directory that contains
67 echo the EDK2 BuildEnv script.
68 return 1
69 fi
70
71 #
72 # Set $WORKSPACE
73 #
80d4f9e8 74 export WORKSPACE=$PWD
d5493449
PB
75 return 0
76}
77
729220ea
PP
78function SetupEnv()
79{
7bc14212
PB
80 if [ -n "$EDK_TOOLS_PATH" ]
81 then
44f79425 82 . $EDK_TOOLS_PATH/BuildEnv
d5493449 83 elif [ -f "$WORKSPACE/BaseTools/BuildEnv" ]
729220ea 84 then
44f79425 85 . $WORKSPACE/BaseTools/BuildEnv
094a6739 86 elif [ -n "$PACKAGES_PATH" ]
7aef7b7c 87 then
094a6739
LG
88 PATH_LIST=$PACKAGES_PATH
89 PATH_LIST=${PATH_LIST//:/ }
90 for DIR in $PATH_LIST
91 do
92 if [ -f "$DIR/BaseTools/BuildEnv" ]
93 then
94 export EDK_TOOLS_PATH=$DIR/BaseTools
44f79425 95 . $DIR/BaseTools/BuildEnv
094a6739
LG
96 break
97 fi
98 done
7bc14212 99 else
d5493449 100 echo BaseTools not found in your tree, and EDK_TOOLS_PATH is not set.
094a6739
LG
101 echo Please check that WORKSPACE or PACKAGES_PATH is not set incorrectly
102 echo in your shell, or point EDK_TOOLS_PATH at the directory that contains
d5493449
PB
103 echo the EDK2 BuildEnv script.
104 return 1
729220ea
PP
105 fi
106}
107
7aef7b7c
LG
108function SetupPython3()
109{
110 if [ $origin_version ];then
aecad6c1
RC
111 origin_version=
112 fi
113 for python in $(whereis python3)
114 do
115 python=$(echo $python | grep "[[:digit:]]$" || true)
116 python_version=${python##*python}
117 if [ -z "${python_version}" ] || (! command -v $python >/dev/null 2>&1);then
118 continue
d8238aaf 119 fi
aecad6c1
RC
120 if [ -z $origin_version ];then
121 origin_version=$python_version
122 export PYTHON_COMMAND=$python
123 continue
124 fi
39744883 125 if [[ "$origin_version" < "$python_version" ]]; then
aecad6c1
RC
126 origin_version=$python_version
127 export PYTHON_COMMAND=$python
128 fi
129 done
130 return 0
7aef7b7c
LG
131}
132
133function SetupPython()
134{
135 if [ $PYTHON_COMMAND ] && [ -z $PYTHON3_ENABLE ];then
136 if ( command -v $PYTHON_COMMAND >/dev/null 2>&1 );then
137 return 0
138 else
139 echo $PYTHON_COMMAND Cannot be used to build or execute the python tools.
140 return 1
141 fi
9c2d68c0 142 fi
7aef7b7c
LG
143
144 if [ $PYTHON3_ENABLE ] && [ $PYTHON3_ENABLE == TRUE ]
145 then
146 SetupPython3
147 fi
148
149 if [ $PYTHON3_ENABLE ] && [ $PYTHON3_ENABLE != TRUE ]
9c2d68c0 150 then
d8238aaf
ZF
151 if [ $origin_version ];then
152 origin_version=
153 fi
154 for python in $(whereis python2)
9c2d68c0
ZF
155 do
156 python=$(echo $python | grep "[[:digit:]]$" || true)
157 python_version=${python##*python}
d8238aaf 158 if [ -z "${python_version}" ] || (! command -v $python >/dev/null 2>&1);then
9c2d68c0
ZF
159 continue
160 fi
d8238aaf 161 if [ -z $origin_version ]
9c2d68c0
ZF
162 then
163 origin_version=$python_version
7aef7b7c 164 export PYTHON_COMMAND=$python
9c2d68c0
ZF
165 continue
166 fi
39744883 167 if [[ "$origin_version" < "$python_version" ]]; then
9c2d68c0 168 origin_version=$python_version
7aef7b7c 169 export PYTHON_COMMAND=$python
9c2d68c0
ZF
170 fi
171 done
7aef7b7c 172 return 0
9c2d68c0 173 fi
7aef7b7c
LG
174
175 SetupPython3
9c2d68c0
ZF
176}
177
729220ea
PP
178function SourceEnv()
179{
44f79425 180 SetWorkspace &&
49693202
FZ
181 SetupEnv
182 SetupPython
729220ea 183}
ef9086c3 184
44f79425
LL
185I=$#
186while [ $I -gt 0 ]
187do
188 case "$1" in
189 BaseTools)
190 # Ignore argument for backwards compatibility
191 shift
192 ;;
c112e371
LL
193 --reconfig)
194 RECONFIG=TRUE
195 shift
196 ;;
cf2d8d49 197 *)
44f79425
LL
198 HelpMsg
199 break
200 ;;
201 esac
11e5fc66 202 I=$((I - 1))
44f79425 203done
1bb6bfaa 204
44f79425 205if [ $I -gt 0 ]
1bb6bfaa 206then
44f79425 207 return 1
ef9086c3
JJ
208fi
209
44f79425 210SourceEnv
b9e16a84 211
c112e371
LL
212unset SCRIPTNAME RECONFIG
213
44f79425 214return $?