udk-2015.ebuild 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. # Copyright 1999-2016 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. EAPI=6
  4. PYTHON_COMPAT=( python2_7 )
  5. PYTHON_REQ_USE="sqlite"
  6. inherit flag-o-matic multiprocessing python-single-r1 toolchain-funcs versionator
  7. DESCRIPTION="Tianocore UEFI Development kit"
  8. HOMEPAGE="http://www.tianocore.org/edk2/"
  9. MY_V="${PN^^}$(get_version_component_range 1)"
  10. SRC_URI="https://github.com/tianocore/${PN}/releases/download/${MY_V}/${MY_V}.Complete.MyWorkSpace.zip"
  11. LICENSE="BSD"
  12. SLOT="0"
  13. KEYWORDS="~amd64 ~x86"
  14. IUSE="doc examples"
  15. DEPEND="app-arch/unzip
  16. dev-lang/nasm
  17. ${PYTHON_DEPS}"
  18. REQUIRED_USE="${PYTHON_REQUIRED_USE}"
  19. S="${WORKDIR}/MyWorkSpace"
  20. pkg_setup() {
  21. python_setup 'python2.7'
  22. local uname_arch=$(uname -m | sed -e 's:i[3456789]86:IA32:')
  23. if [[ ${uname_arch} == "x86_64" ]] || [[ ${uname_arch} == "amd64" ]] ; then
  24. export ARCH=X64
  25. else
  26. export ARCH=${uname_arch}
  27. fi
  28. # We will create a custom toolchain with user defined settings
  29. export TOOLCHAIN_TAG="CUSTOM"
  30. }
  31. src_unpack() {
  32. unpack ${A}
  33. unpack "${WORKDIR}/${MY_V}.MyWorkSpace.zip"
  34. pushd "${S}" || die
  35. unpack "${WORKDIR}/BaseTools(Unix).tar"
  36. local doc_name
  37. local f
  38. if use doc; then
  39. mkdir -p "${S}/doc" || die
  40. pushd "${S}/doc" >/dev/null || die
  41. for f in "${WORKDIR}/Documents/"*" Document.zip"; do
  42. doc_name=$(echo ${f} | sed -e 's:^.*/\([^/]*\) Document[.]zip$:\1:')
  43. if [[ -f "${WORKDIR}/Documents/${doc_name} Document.zip" ]]; then
  44. unpack "${WORKDIR}/Documents/${doc_name} Document.zip"
  45. mv "${S}/doc/html" "${S}/doc/${doc_name}" || die
  46. fi
  47. done
  48. popd >/dev/null || die
  49. fi
  50. popd >/dev/null || die
  51. }
  52. src_configure() {
  53. # Compile of Base Tools is required for further setting up the environment
  54. # Base tools does not like parallel make
  55. local cflags_save=${CFLAGS}
  56. append-cflags $(test-flags-CC -MD) $(test-flags-CC -fshort-wchar)
  57. append-cflags $(test-flags-CC -fno-strict-aliasing)
  58. append-cflags $(test-flags-CC -nostdlib) $(test-flags-CC -c)
  59. append-cflags $(test-flags-CC -fPIC)
  60. sed -e "s:^\(CFLAGS\s*=\).*$:\1 ${CFLAGS}:" \
  61. -i "${S}/BaseTools/Source/C/Makefiles/header.makefile" \
  62. || die "Failed to update makefile header"
  63. local make_flags=(
  64. CC="$(tc-getCC)"
  65. CXX="$(tc-getCXX)"
  66. AS="$(tc-getAS)"
  67. AR="$(tc-getAR)"
  68. LD="$(tc-getLD)"
  69. )
  70. emake "${make_flags[@]}" -j1 -C BaseTools
  71. . edksetup.sh BaseTools
  72. # Update flags in UDK parameter files
  73. CFLAGS=${cflags_save}
  74. append-cflags $(test-flags-CC -fshort-wchar)
  75. append-cflags $(test-flags-CC -fno-strict-aliasing) $(test-flags-CC -c)
  76. append-cflags $(test-flags-CC -ffunction-sections)
  77. append-cflags $(test-flags-CC -fdata-sections)
  78. append-cflags $(test-flags-CC -fno-stack-protector)
  79. append-cflags $(test-flags-CC -fno-asynchronous-unwind-tables)
  80. if [[ "${ARCH}" == "X64" ]]; then
  81. append-cflags $(test-flags-CC -m64) $(test-flags-CC -mno-red-zone)
  82. append-cflags $(test-flags-CC -mcmodel=large)
  83. else
  84. append-cflags $(test-flags-CC -m32) $(test-flags-CC -malign-double)
  85. fi
  86. sed -e "s:^\(ACTIVE_PLATFORM\s*=\).*$:\1 MdeModulePkg/MdeModulePkg.dsc:" \
  87. -e "s:^\(TARGET\s*=\).*$:\1 RELEASE:" \
  88. -e "s:^\(TARGET_ARCH\s*=\).*$:\1 ${ARCH}:" \
  89. -e "s:^\(TOOL_CHAIN_TAG\s*=\).*$:\1 ${TOOLCHAIN_TAG}:" \
  90. -e "s:^\(MAX_CONCURRENT_THREAD_NUMBER\s*=\).*$:\1 $(makeopts_jobs):" \
  91. -i "${S}/Conf/target.txt" || die "Failed to configure target file"
  92. sed -e "s:«CC»:$(tc-getCC):" \
  93. -e "s:«AR»:$(tc-getAR):" \
  94. -e "s:«LD»:$(tc-getLD):" \
  95. -e "s:«OBJCOPY»:$(tc-getOBJCOPY):" \
  96. -e "s:«CFLAGS»:${CFLAGS}:" \
  97. "${FILESDIR}/${PV}-tools_def.template" >>"${S}/Conf/tools_def.txt" \
  98. || die "Failed to prepare tools definition file"
  99. }
  100. src_compile() {
  101. local build_target
  102. if use examples; then
  103. build_target=all
  104. else
  105. build_target=libraries
  106. fi
  107. build ${build_target} || die "Failed to compile environment"
  108. }
  109. src_install() {
  110. local f
  111. local build_dir="${S}/Build/MdeModule/RELEASE_${TOOLCHAIN_TAG}/${ARCH}"
  112. for f in "${build_dir}"/*/Library/*/*/OUTPUT/*.lib; do
  113. newlib.a "${f}" lib$(basename "${f}" .lib).a
  114. done
  115. dolib "${S}/BaseTools/Scripts/GccBase.lds"
  116. local include_dest="/usr/include/${PN}"
  117. for f in "" /Guid /IndustryStandard /Library /Pi /Ppi /Protocol /Uefi; do
  118. insinto "${include_dest}${f}"
  119. doins "${S}/MdePkg/Include${f}"/*.h
  120. done
  121. insinto "${include_dest}"
  122. doins "${S}/MdePkg/Include/${ARCH}"/*.h
  123. local hfile
  124. find "${S}" -name 'BaseTools' -prune -o -name 'MdePkg' -prune -o \
  125. -name 'CryptoPkg' -prune -o -type d -name Include \
  126. -exec find {} -maxdepth 0 \; \
  127. | while read hfile; do
  128. doins -r "${hfile}"/*
  129. done
  130. dobin "${S}/BaseTools/Source/C/bin/GenFw"
  131. if use doc; then
  132. docinto "html"
  133. # Document installation may be very long, so split it and display message
  134. for f in "${S}"/doc/*; do
  135. ebegin "Installing documentation for $(basename ${f}), please wait"
  136. dodoc -r "${f}"
  137. eend $?
  138. done
  139. fi
  140. local ex_rebuild_dir
  141. local ex_name
  142. local ex_build_dir
  143. if use examples; then
  144. ex_rebuild_dir="${S}/${P}-exemples"
  145. for f in "${S}/MdeModulePkg/Application"/*; do
  146. ex_name=$(basename "${f}")
  147. ebegin "Preparing ${ex_name} example"
  148. mkdir -p "${ex_rebuild_dir}/${ex_name}" || die
  149. ex_build_dir="${build_dir}/MdeModulePkg/Application"
  150. ex_build_dir="${ex_build_dir}/${ex_name}/${ex_name}"
  151. copySourceFiles "${f}" "${ex_rebuild_dir}/${ex_name}"
  152. copySourceFiles "${ex_build_dir}/DEBUG" "${ex_rebuild_dir}/${ex_name}"
  153. createMakefile "${ex_rebuild_dir}/${ex_name}/Makefile" \
  154. "${ex_name}" "${ex_build_dir}/GNUmakefile"
  155. tar -C "${ex_rebuild_dir}" -cf "${ex_rebuild_dir}/${ex_name}.tar" \
  156. "${ex_name}" || die
  157. eend $? "Failed to create example file"
  158. done
  159. docinto "examples"
  160. dodoc "${ex_rebuild_dir}"/*.tar
  161. fi
  162. # TODO * QA Notice: The following files contain writable and executable sections
  163. # TODO * !WX --- --- usr/lib64/libBaseLib.a:Thunk16.obj
  164. # TODO * !WX --- --- usr/lib64/libBaseLib.a:SwitchStack.obj
  165. # TODO * !WX --- --- usr/lib64/libBaseLib.a:SetJump.obj
  166. # TODO * !WX --- --- usr/lib64/libBaseLib.a:LongJump.obj
  167. # TODO * !WX --- --- usr/lib64/libBaseLib.a:EnableDisableInterrupts.obj
  168. # TODO * !WX --- --- usr/lib64/libBaseLib.a:DisablePaging64.obj
  169. # TODO * !WX --- --- usr/lib64/libBaseLib.a:CpuId.obj
  170. # TODO * !WX --- --- usr/lib64/libBaseLib.a:CpuIdEx.obj
  171. # TODO * !WX --- --- usr/lib64/libBaseLib.a:EnableCache.obj
  172. # TODO * !WX --- --- usr/lib64/libBaseLib.a:DisableCache.obj
  173. # TODO * QA Notice: Package triggers severe warnings which indicate that it
  174. # TODO * may exhibit random runtime failures.
  175. # TODO * /usr/include/bits/string3.h:90:70: warning: call to void* __builtin___memset_chk(void*, int, long unsigned int, long unsigned int) will always overflow destination buffer
  176. }
  177. ##
  178. # Parameters :
  179. # 1 - Path where to search for source files.
  180. # 2 - Path where source files must be copied.
  181. copySourceFiles() {
  182. local dest_file
  183. while read -d '' -r filename; do
  184. dest_file="${2}${filename#${1}}"
  185. mkdir -p $(dirname "${dest_file}") || die
  186. mv "${filename}" "${dest_file}" || die
  187. done < <(find "${1}" -name '*.h' -print0 -o -name '*.c' -print0)
  188. }
  189. ##
  190. # Parameters :
  191. # 1 - Path of the file to create.
  192. # 2 - Name of the module.
  193. # 3 - Path of the generated Makefile.
  194. createMakefile() {
  195. local static_libs=$(sed -n '/^STATIC_LIBRARY_FILES\s*=/,/^\s*\$(OUTPUT_DIR)/{/^\s*\$(OUTPUT_DIR)/b;p}' ${3} \
  196. | sed -e 's:^\s*\$(BIN_DIR).*/\([^/]*\)\.lib:\t-l\1:' -e 's:\\$:\\\\\\n:' | tr --delete '\n')
  197. local pecoff_header_size;
  198. [[ $ARCH == X64 ]] && pecoff_header_size='0x228' || pecoff_header_size='0x220'
  199. sed -e "s:«MODULE»:${2}:" \
  200. -e "s:«PACKAGE_NAME»:${PN}:" \
  201. -e "s:«STATIC_LIBS»:${static_libs}:" \
  202. -e "s:«MODULE_TYPE»:$(grep -e '^MODULE_TYPE\s*=' ${3} | tail -1):" \
  203. -e "s:«IMAGE_ENTRY_POINT»:$(grep -e '^IMAGE_ENTRY_POINT\s*=' ${3}):" \
  204. -e "s:«CP»:$(grep -e '^CP\s*=' ${3}):" \
  205. -e "s:«RM»:$(grep -e '^RM\s*=' ${3}):" \
  206. -e "s:«CC»:$(grep -e '^CC\s*=' ${3}):" \
  207. -e "s:«DLINK»:$(grep -e '^DLINK\s*=' ${3}):" \
  208. -e "s:«OBJCOPY»:$(grep -e '^OBJCOPY\s*=' ${3}):" \
  209. -e "s:«GENFW»:$(grep -e '^GENFW\s*=' ${3}):" \
  210. -e "s:«PECOFF_HEADER_SIZE»:${pecoff_header_size}:" \
  211. -e "s:«OBJCOPY_FLAGS»:$(grep -e '^OBJCOPY_FLAGS\s*=' ${3}):" \
  212. -e "s:«GENFW_FLAGS»:$(grep -e '^GENFW_FLAGS\s*=' ${3}):" \
  213. "${FILESDIR}/${PV}-makefile.template" >${1} \
  214. || die "Failed to create Makefile"
  215. }