File OVMF.spec of Package OVMF

%define gitcurrent 20160502+gd0a23f9
%define gittarball 20160214+g922db0f
%define ovmfdirname %{name}-0.1+%{gittarball}
Name:       OVMF
Summary:    Intel Open Virtual Machine Firmware (UEFI Secure Boot)
Url:	    https://github.com/tianocore
Version:    0.1+%{gitcurrent}
Release:    1
Group:      Applications/Productivity
License:    GPLv3
Source0:    %{ovmfdirname}.tar.gz
Source1:    http://www.openssl.org/source/openssl-1.0.2g.tar.gz
Source2:    README.txt
Source99:   baselibs.conf
%if "%{gitcurrent}" != "%{gittarball}"
Patch0:	    edk2-%{gittarball}-%{gitcurrent}.diff
%endif
#Patch1:	    gcc-5.x-support.diff
Patch2:	    arm-enable-securitypkg.diff
Patch3:	    pkcs7verify-add-signature.diff
BuildRequires: iasl
BuildRequires: libuuid-devel
BuildRequires: gcc
BuildRequires: gcc-c++
BuildRequires: python
BuildRequires: nasm

Requires: qemu

%package -n edk2-devel
Summary:	Development package with Tianocore Libraries

%package -n edk2-pkcs7verify
Summary:	Installable driver for UEFI 2.5 Pkcs7Verify protocol

# translate Uname into the UEFI architecture extension
%define uefiarch %(uname -m|sed 's/i.86/IA32/;s/x86_64/X64/;s/arm.*/arm/'|tr '[a-z]' '[A-Z]')
%if "%{uefiarch}" == "IA32"
%define ovmfarch Ia32
%else
%if "%{uefiarch}" == "ARM"
%define ovmfarch Arm
%else
%if "%{uefiarch}" == "AARCH64"
%define ovmfarch AArch64
%else
%define ovmfarch %{uefiarch}
%endif
%endif
%endif

%define gccver %(gcc -dumpversion|sed 's/^\\\([0-9]\\\)\./\\1/\;s/^\\\([0-9]\\\)\$/\\10/')

# current tianocore has no build toolchain for anyting bigger than GCC49
%if %{gccver} >= 50
%define gccver 49
%endif

%description

This package contains UEFI rom images for exercising UEFI secure boot in a
qemu environment

See /usr/share/qemu-ovmf/README for details on how to run this environment
with qemu

%description -n edk2-devel

Development libraries extracted from TianoCore for various actions in
efi (like ssl)

%description -n edk2-pkcs7verify

Installs a simple efi driver binary which can be used to install the
Pkcs7Verify protocol on UEFI platforms which do not possess it.


%prep
%setup -q -n %{ovmfdirname}
%setup -T -D -n %{ovmfdirname}/CryptoPkg/Library/OpensslLib -a 1
%setup -T -D -n %{ovmfdirname}
%if "%{gitcurrent}" != "%{gittarball}"
%patch0 -p1
%endif
#%patch1 -p1
%patch2 -p1
%patch3 -p1
cp -p %SOURCE2 .
# Intel has special patches for openssl
pushd CryptoPkg/Library/OpensslLib
cd openssl-1.0.2g
patch -p1 -i ../EDKII_openssl-1.0.2g.patch
cd ..
./Install.sh
popd

%build
export TOOL_CHAIN_TAG=GCC%{gccver}
%define buildflags -t${TOOL_CHAIN_TAG} -a%{uefiarch} -DSECURE_BOOT_ENABLE=TRUE -DDEBUG_ON_SERIAL_PORT=TRUE
make -C BaseTools
printenv
. ./edksetup.sh
build %{buildflags} -pAppPkg/AppPkg.dsc
build %{buildflags} -pShellPkg/ShellPkg.dsc
build %{buildflags} -pSecurityPkg/SecurityPkg.dsc
%if ("%{uefiarch}" == "AARCH64" || "%{uefiarch}" == "ARM" )
build %{buildflags} -pArmVirtPkg/ArmVirtQemu.dsc
%else
build %{buildflags} -pOvmfPkg/OvmfPkg%{ovmfarch}.dsc
%endif

%install
export TOOL_CHAIN_TAG=GCC%{gccver}
rm -rf %{buildroot}
install -m 0644 -D README.txt %{buildroot}/%{_datadir}/qemu-ovmf/README
%if ("%{uefiarch}" == "AARCH64" || "%{uefiarch}" == "ARM" )
install -m 0644 -D Build/ArmVirtQemu-%{uefiarch}/DEBUG_${TOOL_CHAIN_TAG}/FV/QEMU_EFI.fd %{buildroot}/%{_datadir}/qemu-ovmf/bios/bios.bin
%else
install -m 0644 -D Build/Ovmf%{ovmfarch}/DEBUG_${TOOL_CHAIN_TAG}/FV/OVMF.fd %{buildroot}/%{_datadir}/qemu-ovmf/bios/bios.bin
%endif
install -m 0755 -D Build/AppPkg/DEBUG_${TOOL_CHAIN_TAG}/%{uefiarch}/Hello.efi %{buildroot}/%{_datadir}/qemu-ovmf/efi/Hello.efi
install -m 0755 -D Build/Shell/DEBUG_${TOOL_CHAIN_TAG}/%{uefiarch}/Shell.efi %{buildroot}/%{_datadir}/qemu-ovmf/efi/Shell.efi
# development stuff
install -m 0644 -D MdePkg/Include/%{ovmfarch}/ProcessorBind.h %{buildroot}/%{_includedir}/edk2/ProcessorBind.h
install -m 0644 -D MdePkg/Include/Base.h %{buildroot}/%{_includedir}/edk2/Base.h
install -m 0644 -D MdePkg/Include/Uefi/UefiBaseType.h %{buildroot}/%{_includedir}/edk2/Uefi/UefiBaseType.h
install -m 0644 -D CryptoPkg/Include/Library/BaseCryptLib.h %{buildroot}/%{_includedir}/edk2/Library/BaseCryptLib.h
install -m 0644 -D MdePkg/Include/Guid/ImageAuthentication.h %{buildroot}/%{_includedir}/edk2/Guid/ImageAuthentication.h
install -m 0644 -D MdePkg/Include/Guid/GlobalVariable.h %{buildroot}/%{_includedir}/edk2/Guid/GlobalVariable.h
install -m 0644 -D MdePkg/Include/Protocol/Hash.h %{buildroot}/%{_includedir}/edk2/Protocol/Hash.h
install -m 0644 -D MdePkg/Include/Protocol/Pkcs7Verify.h %{buildroot}/%{_includedir}/edk2/Protocol/Pkcs7Verify.h
#
install -m 0644 -D Build/SecurityPkg/DEBUG_${TOOL_CHAIN_TAG}/%{uefiarch}/CryptoPkg/Library/OpensslLib/OpensslLib/OUTPUT/OpensslLib.lib %{buildroot}/%{_libdir}/edk2/OpensslLib.lib
install -m 0755 -D Build/SecurityPkg/DEBUG_${TOOL_CHAIN_TAG}/%{uefiarch}/Pkcs7VerifyDxe.efi %{buildroot}/%{_datadir}/edk2/Pkcs7VerifyDxe.efi


%files 
%defattr(-,root,root,-)
%{_datadir}/qemu-ovmf

%files -n edk2-devel
%defattr(-,root,root,-)
%{_includedir}/edk2
%{_libdir}/edk2

%files -n edk2-pkcs7verify
%defattr(-,root,root,-)
%dir %{_datadir}/edk2
%{_datadir}/edk2/Pkcs7VerifyDxe.efi