jljusten | a310886 | 2007-10-16 20:52:46 +0000 | [diff] [blame] | 1 | # |
lgao4 | 64b2609 | 2012-04-10 07:18:20 +0000 | [diff] [blame^] | 2 | # Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR> |
lgao4 | 40d841f | 2010-05-18 05:04:32 +0000 | [diff] [blame] | 3 | # This program and the accompanying materials |
jljusten | a310886 | 2007-10-16 20:52:46 +0000 | [diff] [blame] | 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 |
| 7 | # |
| 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. |
| 10 | |
jljusten | 66dcb2f | 2007-12-11 09:03:30 +0000 | [diff] [blame] | 11 | # |
jljusten | a310886 | 2007-10-16 20:52:46 +0000 | [diff] [blame] | 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" |
jljusten | 66dcb2f | 2007-12-11 09:03:30 +0000 | [diff] [blame] | 14 | # |
jljusten | a310886 | 2007-10-16 20:52:46 +0000 | [diff] [blame] | 15 | |
jljusten | 66dcb2f | 2007-12-11 09:03:30 +0000 | [diff] [blame] | 16 | SetWorkspace() { |
| 17 | |
| 18 | # |
| 19 | # If WORKSPACE is already set, then we can return right now |
| 20 | # |
| 21 | if [ -n "$WORKSPACE" ] |
| 22 | then |
| 23 | return 0 |
| 24 | fi |
| 25 | |
| 26 | if [ ! ${BASH_SOURCE[0]} -ef ./BaseTools/BuildEnv ] |
| 27 | then |
| 28 | echo Run this script from the base of your tree. For example: |
| 29 | echo " cd /Path/To/Edk/Root" |
| 30 | echo " . BaseTools/BuildEnv" |
qhuang8 | 14c4857 | 2010-07-21 02:46:15 +0000 | [diff] [blame] | 31 | return 1 |
jljusten | 66dcb2f | 2007-12-11 09:03:30 +0000 | [diff] [blame] | 32 | fi |
| 33 | |
| 34 | # |
| 35 | # Set $WORKSPACE |
| 36 | # |
| 37 | export WORKSPACE=`pwd` |
| 38 | |
| 39 | return 0 |
| 40 | |
| 41 | } |
| 42 | |
| 43 | RestorePreviousConfiguration() { |
| 44 | # |
| 45 | # Restore previous configuration |
| 46 | # |
jljusten | 2dffc14 | 2007-12-11 09:12:40 +0000 | [diff] [blame] | 47 | PREVIOUS_CONF_FILE=Conf/BuildEnv.sh |
jljusten | 66dcb2f | 2007-12-11 09:03:30 +0000 | [diff] [blame] | 48 | if [ -e $PREVIOUS_CONF_FILE ] |
| 49 | then |
| 50 | echo Loading previous configuration from \$WORKSPACE/$PREVIOUS_CONF_FILE |
| 51 | . $WORKSPACE/$PREVIOUS_CONF_FILE |
| 52 | fi |
| 53 | } |
| 54 | |
| 55 | GenerateShellCodeToSetVariable() { |
| 56 | VARIABLE=$1 |
| 57 | OUTPUT_FILE=$2 |
| 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 |
| 64 | } |
| 65 | |
| 66 | GenerateShellCodeToUpdatePath() { |
| 67 | OUTPUT_FILE=$1 |
| 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 |
| 75 | } |
| 76 | |
| 77 | StoreCurrentConfiguration() { |
| 78 | # |
| 79 | # Write configuration to a shell script to allow for configuration to be |
| 80 | # easily reloaded. |
| 81 | # |
jljusten | 2dffc14 | 2007-12-11 09:12:40 +0000 | [diff] [blame] | 82 | OUTPUT_FILE=Conf/BuildEnv.sh |
jljusten | 66dcb2f | 2007-12-11 09:03:30 +0000 | [diff] [blame] | 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 |
| 89 | } |
| 90 | |
| 91 | SetEdkToolsPath() { |
| 92 | |
| 93 | # |
| 94 | # If EDK_TOOLS_PATH is already set, then we can return right now |
| 95 | # |
| 96 | if [ -n "$EDK_TOOLS_PATH" ] |
| 97 | then |
| 98 | return 0 |
| 99 | fi |
| 100 | |
| 101 | # |
jljusten | 66dcb2f | 2007-12-11 09:03:30 +0000 | [diff] [blame] | 102 | # Try $WORKSPACE/Conf/EdkTools |
| 103 | # |
| 104 | if [ -e $WORKSPACE/Conf/EdkTools ] |
| 105 | then |
| 106 | export EDK_TOOLS_PATH=$WORKSPACE/Conf/EdkTools |
| 107 | return 0 |
| 108 | fi |
| 109 | |
| 110 | # |
| 111 | # Try $WORKSPACE/Conf/BaseToolsSource |
| 112 | # |
| 113 | if [ -e $WORKSPACE/Conf/BaseToolsSource ] |
| 114 | then |
| 115 | export EDK_TOOLS_PATH=$WORKSPACE/Conf/BaseToolsSource |
| 116 | return 0 |
| 117 | fi |
| 118 | |
| 119 | # |
qhuang8 | 14c4857 | 2010-07-21 02:46:15 +0000 | [diff] [blame] | 120 | # Try $WORKSPACE/BaseTools |
jljusten | 66dcb2f | 2007-12-11 09:03:30 +0000 | [diff] [blame] | 121 | # |
qhuang8 | 14c4857 | 2010-07-21 02:46:15 +0000 | [diff] [blame] | 122 | if [ -e $WORKSPACE/BaseTools ] |
jljusten | 66dcb2f | 2007-12-11 09:03:30 +0000 | [diff] [blame] | 123 | then |
| 124 | export EDK_TOOLS_PATH=$WORKSPACE/BaseTools |
| 125 | return 0 |
| 126 | fi |
| 127 | |
| 128 | echo "Unable to determine EDK_TOOLS_PATH" |
| 129 | echo |
| 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" |
| 133 | echo "variable." |
| 134 | |
| 135 | } |
| 136 | |
| 137 | GetBaseToolsBinSubDir() { |
| 138 | # |
| 139 | # Figure out a uniq directory name from the uname command |
| 140 | # |
| 141 | UNAME_DIRNAME=`uname -sm` |
| 142 | UNAME_DIRNAME=${UNAME_DIRNAME// /-} |
| 143 | UNAME_DIRNAME=${UNAME_DIRNAME//\//-} |
| 144 | echo $UNAME_DIRNAME |
| 145 | } |
| 146 | |
| 147 | GetEdkToolsPathBinDirectory() { |
| 148 | # |
| 149 | # Figure out a uniq directory name from the uname command |
| 150 | # |
| 151 | BIN_SUB_DIR=`GetBaseToolsBinSubDir` |
| 152 | |
jljusten | b9a615f | 2008-02-13 22:44:22 +0000 | [diff] [blame] | 153 | if [ -e $EDK_TOOLS_PATH/BinWrappers/$BIN_SUB_DIR ] |
jljusten | 66dcb2f | 2007-12-11 09:03:30 +0000 | [diff] [blame] | 154 | then |
jljusten | b9a615f | 2008-02-13 22:44:22 +0000 | [diff] [blame] | 155 | EDK_TOOLS_PATH_BIN=$EDK_TOOLS_PATH/BinWrappers/$BIN_SUB_DIR |
jljusten | 66dcb2f | 2007-12-11 09:03:30 +0000 | [diff] [blame] | 156 | else |
| 157 | EDK_TOOLS_PATH_BIN=$EDK_TOOLS_PATH/Bin/$BIN_SUB_DIR |
| 158 | fi |
| 159 | |
| 160 | echo $EDK_TOOLS_PATH_BIN |
| 161 | } |
| 162 | |
lgao4 | 64b2609 | 2012-04-10 07:18:20 +0000 | [diff] [blame^] | 163 | AddDirToStartOfPath() { |
| 164 | DIRNAME=$1 |
| 165 | PATH=$DIRNAME:$DIRNAME:$DIRNAME:$PATH |
| 166 | PATH=${PATH//$DIRNAME:/} |
| 167 | PATH=$DIRNAME:$PATH |
| 168 | export PATH |
| 169 | } |
| 170 | |
jljusten | 66dcb2f | 2007-12-11 09:03:30 +0000 | [diff] [blame] | 171 | AddEdkToolsToPath() { |
| 172 | |
| 173 | # |
| 174 | # If EDK_TOOLS_PATH is not set, then we cannot update PATH |
| 175 | # |
| 176 | if [ -z "$EDK_TOOLS_PATH" ] |
| 177 | then |
qhuang8 | 14c4857 | 2010-07-21 02:46:15 +0000 | [diff] [blame] | 178 | return 1 |
jljusten | 66dcb2f | 2007-12-11 09:03:30 +0000 | [diff] [blame] | 179 | fi |
| 180 | |
| 181 | EDK_TOOLS_PATH_BIN=`GetEdkToolsPathBinDirectory` |
| 182 | |
lgao4 | 64b2609 | 2012-04-10 07:18:20 +0000 | [diff] [blame^] | 183 | AddDirToStartOfPath $EDK_TOOLS_PATH/BinWrappers/PosixLike |
| 184 | AddDirToStartOfPath $EDK_TOOLS_PATH_BIN |
jljusten | 66dcb2f | 2007-12-11 09:03:30 +0000 | [diff] [blame] | 185 | |
| 186 | } |
| 187 | |
| 188 | CopySingleTemplateFile() { |
| 189 | |
lgao4 | a709adf | 2009-12-29 06:16:53 +0000 | [diff] [blame] | 190 | SRC_FILENAME=Conf/$1.template |
jljusten | 66dcb2f | 2007-12-11 09:03:30 +0000 | [diff] [blame] | 191 | DST_FILENAME=Conf/$1.txt |
| 192 | |
| 193 | if [ -e $WORKSPACE/$DST_FILENAME ] |
| 194 | then |
| 195 | return |
| 196 | fi |
| 197 | |
lgao4 | a709adf | 2009-12-29 06:16:53 +0000 | [diff] [blame] | 198 | echo "Copying \$EDK_TOOLS_PATH/$SRC_FILENAME" |
jljusten | 66dcb2f | 2007-12-11 09:03:30 +0000 | [diff] [blame] | 199 | echo " to \$WORKSPACE/$DST_FILENAME" |
lgao4 | a709adf | 2009-12-29 06:16:53 +0000 | [diff] [blame] | 200 | SRC_FILENAME=$EDK_TOOLS_PATH/$SRC_FILENAME |
jljusten | 66dcb2f | 2007-12-11 09:03:30 +0000 | [diff] [blame] | 201 | DST_FILENAME=$WORKSPACE/$DST_FILENAME |
| 202 | cp $SRC_FILENAME $DST_FILENAME |
| 203 | |
| 204 | } |
| 205 | |
| 206 | CopyTemplateFiles() { |
| 207 | |
| 208 | CopySingleTemplateFile build_rule |
jljusten | 66dcb2f | 2007-12-11 09:03:30 +0000 | [diff] [blame] | 209 | CopySingleTemplateFile tools_def |
| 210 | CopySingleTemplateFile target |
| 211 | |
| 212 | } |
| 213 | |
| 214 | ScriptMain() { |
| 215 | |
| 216 | SetWorkspace |
| 217 | if [ -z $WORKSPACE ] |
| 218 | then |
| 219 | echo "Failure setting WORKSPACE" |
qhuang8 | 14c4857 | 2010-07-21 02:46:15 +0000 | [diff] [blame] | 220 | return 1 |
jljusten | 66dcb2f | 2007-12-11 09:03:30 +0000 | [diff] [blame] | 221 | fi |
| 222 | |
| 223 | RestorePreviousConfiguration |
| 224 | |
| 225 | SetEdkToolsPath |
| 226 | if [ -z $EDK_TOOLS_PATH ] |
| 227 | then |
qhuang8 | 14c4857 | 2010-07-21 02:46:15 +0000 | [diff] [blame] | 228 | return 1 |
jljusten | 66dcb2f | 2007-12-11 09:03:30 +0000 | [diff] [blame] | 229 | fi |
| 230 | |
| 231 | AddEdkToolsToPath |
| 232 | if [ $? -ne 0 ] |
| 233 | then |
| 234 | echo "Failure adding EDK Tools into PATH!" |
qhuang8 | 14c4857 | 2010-07-21 02:46:15 +0000 | [diff] [blame] | 235 | return 1 |
jljusten | 66dcb2f | 2007-12-11 09:03:30 +0000 | [diff] [blame] | 236 | fi |
| 237 | |
| 238 | StoreCurrentConfiguration |
| 239 | |
| 240 | echo WORKSPACE: $WORKSPACE |
| 241 | echo EDK_TOOLS_PATH: $EDK_TOOLS_PATH |
| 242 | |
| 243 | CopyTemplateFiles |
| 244 | |
| 245 | } |
jljusten | a310886 | 2007-10-16 20:52:46 +0000 | [diff] [blame] | 246 | |
| 247 | # |
jljusten | 66dcb2f | 2007-12-11 09:03:30 +0000 | [diff] [blame] | 248 | # Run the main function |
jljusten | a310886 | 2007-10-16 20:52:46 +0000 | [diff] [blame] | 249 | # |
jljusten | 66dcb2f | 2007-12-11 09:03:30 +0000 | [diff] [blame] | 250 | ScriptMain |
jljusten | a310886 | 2007-10-16 20:52:46 +0000 | [diff] [blame] | 251 | |