build.sh 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. #!/usr/bin/env bash
  2. #
  3. # Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
  4. # Copyright (c) 2010 - 2019, 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. ARCH_IA32=no
  40. ARCH_X64=no
  41. BUILDTARGET=DEBUG
  42. BUILD_OPTIONS=
  43. PLATFORMFILE=
  44. THREADNUMBER=1
  45. LAST_ARG=
  46. RUN_QEMU=no
  47. ENABLE_FLASH=no
  48. #
  49. # Pick a default tool type for a given OS
  50. #
  51. TARGET_TOOLS=MYTOOLS
  52. case `uname` in
  53. CYGWIN*)
  54. echo Cygwin not fully supported yet.
  55. ;;
  56. Darwin*)
  57. Major=$(uname -r | cut -f 1 -d '.')
  58. # Major is Darwin version, not OS X version.
  59. # OS X Yosemite 10.10.2 returns 14.
  60. case $Major in
  61. [156789])
  62. echo OvmfPkg requires OS X Snow Leopard 10.6 or newer OS
  63. exit 1
  64. ;;
  65. 10)
  66. TARGET_TOOLS=XCODE32
  67. ;;
  68. 1[12])
  69. TARGET_TOOLS=XCLANG
  70. ;;
  71. *)
  72. # Mavericks and future assume XCODE5 (clang + lldb)
  73. TARGET_TOOLS=XCODE5
  74. ;;
  75. esac
  76. ;;
  77. Linux*)
  78. gcc_version=$(gcc -v 2>&1 | tail -1 | awk '{print $3}')
  79. case $gcc_version in
  80. [1-3].*|4.[0-7].*)
  81. echo OvmfPkg requires GCC4.8 or later
  82. exit 1
  83. ;;
  84. 4.8.*)
  85. TARGET_TOOLS=GCC48
  86. ;;
  87. 4.9.*|6.[0-2].*)
  88. TARGET_TOOLS=GCC49
  89. ;;
  90. *)
  91. TARGET_TOOLS=GCC5
  92. ;;
  93. esac
  94. esac
  95. #
  96. # Scan command line to override defaults
  97. #
  98. for arg in "$@"
  99. do
  100. if [ -z "$LAST_ARG" ]; then
  101. case $arg in
  102. -a|-b|-t|-p|-n)
  103. LAST_ARG=$arg
  104. ;;
  105. qemu)
  106. RUN_QEMU=yes
  107. shift
  108. break
  109. ;;
  110. --enable-flash)
  111. ENABLE_FLASH=yes
  112. ;;
  113. *)
  114. BUILD_OPTIONS="$BUILD_OPTIONS $arg"
  115. ;;
  116. esac
  117. else
  118. case $LAST_ARG in
  119. -a)
  120. if [[ x"$arg" != x"IA32" && x"$arg" != x"X64" ]]; then
  121. echo Unsupported processor architecture: $arg
  122. echo Only IA32 or X64 is supported
  123. exit 1
  124. fi
  125. eval ARCH_$arg=yes
  126. ;;
  127. -b)
  128. BUILDTARGET=$arg
  129. ;;
  130. -p)
  131. PLATFORMFILE=$arg
  132. ;;
  133. -t)
  134. TARGET_TOOLS=$arg
  135. ;;
  136. -n)
  137. THREADNUMBER=$arg
  138. ;;
  139. *)
  140. BUILD_OPTIONS="$BUILD_OPTIONS $arg"
  141. ;;
  142. esac
  143. LAST_ARG=
  144. fi
  145. shift
  146. done
  147. if [[ "$ARCH_IA32" == "yes" && "$ARCH_X64" == "yes" ]]; then
  148. PROCESSOR=IA32X64
  149. Processor=Ia32X64
  150. BUILD_OPTIONS="$BUILD_OPTIONS -a IA32 -a X64"
  151. PLATFORM_BUILD_DIR=Ovmf3264
  152. BUILD_ROOT_ARCH=X64
  153. elif [[ "$ARCH_IA32" == "yes" && "$ARCH_X64" == "no" ]]; then
  154. PROCESSOR=IA32
  155. Processor=Ia32
  156. BUILD_OPTIONS="$BUILD_OPTIONS -a IA32"
  157. PLATFORM_BUILD_DIR=Ovmf$Processor
  158. BUILD_ROOT_ARCH=$PROCESSOR
  159. else
  160. PROCESSOR=X64
  161. Processor=X64
  162. BUILD_OPTIONS="$BUILD_OPTIONS -a X64"
  163. PLATFORM_BUILD_DIR=Ovmf$Processor
  164. BUILD_ROOT_ARCH=X64
  165. fi
  166. case $PROCESSOR in
  167. IA32)
  168. if [ -n "$QEMU_COMMAND" ]; then
  169. #
  170. # The user set the QEMU_COMMAND variable. We'll use it to run QEMU.
  171. #
  172. :
  173. elif [ -x `which qemu-system-i386` ]; then
  174. QEMU_COMMAND=qemu-system-i386
  175. elif [ -x `which qemu-system-x86_64` ]; then
  176. QEMU_COMMAND=qemu-system-x86_64
  177. elif [ -x `which qemu` ]; then
  178. QEMU_COMMAND=qemu
  179. else
  180. echo Unable to find QEMU for IA32 architecture!
  181. exit 1
  182. fi
  183. ;;
  184. X64|IA32X64)
  185. if [ -z "$QEMU_COMMAND" ]; then
  186. #
  187. # The user didn't set the QEMU_COMMAND variable.
  188. #
  189. QEMU_COMMAND=qemu-system-x86_64
  190. fi
  191. ;;
  192. *)
  193. echo Unsupported processor architecture: $PROCESSOR
  194. echo Only IA32 or X64 is supported
  195. exit 1
  196. ;;
  197. esac
  198. if [ -z "$PLATFORMFILE" ]; then
  199. PLATFORMFILE=$WORKSPACE/OvmfPkg/OvmfPkg$Processor.dsc
  200. fi
  201. if [[ "$RUN_QEMU" == "yes" ]]; then
  202. qemu_version=$($QEMU_COMMAND -version 2>&1 | \
  203. grep -o -E 'version [0-9]+\.[0-9]+\.[0-9]+' | \
  204. awk '{print $2}')
  205. case $qemu_version in
  206. 1.[6-9].*|[2-9].*.*|[1-9][0-9]*.*.*)
  207. ENABLE_FLASH=yes
  208. ;;
  209. esac
  210. ADD_QEMU_HDA=yes
  211. for arg in "$@"
  212. do
  213. case $arg in
  214. -hd[a-d]|-fd[ab]|-cdrom)
  215. ADD_QEMU_HDA=no
  216. break
  217. ;;
  218. esac
  219. done
  220. fi
  221. #
  222. # Uncomment this block for parameter parsing debug
  223. #
  224. #echo RUN_QEMU=$RUN_QEMU
  225. #echo BUILD_OPTIONS=$BUILD_OPTIONS
  226. #echo BUILDTARGET=$BUILDTARGET
  227. #echo TARGET_TOOLS=$TARGET_TOOLS
  228. #echo PROCESSOR=$PROCESSOR
  229. #echo Remaining for qemu: $*
  230. #exit 1
  231. BUILD_ROOT=$WORKSPACE/Build/$PLATFORM_BUILD_DIR/"$BUILDTARGET"_"$TARGET_TOOLS"
  232. FV_DIR=$BUILD_ROOT/FV
  233. BUILD_ROOT_ARCH=$BUILD_ROOT/$BUILD_ROOT_ARCH
  234. QEMU_FIRMWARE_DIR=$BUILD_ROOT/QEMU
  235. if [[ ! -f `which build` || ! -f `which GenFv` ]];
  236. then
  237. # build the tools if they don't yet exist. Bin scheme
  238. echo Building tools as they are not in the path
  239. make -C $WORKSPACE/BaseTools
  240. elif [[ ( -f `which build` || -f `which GenFv` ) && ! -d $EDK_TOOLS_PATH/Source/C/bin ]];
  241. then
  242. # build the tools if they don't yet exist. BinWrapper scheme
  243. echo Building tools no $EDK_TOOLS_PATH/Source/C/bin directory
  244. make -C $WORKSPACE/BaseTools
  245. else
  246. echo using prebuilt tools
  247. fi
  248. if [[ "$RUN_QEMU" == "yes" ]]; then
  249. if [[ ! -d $QEMU_FIRMWARE_DIR ]]; then
  250. mkdir $QEMU_FIRMWARE_DIR
  251. fi
  252. ln -sf $FV_DIR/OVMF.fd $QEMU_FIRMWARE_DIR/bios.bin
  253. if [[ "$ENABLE_FLASH" == "yes" ]]; then
  254. QEMU_COMMAND="$QEMU_COMMAND -pflash $QEMU_FIRMWARE_DIR/bios.bin"
  255. else
  256. QEMU_COMMAND="$QEMU_COMMAND -L $QEMU_FIRMWARE_DIR"
  257. fi
  258. if [[ "$ADD_QEMU_HDA" == "yes" ]]; then
  259. QEMU_COMMAND="$QEMU_COMMAND -hda fat:$BUILD_ROOT_ARCH"
  260. fi
  261. echo Running: $QEMU_COMMAND "$@"
  262. $QEMU_COMMAND "$@"
  263. exit $?
  264. fi
  265. #
  266. # Build the edk2 OvmfPkg
  267. #
  268. echo Running edk2 build for OvmfPkg$Processor
  269. build -p $PLATFORMFILE $BUILD_OPTIONS -b $BUILDTARGET -t $TARGET_TOOLS -n $THREADNUMBER
  270. exit $?