jljusten | 6632587 | 2011-01-09 03:50:21 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR> |
Jordan Justen | d011527 | 2014-01-20 08:49:58 +0000 | [diff] [blame] | 4 | # Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR> |
jljusten | 6632587 | 2011-01-09 03:50:21 +0000 | [diff] [blame] | 5 | # |
| 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 | set -e |
| 16 | shopt -s nocasematch |
| 17 | |
| 18 | |
| 19 | # |
| 20 | # Setup workspace if it is not set |
| 21 | # |
| 22 | if [ -z "$WORKSPACE" ] |
| 23 | then |
| 24 | echo Initializing workspace |
| 25 | if [ ! -e `pwd`/edksetup.sh ] |
| 26 | then |
| 27 | cd .. |
| 28 | fi |
| 29 | # This version is for the tools in the BaseTools project. |
| 30 | # this assumes svn pulls have the same root dir |
| 31 | # export EDK_TOOLS_PATH=`pwd`/../BaseTools |
| 32 | # This version is for the tools source in edk2 |
| 33 | export EDK_TOOLS_PATH=`pwd`/BaseTools |
| 34 | echo $EDK_TOOLS_PATH |
| 35 | source edksetup.sh BaseTools |
| 36 | else |
| 37 | echo Building from: $WORKSPACE |
| 38 | fi |
| 39 | |
| 40 | # |
| 41 | # Configure defaults for various options |
| 42 | # |
| 43 | |
Jordan Justen | 3f35b14 | 2014-07-28 18:12:11 +0000 | [diff] [blame] | 44 | ARCH_IA32=no |
| 45 | ARCH_X64=no |
jljusten | 6632587 | 2011-01-09 03:50:21 +0000 | [diff] [blame] | 46 | BUILDTARGET=DEBUG |
| 47 | BUILD_OPTIONS= |
jljusten | 0462965 | 2011-01-13 05:46:03 +0000 | [diff] [blame] | 48 | PLATFORMFILE= |
jljusten | 5786308 | 2012-07-10 22:43:30 +0000 | [diff] [blame] | 49 | THREADNUMBER=1 |
jljusten | 6632587 | 2011-01-09 03:50:21 +0000 | [diff] [blame] | 50 | LAST_ARG= |
| 51 | RUN_QEMU=no |
Jordan Justen | bc9be82 | 2013-11-12 18:35:08 +0000 | [diff] [blame] | 52 | ENABLE_FLASH=no |
jljusten | 6632587 | 2011-01-09 03:50:21 +0000 | [diff] [blame] | 53 | |
| 54 | # |
| 55 | # Pick a default tool type for a given OS |
| 56 | # |
| 57 | TARGET_TOOLS=MYTOOLS |
| 58 | case `uname` in |
| 59 | CYGWIN*) |
| 60 | echo Cygwin not fully supported yet. |
| 61 | ;; |
| 62 | Darwin*) |
jljusten | 429c05f | 2013-01-16 06:50:21 +0000 | [diff] [blame] | 63 | Major=$(uname -r | cut -f 1 -d '.') |
| 64 | case $Major in |
| 65 | 10) |
| 66 | TARGET_TOOLS=XCODE32 |
| 67 | ;; |
| 68 | 1[12]) |
| 69 | TARGET_TOOLS=XCLANG |
| 70 | ;; |
| 71 | *) |
jljusten | 6632587 | 2011-01-09 03:50:21 +0000 | [diff] [blame] | 72 | echo OvmfPkg requires Snow Leopard or later OS |
| 73 | exit 1 |
jljusten | 429c05f | 2013-01-16 06:50:21 +0000 | [diff] [blame] | 74 | ;; |
| 75 | esac |
| 76 | ;; |
jljusten | 6632587 | 2011-01-09 03:50:21 +0000 | [diff] [blame] | 77 | Linux*) |
jljusten | 8567a8c | 2011-10-31 15:56:55 +0000 | [diff] [blame] | 78 | gcc_version=$(gcc -v 2>&1 | tail -1 | awk '{print $3}') |
| 79 | case $gcc_version in |
| 80 | 4.5.*) |
| 81 | TARGET_TOOLS=GCC45 |
| 82 | ;; |
| 83 | 4.6.*) |
| 84 | TARGET_TOOLS=GCC46 |
| 85 | ;; |
Jordan Justen | d011527 | 2014-01-20 08:49:58 +0000 | [diff] [blame] | 86 | 4.7.*) |
jljusten | 743094a | 2012-08-13 17:06:49 +0000 | [diff] [blame] | 87 | TARGET_TOOLS=GCC47 |
| 88 | ;; |
Jordan Justen | 595a5bc | 2014-07-28 17:37:19 +0000 | [diff] [blame] | 89 | 4.8.*) |
Jordan Justen | d011527 | 2014-01-20 08:49:58 +0000 | [diff] [blame] | 90 | TARGET_TOOLS=GCC48 |
| 91 | ;; |
Jordan Justen | 595a5bc | 2014-07-28 17:37:19 +0000 | [diff] [blame] | 92 | 4.9.*|4.1[0-9].*) |
| 93 | TARGET_TOOLS=GCC49 |
| 94 | ;; |
jljusten | 8567a8c | 2011-10-31 15:56:55 +0000 | [diff] [blame] | 95 | *) |
| 96 | TARGET_TOOLS=GCC44 |
jljusten | 8567a8c | 2011-10-31 15:56:55 +0000 | [diff] [blame] | 97 | ;; |
| 98 | esac |
jljusten | 6632587 | 2011-01-09 03:50:21 +0000 | [diff] [blame] | 99 | esac |
| 100 | |
| 101 | # |
| 102 | # Scan command line to override defaults |
| 103 | # |
| 104 | |
| 105 | for arg in "$@" |
| 106 | do |
| 107 | if [ -z "$LAST_ARG" ]; then |
| 108 | case $arg in |
jljusten | 5786308 | 2012-07-10 22:43:30 +0000 | [diff] [blame] | 109 | -a|-b|-t|-p|-n) |
jljusten | 6632587 | 2011-01-09 03:50:21 +0000 | [diff] [blame] | 110 | LAST_ARG=$arg |
| 111 | ;; |
| 112 | qemu) |
| 113 | RUN_QEMU=yes |
| 114 | shift |
| 115 | break |
| 116 | ;; |
Jordan Justen | bc9be82 | 2013-11-12 18:35:08 +0000 | [diff] [blame] | 117 | --enable-flash) |
| 118 | ENABLE_FLASH=yes |
| 119 | ;; |
jljusten | 6632587 | 2011-01-09 03:50:21 +0000 | [diff] [blame] | 120 | *) |
| 121 | BUILD_OPTIONS="$BUILD_OPTIONS $arg" |
| 122 | ;; |
| 123 | esac |
| 124 | else |
| 125 | case $LAST_ARG in |
| 126 | -a) |
Jordan Justen | 3f35b14 | 2014-07-28 18:12:11 +0000 | [diff] [blame] | 127 | if [[ x"$arg" != x"IA32" && x"$arg" != x"X64" ]]; then |
| 128 | echo Unsupported processor architecture: $arg |
| 129 | echo Only IA32 or X64 is supported |
| 130 | exit 1 |
| 131 | fi |
| 132 | eval ARCH_$arg=yes |
jljusten | 6632587 | 2011-01-09 03:50:21 +0000 | [diff] [blame] | 133 | ;; |
| 134 | -b) |
| 135 | BUILDTARGET=$arg |
| 136 | ;; |
jljusten | 0462965 | 2011-01-13 05:46:03 +0000 | [diff] [blame] | 137 | -p) |
| 138 | PLATFORMFILE=$arg |
| 139 | ;; |
jljusten | 6632587 | 2011-01-09 03:50:21 +0000 | [diff] [blame] | 140 | -t) |
| 141 | TARGET_TOOLS=$arg |
| 142 | ;; |
jljusten | 5786308 | 2012-07-10 22:43:30 +0000 | [diff] [blame] | 143 | -n) |
| 144 | THREADNUMBER=$arg |
| 145 | ;; |
jljusten | 6632587 | 2011-01-09 03:50:21 +0000 | [diff] [blame] | 146 | *) |
| 147 | BUILD_OPTIONS="$BUILD_OPTIONS $arg" |
| 148 | ;; |
| 149 | esac |
| 150 | LAST_ARG= |
| 151 | fi |
| 152 | shift |
| 153 | done |
| 154 | |
Jordan Justen | 3f35b14 | 2014-07-28 18:12:11 +0000 | [diff] [blame] | 155 | if [[ "$ARCH_IA32" == "yes" && "$ARCH_X64" == "yes" ]]; then |
| 156 | PROCESSOR=IA32X64 |
| 157 | Processor=Ia32X64 |
| 158 | BUILD_OPTIONS="$BUILD_OPTIONS -a IA32 -a X64" |
| 159 | PLATFORM_BUILD_DIR=Ovmf3264 |
| 160 | BUILD_ROOT_ARCH=X64 |
| 161 | elif [[ "$ARCH_IA32" == "yes" && "$ARCH_X64" == "no" ]]; then |
| 162 | PROCESSOR=IA32 |
| 163 | Processor=Ia32 |
| 164 | BUILD_OPTIONS="$BUILD_OPTIONS -a IA32" |
| 165 | PLATFORM_BUILD_DIR=Ovmf$Processor |
| 166 | BUILD_ROOT_ARCH=$PROCESSOR |
| 167 | else |
| 168 | PROCESSOR=X64 |
| 169 | Processor=X64 |
| 170 | BUILD_OPTIONS="$BUILD_OPTIONS -a X64" |
| 171 | PLATFORM_BUILD_DIR=Ovmf$Processor |
| 172 | BUILD_ROOT_ARCH=X64 |
| 173 | fi |
| 174 | |
jljusten | 6632587 | 2011-01-09 03:50:21 +0000 | [diff] [blame] | 175 | case $PROCESSOR in |
| 176 | IA32) |
Jordan Justen | 7e73a64 | 2013-11-06 19:29:09 +0000 | [diff] [blame] | 177 | if [ -n "$QEMU_COMMAND" ]; then |
| 178 | # |
| 179 | # The user set the QEMU_COMMAND variable. We'll use it to run QEMU. |
| 180 | # |
| 181 | : |
| 182 | elif [ -x `which qemu-system-i386` ]; then |
jljusten | 0aedc54 | 2013-01-25 16:22:07 +0000 | [diff] [blame] | 183 | QEMU_COMMAND=qemu-system-i386 |
| 184 | elif [ -x `which qemu-system-x86_64` ]; then |
| 185 | QEMU_COMMAND=qemu-system-x86_64 |
| 186 | elif [ -x `which qemu` ]; then |
| 187 | QEMU_COMMAND=qemu |
| 188 | else |
| 189 | echo Unable to find QEMU for IA32 architecture! |
| 190 | exit 1 |
| 191 | fi |
jljusten | 6632587 | 2011-01-09 03:50:21 +0000 | [diff] [blame] | 192 | ;; |
Jordan Justen | 3f35b14 | 2014-07-28 18:12:11 +0000 | [diff] [blame] | 193 | X64|IA32X64) |
Jordan Justen | 7e73a64 | 2013-11-06 19:29:09 +0000 | [diff] [blame] | 194 | if [ -z "$QEMU_COMMAND" ]; then |
| 195 | # |
| 196 | # The user didn't set the QEMU_COMMAND variable. |
| 197 | # |
| 198 | QEMU_COMMAND=qemu-system-x86_64 |
| 199 | fi |
jljusten | 6632587 | 2011-01-09 03:50:21 +0000 | [diff] [blame] | 200 | ;; |
| 201 | *) |
| 202 | echo Unsupported processor architecture: $PROCESSOR |
| 203 | echo Only IA32 or X64 is supported |
| 204 | exit 1 |
| 205 | ;; |
| 206 | esac |
| 207 | |
jljusten | 0462965 | 2011-01-13 05:46:03 +0000 | [diff] [blame] | 208 | if [ -z "$PLATFORMFILE" ]; then |
| 209 | PLATFORMFILE=$WORKSPACE/OvmfPkg/OvmfPkg$Processor.dsc |
| 210 | fi |
| 211 | |
Jordan Justen | d48ec97 | 2013-11-12 18:35:15 +0000 | [diff] [blame] | 212 | if [[ "$RUN_QEMU" == "yes" ]]; then |
| 213 | qemu_version=$($QEMU_COMMAND -version 2>&1 | tail -1 | awk '{print $4}') |
| 214 | case $qemu_version in |
| 215 | 1.[6-9].*|1.[1-9][0-9].*|2.*.*) |
| 216 | ENABLE_FLASH=yes |
jljusten | 6632587 | 2011-01-09 03:50:21 +0000 | [diff] [blame] | 217 | ;; |
| 218 | esac |
Jordan Justen | d48ec97 | 2013-11-12 18:35:15 +0000 | [diff] [blame] | 219 | |
| 220 | ADD_QEMU_HDA=yes |
| 221 | for arg in "$@" |
| 222 | do |
| 223 | case $arg in |
| 224 | -hd[a-d]|-fd[ab]|-cdrom) |
| 225 | ADD_QEMU_HDA=no |
| 226 | break |
| 227 | ;; |
| 228 | esac |
| 229 | done |
| 230 | fi |
jljusten | 6632587 | 2011-01-09 03:50:21 +0000 | [diff] [blame] | 231 | |
| 232 | # |
| 233 | # Uncomment this block for parameter parsing debug |
| 234 | # |
| 235 | #echo RUN_QEMU=$RUN_QEMU |
| 236 | #echo BUILD_OPTIONS=$BUILD_OPTIONS |
| 237 | #echo BUILDTARGET=$BUILDTARGET |
| 238 | #echo TARGET_TOOLS=$TARGET_TOOLS |
| 239 | #echo PROCESSOR=$PROCESSOR |
| 240 | #echo Remaining for qemu: $* |
| 241 | #exit 1 |
| 242 | |
Jordan Justen | 3f35b14 | 2014-07-28 18:12:11 +0000 | [diff] [blame] | 243 | BUILD_ROOT=$WORKSPACE/Build/$PLATFORM_BUILD_DIR/"$BUILDTARGET"_"$TARGET_TOOLS" |
jljusten | 6632587 | 2011-01-09 03:50:21 +0000 | [diff] [blame] | 244 | FV_DIR=$BUILD_ROOT/FV |
Jordan Justen | 3f35b14 | 2014-07-28 18:12:11 +0000 | [diff] [blame] | 245 | BUILD_ROOT_ARCH=$BUILD_ROOT/$BUILD_ROOT_ARCH |
jljusten | 6632587 | 2011-01-09 03:50:21 +0000 | [diff] [blame] | 246 | QEMU_FIRMWARE_DIR=$BUILD_ROOT/QEMU |
| 247 | |
| 248 | if [[ ! -f `which build` || ! -f `which GenFv` ]]; |
| 249 | then |
| 250 | # build the tools if they don't yet exist. Bin scheme |
| 251 | echo Building tools as they are not in the path |
| 252 | make -C $WORKSPACE/BaseTools |
| 253 | elif [[ ( -f `which build` || -f `which GenFv` ) && ! -d $EDK_TOOLS_PATH/Source/C/bin ]]; |
| 254 | then |
| 255 | # build the tools if they don't yet exist. BinWrapper scheme |
| 256 | echo Building tools no $EDK_TOOLS_PATH/Source/C/bin directory |
| 257 | make -C $WORKSPACE/BaseTools |
| 258 | else |
| 259 | echo using prebuilt tools |
| 260 | fi |
| 261 | |
| 262 | |
| 263 | if [[ "$RUN_QEMU" == "yes" ]]; then |
| 264 | if [[ ! -d $QEMU_FIRMWARE_DIR ]]; then |
| 265 | mkdir $QEMU_FIRMWARE_DIR |
jljusten | 6632587 | 2011-01-09 03:50:21 +0000 | [diff] [blame] | 266 | fi |
jljusten | eaf4f33 | 2011-04-12 15:08:51 +0000 | [diff] [blame] | 267 | ln -sf $FV_DIR/OVMF.fd $QEMU_FIRMWARE_DIR/bios.bin |
Jordan Justen | bc9be82 | 2013-11-12 18:35:08 +0000 | [diff] [blame] | 268 | if [[ "$ENABLE_FLASH" == "yes" ]]; then |
| 269 | QEMU_COMMAND="$QEMU_COMMAND -pflash $QEMU_FIRMWARE_DIR/bios.bin" |
jljusten | 6632587 | 2011-01-09 03:50:21 +0000 | [diff] [blame] | 270 | else |
Jordan Justen | bc9be82 | 2013-11-12 18:35:08 +0000 | [diff] [blame] | 271 | QEMU_COMMAND="$QEMU_COMMAND -L $QEMU_FIRMWARE_DIR" |
jljusten | 6632587 | 2011-01-09 03:50:21 +0000 | [diff] [blame] | 272 | fi |
Jordan Justen | bc9be82 | 2013-11-12 18:35:08 +0000 | [diff] [blame] | 273 | if [[ "$ADD_QEMU_HDA" == "yes" ]]; then |
| 274 | QEMU_COMMAND="$QEMU_COMMAND -hda fat:$BUILD_ROOT_ARCH" |
| 275 | fi |
| 276 | QEMU_COMMAND="$QEMU_COMMAND $*" |
jljusten | 6632587 | 2011-01-09 03:50:21 +0000 | [diff] [blame] | 277 | echo Running: $QEMU_COMMAND |
| 278 | $QEMU_COMMAND |
| 279 | exit $? |
| 280 | fi |
| 281 | |
| 282 | # |
| 283 | # Build the edk2 OvmfPkg |
| 284 | # |
| 285 | echo Running edk2 build for OvmfPkg$Processor |
Jordan Justen | 3f35b14 | 2014-07-28 18:12:11 +0000 | [diff] [blame] | 286 | build -p $PLATFORMFILE $BUILD_OPTIONS -b $BUILDTARGET -t $TARGET_TOOLS -n $THREADNUMBER |
jljusten | 6632587 | 2011-01-09 03:50:21 +0000 | [diff] [blame] | 287 | exit $? |
| 288 | |