]>
Commit | Line | Data |
---|---|---|
1 | # | |
2 | # Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR> | |
3 | # Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR> | |
4 | # This program and the accompanying materials | |
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. | |
11 | # | |
12 | # In *inux environment, the build tools's source is required and need to be compiled | |
13 | # firstly, please reference https://github.com/tianocore/tianocore.github.io/wiki/SourceForge-to-Github-Quick-Start | |
14 | # to get how to setup build tool. | |
15 | # | |
16 | # Setup the environment for unix-like systems running a bash-like shell. | |
17 | # This file must be "sourced" not merely executed. For example: ". edksetup.sh" | |
18 | # | |
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. | |
22 | # | |
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 | |
24 | # | |
25 | ||
26 | SCRIPTNAME="edksetup.sh" | |
27 | RECONFIG=FALSE | |
28 | ||
29 | function HelpMsg() | |
30 | { | |
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 | |
39 | echo " --reconfig Overwrite the WORKSPACE/Conf/*.txt files with the" | |
40 | echo " template files from the BaseTools/Conf directory." | |
41 | echo | |
42 | echo Please note: This script must be \'sourced\' so the environment can be changed. | |
43 | echo ". $SCRIPTNAME" | |
44 | echo "source $SCRIPTNAME" | |
45 | } | |
46 | ||
47 | function SetWorkspace() | |
48 | { | |
49 | # | |
50 | # If WORKSPACE is already set, then we can return right now | |
51 | # | |
52 | export PYTHONHASHSEED=1 | |
53 | if [ -n "$WORKSPACE" ] | |
54 | then | |
55 | return 0 | |
56 | fi | |
57 | ||
58 | if [ ! ${BASH_SOURCE[0]} -ef ./edksetup.sh ] && [ -z "$PACKAGES_PATH" ] | |
59 | then | |
60 | echo Run this script from the base of your tree. For example: | |
61 | echo " cd /Path/To/Edk/Root" | |
62 | echo " . edksetup.sh" | |
63 | return 1 | |
64 | fi | |
65 | ||
66 | # | |
67 | # Check for BaseTools/BuildEnv before dirtying the user's environment. | |
68 | # | |
69 | if [ ! -f BaseTools/BuildEnv ] && [ -z "$EDK_TOOLS_PATH" ] | |
70 | then | |
71 | echo BaseTools not found in your tree, and EDK_TOOLS_PATH is not set. | |
72 | echo Please point EDK_TOOLS_PATH at the directory that contains | |
73 | echo the EDK2 BuildEnv script. | |
74 | return 1 | |
75 | fi | |
76 | ||
77 | # | |
78 | # Set $WORKSPACE | |
79 | # | |
80 | export WORKSPACE=`pwd` | |
81 | return 0 | |
82 | } | |
83 | ||
84 | function SetupEnv() | |
85 | { | |
86 | if [ -n "$EDK_TOOLS_PATH" ] | |
87 | then | |
88 | . $EDK_TOOLS_PATH/BuildEnv | |
89 | elif [ -f "$WORKSPACE/BaseTools/BuildEnv" ] | |
90 | then | |
91 | . $WORKSPACE/BaseTools/BuildEnv | |
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 | |
101 | . $DIR/BaseTools/BuildEnv | |
102 | break | |
103 | fi | |
104 | done | |
105 | else | |
106 | echo BaseTools not found in your tree, and EDK_TOOLS_PATH is not set. | |
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 | |
109 | echo the EDK2 BuildEnv script. | |
110 | return 1 | |
111 | fi | |
112 | } | |
113 | ||
114 | function SetupPython3() | |
115 | { | |
116 | if [ $origin_version ];then | |
117 | origin_version= | |
118 | fi | |
119 | for python in $(whereis python3) | |
120 | do | |
121 | python=$(echo $python | grep "[[:digit:]]$" || true) | |
122 | python_version=${python##*python} | |
123 | if [ -z "${python_version}" ] || (! command -v $python >/dev/null 2>&1);then | |
124 | continue | |
125 | fi | |
126 | if [ -z $origin_version ];then | |
127 | origin_version=$python_version | |
128 | export PYTHON_COMMAND=$python | |
129 | continue | |
130 | fi | |
131 | ret=`echo "$origin_version < $python_version" |bc` | |
132 | if [ "$ret" -eq 1 ]; then | |
133 | origin_version=$python_version | |
134 | export PYTHON_COMMAND=$python | |
135 | fi | |
136 | done | |
137 | return 0 | |
138 | } | |
139 | ||
140 | function SetupPython() | |
141 | { | |
142 | if [ $PYTHON_COMMAND ] && [ -z $PYTHON3_ENABLE ];then | |
143 | if ( command -v $PYTHON_COMMAND >/dev/null 2>&1 );then | |
144 | return 0 | |
145 | else | |
146 | echo $PYTHON_COMMAND Cannot be used to build or execute the python tools. | |
147 | return 1 | |
148 | fi | |
149 | fi | |
150 | ||
151 | if [ $PYTHON3_ENABLE ] && [ $PYTHON3_ENABLE == TRUE ] | |
152 | then | |
153 | SetupPython3 | |
154 | fi | |
155 | ||
156 | if [ $PYTHON3_ENABLE ] && [ $PYTHON3_ENABLE != TRUE ] | |
157 | then | |
158 | if [ $origin_version ];then | |
159 | origin_version= | |
160 | fi | |
161 | for python in $(whereis python2) | |
162 | do | |
163 | python=$(echo $python | grep "[[:digit:]]$" || true) | |
164 | python_version=${python##*python} | |
165 | if [ -z "${python_version}" ] || (! command -v $python >/dev/null 2>&1);then | |
166 | continue | |
167 | fi | |
168 | if [ -z $origin_version ] | |
169 | then | |
170 | origin_version=$python_version | |
171 | export PYTHON_COMMAND=$python | |
172 | continue | |
173 | fi | |
174 | ret=`echo "$origin_version < $python_version" |bc` | |
175 | if [ "$ret" -eq 1 ]; then | |
176 | origin_version=$python_version | |
177 | export PYTHON_COMMAND=$python | |
178 | fi | |
179 | done | |
180 | return 0 | |
181 | fi | |
182 | ||
183 | SetupPython3 | |
184 | } | |
185 | ||
186 | function SourceEnv() | |
187 | { | |
188 | SetWorkspace && | |
189 | SetupEnv | |
190 | SetupPython | |
191 | } | |
192 | ||
193 | I=$# | |
194 | while [ $I -gt 0 ] | |
195 | do | |
196 | case "$1" in | |
197 | BaseTools) | |
198 | # Ignore argument for backwards compatibility | |
199 | shift | |
200 | ;; | |
201 | --reconfig) | |
202 | RECONFIG=TRUE | |
203 | shift | |
204 | ;; | |
205 | -?|-h|--help|*) | |
206 | HelpMsg | |
207 | break | |
208 | ;; | |
209 | esac | |
210 | I=$(($I - 1)) | |
211 | done | |
212 | ||
213 | if [ $I -gt 0 ] | |
214 | then | |
215 | return 1 | |
216 | fi | |
217 | ||
218 | SourceEnv | |
219 | ||
220 | unset SCRIPTNAME RECONFIG | |
221 | ||
222 | return $? |