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