]> git.proxmox.com Git - mirror_edk2.git/blame - edksetup.sh
NetworkPkg: Move Network library and drivers from MdeModulePkg to NetworkPkg
[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
95cc9a51 52 if [ ! ${BASH_SOURCE[0]} -ef ./edksetup.sh ] && [ -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"
56 echo " . edksetup.sh"
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 #
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
d8238aaf
ZF
111 origin_version=
112 fi
113 for python in $(whereis python3)
9c2d68c0
ZF
114 do
115 python=$(echo $python | grep "[[:digit:]]$" || true)
116 python_version=${python##*python}
d8238aaf 117 if [ -z "${python_version}" ] || (! command -v $python >/dev/null 2>&1);then
9c2d68c0
ZF
118 continue
119 fi
120 if [ -z $origin_version ];then
121 origin_version=$python_version
7aef7b7c 122 export PYTHON_COMMAND=$python
9c2d68c0
ZF
123 continue
124 fi
125 ret=`echo "$origin_version < $python_version" |bc`
126 if [ "$ret" -eq 1 ]; then
127 origin_version=$python_version
7aef7b7c 128 export PYTHON_COMMAND=$python
9c2d68c0
ZF
129 fi
130 done
7aef7b7c
LG
131 return 0
132}
133
134function SetupPython()
135{
136 if [ $PYTHON_COMMAND ] && [ -z $PYTHON3_ENABLE ];then
137 if ( command -v $PYTHON_COMMAND >/dev/null 2>&1 );then
138 return 0
139 else
140 echo $PYTHON_COMMAND Cannot be used to build or execute the python tools.
141 return 1
142 fi
9c2d68c0 143 fi
7aef7b7c
LG
144
145 if [ $PYTHON3_ENABLE ] && [ $PYTHON3_ENABLE == TRUE ]
146 then
147 SetupPython3
148 fi
149
150 if [ $PYTHON3_ENABLE ] && [ $PYTHON3_ENABLE != TRUE ]
9c2d68c0 151 then
d8238aaf
ZF
152 if [ $origin_version ];then
153 origin_version=
154 fi
155 for python in $(whereis python2)
9c2d68c0
ZF
156 do
157 python=$(echo $python | grep "[[:digit:]]$" || true)
158 python_version=${python##*python}
d8238aaf 159 if [ -z "${python_version}" ] || (! command -v $python >/dev/null 2>&1);then
9c2d68c0
ZF
160 continue
161 fi
d8238aaf 162 if [ -z $origin_version ]
9c2d68c0
ZF
163 then
164 origin_version=$python_version
7aef7b7c 165 export PYTHON_COMMAND=$python
9c2d68c0
ZF
166 continue
167 fi
168 ret=`echo "$origin_version < $python_version" |bc`
169 if [ "$ret" -eq 1 ]; then
170 origin_version=$python_version
7aef7b7c 171 export PYTHON_COMMAND=$python
9c2d68c0
ZF
172 fi
173 done
7aef7b7c 174 return 0
9c2d68c0 175 fi
7aef7b7c
LG
176
177 SetupPython3
9c2d68c0
ZF
178}
179
729220ea
PP
180function SourceEnv()
181{
44f79425 182 SetWorkspace &&
49693202
FZ
183 SetupEnv
184 SetupPython
729220ea 185}
ef9086c3 186
44f79425
LL
187I=$#
188while [ $I -gt 0 ]
189do
190 case "$1" in
191 BaseTools)
192 # Ignore argument for backwards compatibility
193 shift
194 ;;
c112e371
LL
195 --reconfig)
196 RECONFIG=TRUE
197 shift
198 ;;
44f79425
LL
199 -?|-h|--help|*)
200 HelpMsg
201 break
202 ;;
203 esac
204 I=$(($I - 1))
205done
1bb6bfaa 206
44f79425 207if [ $I -gt 0 ]
1bb6bfaa 208then
44f79425 209 return 1
ef9086c3
JJ
210fi
211
44f79425 212SourceEnv
b9e16a84 213
c112e371
LL
214unset SCRIPTNAME RECONFIG
215
44f79425 216return $?