SUMMARY="EFI firmware development environment"
DESCRIPTION="The EDK II project is the response to the EFI community’s \
request for a better build and version tracking environment for UEFI and PI \
development. The main difference between the EDK II to the original EDK is \
the Enhanced Build Environment of the EDK II. The advantages of the Enhanced \
Build Environment include:

* Operating System independence
* Flexibility in choosing the compiler and assembler tools
* The ability to generate working code using open source build tools and \
applications
* Enhanced development and build capability of modules and module packages
* Use of build configuration tools and data sets to provide flexible process
* Online source control allows users to contribute code and become participants"
HOMEPAGE="https://www.tianocore.org/"
COPYRIGHT="2004-2016 Intel Corporation
	2008-2010 Apple Inc
	2011-2015 ARM Limited
	2014-2015 Linaro Limited
	2013-2015 Red Hat, Inc."
LICENSE="MIT"
REVISION="2"
SOURCE_URI="https://github.com/tianocore/edk2/archive/vUDK$portVersion.tar.gz"
CHECKSUM_SHA256="a37aa6dc7a4326b562ce03e225afd96a0cd1dc847d9aeddfd867ce6b2e7cc7bc"
SOURCE_DIR="edk2-vUDK$portVersion"
PATCHES="edk2-$portVersion.patchset"

ARCHITECTURES="all !x86_gcc2 ?x86"
if [ "$targetArchitecture" = x86_gcc2 ]; then
SECONDARY_ARCHITECTURES="?x86"
fi
DISABLE_SOURCE_PACKAGE="yes"

PROVIDES="
	edk2$secondaryArchSuffix = $portVersion compat >= 0
	"
REQUIRES="
	haiku$secondaryArchSuffix
 	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libuuid$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:find
	cmd:gcc$secondaryArchSuffix
	cmd:iasl
	cmd:make
	cmd:nasm
	cmd:python2
	cmd:sed
	"

PATCH()
{
	local ACTIVE_PLATFORM="MdeModulePkg/MdeModulePkg.dsc"
	local TARGET="RELEASE" # DEBUG, RELEASE, NOOPT
	local TARGET_ARCH="X64" # IA32, IPF, X64, EBC, ARM or AArch64
	local TOOL_CHAIN_TAG="GCC5"

	if [ "$effectiveTargetArchitecture" = x86 ]; then
		local TARGET_ARCH="IA32" # IA32, IPF, X64, EBC, ARM or AArch64
	fi

	sed -i "s|@ACTIVE_PLATFORM@|$ACTIVE_PLATFORM|g" BaseTools/Conf/target.template
	sed -i "s|@TARGET@|$TARGET|g" BaseTools/Conf/target.template
	sed -i "s|@TARGET_ARCH@|$TARGET_ARCH|g" BaseTools/Conf/target.template
	sed -i "s|@TOOL_CHAIN_TAG@|$TOOL_CHAIN_TAG|g" BaseTools/Conf/target.template

	sed -i "s|gcc-ar|ar|g" BaseTools/Conf/tools_def.template
}

BUILD()
{
	if [ "$effectiveTargetArchitecture" = x86 ]; then
		HOST_ARCH=IA32
	fi
	make -C BaseTools ${HOST_ARCH:+HOST_ARCH=$HOST_ARCH}
	. ./edksetup.sh
	local EDK_TOOLS_PATH="$sourceDir"/BaseTools
	. ./edksetup.sh BaseTools
	build
}

INSTALL()
{
	install -m 0755 -d "$dataDir"/edk2
	cd Build
	install -m 0644 -t "$dataDir"/edk2 */RELEASE*/*/*.efi
}
