]> git.proxmox.com Git - mirror_edk2.git/blame - EmulatorPkg/build.sh
EDK II Packages: Add Contributions.txt and License.txt files
[mirror_edk2.git] / EmulatorPkg / build.sh
CommitLineData
417a8020 1#!/bin/bash
2#
461e8e8e 3# Copyright (c) 2008 - 2011, Apple Inc. All rights reserved.<BR>
4# Copyright (c) 2010 - 2011, 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
c8a556e3 66 HOST_TOOLS=XCODE32
67 TARGET_TOOLS=XCLANG
461e8e8e 68 fi
69 BUILD_NEW_SHELL="-D BUILD_NEW_SHELL"
70 BUILD_FAT="-D BUILD_FAT"
71 ;;
72 Linux*)
73 case `uname -m` in
74 i386)
75 HOST_PROCESSOR=IA32
76 ;;
77 i686)
78 HOST_PROCESSOR=IA32
79 ;;
80 x86_64)
81 HOST_PROCESSOR=X64
82 ;;
83 esac
ca3ba72c 84
85 gcc_version=$(gcc -v 2>&1 | tail -1 | awk '{print $3}')
86 case $gcc_version in
87 4.5.*)
88 TARGET_TOOLS=GCC45
89 ;;
90 4.6.*)
91 TARGET_TOOLS=GCC46
92 ;;
93 *)
94 TARGET_TOOLS=GCC44
ca3ba72c 95 ;;
96 esac
461e8e8e 97 ;;
98esac
99
100#
101# Scan command line to override defaults
102#
103
104for arg in "$@"
105do
106 if [ -z "$LAST_ARG" ]; then
107 case $arg in
108 -a|-b|-t|-p)
109 LAST_ARG=$arg
110 ;;
111 run)
112 RUN_EMULATOR=yes
113 shift
114 break
115 ;;
116 clean|cleanall)
117 CLEAN_TYPE=$arg
118 shift
119 break
120 ;;
121 *)
122 BUILD_OPTIONS="$BUILD_OPTIONS $arg"
123 ;;
124 esac
125 else
126 case $LAST_ARG in
127 -a)
128 PROCESSOR=$arg
129 ;;
130 -b)
131 BUILDTARGET=$arg
132 ;;
133 -p)
134 PLATFORMFILE=$arg
135 ;;
136 -t)
c8a556e3 137 HOST_TOOLS=$arg
461e8e8e 138 ;;
139 *)
140 BUILD_OPTIONS="$BUILD_OPTIONS $arg"
141 ;;
142 esac
143 LAST_ARG=
144 fi
145 shift
146done
c8a556e3 147if [ -z "$HOST_TOOLS" ]
461e8e8e 148then
c8a556e3 149 HOST_TOOLS=$TARGET_TOOLS
461e8e8e 150fi
151
152if [ -z "$PROCESSOR" ]
153then
154 PROCESSOR=$HOST_PROCESSOR
155fi
156
157case $PROCESSOR in
158 IA32)
159 ARCH_SIZE=32
160 BUILD_OUTPUT_DIR=$WORKSPACE/Build/Emulator32
d142bb63 161 LIB_NAMES="ld-linux.so.2 crt1.o crti.o crtn.o"
162 LIB_SEARCH_PATHS="/usr/lib/i386-linux-gnu /usr/lib32 /lib32 /usr/lib /lib"
461e8e8e 163 ;;
164 X64)
165 ARCH_SIZE=64
166 BUILD_OUTPUT_DIR=$WORKSPACE/Build/Emulator
d142bb63 167 LIB_NAMES="ld-linux-x86-64.so.2 crt1.o crti.o crtn.o"
168 LIB_SEARCH_PATHS="/usr/lib/x86_64-linux-gnu /usr/lib64 /lib64 /usr/lib /lib"
461e8e8e 169 ;;
170esac
171
d142bb63 172for libname in $LIB_NAMES
173do
174 for dirname in $LIB_SEARCH_PATHS
175 do
176 if [ -e $dirname/$libname ]; then
177 export HOST_DLINK_PATHS="$HOST_DLINK_PATHS $dirname/$libname"
178 break
179 fi
180 done
181done
461e8e8e 182
183PLATFORMFILE=$WORKSPACE/EmulatorPkg/EmulatorPkg.dsc
c8a556e3 184BUILD_ROOT_ARCH=$BUILD_OUTPUT_DIR/DEBUG_"$TARGET_TOOLS"/$PROCESSOR
461e8e8e 185
186if [[ ! -f `which build` || ! -f `which GenFv` ]];
187then
188 # build the tools if they don't yet exist. Bin scheme
189 echo Building tools as they are not in the path
190 make -C $WORKSPACE/BaseTools
191elif [[ ( -f `which build` || -f `which GenFv` ) && ! -d $EDK_TOOLS_PATH/Source/C/bin ]];
192then
193 # build the tools if they don't yet exist. BinWrapper scheme
194 echo Building tools no $EDK_TOOLS_PATH/Source/C/bin directory
195 make -C $WORKSPACE/BaseTools
196else
197 echo using prebuilt tools
198fi
199
200
201if [[ "$RUN_EMULATOR" == "yes" ]]; then
202 case `uname` in
203 Darwin*)
204 #
205 # On Darwin we can't use dlopen, so we have to load the real PE/COFF images.
206 # This .gdbinit script sets a breakpoint that loads symbols for the PE/COFFEE
207 # images that get loaded in Host
208 #
c8a556e3 209 cp $WORKSPACE/EmulatorPkg/Unix/.gdbinit $BUILD_OUTPUT_DIR/DEBUG_"$TARGET_TOOLS"/$PROCESSOR
461e8e8e 210 ;;
211 esac
212
213 /usr/bin/gdb $BUILD_ROOT_ARCH/Host -q -cd=$BUILD_ROOT_ARCH -x $WORKSPACE/EmulatorPkg/Unix/GdbRun
214 exit
215fi
216
217case $CLEAN_TYPE in
218 clean)
c8a556e3 219 build -p $WORKSPACE/EmulatorPkg/EmulatorPkg.dsc -a $PROCESSOR -b $BUILDTARGET -t $HOST_TOOLS -D UNIX_SEC_BUILD -n 3 clean
220 build -p $WORKSPACE/EmulatorPkg/EmulatorPkg.dsc -a $PROCESSOR -b $BUILDTARGET -t $TARGET_TOOLS -n 3 clean
461e8e8e 221 exit $?
222 ;;
223 cleanall)
224 make -C $WORKSPACE/BaseTools clean
c8a556e3 225 build -p $WORKSPACE/EmulatorPkg/EmulatorPkg.dsc -a $PROCESSOR -b $BUILDTARGET -t $HOST_TOOLS -D UNIX_SEC_BUILD -n 3 clean
226 build -p $WORKSPACE/EmulatorPkg/EmulatorPkg.dsc -a $PROCESSOR -b $BUILDTARGET -t $TARGET_TOOLS -n 3 clean
227 build -p $WORKSPACE/ShellPkg/ShellPkg.dsc -a IA32 -b $BUILDTARGET -t $TARGET_TOOLS -n 3 clean
461e8e8e 228 exit $?
229 ;;
230esac
231
232
233#
234# Build the edk2 EmulatorPkg
235#
c8a556e3 236if [[ $HOST_TOOLS == $TARGET_TOOLS ]]; then
237 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 238else
c8a556e3 239 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
240 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
241 cp $BUILD_OUTPUT_DIR/DEBUG_"$HOST_TOOLS"/$PROCESSOR/Host $BUILD_ROOT_ARCH
461e8e8e 242fi
243exit $?
417a8020 244