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 - 2014, Intel Corporation. All rights reserved.<BR>
|
---|
6 | # This program and the accompanying materials
|
---|
7 | # 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.
|
---|
13 | #
|
---|
14 |
|
---|
15 | SetWorkspace() {
|
---|
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 |
|
---|
25 | #
|
---|
26 | # Set $WORKSPACE
|
---|
27 | #
|
---|
28 | export WORKSPACE=`pwd`
|
---|
29 |
|
---|
30 | return 0
|
---|
31 |
|
---|
32 | }
|
---|
33 |
|
---|
34 | RestorePreviousConfiguration() {
|
---|
35 | #
|
---|
36 | # Restore previous configuration
|
---|
37 | #
|
---|
38 | PREVIOUS_CONF_FILE=Conf/BuildEnv.sh
|
---|
39 | if [ -e $PREVIOUS_CONF_FILE ]
|
---|
40 | then
|
---|
41 | echo Loading previous configuration from \$WORKSPACE/$PREVIOUS_CONF_FILE
|
---|
42 | . $WORKSPACE/$PREVIOUS_CONF_FILE
|
---|
43 | fi
|
---|
44 | }
|
---|
45 |
|
---|
46 | GenerateShellCodeToSetVariable() {
|
---|
47 | VARIABLE=$1
|
---|
48 | OUTPUT_FILE=$2
|
---|
49 | VAR_VALUE="echo \${${VARIABLE}}"
|
---|
50 | VAR_VALUE=`eval $VAR_VALUE`
|
---|
51 | echo "if [ -z \"\$${VARIABLE}\" ]" >> $OUTPUT_FILE
|
---|
52 | echo "then" >> $OUTPUT_FILE
|
---|
53 | echo " export ${VARIABLE}=${VAR_VALUE}" >> $OUTPUT_FILE
|
---|
54 | echo "fi" >> $OUTPUT_FILE
|
---|
55 | }
|
---|
56 |
|
---|
57 | GenerateShellCodeToUpdatePath() {
|
---|
58 | OUTPUT_FILE=$1
|
---|
59 | echo "if [ -e $EDK_TOOLS_PATH_BIN ]" >> $OUTPUT_FILE
|
---|
60 | echo "then" >> $OUTPUT_FILE
|
---|
61 | echo " if [ "\${PATH/$EDK_TOOLS_PATH_BIN/}" == "\$PATH" ]" >> $OUTPUT_FILE
|
---|
62 | echo " then" >> $OUTPUT_FILE
|
---|
63 | echo " export PATH=$EDK_TOOLS_PATH_BIN:\$PATH" >> $OUTPUT_FILE
|
---|
64 | echo " fi" >> $OUTPUT_FILE
|
---|
65 | echo "fi" >> $OUTPUT_FILE
|
---|
66 | }
|
---|
67 |
|
---|
68 | StoreCurrentConfiguration() {
|
---|
69 | #
|
---|
70 | # Write configuration to a shell script to allow for configuration to be
|
---|
71 | # easily reloaded.
|
---|
72 | #
|
---|
73 | OUTPUT_FILE=Conf/BuildEnv.sh
|
---|
74 | #echo Storing current configuration into \$WORKSPACE/$OUTPUT_FILE
|
---|
75 | OUTPUT_FILE=$WORKSPACE/$OUTPUT_FILE
|
---|
76 | echo "# Auto-generated by ${BASH_SOURCE[0]}" > $OUTPUT_FILE
|
---|
77 | GenerateShellCodeToSetVariable WORKSPACE $OUTPUT_FILE
|
---|
78 | GenerateShellCodeToSetVariable EDK_TOOLS_PATH $OUTPUT_FILE
|
---|
79 | GenerateShellCodeToUpdatePath $OUTPUT_FILE
|
---|
80 | }
|
---|
81 |
|
---|
82 | SetEdkToolsPath() {
|
---|
83 |
|
---|
84 | #
|
---|
85 | # If EDK_TOOLS_PATH is already set, then we can return right now
|
---|
86 | #
|
---|
87 | if [ -n "$EDK_TOOLS_PATH" ]
|
---|
88 | then
|
---|
89 | return 0
|
---|
90 | fi
|
---|
91 |
|
---|
92 | #
|
---|
93 | # Try $WORKSPACE/Conf/EdkTools
|
---|
94 | #
|
---|
95 | if [ -e $WORKSPACE/Conf/EdkTools ]
|
---|
96 | then
|
---|
97 | export EDK_TOOLS_PATH=$WORKSPACE/Conf/EdkTools
|
---|
98 | return 0
|
---|
99 | fi
|
---|
100 |
|
---|
101 | #
|
---|
102 | # Try $WORKSPACE/Conf/BaseToolsSource
|
---|
103 | #
|
---|
104 | if [ -e $WORKSPACE/Conf/BaseToolsSource ]
|
---|
105 | then
|
---|
106 | export EDK_TOOLS_PATH=$WORKSPACE/Conf/BaseToolsSource
|
---|
107 | return 0
|
---|
108 | fi
|
---|
109 |
|
---|
110 | #
|
---|
111 | # Try $WORKSPACE/BaseTools
|
---|
112 | #
|
---|
113 | if [ -e $WORKSPACE/BaseTools ]
|
---|
114 | then
|
---|
115 | export EDK_TOOLS_PATH=$WORKSPACE/BaseTools
|
---|
116 | return 0
|
---|
117 | fi
|
---|
118 |
|
---|
119 | echo "Unable to determine EDK_TOOLS_PATH"
|
---|
120 | echo
|
---|
121 | echo "You may need to download the 'BaseTools' from buildtools.tianocore.org."
|
---|
122 | echo "After downloading, either create a symbolic link to the source at"
|
---|
123 | echo "\$WORKSPACE/Conf/BaseToolsSource, or set the EDK_TOOLS_PATH environment"
|
---|
124 | echo "variable."
|
---|
125 |
|
---|
126 | }
|
---|
127 |
|
---|
128 | GetBaseToolsBinSubDir() {
|
---|
129 | #
|
---|
130 | # Figure out a uniq directory name from the uname command
|
---|
131 | #
|
---|
132 | UNAME_DIRNAME=`uname -sm`
|
---|
133 | UNAME_DIRNAME=${UNAME_DIRNAME// /-}
|
---|
134 | UNAME_DIRNAME=${UNAME_DIRNAME//\//-}
|
---|
135 | echo $UNAME_DIRNAME
|
---|
136 | }
|
---|
137 |
|
---|
138 | GetEdkToolsPathBinDirectory() {
|
---|
139 | #
|
---|
140 | # Figure out a uniq directory name from the uname command
|
---|
141 | #
|
---|
142 | BIN_SUB_DIR=`GetBaseToolsBinSubDir`
|
---|
143 |
|
---|
144 | if [ -e $EDK_TOOLS_PATH/BinWrappers/$BIN_SUB_DIR ]
|
---|
145 | then
|
---|
146 | EDK_TOOLS_PATH_BIN=$EDK_TOOLS_PATH/BinWrappers/$BIN_SUB_DIR
|
---|
147 | else
|
---|
148 | EDK_TOOLS_PATH_BIN=$EDK_TOOLS_PATH/Bin/$BIN_SUB_DIR
|
---|
149 | fi
|
---|
150 |
|
---|
151 | echo $EDK_TOOLS_PATH_BIN
|
---|
152 | }
|
---|
153 |
|
---|
154 | AddDirToStartOfPath() {
|
---|
155 | DIRNAME=$1
|
---|
156 | PATH=$DIRNAME:$DIRNAME:$DIRNAME:$PATH
|
---|
157 | PATH=${PATH//$DIRNAME:/}
|
---|
158 | PATH=$DIRNAME:$PATH
|
---|
159 | export PATH
|
---|
160 | }
|
---|
161 |
|
---|
162 | AddEdkToolsToPath() {
|
---|
163 |
|
---|
164 | #
|
---|
165 | # If EDK_TOOLS_PATH is not set, then we cannot update PATH
|
---|
166 | #
|
---|
167 | if [ -z "$EDK_TOOLS_PATH" ]
|
---|
168 | then
|
---|
169 | return 1
|
---|
170 | fi
|
---|
171 |
|
---|
172 | EDK_TOOLS_PATH_BIN=`GetEdkToolsPathBinDirectory`
|
---|
173 |
|
---|
174 | AddDirToStartOfPath $EDK_TOOLS_PATH/BinWrappers/PosixLike
|
---|
175 | AddDirToStartOfPath $EDK_TOOLS_PATH_BIN
|
---|
176 |
|
---|
177 | }
|
---|
178 |
|
---|
179 | CopySingleTemplateFile() {
|
---|
180 |
|
---|
181 | SRC_FILENAME=Conf/$1.template
|
---|
182 | DST_FILENAME=Conf/$1.txt
|
---|
183 |
|
---|
184 | if [ -e $WORKSPACE/$DST_FILENAME ]
|
---|
185 | then
|
---|
186 | return
|
---|
187 | fi
|
---|
188 |
|
---|
189 | echo "Copying \$EDK_TOOLS_PATH/$SRC_FILENAME"
|
---|
190 | echo " to \$WORKSPACE/$DST_FILENAME"
|
---|
191 | SRC_FILENAME=$EDK_TOOLS_PATH/$SRC_FILENAME
|
---|
192 | DST_FILENAME=$WORKSPACE/$DST_FILENAME
|
---|
193 | cp $SRC_FILENAME $DST_FILENAME
|
---|
194 |
|
---|
195 | }
|
---|
196 |
|
---|
197 | CopyTemplateFiles() {
|
---|
198 |
|
---|
199 | CopySingleTemplateFile build_rule
|
---|
200 | CopySingleTemplateFile tools_def
|
---|
201 | CopySingleTemplateFile target
|
---|
202 |
|
---|
203 | }
|
---|
204 |
|
---|
205 | ScriptMain() {
|
---|
206 |
|
---|
207 | SetWorkspace
|
---|
208 | if [ -z $WORKSPACE ]
|
---|
209 | then
|
---|
210 | echo "Failure setting WORKSPACE"
|
---|
211 | return 1
|
---|
212 | fi
|
---|
213 |
|
---|
214 | RestorePreviousConfiguration
|
---|
215 |
|
---|
216 | SetEdkToolsPath
|
---|
217 | if [ -z $EDK_TOOLS_PATH ]
|
---|
218 | then
|
---|
219 | return 1
|
---|
220 | fi
|
---|
221 |
|
---|
222 | AddEdkToolsToPath
|
---|
223 | if [ $? -ne 0 ]
|
---|
224 | then
|
---|
225 | echo "Failure adding EDK Tools into PATH!"
|
---|
226 | return 1
|
---|
227 | fi
|
---|
228 |
|
---|
229 | StoreCurrentConfiguration
|
---|
230 |
|
---|
231 | echo WORKSPACE: $WORKSPACE
|
---|
232 | echo EDK_TOOLS_PATH: $EDK_TOOLS_PATH
|
---|
233 |
|
---|
234 | CopyTemplateFiles
|
---|
235 |
|
---|
236 | }
|
---|
237 |
|
---|
238 | #
|
---|
239 | # Run the main function
|
---|
240 | #
|
---|
241 | ScriptMain
|
---|
242 |
|
---|