2 # Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
3 # This program and the accompanying materials
4 # are licensed and made available under the terms and conditions of the BSD License
5 # which accompanies this distribution. The full text of the license may be found at
6 # http://opensource.org/licenses/bsd-license.php
8 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
9 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 # Setup the environment for unix-like systems running a bash-like shell.
13 # This file must be "sourced" not merely executed. For example: ". edksetup.sh"
19 # If WORKSPACE is already set, then we can return right now
21 if [ -n "$WORKSPACE" ]
26 if [ ! ${BASH_SOURCE[0]} -ef ./BaseTools/BuildEnv ]
28 echo Run this script from the base of your tree. For example:
29 echo " cd /Path/To/Edk/Root"
30 echo " . BaseTools/BuildEnv"
37 export WORKSPACE=`pwd`
43 RestorePreviousConfiguration() {
45 # Restore previous configuration
47 PREVIOUS_CONF_FILE=Conf/BuildEnv.sh
48 if [ -e $PREVIOUS_CONF_FILE ]
50 echo Loading previous configuration from \$WORKSPACE/$PREVIOUS_CONF_FILE
51 . $WORKSPACE/$PREVIOUS_CONF_FILE
55 GenerateShellCodeToSetVariable() {
58 VAR_VALUE="echo \${${VARIABLE}}"
59 VAR_VALUE=`eval $VAR_VALUE`
60 echo "if [ -z \"\$${VARIABLE}\" ]" >> $OUTPUT_FILE
61 echo "then" >> $OUTPUT_FILE
62 echo " export ${VARIABLE}=${VAR_VALUE}" >> $OUTPUT_FILE
63 echo "fi" >> $OUTPUT_FILE
66 GenerateShellCodeToUpdatePath() {
68 echo "if [ -e $EDK_TOOLS_PATH_BIN ]" >> $OUTPUT_FILE
69 echo "then" >> $OUTPUT_FILE
70 echo " if [ "\${PATH/$EDK_TOOLS_PATH_BIN/}" == "\$PATH" ]" >> $OUTPUT_FILE
71 echo " then" >> $OUTPUT_FILE
72 echo " export PATH=$EDK_TOOLS_PATH_BIN:\$PATH" >> $OUTPUT_FILE
73 echo " fi" >> $OUTPUT_FILE
74 echo "fi" >> $OUTPUT_FILE
77 StoreCurrentConfiguration() {
79 # Write configuration to a shell script to allow for configuration to be
82 OUTPUT_FILE=Conf/BuildEnv.sh
83 #echo Storing current configuration into \$WORKSPACE/$OUTPUT_FILE
84 OUTPUT_FILE=$WORKSPACE/$OUTPUT_FILE
85 echo "# Auto-generated by ${BASH_SOURCE[0]}" > $OUTPUT_FILE
86 GenerateShellCodeToSetVariable WORKSPACE $OUTPUT_FILE
87 GenerateShellCodeToSetVariable EDK_TOOLS_PATH $OUTPUT_FILE
88 GenerateShellCodeToUpdatePath $OUTPUT_FILE
94 # If EDK_TOOLS_PATH is already set, then we can return right now
96 if [ -n "$EDK_TOOLS_PATH" ]
102 # Try $WORKSPACE/Conf/EdkTools
104 if [ -e $WORKSPACE/Conf/EdkTools ]
106 export EDK_TOOLS_PATH=$WORKSPACE/Conf/EdkTools
111 # Try $WORKSPACE/Conf/BaseToolsSource
113 if [ -e $WORKSPACE/Conf/BaseToolsSource ]
115 export EDK_TOOLS_PATH=$WORKSPACE/Conf/BaseToolsSource
120 # Try $WORKSPACE/BaseTools
122 if [ -e $WORKSPACE/BaseTools ]
124 export EDK_TOOLS_PATH=$WORKSPACE/BaseTools
128 echo "Unable to determine EDK_TOOLS_PATH"
130 echo "You may need to download the 'BaseTools' from buildtools.tianocore.org."
131 echo "After downloading, either create a symbolic link to the source at"
132 echo "\$WORKSPACE/Conf/BaseToolsSource, or set the EDK_TOOLS_PATH environment"
137 GetBaseToolsBinSubDir() {
139 # Figure out a uniq directory name from the uname command
141 UNAME_DIRNAME=`uname -sm`
142 UNAME_DIRNAME=${UNAME_DIRNAME// /-}
143 UNAME_DIRNAME=${UNAME_DIRNAME//\//-}
147 GetEdkToolsPathBinDirectory() {
149 # Figure out a uniq directory name from the uname command
151 BIN_SUB_DIR=`GetBaseToolsBinSubDir`
153 if [ -e $EDK_TOOLS_PATH/BinWrappers/$BIN_SUB_DIR ]
155 EDK_TOOLS_PATH_BIN=$EDK_TOOLS_PATH/BinWrappers/$BIN_SUB_DIR
157 EDK_TOOLS_PATH_BIN=$EDK_TOOLS_PATH/Bin/$BIN_SUB_DIR
160 echo $EDK_TOOLS_PATH_BIN
163 AddDirToStartOfPath() {
165 PATH=$DIRNAME:$DIRNAME:$DIRNAME:$PATH
166 PATH=${PATH//$DIRNAME:/}
171 AddEdkToolsToPath() {
174 # If EDK_TOOLS_PATH is not set, then we cannot update PATH
176 if [ -z "$EDK_TOOLS_PATH" ]
181 EDK_TOOLS_PATH_BIN=`GetEdkToolsPathBinDirectory`
183 AddDirToStartOfPath $EDK_TOOLS_PATH/BinWrappers/PosixLike
184 AddDirToStartOfPath $EDK_TOOLS_PATH_BIN
188 CopySingleTemplateFile() {
190 SRC_FILENAME=Conf/$1.template
191 DST_FILENAME=Conf/$1.txt
193 if [ -e $WORKSPACE/$DST_FILENAME ]
198 echo "Copying \$EDK_TOOLS_PATH/$SRC_FILENAME"
199 echo " to \$WORKSPACE/$DST_FILENAME"
200 SRC_FILENAME=$EDK_TOOLS_PATH/$SRC_FILENAME
201 DST_FILENAME=$WORKSPACE/$DST_FILENAME
202 cp $SRC_FILENAME $DST_FILENAME
206 CopyTemplateFiles() {
208 CopySingleTemplateFile build_rule
209 CopySingleTemplateFile tools_def
210 CopySingleTemplateFile target
219 echo "Failure setting WORKSPACE"
223 RestorePreviousConfiguration
226 if [ -z $EDK_TOOLS_PATH ]
234 echo "Failure adding EDK Tools into PATH!"
238 StoreCurrentConfiguration
240 echo WORKSPACE: $WORKSPACE
241 echo EDK_TOOLS_PATH: $EDK_TOOLS_PATH
248 # Run the main function