]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/build.sh
OvmfPkg/README: Add information about OVMF flash layout
[mirror_edk2.git] / OvmfPkg / build.sh
CommitLineData
5a9745b9 1#!/bin/bash
2#
3# Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
0aedc542 4# Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>
5a9745b9 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
15set -e
16shopt -s nocasematch
17
18
19#
20# Setup workspace if it is not set
21#
22if [ -z "$WORKSPACE" ]
23then
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
36else
37 echo Building from: $WORKSPACE
38fi
39
66325870 40#
41# Configure defaults for various options
42#
43
5a9745b9 44PROCESSOR=X64
66325870 45BUILDTARGET=DEBUG
46BUILD_OPTIONS=
04629652 47PLATFORMFILE=
57863080 48THREADNUMBER=1
66325870 49LAST_ARG=
50RUN_QEMU=no
5a9745b9 51
52#
53# Pick a default tool type for a given OS
54#
55TARGET_TOOLS=MYTOOLS
56case `uname` in
66325870 57 CYGWIN*)
58 echo Cygwin not fully supported yet.
59 ;;
5a9745b9 60 Darwin*)
429c05fa 61 Major=$(uname -r | cut -f 1 -d '.')
62 case $Major in
63 10)
64 TARGET_TOOLS=XCODE32
65 ;;
66 1[12])
67 TARGET_TOOLS=XCLANG
68 ;;
69 *)
5a9745b9 70 echo OvmfPkg requires Snow Leopard or later OS
71 exit 1
429c05fa 72 ;;
73 esac
74 ;;
5a9745b9 75 Linux*)
8567a8ca 76 gcc_version=$(gcc -v 2>&1 | tail -1 | awk '{print $3}')
77 case $gcc_version in
78 4.5.*)
79 TARGET_TOOLS=GCC45
80 ;;
81 4.6.*)
82 TARGET_TOOLS=GCC46
83 ;;
743094a2 84 4.[789].*)
85 TARGET_TOOLS=GCC47
86 ;;
8567a8ca 87 *)
88 TARGET_TOOLS=GCC44
8567a8ca 89 ;;
90 esac
66325870 91esac
92
93#
94# Scan command line to override defaults
95#
5a9745b9 96
66325870 97for arg in "$@"
98do
99 if [ -z "$LAST_ARG" ]; then
100 case $arg in
57863080 101 -a|-b|-t|-p|-n)
66325870 102 LAST_ARG=$arg
103 ;;
104 qemu)
105 RUN_QEMU=yes
106 shift
107 break
108 ;;
109 *)
110 BUILD_OPTIONS="$BUILD_OPTIONS $arg"
111 ;;
112 esac
113 else
114 case $LAST_ARG in
115 -a)
116 PROCESSOR=$arg
117 ;;
118 -b)
119 BUILDTARGET=$arg
120 ;;
04629652 121 -p)
122 PLATFORMFILE=$arg
123 ;;
66325870 124 -t)
125 TARGET_TOOLS=$arg
126 ;;
57863080 127 -n)
128 THREADNUMBER=$arg
129 ;;
66325870 130 *)
131 BUILD_OPTIONS="$BUILD_OPTIONS $arg"
132 ;;
133 esac
134 LAST_ARG=
135 fi
136 shift
137done
138
139case $PROCESSOR in
140 IA32)
141 Processor=Ia32
7e73a64f
JJ
142 if [ -n "$QEMU_COMMAND" ]; then
143 #
144 # The user set the QEMU_COMMAND variable. We'll use it to run QEMU.
145 #
146 :
147 elif [ -x `which qemu-system-i386` ]; then
0aedc542 148 QEMU_COMMAND=qemu-system-i386
149 elif [ -x `which qemu-system-x86_64` ]; then
150 QEMU_COMMAND=qemu-system-x86_64
151 elif [ -x `which qemu` ]; then
152 QEMU_COMMAND=qemu
153 else
154 echo Unable to find QEMU for IA32 architecture!
155 exit 1
156 fi
66325870 157 ;;
158 X64)
159 Processor=X64
7e73a64f
JJ
160 if [ -z "$QEMU_COMMAND" ]; then
161 #
162 # The user didn't set the QEMU_COMMAND variable.
163 #
164 QEMU_COMMAND=qemu-system-x86_64
165 fi
66325870 166 ;;
167 *)
168 echo Unsupported processor architecture: $PROCESSOR
169 echo Only IA32 or X64 is supported
170 exit 1
171 ;;
5a9745b9 172esac
173
04629652 174if [ -z "$PLATFORMFILE" ]; then
175 PLATFORMFILE=$WORKSPACE/OvmfPkg/OvmfPkg$Processor.dsc
176fi
177
66325870 178ADD_QEMU_HDA=yes
179for arg in "$@"
180do
181 case $arg in
182 -hd[a-d]|-fd[ab]|-cdrom)
183 ADD_QEMU_HDA=no
184 break
185 ;;
186 esac
187done
188
189#
190# Uncomment this block for parameter parsing debug
191#
192#echo RUN_QEMU=$RUN_QEMU
193#echo BUILD_OPTIONS=$BUILD_OPTIONS
194#echo BUILDTARGET=$BUILDTARGET
195#echo TARGET_TOOLS=$TARGET_TOOLS
196#echo PROCESSOR=$PROCESSOR
197#echo Remaining for qemu: $*
198#exit 1
199
200BUILD_ROOT=$WORKSPACE/Build/Ovmf$Processor/"$BUILDTARGET"_"$TARGET_TOOLS"
5a9745b9 201FV_DIR=$BUILD_ROOT/FV
202BUILD_ROOT_ARCH=$BUILD_ROOT/$PROCESSOR
203QEMU_FIRMWARE_DIR=$BUILD_ROOT/QEMU
204
205if [[ ! -f `which build` || ! -f `which GenFv` ]];
206then
207 # build the tools if they don't yet exist. Bin scheme
208 echo Building tools as they are not in the path
209 make -C $WORKSPACE/BaseTools
210elif [[ ( -f `which build` || -f `which GenFv` ) && ! -d $EDK_TOOLS_PATH/Source/C/bin ]];
211then
212 # build the tools if they don't yet exist. BinWrapper scheme
213 echo Building tools no $EDK_TOOLS_PATH/Source/C/bin directory
214 make -C $WORKSPACE/BaseTools
215else
216 echo using prebuilt tools
217fi
218
219
66325870 220if [[ "$RUN_QEMU" == "yes" ]]; then
221 if [[ ! -d $QEMU_FIRMWARE_DIR ]]; then
222 mkdir $QEMU_FIRMWARE_DIR
5a9745b9 223 fi
eaf4f336 224 ln -sf $FV_DIR/OVMF.fd $QEMU_FIRMWARE_DIR/bios.bin
66325870 225 if [[ "$ADD_QEMU_HDA" == "yes" ]]; then
226 AUTO_QEMU_HDA="-hda fat:$BUILD_ROOT_ARCH"
227 else
228 AUTO_QEMU_HDA=
5a9745b9 229 fi
66325870 230 QEMU_COMMAND="$QEMU_COMMAND -L $QEMU_FIRMWARE_DIR $AUTO_QEMU_HDA $*"
231 echo Running: $QEMU_COMMAND
232 $QEMU_COMMAND
233 exit $?
234fi
5a9745b9 235
236#
237# Build the edk2 OvmfPkg
238#
239echo Running edk2 build for OvmfPkg$Processor
57863080 240build -p $PLATFORMFILE $BUILD_OPTIONS -a $PROCESSOR -b $BUILDTARGET -t $TARGET_TOOLS -n $THREADNUMBER
5a9745b9 241exit $?
242