]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/BuildEnv
UefiCpuPkg/CpuDxe: Remove PcdCpuMaxLogicalProcessorNumber consuming
[mirror_edk2.git] / BaseTools / BuildEnv
CommitLineData
97fa0ee9
YL
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"
a310886b 4#
094a6739 5# Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
40d841f6 6# This program and the accompanying materials
a310886b 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.
66dcb2f0 13#
a310886b 14
66dcb2f0 15SetWorkspace() {
a310886b 16
66dcb2f0 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
66dcb2f0 25 #
26 # Set $WORKSPACE
27 #
28 export WORKSPACE=`pwd`
29
30 return 0
31
32}
33
34RestorePreviousConfiguration() {
35 #
36 # Restore previous configuration
37 #
094a6739
LG
38 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
66dcb2f0 56 if [ -e $PREVIOUS_CONF_FILE ]
57 then
094a6739
LG
58 echo Loading previous configuration from $PREVIOUS_CONF_FILE
59 . $PREVIOUS_CONF_FILE
66dcb2f0 60 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 #
094a6739
LG
90 OUTPUT_FILE=$CONF_PATH/BuildEnv.sh
91 #echo Storing current configuration into $OUTPUT_FILE
66dcb2f0 92 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
66dcb2f0 108 #
094a6739 109 # Try $CONF_PATH/EdkTools
66dcb2f0 110 #
094a6739 111 if [ -e $CONF_PATH/EdkTools ]
66dcb2f0 112 then
094a6739 113 export EDK_TOOLS_PATH=$CONF_PATH/EdkTools
66dcb2f0 114 return 0
115 fi
116
117 #
094a6739 118 # Try $CONF_PATH/BaseToolsSource
66dcb2f0 119 #
094a6739 120 if [ -e $CONF_PATH/BaseToolsSource ]
66dcb2f0 121 then
094a6739 122 export EDK_TOOLS_PATH=$CONF_PATH/BaseToolsSource
66dcb2f0 123 return 0
124 fi
125
126 #
14c48571 127 # Try $WORKSPACE/BaseTools
66dcb2f0 128 #
14c48571 129 if [ -e $WORKSPACE/BaseTools ]
66dcb2f0 130 then
131 export EDK_TOOLS_PATH=$WORKSPACE/BaseTools
132 return 0
133 fi
134
094a6739
LG
135 #
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
66dcb2f0 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 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
b9a615fa 176 if [ -e $EDK_TOOLS_PATH/BinWrappers/$BIN_SUB_DIR ]
66dcb2f0 177 then
b9a615fa 178 EDK_TOOLS_PATH_BIN=$EDK_TOOLS_PATH/BinWrappers/$BIN_SUB_DIR
66dcb2f0 179 else
180 EDK_TOOLS_PATH_BIN=$EDK_TOOLS_PATH/Bin/$BIN_SUB_DIR
181 fi
182
183 echo $EDK_TOOLS_PATH_BIN
184}
185
64b2609f
LG
186AddDirToStartOfPath() {
187 DIRNAME=$1
188 PATH=$DIRNAME:$DIRNAME:$DIRNAME:$PATH
189 PATH=${PATH//$DIRNAME:/}
190 PATH=$DIRNAME:$PATH
191 export PATH
192}
193
66dcb2f0 194AddEdkToolsToPath() {
195
196 #
197 # If EDK_TOOLS_PATH is not set, then we cannot update PATH
198 #
199 if [ -z "$EDK_TOOLS_PATH" ]
200 then
14c48571 201 return 1
66dcb2f0 202 fi
203
204 EDK_TOOLS_PATH_BIN=`GetEdkToolsPathBinDirectory`
205
64b2609f
LG
206 AddDirToStartOfPath $EDK_TOOLS_PATH/BinWrappers/PosixLike
207 AddDirToStartOfPath $EDK_TOOLS_PATH_BIN
66dcb2f0 208
209}
210
211CopySingleTemplateFile() {
212
a709adfa 213 SRC_FILENAME=Conf/$1.template
094a6739 214 DST_FILENAME=$CONF_PATH/$1.txt
66dcb2f0 215
094a6739 216 if [ -e $DST_FILENAME ]
66dcb2f0 217 then
218 return
219 fi
220
a709adfa 221 echo "Copying \$EDK_TOOLS_PATH/$SRC_FILENAME"
094a6739 222 echo " to $DST_FILENAME"
a709adfa 223 SRC_FILENAME=$EDK_TOOLS_PATH/$SRC_FILENAME
66dcb2f0 224 cp $SRC_FILENAME $DST_FILENAME
225
226}
227
228CopyTemplateFiles() {
229
230 CopySingleTemplateFile build_rule
66dcb2f0 231 CopySingleTemplateFile tools_def
232 CopySingleTemplateFile target
233
234}
235
236ScriptMain() {
237
238 SetWorkspace
239 if [ -z $WORKSPACE ]
240 then
241 echo "Failure setting WORKSPACE"
14c48571 242 return 1
66dcb2f0 243 fi
244
245 RestorePreviousConfiguration
246
247 SetEdkToolsPath
248 if [ -z $EDK_TOOLS_PATH ]
249 then
14c48571 250 return 1
66dcb2f0 251 fi
252
253 AddEdkToolsToPath
254 if [ $? -ne 0 ]
255 then
256 echo "Failure adding EDK Tools into PATH!"
14c48571 257 return 1
66dcb2f0 258 fi
259
260 StoreCurrentConfiguration
261
262 echo WORKSPACE: $WORKSPACE
263 echo EDK_TOOLS_PATH: $EDK_TOOLS_PATH
094a6739 264 echo CONF_PATH: $CONF_PATH
66dcb2f0 265
266 CopyTemplateFiles
267
268}
a310886b 269
270#
66dcb2f0 271# Run the main function
a310886b 272#
66dcb2f0 273ScriptMain
a310886b 274