]> git.proxmox.com Git - mirror_edk2.git/blame - EmulatorPkg/build.sh
ArmPkg/DefaultExceptionHandlerLib: declare the permitted usage context
[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
8ff12211 51TARGET_TOOLS=GCC48
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
8ff12211
LE
96 [1-3].*|4.[0-7].*)
97 echo EmulatorPkg requires GCC4.8 or later
a04ec6d9
JJ
98 exit 1
99 ;;
dc4ad153
JJ
100 4.8.*)
101 TARGET_TOOLS=GCC48
102 ;;
a04ec6d9 103 4.9.*|6.[0-2].*)
dc4ad153
JJ
104 TARGET_TOOLS=GCC49
105 ;;
ca3ba72c 106 *)
a04ec6d9 107 TARGET_TOOLS=GCC5
ca3ba72c 108 ;;
109 esac
461e8e8e 110 ;;
111esac
112
113#
114# Scan command line to override defaults
115#
116
117for arg in "$@"
118do
119 if [ -z "$LAST_ARG" ]; then
120 case $arg in
121 -a|-b|-t|-p)
122 LAST_ARG=$arg
123 ;;
124 run)
125 RUN_EMULATOR=yes
126 shift
127 break
128 ;;
129 clean|cleanall)
130 CLEAN_TYPE=$arg
131 shift
132 break
133 ;;
134 *)
135 BUILD_OPTIONS="$BUILD_OPTIONS $arg"
136 ;;
137 esac
138 else
139 case $LAST_ARG in
140 -a)
141 PROCESSOR=$arg
142 ;;
143 -b)
144 BUILDTARGET=$arg
145 ;;
146 -p)
147 PLATFORMFILE=$arg
148 ;;
149 -t)
c8a556e3 150 HOST_TOOLS=$arg
461e8e8e 151 ;;
152 *)
153 BUILD_OPTIONS="$BUILD_OPTIONS $arg"
154 ;;
155 esac
156 LAST_ARG=
157 fi
158 shift
159done
c8a556e3 160if [ -z "$HOST_TOOLS" ]
461e8e8e 161then
c8a556e3 162 HOST_TOOLS=$TARGET_TOOLS
461e8e8e 163fi
164
165if [ -z "$PROCESSOR" ]
166then
167 PROCESSOR=$HOST_PROCESSOR
168fi
169
90fa59f6
LY
170BUILD_OUTPUT_DIR=$WORKSPACE/Build/Emulator$PROCESSOR
171
461e8e8e 172case $PROCESSOR in
173 IA32)
174 ARCH_SIZE=32
1d602b12 175 LIB_NAMES="ld-linux.so.2 libdl.so.2 crt1.o crti.o crtn.o"
d142bb63 176 LIB_SEARCH_PATHS="/usr/lib/i386-linux-gnu /usr/lib32 /lib32 /usr/lib /lib"
461e8e8e 177 ;;
178 X64)
179 ARCH_SIZE=64
1d602b12 180 LIB_NAMES="ld-linux-x86-64.so.2 libdl.so.2 crt1.o crti.o crtn.o"
d142bb63 181 LIB_SEARCH_PATHS="/usr/lib/x86_64-linux-gnu /usr/lib64 /lib64 /usr/lib /lib"
461e8e8e 182 ;;
183esac
184
d142bb63 185for libname in $LIB_NAMES
186do
187 for dirname in $LIB_SEARCH_PATHS
188 do
189 if [ -e $dirname/$libname ]; then
190 export HOST_DLINK_PATHS="$HOST_DLINK_PATHS $dirname/$libname"
191 break
192 fi
193 done
194done
461e8e8e 195
196PLATFORMFILE=$WORKSPACE/EmulatorPkg/EmulatorPkg.dsc
8649abce
AF
197BUILD_DIR=$BUILD_OUTPUT_DIR/DEBUG_"$TARGET_TOOLS"
198BUILD_ROOT_ARCH=$BUILD_DIR/$PROCESSOR
461e8e8e 199
200if [[ ! -f `which build` || ! -f `which GenFv` ]];
201then
202 # build the tools if they don't yet exist. Bin scheme
203 echo Building tools as they are not in the path
204 make -C $WORKSPACE/BaseTools
205elif [[ ( -f `which build` || -f `which GenFv` ) && ! -d $EDK_TOOLS_PATH/Source/C/bin ]];
206then
207 # build the tools if they don't yet exist. BinWrapper scheme
208 echo Building tools no $EDK_TOOLS_PATH/Source/C/bin directory
209 make -C $WORKSPACE/BaseTools
210else
211 echo using prebuilt tools
212fi
213
214
215if [[ "$RUN_EMULATOR" == "yes" ]]; then
216 case `uname` in
217 Darwin*)
218 #
219 # On Darwin we can't use dlopen, so we have to load the real PE/COFF images.
220 # This .gdbinit script sets a breakpoint that loads symbols for the PE/COFFEE
221 # images that get loaded in Host
222 #
8649abce
AF
223 if [[ "$CLANG_VER" == *-ccc-host-triple* ]]
224 then
225 # only older versions of Xcode support -ccc-host-tripe, for newer versions
226 # it is -target
227 cp $WORKSPACE/EmulatorPkg/Unix/lldbefi.py $BUILD_OUTPUT_DIR/DEBUG_"$TARGET_TOOLS"/$PROCESSOR
228 cd $BUILD_ROOT_ARCH; /usr/bin/lldb --source $WORKSPACE/EmulatorPkg/Unix/lldbinit Host
229 exit $?
230 else
231 cp $WORKSPACE/EmulatorPkg/Unix/.gdbinit $BUILD_OUTPUT_DIR/DEBUG_"$TARGET_TOOLS"/$PROCESSOR
232 fi
461e8e8e 233 ;;
234 esac
235
236 /usr/bin/gdb $BUILD_ROOT_ARCH/Host -q -cd=$BUILD_ROOT_ARCH -x $WORKSPACE/EmulatorPkg/Unix/GdbRun
237 exit
238fi
239
240case $CLEAN_TYPE in
241 clean)
c8a556e3 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
461e8e8e 244 exit $?
245 ;;
246 cleanall)
247 make -C $WORKSPACE/BaseTools clean
c8a556e3 248 build -p $WORKSPACE/EmulatorPkg/EmulatorPkg.dsc -a $PROCESSOR -b $BUILDTARGET -t $HOST_TOOLS -D UNIX_SEC_BUILD -n 3 clean
249 build -p $WORKSPACE/EmulatorPkg/EmulatorPkg.dsc -a $PROCESSOR -b $BUILDTARGET -t $TARGET_TOOLS -n 3 clean
250 build -p $WORKSPACE/ShellPkg/ShellPkg.dsc -a IA32 -b $BUILDTARGET -t $TARGET_TOOLS -n 3 clean
461e8e8e 251 exit $?
252 ;;
253esac
254
255
256#
257# Build the edk2 EmulatorPkg
258#
c8a556e3 259if [[ $HOST_TOOLS == $TARGET_TOOLS ]]; then
260 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 261else
c8a556e3 262 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
263 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
264 cp $BUILD_OUTPUT_DIR/DEBUG_"$HOST_TOOLS"/$PROCESSOR/Host $BUILD_ROOT_ARCH
461e8e8e 265fi
266exit $?
417a8020 267