]> git.proxmox.com Git - mirror_edk2.git/blob - edksetup.sh
ArmPkg/ArmSoftFloatLib: remove source files that are no longer used
[mirror_edk2.git] / edksetup.sh
1 #
2 # Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
3 # Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>
4 # SPDX-License-Identifier: BSD-2-Clause-Patent
5 #
6 # In *inux environment, the build tools's source is required and need to be compiled
7 # firstly, please reference https://github.com/tianocore/tianocore.github.io/wiki/SourceForge-to-Github-Quick-Start
8 # to get how to setup build tool.
9 #
10 # Setup the environment for unix-like systems running a bash-like shell.
11 # This file must be "sourced" not merely executed. For example: ". edksetup.sh"
12 #
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.
16 #
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
18 #
19
20 SCRIPTNAME="edksetup.sh"
21 RECONFIG=FALSE
22
23 function HelpMsg()
24 {
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
33 echo " --reconfig Overwrite the WORKSPACE/Conf/*.txt files with the"
34 echo " template files from the BaseTools/Conf directory."
35 echo
36 echo Please note: This script must be \'sourced\' so the environment can be changed.
37 echo ". $SCRIPTNAME"
38 echo "source $SCRIPTNAME"
39 }
40
41 function SetWorkspace()
42 {
43 #
44 # If WORKSPACE is already set, then we can return right now
45 #
46 export PYTHONHASHSEED=1
47 if [ -n "$WORKSPACE" ]
48 then
49 return 0
50 fi
51
52 if [ ! ${BASH_SOURCE[0]} -ef ./edksetup.sh ] && [ -z "$PACKAGES_PATH" ]
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`
75 return 0
76 }
77
78 function SetupEnv()
79 {
80 if [ -n "$EDK_TOOLS_PATH" ]
81 then
82 . $EDK_TOOLS_PATH/BuildEnv
83 elif [ -f "$WORKSPACE/BaseTools/BuildEnv" ]
84 then
85 . $WORKSPACE/BaseTools/BuildEnv
86 elif [ -n "$PACKAGES_PATH" ]
87 then
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
95 . $DIR/BaseTools/BuildEnv
96 break
97 fi
98 done
99 else
100 echo BaseTools not found in your tree, and EDK_TOOLS_PATH is not set.
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
103 echo the EDK2 BuildEnv script.
104 return 1
105 fi
106 }
107
108 function SetupPython3()
109 {
110 if [ $origin_version ];then
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
119 fi
120 if [ -z $origin_version ];then
121 origin_version=$python_version
122 export PYTHON_COMMAND=$python
123 continue
124 fi
125 ret=`echo "$origin_version < $python_version" |bc`
126 if [ "$ret" -eq 1 ]; then
127 origin_version=$python_version
128 export PYTHON_COMMAND=$python
129 fi
130 done
131 return 0
132 }
133
134 function 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
143 fi
144
145 if [ $PYTHON3_ENABLE ] && [ $PYTHON3_ENABLE == TRUE ]
146 then
147 SetupPython3
148 fi
149
150 if [ $PYTHON3_ENABLE ] && [ $PYTHON3_ENABLE != TRUE ]
151 then
152 if [ $origin_version ];then
153 origin_version=
154 fi
155 for python in $(whereis python2)
156 do
157 python=$(echo $python | grep "[[:digit:]]$" || true)
158 python_version=${python##*python}
159 if [ -z "${python_version}" ] || (! command -v $python >/dev/null 2>&1);then
160 continue
161 fi
162 if [ -z $origin_version ]
163 then
164 origin_version=$python_version
165 export PYTHON_COMMAND=$python
166 continue
167 fi
168 ret=`echo "$origin_version < $python_version" |bc`
169 if [ "$ret" -eq 1 ]; then
170 origin_version=$python_version
171 export PYTHON_COMMAND=$python
172 fi
173 done
174 return 0
175 fi
176
177 SetupPython3
178 }
179
180 function SourceEnv()
181 {
182 SetWorkspace &&
183 SetupEnv
184 SetupPython
185 }
186
187 I=$#
188 while [ $I -gt 0 ]
189 do
190 case "$1" in
191 BaseTools)
192 # Ignore argument for backwards compatibility
193 shift
194 ;;
195 --reconfig)
196 RECONFIG=TRUE
197 shift
198 ;;
199 -?|-h|--help|*)
200 HelpMsg
201 break
202 ;;
203 esac
204 I=$(($I - 1))
205 done
206
207 if [ $I -gt 0 ]
208 then
209 return 1
210 fi
211
212 SourceEnv
213
214 unset SCRIPTNAME RECONFIG
215
216 return $?