VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware/BaseTools/BuildEnv

Last change on this file was 101291, checked in by vboxsync, 14 months ago

EFI/FirmwareNew: Make edk2-stable202308 build on all supported platforms (using gcc at least, msvc not tested yet), bugref:4643

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
File size: 6.3 KB
Line 
1## @file
2# Setup the environment for unix-like systems running a bash-like shell.
3# This file must be "sourced" not merely executed. For example: ". edksetup.sh"
4#
5# Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
6# Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>
7# SPDX-License-Identifier: BSD-2-Clause-Patent
8#
9
10SetWorkspace() {
11
12 #
13 # If WORKSPACE is already set, then we can return right now
14 #
15 if [ -n "$WORKSPACE" ]
16 then
17 return 0
18 fi
19
20 #
21 # Set $WORKSPACE
22 #
23 WORKSPACE=$(pwd)
24 export WORKSPACE
25
26 return 0
27
28}
29
30RestorePreviousConfiguration() {
31 #
32 # Restore previous configuration
33 #
34 if [ -z "$CONF_PATH" ]
35 then
36 export CONF_PATH=$WORKSPACE/Conf
37 if [ ! -d $WORKSPACE/Conf ] && [ -n "$PACKAGES_PATH" ]
38 then
39 for DIR in $(echo $PACKAGES_PATH | tr ':' ' ')
40 do
41 if [ -d $DIR/Conf ]
42 then
43 export CONF_PATH=$DIR/Conf
44 break
45 fi
46 done
47 fi
48 fi
49
50 PREVIOUS_CONF_FILE=$CONF_PATH/BuildEnv.sh
51 if [ -e $PREVIOUS_CONF_FILE ]
52 then
53 echo Loading previous configuration from $PREVIOUS_CONF_FILE
54 . $PREVIOUS_CONF_FILE
55 fi
56}
57
58GenerateShellCodeToSetVariable() {
59 VARIABLE=$1
60 OUTPUT_FILE=$2
61 VAR_VALUE="echo \${${VARIABLE}}"
62 VAR_VALUE=`eval $VAR_VALUE`
63 echo "if [ -z \"\$${VARIABLE}\" ]" >> $OUTPUT_FILE
64 echo "then" >> $OUTPUT_FILE
65 echo " export ${VARIABLE}=${VAR_VALUE}" >> $OUTPUT_FILE
66 echo "fi" >> $OUTPUT_FILE
67}
68
69GenerateShellCodeToUpdatePath() {
70 OUTPUT_FILE=$1
71 echo "if [ -e $EDK_TOOLS_PATH_BIN ]" >> $OUTPUT_FILE
72 echo "then" >> $OUTPUT_FILE
73 echo " FOUND_TOOLS_PATH_BIN=0" >> $OUTPUT_FILE
74 echo " for DIR in \$(echo \$PATH | tr ':' ' '); do" >> $OUTPUT_FILE
75 echo " if [ \"\$DIR\" = \"$EDK_TOOLS_PATH_BIN\" ]; then" >> $OUTPUT_FILE
76 echo " FOUND_TOOLS_PATH_BIN=1" >> $OUTPUT_FILE
77 echo " fi" >> $OUTPUT_FILE
78 echo " done" >> $OUTPUT_FILE
79 echo " if [ \$FOUND_TOOLS_PATH_BIN = 0 ]" >> $OUTPUT_FILE
80 echo " then" >> $OUTPUT_FILE
81 echo " export PATH=$EDK_TOOLS_PATH_BIN:\$PATH" >> $OUTPUT_FILE
82 echo " fi" >> $OUTPUT_FILE
83 echo "fi" >> $OUTPUT_FILE
84}
85
86StoreCurrentConfiguration() {
87 #
88 # Write configuration to a shell script to allow for configuration to be
89 # easily reloaded.
90 #
91 OUTPUT_FILE=$CONF_PATH/BuildEnv.sh
92 #echo Storing current configuration into $OUTPUT_FILE
93 echo "# Auto-generated by BaseTools/BuildEnv" >| $OUTPUT_FILE
94 GenerateShellCodeToSetVariable WORKSPACE $OUTPUT_FILE
95 GenerateShellCodeToSetVariable EDK_TOOLS_PATH $OUTPUT_FILE
96 GenerateShellCodeToUpdatePath $OUTPUT_FILE
97}
98
99SetEdkToolsPath() {
100
101 #
102 # If EDK_TOOLS_PATH is already set, then we can return right now
103 #
104 if [ -n "$EDK_TOOLS_PATH" ]
105 then
106 return 0
107 fi
108
109 #
110 # Try $CONF_PATH/EdkTools
111 #
112 if [ -e $CONF_PATH/EdkTools ]
113 then
114 export EDK_TOOLS_PATH=$CONF_PATH/EdkTools
115 return 0
116 fi
117
118 #
119 # Try $CONF_PATH/BaseToolsSource
120 #
121 if [ -e $CONF_PATH/BaseToolsSource ]
122 then
123 export EDK_TOOLS_PATH=$CONF_PATH/BaseToolsSource
124 return 0
125 fi
126
127 #
128 # Try $WORKSPACE/BaseTools
129 #
130 if [ -e $WORKSPACE/BaseTools ]
131 then
132 export EDK_TOOLS_PATH=$WORKSPACE/BaseTools
133 return 0
134 fi
135
136 #
137 # Try $PACKAGES_PATH
138 #
139 if [ -n "$PACKAGES_PATH" ]
140 then
141 for DIR in $(echo $PACKAGES_PATH | tr ':' ' ')
142 do
143 if [ -d $DIR/BaseTools ]
144 then
145 export EDK_TOOLS_PATH=$DIR/BaseTools
146 return 0
147 fi
148 done
149 fi
150
151 echo "Unable to determine EDK_TOOLS_PATH"
152 echo
153 echo "You may need to download the 'BaseTools' from buildtools.tianocore.org."
154 echo "After downloading, either create a symbolic link to the source at"
155 echo "\$WORKSPACE/Conf/BaseToolsSource, or set the EDK_TOOLS_PATH environment"
156 echo "variable."
157
158}
159
160GetBaseToolsBinSubDir() {
161 #
162 # Figure out a uniq directory name from the uname command
163 #
164 echo $(uname -sm | tr ' ' '-')
165}
166
167GetEdkToolsPathBinDirectory() {
168 #
169 # Figure out a uniq directory name from the uname command
170 #
171 BIN_SUB_DIR=`GetBaseToolsBinSubDir`
172
173 if [ -e $EDK_TOOLS_PATH/BinWrappers/$BIN_SUB_DIR ]
174 then
175 EDK_TOOLS_PATH_BIN=$EDK_TOOLS_PATH/BinWrappers/$BIN_SUB_DIR
176 else
177 EDK_TOOLS_PATH_BIN=$EDK_TOOLS_PATH/Bin/$BIN_SUB_DIR
178 fi
179
180 echo $EDK_TOOLS_PATH_BIN
181}
182
183AddDirToStartOfPath() {
184 DIRNAME=$1
185 PATH=$DIRNAME:$PATH
186 export PATH
187}
188
189AddEdkToolsToPath() {
190
191 #
192 # If EDK_TOOLS_PATH is not set, then we cannot update PATH
193 #
194 if [ -z "$EDK_TOOLS_PATH" ]
195 then
196 return 1
197 fi
198
199 EDK_TOOLS_PATH_BIN=`GetEdkToolsPathBinDirectory`
200
201 # check if the edk2basetools pip package is available
202 if $PYTHON_COMMAND -c "import edk2basetools" > /dev/null 2>&1; then
203 # if it is, use the pip version of the wrappers
204 echo "Using Pip Basetools"
205 AddDirToStartOfPath $EDK_TOOLS_PATH/BinPipWrappers/PosixLike
206 else
207 echo "Using EDK2 in-source Basetools"
208 AddDirToStartOfPath $EDK_TOOLS_PATH/BinWrappers/PosixLike
209 fi
210
211
212 AddDirToStartOfPath $EDK_TOOLS_PATH_BIN
213
214}
215
216CopySingleTemplateFile() {
217
218 SRC_FILENAME=Conf/$1.template
219 DST_FILENAME=$CONF_PATH/$1.txt
220
221 if [ -e $DST_FILENAME ]
222 then
223 [ $RECONFIG != TRUE ] && return
224 fi
225
226 echo "Copying \$EDK_TOOLS_PATH/$SRC_FILENAME"
227 echo " to $DST_FILENAME"
228 SRC_FILENAME=$EDK_TOOLS_PATH/$SRC_FILENAME
229 cp $SRC_FILENAME $DST_FILENAME
230
231}
232
233CopyTemplateFiles() {
234
235 CopySingleTemplateFile build_rule
236 CopySingleTemplateFile tools_def
237 CopySingleTemplateFile target
238
239}
240
241ScriptMain() {
242
243 SetWorkspace
244 if [ -z $WORKSPACE ]
245 then
246 echo "Failure setting WORKSPACE"
247 return 1
248 fi
249
250 RestorePreviousConfiguration
251
252 SetEdkToolsPath
253 if [ -z $EDK_TOOLS_PATH ]
254 then
255 return 1
256 fi
257
258 AddEdkToolsToPath
259 if [ $? -ne 0 ]
260 then
261 echo "Failure adding EDK Tools into PATH!"
262 return 1
263 fi
264
265 StoreCurrentConfiguration
266
267 echo WORKSPACE: $WORKSPACE
268 echo EDK_TOOLS_PATH: $EDK_TOOLS_PATH
269 echo CONF_PATH: $CONF_PATH
270
271 CopyTemplateFiles
272
273}
274
275#
276# Run the main function
277#
278ScriptMain
279
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette