]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/build.sh
OvmfPkg: Fix the build.sh shebang line to avoid depending on location of bash
[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 - 2015, 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 4.5.*)
87 TARGET_TOOLS=GCC45
88 ;;
89 4.6.*)
90 TARGET_TOOLS=GCC46
91 ;;
92 4.7.*)
93 TARGET_TOOLS=GCC47
94 ;;
95 4.8.*)
96 TARGET_TOOLS=GCC48
97 ;;
98 4.9.*|4.1[0-9].*)
99 TARGET_TOOLS=GCC49
100 ;;
101 *)
102 TARGET_TOOLS=GCC44
103 ;;
104 esac
105 esac
106
107 #
108 # Scan command line to override defaults
109 #
110
111 for arg in "$@"
112 do
113 if [ -z "$LAST_ARG" ]; then
114 case $arg in
115 -a|-b|-t|-p|-n)
116 LAST_ARG=$arg
117 ;;
118 qemu)
119 RUN_QEMU=yes
120 shift
121 break
122 ;;
123 --enable-flash)
124 ENABLE_FLASH=yes
125 ;;
126 *)
127 BUILD_OPTIONS="$BUILD_OPTIONS $arg"
128 ;;
129 esac
130 else
131 case $LAST_ARG in
132 -a)
133 if [[ x"$arg" != x"IA32" && x"$arg" != x"X64" ]]; then
134 echo Unsupported processor architecture: $arg
135 echo Only IA32 or X64 is supported
136 exit 1
137 fi
138 eval ARCH_$arg=yes
139 ;;
140 -b)
141 BUILDTARGET=$arg
142 ;;
143 -p)
144 PLATFORMFILE=$arg
145 ;;
146 -t)
147 TARGET_TOOLS=$arg
148 ;;
149 -n)
150 THREADNUMBER=$arg
151 ;;
152 *)
153 BUILD_OPTIONS="$BUILD_OPTIONS $arg"
154 ;;
155 esac
156 LAST_ARG=
157 fi
158 shift
159 done
160
161 if [[ "$ARCH_IA32" == "yes" && "$ARCH_X64" == "yes" ]]; then
162 PROCESSOR=IA32X64
163 Processor=Ia32X64
164 BUILD_OPTIONS="$BUILD_OPTIONS -a IA32 -a X64"
165 PLATFORM_BUILD_DIR=Ovmf3264
166 BUILD_ROOT_ARCH=X64
167 elif [[ "$ARCH_IA32" == "yes" && "$ARCH_X64" == "no" ]]; then
168 PROCESSOR=IA32
169 Processor=Ia32
170 BUILD_OPTIONS="$BUILD_OPTIONS -a IA32"
171 PLATFORM_BUILD_DIR=Ovmf$Processor
172 BUILD_ROOT_ARCH=$PROCESSOR
173 else
174 PROCESSOR=X64
175 Processor=X64
176 BUILD_OPTIONS="$BUILD_OPTIONS -a X64"
177 PLATFORM_BUILD_DIR=Ovmf$Processor
178 BUILD_ROOT_ARCH=X64
179 fi
180
181 case $PROCESSOR in
182 IA32)
183 if [ -n "$QEMU_COMMAND" ]; then
184 #
185 # The user set the QEMU_COMMAND variable. We'll use it to run QEMU.
186 #
187 :
188 elif [ -x `which qemu-system-i386` ]; then
189 QEMU_COMMAND=qemu-system-i386
190 elif [ -x `which qemu-system-x86_64` ]; then
191 QEMU_COMMAND=qemu-system-x86_64
192 elif [ -x `which qemu` ]; then
193 QEMU_COMMAND=qemu
194 else
195 echo Unable to find QEMU for IA32 architecture!
196 exit 1
197 fi
198 ;;
199 X64|IA32X64)
200 if [ -z "$QEMU_COMMAND" ]; then
201 #
202 # The user didn't set the QEMU_COMMAND variable.
203 #
204 QEMU_COMMAND=qemu-system-x86_64
205 fi
206 ;;
207 *)
208 echo Unsupported processor architecture: $PROCESSOR
209 echo Only IA32 or X64 is supported
210 exit 1
211 ;;
212 esac
213
214 if [ -z "$PLATFORMFILE" ]; then
215 PLATFORMFILE=$WORKSPACE/OvmfPkg/OvmfPkg$Processor.dsc
216 fi
217
218 if [[ "$RUN_QEMU" == "yes" ]]; then
219 qemu_version=$($QEMU_COMMAND -version 2>&1 | tail -1 | awk '{print $4}')
220 case $qemu_version in
221 1.[6-9].*|1.[1-9][0-9].*|2.*.*)
222 ENABLE_FLASH=yes
223 ;;
224 esac
225
226 ADD_QEMU_HDA=yes
227 for arg in "$@"
228 do
229 case $arg in
230 -hd[a-d]|-fd[ab]|-cdrom)
231 ADD_QEMU_HDA=no
232 break
233 ;;
234 esac
235 done
236 fi
237
238 #
239 # Uncomment this block for parameter parsing debug
240 #
241 #echo RUN_QEMU=$RUN_QEMU
242 #echo BUILD_OPTIONS=$BUILD_OPTIONS
243 #echo BUILDTARGET=$BUILDTARGET
244 #echo TARGET_TOOLS=$TARGET_TOOLS
245 #echo PROCESSOR=$PROCESSOR
246 #echo Remaining for qemu: $*
247 #exit 1
248
249 BUILD_ROOT=$WORKSPACE/Build/$PLATFORM_BUILD_DIR/"$BUILDTARGET"_"$TARGET_TOOLS"
250 FV_DIR=$BUILD_ROOT/FV
251 BUILD_ROOT_ARCH=$BUILD_ROOT/$BUILD_ROOT_ARCH
252 QEMU_FIRMWARE_DIR=$BUILD_ROOT/QEMU
253
254 if [[ ! -f `which build` || ! -f `which GenFv` ]];
255 then
256 # build the tools if they don't yet exist. Bin scheme
257 echo Building tools as they are not in the path
258 make -C $WORKSPACE/BaseTools
259 elif [[ ( -f `which build` || -f `which GenFv` ) && ! -d $EDK_TOOLS_PATH/Source/C/bin ]];
260 then
261 # build the tools if they don't yet exist. BinWrapper scheme
262 echo Building tools no $EDK_TOOLS_PATH/Source/C/bin directory
263 make -C $WORKSPACE/BaseTools
264 else
265 echo using prebuilt tools
266 fi
267
268
269 if [[ "$RUN_QEMU" == "yes" ]]; then
270 if [[ ! -d $QEMU_FIRMWARE_DIR ]]; then
271 mkdir $QEMU_FIRMWARE_DIR
272 fi
273 ln -sf $FV_DIR/OVMF.fd $QEMU_FIRMWARE_DIR/bios.bin
274 if [[ "$ENABLE_FLASH" == "yes" ]]; then
275 QEMU_COMMAND="$QEMU_COMMAND -pflash $QEMU_FIRMWARE_DIR/bios.bin"
276 else
277 QEMU_COMMAND="$QEMU_COMMAND -L $QEMU_FIRMWARE_DIR"
278 fi
279 if [[ "$ADD_QEMU_HDA" == "yes" ]]; then
280 QEMU_COMMAND="$QEMU_COMMAND -hda fat:$BUILD_ROOT_ARCH"
281 fi
282 echo Running: $QEMU_COMMAND "$@"
283 $QEMU_COMMAND "$@"
284 exit $?
285 fi
286
287 #
288 # Build the edk2 OvmfPkg
289 #
290 echo Running edk2 build for OvmfPkg$Processor
291 build -p $PLATFORMFILE $BUILD_OPTIONS -b $BUILDTARGET -t $TARGET_TOOLS -n $THREADNUMBER
292 exit $?
293