Yingke Liu | 97fa0ee | 2014-08-28 13:53:34 +0000 | [diff] [blame] | 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" |
jljusten | a310886 | 2007-10-16 20:52:46 +0000 | [diff] [blame] | 4 | # |
Liming Gao | 094a673 | 2015-10-08 09:29:56 +0000 | [diff] [blame] | 5 | # Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR> |
lgao4 | 40d841f | 2010-05-18 05:04:32 +0000 | [diff] [blame] | 6 | # This program and the accompanying materials |
jljusten | a310886 | 2007-10-16 20:52:46 +0000 | [diff] [blame] | 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. |
jljusten | 66dcb2f | 2007-12-11 09:03:30 +0000 | [diff] [blame] | 13 | # |
jljusten | a310886 | 2007-10-16 20:52:46 +0000 | [diff] [blame] | 14 | |
jljusten | 66dcb2f | 2007-12-11 09:03:30 +0000 | [diff] [blame] | 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 | |
jljusten | 66dcb2f | 2007-12-11 09:03:30 +0000 | [diff] [blame] | 25 | # |
| 26 | # Set $WORKSPACE |
| 27 | # |
| 28 | export WORKSPACE=`pwd` |
| 29 | |
| 30 | return 0 |
| 31 | |
| 32 | } |
| 33 | |
| 34 | RestorePreviousConfiguration() { |
| 35 | # |
| 36 | # Restore previous configuration |
| 37 | # |
Liming Gao | 094a673 | 2015-10-08 09:29:56 +0000 | [diff] [blame] | 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 |
jljusten | 66dcb2f | 2007-12-11 09:03:30 +0000 | [diff] [blame] | 56 | if [ -e $PREVIOUS_CONF_FILE ] |
| 57 | then |
Liming Gao | 094a673 | 2015-10-08 09:29:56 +0000 | [diff] [blame] | 58 | echo Loading previous configuration from $PREVIOUS_CONF_FILE |
| 59 | . $PREVIOUS_CONF_FILE |
jljusten | 66dcb2f | 2007-12-11 09:03:30 +0000 | [diff] [blame] | 60 | fi |
| 61 | } |
| 62 | |
| 63 | GenerateShellCodeToSetVariable() { |
| 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 | |
| 74 | GenerateShellCodeToUpdatePath() { |
| 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 | |
| 85 | StoreCurrentConfiguration() { |
| 86 | # |
| 87 | # Write configuration to a shell script to allow for configuration to be |
| 88 | # easily reloaded. |
| 89 | # |
Liming Gao | 094a673 | 2015-10-08 09:29:56 +0000 | [diff] [blame] | 90 | OUTPUT_FILE=$CONF_PATH/BuildEnv.sh |
| 91 | #echo Storing current configuration into $OUTPUT_FILE |
jljusten | 66dcb2f | 2007-12-11 09:03:30 +0000 | [diff] [blame] | 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 | |
| 98 | SetEdkToolsPath() { |
| 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 Gao | 094a673 | 2015-10-08 09:29:56 +0000 | [diff] [blame] | 109 | # Try $CONF_PATH/EdkTools |
jljusten | 66dcb2f | 2007-12-11 09:03:30 +0000 | [diff] [blame] | 110 | # |
Liming Gao | 094a673 | 2015-10-08 09:29:56 +0000 | [diff] [blame] | 111 | if [ -e $CONF_PATH/EdkTools ] |
jljusten | 66dcb2f | 2007-12-11 09:03:30 +0000 | [diff] [blame] | 112 | then |
Liming Gao | 094a673 | 2015-10-08 09:29:56 +0000 | [diff] [blame] | 113 | export EDK_TOOLS_PATH=$CONF_PATH/EdkTools |
jljusten | 66dcb2f | 2007-12-11 09:03:30 +0000 | [diff] [blame] | 114 | return 0 |
| 115 | fi |
| 116 | |
| 117 | # |
Liming Gao | 094a673 | 2015-10-08 09:29:56 +0000 | [diff] [blame] | 118 | # Try $CONF_PATH/BaseToolsSource |
jljusten | 66dcb2f | 2007-12-11 09:03:30 +0000 | [diff] [blame] | 119 | # |
Liming Gao | 094a673 | 2015-10-08 09:29:56 +0000 | [diff] [blame] | 120 | if [ -e $CONF_PATH/BaseToolsSource ] |
jljusten | 66dcb2f | 2007-12-11 09:03:30 +0000 | [diff] [blame] | 121 | then |
Liming Gao | 094a673 | 2015-10-08 09:29:56 +0000 | [diff] [blame] | 122 | export EDK_TOOLS_PATH=$CONF_PATH/BaseToolsSource |
jljusten | 66dcb2f | 2007-12-11 09:03:30 +0000 | [diff] [blame] | 123 | return 0 |
| 124 | fi |
| 125 | |
| 126 | # |
qhuang8 | 14c4857 | 2010-07-21 02:46:15 +0000 | [diff] [blame] | 127 | # Try $WORKSPACE/BaseTools |
jljusten | 66dcb2f | 2007-12-11 09:03:30 +0000 | [diff] [blame] | 128 | # |
qhuang8 | 14c4857 | 2010-07-21 02:46:15 +0000 | [diff] [blame] | 129 | if [ -e $WORKSPACE/BaseTools ] |
jljusten | 66dcb2f | 2007-12-11 09:03:30 +0000 | [diff] [blame] | 130 | then |
| 131 | export EDK_TOOLS_PATH=$WORKSPACE/BaseTools |
| 132 | return 0 |
| 133 | fi |
| 134 | |
Liming Gao | 094a673 | 2015-10-08 09:29:56 +0000 | [diff] [blame] | 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 | |
jljusten | 66dcb2f | 2007-12-11 09:03:30 +0000 | [diff] [blame] | 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 | |
| 160 | GetBaseToolsBinSubDir() { |
| 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 | |
| 170 | GetEdkToolsPathBinDirectory() { |
| 171 | # |
| 172 | # Figure out a uniq directory name from the uname command |
| 173 | # |
| 174 | BIN_SUB_DIR=`GetBaseToolsBinSubDir` |
| 175 | |
jljusten | b9a615f | 2008-02-13 22:44:22 +0000 | [diff] [blame] | 176 | if [ -e $EDK_TOOLS_PATH/BinWrappers/$BIN_SUB_DIR ] |
jljusten | 66dcb2f | 2007-12-11 09:03:30 +0000 | [diff] [blame] | 177 | then |
jljusten | b9a615f | 2008-02-13 22:44:22 +0000 | [diff] [blame] | 178 | EDK_TOOLS_PATH_BIN=$EDK_TOOLS_PATH/BinWrappers/$BIN_SUB_DIR |
jljusten | 66dcb2f | 2007-12-11 09:03:30 +0000 | [diff] [blame] | 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 | |
lgao4 | 64b2609 | 2012-04-10 07:18:20 +0000 | [diff] [blame] | 186 | AddDirToStartOfPath() { |
| 187 | DIRNAME=$1 |
| 188 | PATH=$DIRNAME:$DIRNAME:$DIRNAME:$PATH |
| 189 | PATH=${PATH//$DIRNAME:/} |
| 190 | PATH=$DIRNAME:$PATH |
| 191 | export PATH |
| 192 | } |
| 193 | |
jljusten | 66dcb2f | 2007-12-11 09:03:30 +0000 | [diff] [blame] | 194 | AddEdkToolsToPath() { |
| 195 | |
| 196 | # |
| 197 | # If EDK_TOOLS_PATH is not set, then we cannot update PATH |
| 198 | # |
| 199 | if [ -z "$EDK_TOOLS_PATH" ] |
| 200 | then |
qhuang8 | 14c4857 | 2010-07-21 02:46:15 +0000 | [diff] [blame] | 201 | return 1 |
jljusten | 66dcb2f | 2007-12-11 09:03:30 +0000 | [diff] [blame] | 202 | fi |
| 203 | |
| 204 | EDK_TOOLS_PATH_BIN=`GetEdkToolsPathBinDirectory` |
| 205 | |
lgao4 | 64b2609 | 2012-04-10 07:18:20 +0000 | [diff] [blame] | 206 | AddDirToStartOfPath $EDK_TOOLS_PATH/BinWrappers/PosixLike |
| 207 | AddDirToStartOfPath $EDK_TOOLS_PATH_BIN |
jljusten | 66dcb2f | 2007-12-11 09:03:30 +0000 | [diff] [blame] | 208 | |
| 209 | } |
| 210 | |
| 211 | CopySingleTemplateFile() { |
| 212 | |
lgao4 | a709adf | 2009-12-29 06:16:53 +0000 | [diff] [blame] | 213 | SRC_FILENAME=Conf/$1.template |
Liming Gao | 094a673 | 2015-10-08 09:29:56 +0000 | [diff] [blame] | 214 | DST_FILENAME=$CONF_PATH/$1.txt |
jljusten | 66dcb2f | 2007-12-11 09:03:30 +0000 | [diff] [blame] | 215 | |
Liming Gao | 094a673 | 2015-10-08 09:29:56 +0000 | [diff] [blame] | 216 | if [ -e $DST_FILENAME ] |
jljusten | 66dcb2f | 2007-12-11 09:03:30 +0000 | [diff] [blame] | 217 | then |
| 218 | return |
| 219 | fi |
| 220 | |
lgao4 | a709adf | 2009-12-29 06:16:53 +0000 | [diff] [blame] | 221 | echo "Copying \$EDK_TOOLS_PATH/$SRC_FILENAME" |
Liming Gao | 094a673 | 2015-10-08 09:29:56 +0000 | [diff] [blame] | 222 | echo " to $DST_FILENAME" |
lgao4 | a709adf | 2009-12-29 06:16:53 +0000 | [diff] [blame] | 223 | SRC_FILENAME=$EDK_TOOLS_PATH/$SRC_FILENAME |
jljusten | 66dcb2f | 2007-12-11 09:03:30 +0000 | [diff] [blame] | 224 | cp $SRC_FILENAME $DST_FILENAME |
| 225 | |
| 226 | } |
| 227 | |
| 228 | CopyTemplateFiles() { |
| 229 | |
| 230 | CopySingleTemplateFile build_rule |
jljusten | 66dcb2f | 2007-12-11 09:03:30 +0000 | [diff] [blame] | 231 | CopySingleTemplateFile tools_def |
| 232 | CopySingleTemplateFile target |
| 233 | |
| 234 | } |
| 235 | |
| 236 | ScriptMain() { |
| 237 | |
| 238 | SetWorkspace |
| 239 | if [ -z $WORKSPACE ] |
| 240 | then |
| 241 | echo "Failure setting WORKSPACE" |
qhuang8 | 14c4857 | 2010-07-21 02:46:15 +0000 | [diff] [blame] | 242 | return 1 |
jljusten | 66dcb2f | 2007-12-11 09:03:30 +0000 | [diff] [blame] | 243 | fi |
| 244 | |
| 245 | RestorePreviousConfiguration |
| 246 | |
| 247 | SetEdkToolsPath |
| 248 | if [ -z $EDK_TOOLS_PATH ] |
| 249 | then |
qhuang8 | 14c4857 | 2010-07-21 02:46:15 +0000 | [diff] [blame] | 250 | return 1 |
jljusten | 66dcb2f | 2007-12-11 09:03:30 +0000 | [diff] [blame] | 251 | fi |
| 252 | |
| 253 | AddEdkToolsToPath |
| 254 | if [ $? -ne 0 ] |
| 255 | then |
| 256 | echo "Failure adding EDK Tools into PATH!" |
qhuang8 | 14c4857 | 2010-07-21 02:46:15 +0000 | [diff] [blame] | 257 | return 1 |
jljusten | 66dcb2f | 2007-12-11 09:03:30 +0000 | [diff] [blame] | 258 | fi |
| 259 | |
| 260 | StoreCurrentConfiguration |
| 261 | |
| 262 | echo WORKSPACE: $WORKSPACE |
| 263 | echo EDK_TOOLS_PATH: $EDK_TOOLS_PATH |
Liming Gao | 094a673 | 2015-10-08 09:29:56 +0000 | [diff] [blame] | 264 | echo CONF_PATH: $CONF_PATH |
jljusten | 66dcb2f | 2007-12-11 09:03:30 +0000 | [diff] [blame] | 265 | |
| 266 | CopyTemplateFiles |
| 267 | |
| 268 | } |
jljusten | a310886 | 2007-10-16 20:52:46 +0000 | [diff] [blame] | 269 | |
| 270 | # |
jljusten | 66dcb2f | 2007-12-11 09:03:30 +0000 | [diff] [blame] | 271 | # Run the main function |
jljusten | a310886 | 2007-10-16 20:52:46 +0000 | [diff] [blame] | 272 | # |
jljusten | 66dcb2f | 2007-12-11 09:03:30 +0000 | [diff] [blame] | 273 | ScriptMain |
jljusten | a310886 | 2007-10-16 20:52:46 +0000 | [diff] [blame] | 274 | |