]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/build.sh
OvmfPkg: Support GCC47 toolchain
[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 - 2012, 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 if [[ $Major == 9 ]]
63 then
64 echo OvmfPkg requires Snow Leopard or later OS
65 exit 1
66 else
67 TARGET_TOOLS=XCODE32
68 fi
69 ;;
70 Linux*)
71 gcc_version=$(gcc -v 2>&1 | tail -1 | awk '{print $3}')
72 case $gcc_version in
73 4.5.*)
74 TARGET_TOOLS=GCC45
75 ;;
76 4.6.*)
77 TARGET_TOOLS=GCC46
78 ;;
79 4.[789].*)
80 TARGET_TOOLS=GCC47
81 ;;
82 *)
83 TARGET_TOOLS=GCC44
84 ;;
85 esac
86 esac
87
88 #
89 # Scan command line to override defaults
90 #
91
92 for arg in "$@"
93 do
94 if [ -z "$LAST_ARG" ]; then
95 case $arg in
96 -a|-b|-t|-p|-n)
97 LAST_ARG=$arg
98 ;;
99 qemu)
100 RUN_QEMU=yes
101 shift
102 break
103 ;;
104 *)
105 BUILD_OPTIONS="$BUILD_OPTIONS $arg"
106 ;;
107 esac
108 else
109 case $LAST_ARG in
110 -a)
111 PROCESSOR=$arg
112 ;;
113 -b)
114 BUILDTARGET=$arg
115 ;;
116 -p)
117 PLATFORMFILE=$arg
118 ;;
119 -t)
120 TARGET_TOOLS=$arg
121 ;;
122 -n)
123 THREADNUMBER=$arg
124 ;;
125 *)
126 BUILD_OPTIONS="$BUILD_OPTIONS $arg"
127 ;;
128 esac
129 LAST_ARG=
130 fi
131 shift
132 done
133
134 case $PROCESSOR in
135 IA32)
136 Processor=Ia32
137 QEMU_COMMAND=qemu
138 ;;
139 X64)
140 Processor=X64
141 QEMU_COMMAND=qemu-system-x86_64
142 ;;
143 *)
144 echo Unsupported processor architecture: $PROCESSOR
145 echo Only IA32 or X64 is supported
146 exit 1
147 ;;
148 esac
149
150 if [ -z "$PLATFORMFILE" ]; then
151 PLATFORMFILE=$WORKSPACE/OvmfPkg/OvmfPkg$Processor.dsc
152 fi
153
154 ADD_QEMU_HDA=yes
155 for arg in "$@"
156 do
157 case $arg in
158 -hd[a-d]|-fd[ab]|-cdrom)
159 ADD_QEMU_HDA=no
160 break
161 ;;
162 esac
163 done
164
165 #
166 # Uncomment this block for parameter parsing debug
167 #
168 #echo RUN_QEMU=$RUN_QEMU
169 #echo BUILD_OPTIONS=$BUILD_OPTIONS
170 #echo BUILDTARGET=$BUILDTARGET
171 #echo TARGET_TOOLS=$TARGET_TOOLS
172 #echo PROCESSOR=$PROCESSOR
173 #echo Remaining for qemu: $*
174 #exit 1
175
176 BUILD_ROOT=$WORKSPACE/Build/Ovmf$Processor/"$BUILDTARGET"_"$TARGET_TOOLS"
177 FV_DIR=$BUILD_ROOT/FV
178 BUILD_ROOT_ARCH=$BUILD_ROOT/$PROCESSOR
179 QEMU_FIRMWARE_DIR=$BUILD_ROOT/QEMU
180
181 if [[ ! -f `which build` || ! -f `which GenFv` ]];
182 then
183 # build the tools if they don't yet exist. Bin scheme
184 echo Building tools as they are not in the path
185 make -C $WORKSPACE/BaseTools
186 elif [[ ( -f `which build` || -f `which GenFv` ) && ! -d $EDK_TOOLS_PATH/Source/C/bin ]];
187 then
188 # build the tools if they don't yet exist. BinWrapper scheme
189 echo Building tools no $EDK_TOOLS_PATH/Source/C/bin directory
190 make -C $WORKSPACE/BaseTools
191 else
192 echo using prebuilt tools
193 fi
194
195
196 if [[ "$RUN_QEMU" == "yes" ]]; then
197 if [[ ! -d $QEMU_FIRMWARE_DIR ]]; then
198 mkdir $QEMU_FIRMWARE_DIR
199 fi
200 ln -sf $FV_DIR/OVMF.fd $QEMU_FIRMWARE_DIR/bios.bin
201 if [[ "$ADD_QEMU_HDA" == "yes" ]]; then
202 AUTO_QEMU_HDA="-hda fat:$BUILD_ROOT_ARCH"
203 else
204 AUTO_QEMU_HDA=
205 fi
206 QEMU_COMMAND="$QEMU_COMMAND -L $QEMU_FIRMWARE_DIR $AUTO_QEMU_HDA $*"
207 echo Running: $QEMU_COMMAND
208 $QEMU_COMMAND
209 exit $?
210 fi
211
212 #
213 # Build the edk2 OvmfPkg
214 #
215 echo Running edk2 build for OvmfPkg$Processor
216 build -p $PLATFORMFILE $BUILD_OPTIONS -a $PROCESSOR -b $BUILDTARGET -t $TARGET_TOOLS -n $THREADNUMBER
217 exit $?
218