build.sh 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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. # 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. set -e
  15. shopt -s nocasematch
  16. #
  17. # Setup workspace if it is not set
  18. #
  19. if [ -z "$WORKSPACE" ]
  20. then
  21. echo Initializing workspace
  22. if [ ! -e `pwd`/edksetup.sh ]
  23. then
  24. cd ..
  25. fi
  26. # This version is for the tools in the BaseTools project.
  27. # this assumes svn pulls have the same root dir
  28. # export EDK_TOOLS_PATH=`pwd`/../BaseTools
  29. # This version is for the tools source in edk2
  30. export EDK_TOOLS_PATH=`pwd`/BaseTools
  31. echo $EDK_TOOLS_PATH
  32. source edksetup.sh BaseTools
  33. else
  34. echo Building from: $WORKSPACE
  35. fi
  36. #
  37. # Configure defaults for various options
  38. #
  39. PROCESSOR=
  40. BUILDTARGET=DEBUG
  41. BUILD_OPTIONS=
  42. PLATFORMFILE=
  43. LAST_ARG=
  44. RUN_EMULATOR=no
  45. CLEAN_TYPE=none
  46. TARGET_TOOLS=GCC48
  47. NETWORK_SUPPORT=
  48. BUILD_NEW_SHELL=
  49. BUILD_FAT=
  50. HOST_PROCESSOR=X64
  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. gcc_version=$(gcc -v 2>&1 | tail -1 | awk '{print $3}')
  88. case $gcc_version in
  89. [1-3].*|4.[0-7].*)
  90. echo EmulatorPkg requires GCC4.8 or later
  91. exit 1
  92. ;;
  93. 4.8.*)
  94. TARGET_TOOLS=GCC48
  95. ;;
  96. 4.9.*|6.[0-2].*)
  97. TARGET_TOOLS=GCC49
  98. ;;
  99. *)
  100. TARGET_TOOLS=GCC5
  101. ;;
  102. esac
  103. ;;
  104. esac
  105. #
  106. # Scan command line to override defaults
  107. #
  108. for arg in "$@"
  109. do
  110. if [ -z "$LAST_ARG" ]; then
  111. case $arg in
  112. -a|-b|-t|-p)
  113. LAST_ARG=$arg
  114. ;;
  115. run)
  116. RUN_EMULATOR=yes
  117. shift
  118. break
  119. ;;
  120. clean|cleanall)
  121. CLEAN_TYPE=$arg
  122. shift
  123. break
  124. ;;
  125. *)
  126. BUILD_OPTIONS="$BUILD_OPTIONS $arg"
  127. ;;
  128. esac
  129. else
  130. case $LAST_ARG in
  131. -a)
  132. PROCESSOR=$arg
  133. ;;
  134. -b)
  135. BUILDTARGET=$arg
  136. ;;
  137. -p)
  138. PLATFORMFILE=$arg
  139. ;;
  140. -t)
  141. HOST_TOOLS=$arg
  142. ;;
  143. *)
  144. BUILD_OPTIONS="$BUILD_OPTIONS $arg"
  145. ;;
  146. esac
  147. LAST_ARG=
  148. fi
  149. shift
  150. done
  151. if [ -z "$HOST_TOOLS" ]
  152. then
  153. HOST_TOOLS=$TARGET_TOOLS
  154. fi
  155. if [ -z "$PROCESSOR" ]
  156. then
  157. PROCESSOR=$HOST_PROCESSOR
  158. fi
  159. BUILD_OUTPUT_DIR=$WORKSPACE/Build/Emulator$PROCESSOR
  160. case $PROCESSOR in
  161. IA32)
  162. ARCH_SIZE=32
  163. LIB_NAMES="ld-linux.so.2 libdl.so.2 crt1.o crti.o crtn.o"
  164. LIB_SEARCH_PATHS="/usr/lib/i386-linux-gnu /usr/lib32 /lib32 /usr/lib /lib"
  165. ;;
  166. X64)
  167. ARCH_SIZE=64
  168. LIB_NAMES="ld-linux-x86-64.so.2 libdl.so.2 crt1.o crti.o crtn.o"
  169. LIB_SEARCH_PATHS="/usr/lib/x86_64-linux-gnu /usr/lib64 /lib64 /usr/lib /lib"
  170. ;;
  171. esac
  172. for libname in $LIB_NAMES
  173. do
  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
  181. done
  182. PLATFORMFILE=$WORKSPACE/EmulatorPkg/EmulatorPkg.dsc
  183. BUILD_DIR=$BUILD_OUTPUT_DIR/DEBUG_"$TARGET_TOOLS"
  184. BUILD_ROOT_ARCH=$BUILD_DIR/$PROCESSOR
  185. if [[ ! -f `which build` || ! -f `which GenFv` ]];
  186. then
  187. # build the tools if they don't yet exist. Bin scheme
  188. echo Building tools as they are not in the path
  189. make -C $WORKSPACE/BaseTools
  190. elif [[ ( -f `which build` || -f `which GenFv` ) && ! -d $EDK_TOOLS_PATH/Source/C/bin ]];
  191. then
  192. # build the tools if they don't yet exist. BinWrapper scheme
  193. echo Building tools no $EDK_TOOLS_PATH/Source/C/bin directory
  194. make -C $WORKSPACE/BaseTools
  195. else
  196. echo using prebuilt tools
  197. fi
  198. if [[ "$RUN_EMULATOR" == "yes" ]]; then
  199. case `uname` in
  200. Darwin*)
  201. #
  202. # On Darwin we can't use dlopen, so we have to load the real PE/COFF images.
  203. # This .gdbinit script sets a breakpoint that loads symbols for the PE/COFFEE
  204. # images that get loaded in Host
  205. #
  206. if [[ "$CLANG_VER" == *-ccc-host-triple* ]]
  207. then
  208. # only older versions of Xcode support -ccc-host-tripe, for newer versions
  209. # it is -target
  210. cp $WORKSPACE/EmulatorPkg/Unix/lldbefi.py $BUILD_OUTPUT_DIR/DEBUG_"$TARGET_TOOLS"/$PROCESSOR
  211. cd $BUILD_ROOT_ARCH; /usr/bin/lldb --source $WORKSPACE/EmulatorPkg/Unix/lldbinit Host
  212. exit $?
  213. else
  214. cp $WORKSPACE/EmulatorPkg/Unix/.gdbinit $BUILD_OUTPUT_DIR/DEBUG_"$TARGET_TOOLS"/$PROCESSOR
  215. fi
  216. ;;
  217. esac
  218. /usr/bin/gdb $BUILD_ROOT_ARCH/Host -q -cd=$BUILD_ROOT_ARCH -x $WORKSPACE/EmulatorPkg/Unix/GdbRun
  219. exit
  220. fi
  221. case $CLEAN_TYPE in
  222. clean)
  223. build -p $WORKSPACE/EmulatorPkg/EmulatorPkg.dsc -a $PROCESSOR -b $BUILDTARGET -t $HOST_TOOLS -D UNIX_SEC_BUILD -n 3 clean
  224. build -p $WORKSPACE/EmulatorPkg/EmulatorPkg.dsc -a $PROCESSOR -b $BUILDTARGET -t $TARGET_TOOLS -n 3 clean
  225. exit $?
  226. ;;
  227. cleanall)
  228. make -C $WORKSPACE/BaseTools clean
  229. build -p $WORKSPACE/EmulatorPkg/EmulatorPkg.dsc -a $PROCESSOR -b $BUILDTARGET -t $HOST_TOOLS -D UNIX_SEC_BUILD -n 3 clean
  230. build -p $WORKSPACE/EmulatorPkg/EmulatorPkg.dsc -a $PROCESSOR -b $BUILDTARGET -t $TARGET_TOOLS -n 3 clean
  231. build -p $WORKSPACE/ShellPkg/ShellPkg.dsc -a IA32 -b $BUILDTARGET -t $TARGET_TOOLS -n 3 clean
  232. exit $?
  233. ;;
  234. esac
  235. #
  236. # Build the edk2 EmulatorPkg
  237. #
  238. if [[ $HOST_TOOLS == $TARGET_TOOLS ]]; then
  239. 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
  240. else
  241. 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
  242. 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
  243. cp $BUILD_OUTPUT_DIR/DEBUG_"$HOST_TOOLS"/$PROCESSOR/Host $BUILD_ROOT_ARCH
  244. fi
  245. exit $?