]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/build.sh
OvmfPkg/build.sh: Use QEMU_COMMAND environment variable
[mirror_edk2.git] / OvmfPkg / build.sh
1 #!/bin/bash
2 #
3 # Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
4 # Copyright (c) 2010 - 2013, 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 PROCESSOR=X64
45 BUILDTARGET=DEBUG
46 BUILD_OPTIONS=
47 PLATFORMFILE=
48 THREADNUMBER=1
49 LAST_ARG=
50 RUN_QEMU=no
51
52 #
53 # Pick a default tool type for a given OS
54 #
55 TARGET_TOOLS=MYTOOLS
56 case `uname` in
57 CYGWIN*)
58 echo Cygwin not fully supported yet.
59 ;;
60 Darwin*)
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 *)
70 echo OvmfPkg requires Snow Leopard or later OS
71 exit 1
72 ;;
73 esac
74 ;;
75 Linux*)
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 ;;
84 4.[789].*)
85 TARGET_TOOLS=GCC47
86 ;;
87 *)
88 TARGET_TOOLS=GCC44
89 ;;
90 esac
91 esac
92
93 #
94 # Scan command line to override defaults
95 #
96
97 for arg in "$@"
98 do
99 if [ -z "$LAST_ARG" ]; then
100 case $arg in
101 -a|-b|-t|-p|-n)
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 ;;
121 -p)
122 PLATFORMFILE=$arg
123 ;;
124 -t)
125 TARGET_TOOLS=$arg
126 ;;
127 -n)
128 THREADNUMBER=$arg
129 ;;
130 *)
131 BUILD_OPTIONS="$BUILD_OPTIONS $arg"
132 ;;
133 esac
134 LAST_ARG=
135 fi
136 shift
137 done
138
139 case $PROCESSOR in
140 IA32)
141 Processor=Ia32
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
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
157 ;;
158 X64)
159 Processor=X64
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
166 ;;
167 *)
168 echo Unsupported processor architecture: $PROCESSOR
169 echo Only IA32 or X64 is supported
170 exit 1
171 ;;
172 esac
173
174 if [ -z "$PLATFORMFILE" ]; then
175 PLATFORMFILE=$WORKSPACE/OvmfPkg/OvmfPkg$Processor.dsc
176 fi
177
178 ADD_QEMU_HDA=yes
179 for arg in "$@"
180 do
181 case $arg in
182 -hd[a-d]|-fd[ab]|-cdrom)
183 ADD_QEMU_HDA=no
184 break
185 ;;
186 esac
187 done
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
200 BUILD_ROOT=$WORKSPACE/Build/Ovmf$Processor/"$BUILDTARGET"_"$TARGET_TOOLS"
201 FV_DIR=$BUILD_ROOT/FV
202 BUILD_ROOT_ARCH=$BUILD_ROOT/$PROCESSOR
203 QEMU_FIRMWARE_DIR=$BUILD_ROOT/QEMU
204
205 if [[ ! -f `which build` || ! -f `which GenFv` ]];
206 then
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
210 elif [[ ( -f `which build` || -f `which GenFv` ) && ! -d $EDK_TOOLS_PATH/Source/C/bin ]];
211 then
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
215 else
216 echo using prebuilt tools
217 fi
218
219
220 if [[ "$RUN_QEMU" == "yes" ]]; then
221 if [[ ! -d $QEMU_FIRMWARE_DIR ]]; then
222 mkdir $QEMU_FIRMWARE_DIR
223 fi
224 ln -sf $FV_DIR/OVMF.fd $QEMU_FIRMWARE_DIR/bios.bin
225 if [[ "$ADD_QEMU_HDA" == "yes" ]]; then
226 AUTO_QEMU_HDA="-hda fat:$BUILD_ROOT_ARCH"
227 else
228 AUTO_QEMU_HDA=
229 fi
230 QEMU_COMMAND="$QEMU_COMMAND -L $QEMU_FIRMWARE_DIR $AUTO_QEMU_HDA $*"
231 echo Running: $QEMU_COMMAND
232 $QEMU_COMMAND
233 exit $?
234 fi
235
236 #
237 # Build the edk2 OvmfPkg
238 #
239 echo Running edk2 build for OvmfPkg$Processor
240 build -p $PLATFORMFILE $BUILD_OPTIONS -a $PROCESSOR -b $BUILDTARGET -t $TARGET_TOOLS -n $THREADNUMBER
241 exit $?
242