blob: 7c77454bf88bdf106a720400a64f1c8446115a09 [file] [log] [blame]
Yingke Liu97fa0ee2014-08-28 13:53:34 +00001## @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"
jljustena3108862007-10-16 20:52:46 +00004#
Liming Gao094a6732015-10-08 09:29:56 +00005# Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
lgao440d841f2010-05-18 05:04:32 +00006# This program and the accompanying materials
jljustena3108862007-10-16 20:52:46 +00007# are licensed and made available under the terms and conditions of the BSD License
8# which accompanies this distribution. The full text of the license may be found at
9# http://opensource.org/licenses/bsd-license.php
10#
11# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
jljusten66dcb2f2007-12-11 09:03:30 +000013#
jljustena3108862007-10-16 20:52:46 +000014
jljusten66dcb2f2007-12-11 09:03:30 +000015SetWorkspace() {
16
17 #
18 # If WORKSPACE is already set, then we can return right now
19 #
20 if [ -n "$WORKSPACE" ]
21 then
22 return 0
23 fi
24
jljusten66dcb2f2007-12-11 09:03:30 +000025 #
26 # Set $WORKSPACE
27 #
28 export WORKSPACE=`pwd`
29
30 return 0
31
32}
33
34RestorePreviousConfiguration() {
35 #
36 # Restore previous configuration
37 #
Liming Gao094a6732015-10-08 09:29:56 +000038 if [ -z "$CONF_PATH" ]
39 then
40 export CONF_PATH=$WORKSPACE/Conf
41 if [ ! -d $WORKSPACE/Conf ] && [ -n "$PACKAGES_PATH" ]
42 then
43 PACKAGES_PATH=${PACKAGES_PATH//:/ }
44 for DIR in $PACKAGES_PATH
45 do
46 if [ -d $DIR/Conf ]
47 then
48 export CONF_PATH=$DIR/Conf
49 break
50 fi
51 done
52 fi
53 fi
54
55 PREVIOUS_CONF_FILE=$CONF_PATH/BuildEnv.sh
jljusten66dcb2f2007-12-11 09:03:30 +000056 if [ -e $PREVIOUS_CONF_FILE ]
57 then
Liming Gao094a6732015-10-08 09:29:56 +000058 echo Loading previous configuration from $PREVIOUS_CONF_FILE
59 . $PREVIOUS_CONF_FILE
jljusten66dcb2f2007-12-11 09:03:30 +000060 fi
61}
62
63GenerateShellCodeToSetVariable() {
64 VARIABLE=$1
65 OUTPUT_FILE=$2
66 VAR_VALUE="echo \${${VARIABLE}}"
67 VAR_VALUE=`eval $VAR_VALUE`
68 echo "if [ -z \"\$${VARIABLE}\" ]" >> $OUTPUT_FILE
69 echo "then" >> $OUTPUT_FILE
70 echo " export ${VARIABLE}=${VAR_VALUE}" >> $OUTPUT_FILE
71 echo "fi" >> $OUTPUT_FILE
72}
73
74GenerateShellCodeToUpdatePath() {
75 OUTPUT_FILE=$1
76 echo "if [ -e $EDK_TOOLS_PATH_BIN ]" >> $OUTPUT_FILE
77 echo "then" >> $OUTPUT_FILE
78 echo " if [ "\${PATH/$EDK_TOOLS_PATH_BIN/}" == "\$PATH" ]" >> $OUTPUT_FILE
79 echo " then" >> $OUTPUT_FILE
80 echo " export PATH=$EDK_TOOLS_PATH_BIN:\$PATH" >> $OUTPUT_FILE
81 echo " fi" >> $OUTPUT_FILE
82 echo "fi" >> $OUTPUT_FILE
83}
84
85StoreCurrentConfiguration() {
86 #
87 # Write configuration to a shell script to allow for configuration to be
88 # easily reloaded.
89 #
Liming Gao094a6732015-10-08 09:29:56 +000090 OUTPUT_FILE=$CONF_PATH/BuildEnv.sh
91 #echo Storing current configuration into $OUTPUT_FILE
jljusten66dcb2f2007-12-11 09:03:30 +000092 echo "# Auto-generated by ${BASH_SOURCE[0]}" > $OUTPUT_FILE
93 GenerateShellCodeToSetVariable WORKSPACE $OUTPUT_FILE
94 GenerateShellCodeToSetVariable EDK_TOOLS_PATH $OUTPUT_FILE
95 GenerateShellCodeToUpdatePath $OUTPUT_FILE
96}
97
98SetEdkToolsPath() {
99
100 #
101 # If EDK_TOOLS_PATH is already set, then we can return right now
102 #
103 if [ -n "$EDK_TOOLS_PATH" ]
104 then
105 return 0
106 fi
107
108 #
Liming Gao094a6732015-10-08 09:29:56 +0000109 # Try $CONF_PATH/EdkTools
jljusten66dcb2f2007-12-11 09:03:30 +0000110 #
Liming Gao094a6732015-10-08 09:29:56 +0000111 if [ -e $CONF_PATH/EdkTools ]
jljusten66dcb2f2007-12-11 09:03:30 +0000112 then
Liming Gao094a6732015-10-08 09:29:56 +0000113 export EDK_TOOLS_PATH=$CONF_PATH/EdkTools
jljusten66dcb2f2007-12-11 09:03:30 +0000114 return 0
115 fi
116
117 #
Liming Gao094a6732015-10-08 09:29:56 +0000118 # Try $CONF_PATH/BaseToolsSource
jljusten66dcb2f2007-12-11 09:03:30 +0000119 #
Liming Gao094a6732015-10-08 09:29:56 +0000120 if [ -e $CONF_PATH/BaseToolsSource ]
jljusten66dcb2f2007-12-11 09:03:30 +0000121 then
Liming Gao094a6732015-10-08 09:29:56 +0000122 export EDK_TOOLS_PATH=$CONF_PATH/BaseToolsSource
jljusten66dcb2f2007-12-11 09:03:30 +0000123 return 0
124 fi
125
126 #
qhuang814c48572010-07-21 02:46:15 +0000127 # Try $WORKSPACE/BaseTools
jljusten66dcb2f2007-12-11 09:03:30 +0000128 #
qhuang814c48572010-07-21 02:46:15 +0000129 if [ -e $WORKSPACE/BaseTools ]
jljusten66dcb2f2007-12-11 09:03:30 +0000130 then
131 export EDK_TOOLS_PATH=$WORKSPACE/BaseTools
132 return 0
133 fi
134
Liming Gao094a6732015-10-08 09:29:56 +0000135 #
136 # Try $PACKAGES_PATH
137 #
138 if [ -n "$PACKAGES_PATH"]
139 then
140 PACKAGES_PATH=${PACKAGES_PATH//:/ }
141 for DIR in $PACKAGES_PATH
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
jljusten66dcb2f2007-12-11 09:03:30 +0000151 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 UNAME_DIRNAME=`uname -sm`
165 UNAME_DIRNAME=${UNAME_DIRNAME// /-}
166 UNAME_DIRNAME=${UNAME_DIRNAME//\//-}
167 echo $UNAME_DIRNAME
168}
169
170GetEdkToolsPathBinDirectory() {
171 #
172 # Figure out a uniq directory name from the uname command
173 #
174 BIN_SUB_DIR=`GetBaseToolsBinSubDir`
175
jljustenb9a615f2008-02-13 22:44:22 +0000176 if [ -e $EDK_TOOLS_PATH/BinWrappers/$BIN_SUB_DIR ]
jljusten66dcb2f2007-12-11 09:03:30 +0000177 then
jljustenb9a615f2008-02-13 22:44:22 +0000178 EDK_TOOLS_PATH_BIN=$EDK_TOOLS_PATH/BinWrappers/$BIN_SUB_DIR
jljusten66dcb2f2007-12-11 09:03:30 +0000179 else
180 EDK_TOOLS_PATH_BIN=$EDK_TOOLS_PATH/Bin/$BIN_SUB_DIR
181 fi
182
183 echo $EDK_TOOLS_PATH_BIN
184}
185
lgao464b26092012-04-10 07:18:20 +0000186AddDirToStartOfPath() {
187 DIRNAME=$1
188 PATH=$DIRNAME:$DIRNAME:$DIRNAME:$PATH
189 PATH=${PATH//$DIRNAME:/}
190 PATH=$DIRNAME:$PATH
191 export PATH
192}
193
jljusten66dcb2f2007-12-11 09:03:30 +0000194AddEdkToolsToPath() {
195
196 #
197 # If EDK_TOOLS_PATH is not set, then we cannot update PATH
198 #
199 if [ -z "$EDK_TOOLS_PATH" ]
200 then
qhuang814c48572010-07-21 02:46:15 +0000201 return 1
jljusten66dcb2f2007-12-11 09:03:30 +0000202 fi
203
204 EDK_TOOLS_PATH_BIN=`GetEdkToolsPathBinDirectory`
205
lgao464b26092012-04-10 07:18:20 +0000206 AddDirToStartOfPath $EDK_TOOLS_PATH/BinWrappers/PosixLike
207 AddDirToStartOfPath $EDK_TOOLS_PATH_BIN
jljusten66dcb2f2007-12-11 09:03:30 +0000208
209}
210
211CopySingleTemplateFile() {
212
lgao4a709adf2009-12-29 06:16:53 +0000213 SRC_FILENAME=Conf/$1.template
Liming Gao094a6732015-10-08 09:29:56 +0000214 DST_FILENAME=$CONF_PATH/$1.txt
jljusten66dcb2f2007-12-11 09:03:30 +0000215
Liming Gao094a6732015-10-08 09:29:56 +0000216 if [ -e $DST_FILENAME ]
jljusten66dcb2f2007-12-11 09:03:30 +0000217 then
218 return
219 fi
220
lgao4a709adf2009-12-29 06:16:53 +0000221 echo "Copying \$EDK_TOOLS_PATH/$SRC_FILENAME"
Liming Gao094a6732015-10-08 09:29:56 +0000222 echo " to $DST_FILENAME"
lgao4a709adf2009-12-29 06:16:53 +0000223 SRC_FILENAME=$EDK_TOOLS_PATH/$SRC_FILENAME
jljusten66dcb2f2007-12-11 09:03:30 +0000224 cp $SRC_FILENAME $DST_FILENAME
225
226}
227
228CopyTemplateFiles() {
229
230 CopySingleTemplateFile build_rule
jljusten66dcb2f2007-12-11 09:03:30 +0000231 CopySingleTemplateFile tools_def
232 CopySingleTemplateFile target
233
234}
235
236ScriptMain() {
237
238 SetWorkspace
239 if [ -z $WORKSPACE ]
240 then
241 echo "Failure setting WORKSPACE"
qhuang814c48572010-07-21 02:46:15 +0000242 return 1
jljusten66dcb2f2007-12-11 09:03:30 +0000243 fi
244
245 RestorePreviousConfiguration
246
247 SetEdkToolsPath
248 if [ -z $EDK_TOOLS_PATH ]
249 then
qhuang814c48572010-07-21 02:46:15 +0000250 return 1
jljusten66dcb2f2007-12-11 09:03:30 +0000251 fi
252
253 AddEdkToolsToPath
254 if [ $? -ne 0 ]
255 then
256 echo "Failure adding EDK Tools into PATH!"
qhuang814c48572010-07-21 02:46:15 +0000257 return 1
jljusten66dcb2f2007-12-11 09:03:30 +0000258 fi
259
260 StoreCurrentConfiguration
261
262 echo WORKSPACE: $WORKSPACE
263 echo EDK_TOOLS_PATH: $EDK_TOOLS_PATH
Liming Gao094a6732015-10-08 09:29:56 +0000264 echo CONF_PATH: $CONF_PATH
jljusten66dcb2f2007-12-11 09:03:30 +0000265
266 CopyTemplateFiles
267
268}
jljustena3108862007-10-16 20:52:46 +0000269
270#
jljusten66dcb2f2007-12-11 09:03:30 +0000271# Run the main function
jljustena3108862007-10-16 20:52:46 +0000272#
jljusten66dcb2f2007-12-11 09:03:30 +0000273ScriptMain
jljustena3108862007-10-16 20:52:46 +0000274