build.sh 6.0 KB

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