]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/build.sh
ShellPkg: add array index check for shell delay option
[mirror_edk2.git] / OvmfPkg / build.sh
1 #!/usr/bin/env bash
2 #
3 # Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
4 # Copyright (c) 2010 - 2019, Intel Corporation. All rights reserved.<BR>
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
44 ARCH_IA32=no
45 ARCH_X64=no
46 BUILDTARGET=DEBUG
47 BUILD_OPTIONS=
48 PLATFORMFILE=
49 THREADNUMBER=1
50 LAST_ARG=
51 RUN_QEMU=no
52 ENABLE_FLASH=no
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*)
63 Major=$(uname -r | cut -f 1 -d '.')
64 # Major is Darwin version, not OS X version.
65 # OS X Yosemite 10.10.2 returns 14.
66 case $Major in
67 [156789])
68 echo OvmfPkg requires OS X Snow Leopard 10.6 or newer OS
69 exit 1
70 ;;
71 10)
72 TARGET_TOOLS=XCODE32
73 ;;
74 1[12])
75 TARGET_TOOLS=XCLANG
76 ;;
77 *)
78 # Mavericks and future assume XCODE5 (clang + lldb)
79 TARGET_TOOLS=XCODE5
80 ;;
81 esac
82 ;;
83 Linux*)
84 gcc_version=$(gcc -v 2>&1 | tail -1 | awk '{print $3}')
85 case $gcc_version in
86 [1-3].*|4.[0-7].*)
87 echo OvmfPkg requires GCC4.8 or later
88 exit 1
89 ;;
90 4.8.*)
91 TARGET_TOOLS=GCC48
92 ;;
93 4.9.*|6.[0-2].*)
94 TARGET_TOOLS=GCC49
95 ;;
96 *)
97 TARGET_TOOLS=GCC5
98 ;;
99 esac
100 esac
101
102 #
103 # Scan command line to override defaults
104 #
105
106 for arg in "$@"
107 do
108 if [ -z "$LAST_ARG" ]; then
109 case $arg in
110 -a|-b|-t|-p|-n)
111 LAST_ARG=$arg
112 ;;
113 qemu)
114 RUN_QEMU=yes
115 shift
116 break
117 ;;
118 --enable-flash)
119 ENABLE_FLASH=yes
120 ;;
121 *)
122 BUILD_OPTIONS="$BUILD_OPTIONS $arg"
123 ;;
124 esac
125 else
126 case $LAST_ARG in
127 -a)
128 if [[ x"$arg" != x"IA32" && x"$arg" != x"X64" ]]; then
129 echo Unsupported processor architecture: $arg
130 echo Only IA32 or X64 is supported
131 exit 1
132 fi
133 eval ARCH_$arg=yes
134 ;;
135 -b)
136 BUILDTARGET=$arg
137 ;;
138 -p)
139 PLATFORMFILE=$arg
140 ;;
141 -t)
142 TARGET_TOOLS=$arg
143 ;;
144 -n)
145 THREADNUMBER=$arg
146 ;;
147 *)
148 BUILD_OPTIONS="$BUILD_OPTIONS $arg"
149 ;;
150 esac
151 LAST_ARG=
152 fi
153 shift
154 done
155
156 if [[ "$ARCH_IA32" == "yes" && "$ARCH_X64" == "yes" ]]; then
157 PROCESSOR=IA32X64
158 Processor=Ia32X64
159 BUILD_OPTIONS="$BUILD_OPTIONS -a IA32 -a X64"
160 PLATFORM_BUILD_DIR=Ovmf3264
161 BUILD_ROOT_ARCH=X64
162 elif [[ "$ARCH_IA32" == "yes" && "$ARCH_X64" == "no" ]]; then
163 PROCESSOR=IA32
164 Processor=Ia32
165 BUILD_OPTIONS="$BUILD_OPTIONS -a IA32"
166 PLATFORM_BUILD_DIR=Ovmf$Processor
167 BUILD_ROOT_ARCH=$PROCESSOR
168 else
169 PROCESSOR=X64
170 Processor=X64
171 BUILD_OPTIONS="$BUILD_OPTIONS -a X64"
172 PLATFORM_BUILD_DIR=Ovmf$Processor
173 BUILD_ROOT_ARCH=X64
174 fi
175
176 case $PROCESSOR in
177 IA32)
178 if [ -n "$QEMU_COMMAND" ]; then
179 #
180 # The user set the QEMU_COMMAND variable. We'll use it to run QEMU.
181 #
182 :
183 elif [ -x `which qemu-system-i386` ]; then
184 QEMU_COMMAND=qemu-system-i386
185 elif [ -x `which qemu-system-x86_64` ]; then
186 QEMU_COMMAND=qemu-system-x86_64
187 elif [ -x `which qemu` ]; then
188 QEMU_COMMAND=qemu
189 else
190 echo Unable to find QEMU for IA32 architecture!
191 exit 1
192 fi
193 ;;
194 X64|IA32X64)
195 if [ -z "$QEMU_COMMAND" ]; then
196 #
197 # The user didn't set the QEMU_COMMAND variable.
198 #
199 QEMU_COMMAND=qemu-system-x86_64
200 fi
201 ;;
202 *)
203 echo Unsupported processor architecture: $PROCESSOR
204 echo Only IA32 or X64 is supported
205 exit 1
206 ;;
207 esac
208
209 if [ -z "$PLATFORMFILE" ]; then
210 PLATFORMFILE=$WORKSPACE/OvmfPkg/OvmfPkg$Processor.dsc
211 fi
212
213 if [[ "$RUN_QEMU" == "yes" ]]; then
214 qemu_version=$($QEMU_COMMAND -version 2>&1 | \
215 grep -o -E 'version [0-9]+\.[0-9]+\.[0-9]+' | \
216 awk '{print $2}')
217 case $qemu_version in
218 1.[6-9].*|[2-9].*.*|[1-9][0-9]*.*.*)
219 ENABLE_FLASH=yes
220 ;;
221 esac
222
223 ADD_QEMU_HDA=yes
224 for arg in "$@"
225 do
226 case $arg in
227 -hd[a-d]|-fd[ab]|-cdrom)
228 ADD_QEMU_HDA=no
229 break
230 ;;
231 esac
232 done
233 fi
234
235 #
236 # Uncomment this block for parameter parsing debug
237 #
238 #echo RUN_QEMU=$RUN_QEMU
239 #echo BUILD_OPTIONS=$BUILD_OPTIONS
240 #echo BUILDTARGET=$BUILDTARGET
241 #echo TARGET_TOOLS=$TARGET_TOOLS
242 #echo PROCESSOR=$PROCESSOR
243 #echo Remaining for qemu: $*
244 #exit 1
245
246 BUILD_ROOT=$WORKSPACE/Build/$PLATFORM_BUILD_DIR/"$BUILDTARGET"_"$TARGET_TOOLS"
247 FV_DIR=$BUILD_ROOT/FV
248 BUILD_ROOT_ARCH=$BUILD_ROOT/$BUILD_ROOT_ARCH
249 QEMU_FIRMWARE_DIR=$BUILD_ROOT/QEMU
250
251 if [[ ! -f `which build` || ! -f `which GenFv` ]];
252 then
253 # build the tools if they don't yet exist. Bin scheme
254 echo Building tools as they are not in the path
255 make -C $WORKSPACE/BaseTools
256 elif [[ ( -f `which build` || -f `which GenFv` ) && ! -d $EDK_TOOLS_PATH/Source/C/bin ]];
257 then
258 # build the tools if they don't yet exist. BinWrapper scheme
259 echo Building tools no $EDK_TOOLS_PATH/Source/C/bin directory
260 make -C $WORKSPACE/BaseTools
261 else
262 echo using prebuilt tools
263 fi
264
265
266 if [[ "$RUN_QEMU" == "yes" ]]; then
267 if [[ ! -d $QEMU_FIRMWARE_DIR ]]; then
268 mkdir $QEMU_FIRMWARE_DIR
269 fi
270 ln -sf $FV_DIR/OVMF.fd $QEMU_FIRMWARE_DIR/bios.bin
271 if [[ "$ENABLE_FLASH" == "yes" ]]; then
272 QEMU_COMMAND="$QEMU_COMMAND -pflash $QEMU_FIRMWARE_DIR/bios.bin"
273 else
274 QEMU_COMMAND="$QEMU_COMMAND -L $QEMU_FIRMWARE_DIR"
275 fi
276 if [[ "$ADD_QEMU_HDA" == "yes" ]]; then
277 QEMU_COMMAND="$QEMU_COMMAND -hda fat:$BUILD_ROOT_ARCH"
278 fi
279 echo Running: $QEMU_COMMAND "$@"
280 $QEMU_COMMAND "$@"
281 exit $?
282 fi
283
284 #
285 # Build the edk2 OvmfPkg
286 #
287 echo Running edk2 build for OvmfPkg$Processor
288 build -p $PLATFORMFILE $BUILD_OPTIONS -b $BUILDTARGET -t $TARGET_TOOLS -n $THREADNUMBER
289 exit $?
290