]> git.proxmox.com Git - mirror_edk2.git/blob - EmulatorPkg/build.sh
OvmfPkg/Csm/LegacyBiosDxe: Update to make it build for OVMF
[mirror_edk2.git] / EmulatorPkg / build.sh
1 #!/bin/bash
2 #
3 # Copyright (c) 2008 - 2011, Apple Inc. All rights reserved.<BR>
4 # Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR>
5 #
6 # SPDX-License-Identifier: BSD-2-Clause-Patent
7 #
8
9 set -e
10 shopt -s nocasematch
11
12
13 #
14 # Setup workspace if it is not set
15 #
16 if [ -z "$WORKSPACE" ]
17 then
18 echo Initializing workspace
19 if [ ! -e `pwd`/edksetup.sh ]
20 then
21 cd ..
22 fi
23 # This version is for the tools in the BaseTools project.
24 # this assumes svn pulls have the same root dir
25 # export EDK_TOOLS_PATH=`pwd`/../BaseTools
26 # This version is for the tools source in edk2
27 export EDK_TOOLS_PATH=`pwd`/BaseTools
28 echo $EDK_TOOLS_PATH
29 source edksetup.sh BaseTools
30 else
31 echo Building from: $WORKSPACE
32 fi
33
34 #
35 # Configure defaults for various options
36 #
37
38 PROCESSOR=
39 BUILDTARGET=DEBUG
40 BUILD_OPTIONS=
41 PLATFORMFILE=
42 LAST_ARG=
43 RUN_EMULATOR=no
44 CLEAN_TYPE=none
45 TARGET_TOOLS=GCC48
46 NETWORK_SUPPORT=
47 BUILD_NEW_SHELL=
48 BUILD_FAT=
49 HOST_PROCESSOR=X64
50
51 case `uname` in
52 CYGWIN*) echo Cygwin not fully supported yet. ;;
53 Darwin*)
54 Major=$(uname -r | cut -f 1 -d '.')
55 if [[ $Major == 9 ]]
56 then
57 echo UnixPkg requires Snow Leopard or later OS
58 exit 1
59 else
60 CLANG_VER=$(clang -ccc-host-triple x86_64-pc-win32-macho 2>&1 >/dev/null) || true
61 if [[ "$CLANG_VER" == *-ccc-host-triple* ]]
62 then
63 # only older versions of Xcode support -ccc-host-tripe, for newer versions
64 # it is -target
65 HOST_TOOLS=XCODE32
66 TARGET_TOOLS=XCODE5
67 else
68 HOST_TOOLS=XCODE32
69 TARGET_TOOLS=XCLANG
70 fi
71 fi
72 BUILD_NEW_SHELL="-D BUILD_NEW_SHELL"
73 BUILD_FAT="-D BUILD_FAT"
74 ;;
75 Linux*)
76 case `uname -m` in
77 i386)
78 HOST_PROCESSOR=IA32
79 ;;
80 i686)
81 HOST_PROCESSOR=IA32
82 ;;
83 x86_64)
84 HOST_PROCESSOR=X64
85 ;;
86 esac
87
88 gcc_version=$(gcc -v 2>&1 | tail -1 | awk '{print $3}')
89 case $gcc_version in
90 [1-3].*|4.[0-7].*)
91 echo EmulatorPkg requires GCC4.8 or later
92 exit 1
93 ;;
94 4.8.*)
95 TARGET_TOOLS=GCC48
96 ;;
97 4.9.*|6.[0-2].*)
98 TARGET_TOOLS=GCC49
99 ;;
100 *)
101 TARGET_TOOLS=GCC5
102 ;;
103 esac
104 ;;
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)
116 LAST_ARG=$arg
117 ;;
118 run)
119 RUN_EMULATOR=yes
120 shift
121 break
122 ;;
123 clean|cleanall)
124 CLEAN_TYPE=$arg
125 shift
126 break
127 ;;
128 *)
129 BUILD_OPTIONS="$BUILD_OPTIONS $arg"
130 ;;
131 esac
132 else
133 case $LAST_ARG in
134 -a)
135 PROCESSOR=$arg
136 ;;
137 -b)
138 BUILDTARGET=$arg
139 ;;
140 -p)
141 PLATFORMFILE=$arg
142 ;;
143 -t)
144 HOST_TOOLS=$arg
145 ;;
146 *)
147 BUILD_OPTIONS="$BUILD_OPTIONS $arg"
148 ;;
149 esac
150 LAST_ARG=
151 fi
152 shift
153 done
154 if [ -z "$HOST_TOOLS" ]
155 then
156 HOST_TOOLS=$TARGET_TOOLS
157 fi
158
159 if [ -z "$PROCESSOR" ]
160 then
161 PROCESSOR=$HOST_PROCESSOR
162 fi
163
164 BUILD_OUTPUT_DIR=$WORKSPACE/Build/Emulator$PROCESSOR
165
166 case $PROCESSOR in
167 IA32)
168 ARCH_SIZE=32
169 LIB_NAMES="ld-linux.so.2 libdl.so.2 crt1.o crti.o crtn.o"
170 LIB_SEARCH_PATHS="/usr/lib/i386-linux-gnu /usr/lib32 /lib32 /usr/lib /lib"
171 ;;
172 X64)
173 ARCH_SIZE=64
174 LIB_NAMES="ld-linux-x86-64.so.2 libdl.so.2 crt1.o crti.o crtn.o"
175 LIB_SEARCH_PATHS="/usr/lib/x86_64-linux-gnu /usr/lib64 /lib64 /usr/lib /lib"
176 ;;
177 esac
178
179 for libname in $LIB_NAMES
180 do
181 for dirname in $LIB_SEARCH_PATHS
182 do
183 if [ -e $dirname/$libname ]; then
184 export HOST_DLINK_PATHS="$HOST_DLINK_PATHS $dirname/$libname"
185 break
186 fi
187 done
188 done
189
190 PLATFORMFILE=$WORKSPACE/EmulatorPkg/EmulatorPkg.dsc
191 BUILD_DIR=$BUILD_OUTPUT_DIR/DEBUG_"$TARGET_TOOLS"
192 BUILD_ROOT_ARCH=$BUILD_DIR/$PROCESSOR
193
194 if [[ ! -f `which build` || ! -f `which GenFv` ]];
195 then
196 # build the tools if they don't yet exist. Bin scheme
197 echo Building tools as they are not in the path
198 make -C $WORKSPACE/BaseTools
199 elif [[ ( -f `which build` || -f `which GenFv` ) && ! -d $EDK_TOOLS_PATH/Source/C/bin ]];
200 then
201 # build the tools if they don't yet exist. BinWrapper scheme
202 echo Building tools no $EDK_TOOLS_PATH/Source/C/bin directory
203 make -C $WORKSPACE/BaseTools
204 else
205 echo using prebuilt tools
206 fi
207
208
209 if [[ "$RUN_EMULATOR" == "yes" ]]; then
210 case `uname` in
211 Darwin*)
212 #
213 # On Darwin we can't use dlopen, so we have to load the real PE/COFF images.
214 # This .gdbinit script sets a breakpoint that loads symbols for the PE/COFFEE
215 # images that get loaded in Host
216 #
217 if [[ "$CLANG_VER" == *-ccc-host-triple* ]]
218 then
219 # only older versions of Xcode support -ccc-host-tripe, for newer versions
220 # it is -target
221 cp $WORKSPACE/EmulatorPkg/Unix/lldbefi.py $BUILD_OUTPUT_DIR/DEBUG_"$TARGET_TOOLS"/$PROCESSOR
222 cd $BUILD_ROOT_ARCH; /usr/bin/lldb --source $WORKSPACE/EmulatorPkg/Unix/lldbinit Host
223 exit $?
224 else
225 cp $WORKSPACE/EmulatorPkg/Unix/.gdbinit $BUILD_OUTPUT_DIR/DEBUG_"$TARGET_TOOLS"/$PROCESSOR
226 fi
227 ;;
228 esac
229
230 /usr/bin/gdb $BUILD_ROOT_ARCH/Host -q -cd=$BUILD_ROOT_ARCH -x $WORKSPACE/EmulatorPkg/Unix/GdbRun.sh
231 exit
232 fi
233
234 case $CLEAN_TYPE in
235 clean)
236 build -p $WORKSPACE/EmulatorPkg/EmulatorPkg.dsc -a $PROCESSOR -b $BUILDTARGET -t $HOST_TOOLS -D UNIX_SEC_BUILD -n 3 clean
237 build -p $WORKSPACE/EmulatorPkg/EmulatorPkg.dsc -a $PROCESSOR -b $BUILDTARGET -t $TARGET_TOOLS -n 3 clean
238 exit $?
239 ;;
240 cleanall)
241 make -C $WORKSPACE/BaseTools clean
242 build -p $WORKSPACE/EmulatorPkg/EmulatorPkg.dsc -a $PROCESSOR -b $BUILDTARGET -t $HOST_TOOLS -D UNIX_SEC_BUILD -n 3 clean
243 build -p $WORKSPACE/EmulatorPkg/EmulatorPkg.dsc -a $PROCESSOR -b $BUILDTARGET -t $TARGET_TOOLS -n 3 clean
244 build -p $WORKSPACE/ShellPkg/ShellPkg.dsc -a IA32 -b $BUILDTARGET -t $TARGET_TOOLS -n 3 clean
245 exit $?
246 ;;
247 esac
248
249
250 #
251 # Build the edk2 EmulatorPkg
252 #
253 if [[ $HOST_TOOLS == $TARGET_TOOLS ]]; then
254 build -p $WORKSPACE/EmulatorPkg/EmulatorPkg.dsc $BUILD_OPTIONS -a $PROCESSOR -b $BUILDTARGET -t $TARGET_TOOLS -D BUILD_$ARCH_SIZE -D UNIX_SEC_BUILD $NETWORK_SUPPORT $BUILD_NEW_SHELL $BUILD_FAT -n 3
255 else
256 build -p $WORKSPACE/EmulatorPkg/EmulatorPkg.dsc $BUILD_OPTIONS -a $PROCESSOR -b $BUILDTARGET -t $HOST_TOOLS -D BUILD_$ARCH_SIZE -D UNIX_SEC_BUILD -D SKIP_MAIN_BUILD -n 3 modules
257 build -p $WORKSPACE/EmulatorPkg/EmulatorPkg.dsc $BUILD_OPTIONS -a $PROCESSOR -b $BUILDTARGET -t $TARGET_TOOLS -D BUILD_$ARCH_SIZE $NETWORK_SUPPORT $BUILD_NEW_SHELL $BUILD_FAT -n 3
258 cp $BUILD_OUTPUT_DIR/DEBUG_"$HOST_TOOLS"/$PROCESSOR/Host $BUILD_ROOT_ARCH
259 fi
260 exit $?
261