--- opensc-0.12.2/opensc.spec	2012-04-11 01:59:42.000000000 +0200
+++ opensc-opendnie-0.12.2/opensc-opendnie.spec	2012-04-20 00:49:44.201016766 +0200
@@ -1,16 +1,21 @@
 %define major 3
-%define libname %mklibname %{name} %{major}
+%define originalname opensc
+%define originallibname %mklibname %{originalname} %{major}
+%define libname %{originallibname}-opendnie
 %define develname %mklibname -d %{name}
 
 Summary:	Library for accessing SmartCard devices
-Name:		opensc
+Name:		%{originalname}-opendnie
 Version:	0.12.2
-Release:	%mkrel 1
+Release:	%mkrel 1bdk
 License:	LGPLv2+
 Group:		System/Kernel and hardware
 URL:		http://www.opensc.org/
-Source:		http://www.opensc-project.org/files/opensc/%{name}-%{version}.tar.gz
+Source0:	http://www.opensc-project.org/files/opensc/%{originalname}-%{version}.tar.gz
 Source1:	oberthur.profile
+Patch0:		https://forja.cenatic.es/frs/download.php/1334/opensc-to-opendnie-%{version}.patch
+Patch1:		opensc-fix-ld-dso.patch
+Provides:	%{originalname} = %{version}-%{release}
 BuildRequires:	flex
 BuildRequires:	openssl-devel
 BuildRequires:	libltdl-devel
@@ -19,42 +24,61 @@
 BuildRequires:	pcsc-lite-devel
 BuildRequires:	xsltproc
 BuildRequires:	docbook-style-xsl
+BuildRequires:	automake
 Requires:	%{_lib}pcsclite1
-Conflicts:	%{libname} < 0.12.0-4
+Requires:	%{libname} = %{version}
+Requires:	pinentry-gui
+Conflicts:	%{originalname} < %{version}-%{release}
+Conflicts:	%{originalname} > %{version}-%{release}
 
 %description
-%{name} is a library for accessing smart card devices using PC/SC Lite
+%{originalname} is a library for accessing smart card devices using PC/SC Lite
 middleware package. It is also the core library of the OpenSC project.
 Basic functionality (e.g. SELECT FILE, READ BINARY) should work on any
 ISO 7816-4 compatible smart card. Encryption and decryption using private
 keys on the SmartCard is at the moment possible only with PKCS #15
 compatible cards.
 
+This package is a patched version of %{originalname} with support for the
+Spanish DNIe from the OpenDNIe project (http://opendnie.cenatic.es/).
+
 %package -n	%{libname}
 Summary:	Library for accessing SmartCard devices
 Group:		System/Libraries
+Provides:	%{originallibname} = %{version}-%{release}
 Obsoletes:	%{_lib}opensc2 < 0.12.0
-Obsoletes:	mozilla-plugin-%{name} < 0.12.0
+Obsoletes:	mozilla-plugin-%{originalname} < 0.12.0
+Conflicts:	%{originalname} < %{version}-%{release}
+Conflicts:	%{originallibname} < %{version}-%{release}
+Conflicts:	lib%{originalname}-devel < %{version}-%{release}
+Conflicts:	%{originalname} > %{version}-%{release}
+Conflicts:	%{originallibname} > %{version}-%{release}
+Conflicts:	lib%{originalname}-devel > %{version}-%{release}
 
 %description -n	%{libname}
-%{name} is a library for accessing smart card devices using PC/SC Lite
+%{originalname} is a library for accessing smart card devices using PC/SC Lite
 middleware package. It is also the core library of the OpenSC project.
 Basic functionality (e.g. SELECT FILE, READ BINARY) should work on any
 ISO 7816-4 compatible smart card. Encryption and decryption using private
 keys on the SmartCard is at the moment possible only with PKCS #15
 compatible cards.
 
+This package is a patched version of %{originalname} with support for the
+Spanish DNIe from the OpenDNIe project (http://opendnie.cenatic.es/).
+
 %package -n	%{develname}
-Summary:	Development related files for %{name}
+Summary:	Development related files for %{originalname}
 Group:		Development/C
-Provides:	lib%{name}-devel = %{version}-%{release}
-Provides:	%{name}-devel = %{version}-%{release}
+Provides:	lib%{originalname}-devel = %{version}-%{release}
+Provides:	%{originalname}-devel = %{version}-%{release}
 Requires:	%{libname} = %{version}
 Conflicts:	%{mklibname opensc 0 -d}
 Obsoletes:	%{mklibname opensc 2 -d} < 0.11.3
+Conflicts:	lib%{originalname}-devel < %{version}-%{release}
+Conflicts:	lib%{originalname}-devel > %{version}-%{release}
 
 %description -n	%{develname}
-%{name} is a library for accessing smart card devices using PC/SC Lite
+%{originalname} is a library for accessing smart card devices using PC/SC Lite
 middleware package. It is also the core library of the OpenSC project.
 Basic functionality (e.g. SELECT FILE, READ BINARY) should work on any
 ISO 7816-4 compatible smart card. Encryption and decryption using private
@@ -62,14 +86,26 @@
 compatible cards.
 
 This package contains all necessary files to develop or compile any
-applications or libraries that use %{name}. 
+applications or libraries that use %{originalname}. 
+
+This package is a patched version of %{originalname} with support for the
+Spanish DNIe from the OpenDNIe project (http://opendnie.cenatic.es/).
 
 %prep
-%setup -q
+%setup -q -n %{originalname}-%{version}
+%patch0 -p1
+#Needed to prevent a linking error due to DSO (http://fedoraproject.org/wiki/UnderstandingDSOLinkChange).
+#This error only appears if Makefile are regenerated, which is needed due to the
+#patch 0 modifying the Makefile.am
+%patch1 -p1
 
 install -m 0644 %{_sourcedir}/oberthur.profile oberthur-alternate.profile
 
 %build
+#Needed due to the patch 0 modifying the Makefile.am
+aclocal
+automake
+
 %configure2_5x --disable-static
 %make
 
@@ -85,6 +121,9 @@
 #don't ship .la
 find %{buildroot} -name "*.la" | xargs rm -f
 
+#%doc can not be used, so the files must be copied during the installation
+install -m 0644 COPYING NEWS README oberthur-alternate.profile %{buildroot}%{_defaultdocdir}/%{originalname}
+
 %post
 %_install_info %{name}.info
 
@@ -96,8 +135,14 @@
 
 %files
 %defattr(-,root,root)
-%doc COPYING NEWS README
-%doc oberthur-alternate.profile
+#doc can not be used, as it would copy the files in doc/opensc-opendnie
+#%doc COPYING NEWS README
+#%doc oberthur-alternate.profile
+%{_defaultdocdir}/%{originalname}
+%{_defaultdocdir}/%{originalname}/COPYING
+%{_defaultdocdir}/%{originalname}/NEWS
+%{_defaultdocdir}/%{originalname}/README
+%{_defaultdocdir}/%{originalname}/oberthur-alternate.profile
 %config(noreplace) %{_sysconfdir}/opensc.conf
 %{_bindir}/cardos-tool
 %{_bindir}/cryptoflex-tool
@@ -110,8 +155,9 @@
 %{_bindir}/pkcs15-crypt
 %{_bindir}/pkcs15-init
 %{_bindir}/pkcs15-tool
-%{_datadir}/%{name}
-%{_libdir}/pkcs11-spy.*
+%{_bindir}/dnie-tool
+%{_datadir}/%{originalname}
+#%{_libdir}/pkcs11-spy.*
 %{_libdir}/onepin-opensc-pkcs11.so
 %{_libdir}/opensc-pkcs11.so
 %{_libdir}/pkcs11-spy.so
@@ -130,6 +176,9 @@
 
 
 %changelog
+* Mon Apr 16 2012 Daniel Calviño Sánchez <danxuliu@gmail.com> 0.12.2-1bdk.mga2
+- Merged with OpenDNIe branch from https://forja.cenatic.es/frs/download.php/1262/opensc-to-opendnie-0.12.2.patch
+
 * Sat Jul 16 2011 fwang <fwang> 0.12.2-1.mga2
 + Revision: 124863
 - new version 0.12.2
@@ -141,8 +190,8 @@
 
 * Fri Apr 22 2011 ahmad <ahmad> 0.12.0-5.mga1
 + Revision: 89649
-- Move the mozilla-plugin-%%{name} Obsoletes to the lib package to ease upgrades
-- Obsolete mozilla-plugin-%%{name} (mga#698)
+- Move the mozilla-plugin-%%{originalname} Obsoletes to the lib package to ease upgrades
+- Obsolete mozilla-plugin-%%{originalname} (mga#698)
 - Stick all the libs without major in the main package (to ease major upgrades,
   not optimal, but the best idea I could come up with)
 - Move %%{_sysconfdir}/opensc.conf to the main package
@@ -296,7 +345,7 @@
 - make the mozilla plugin require mozilla-firefox, and not mozila as it was
   requiring in 1mdk. The plugin package needs a mozilla-type browser
 
-* Thu Apr 06 2006 G�tz Waschk <waschk@mandriva.org> 0.10.1-2mdk
+* Thu Apr 06 2006 Götz Waschk <waschk@mandriva.org> 0.10.1-2mdk
 - don't depend on mozilla
 
 * Thu Mar 09 2006 ANdreas Hasenack <andreas@mandriva.com> 0.10.1-1mdk
@@ -354,7 +403,7 @@
 - rebuild for ldap2.2_7
 - fix multiarch
 
-* Sat Jan 22 2005 Per �yvind Karlsen <peroyvind@linux-mandrake.com> 0.8.1-5mdk
+* Sat Jan 22 2005 Per Øyvind Karlsen <peroyvind@linux-mandrake.com> 0.8.1-5mdk
 - rebuild for new readline
 
 * Thu Dec 02 2004 Abel Cheung <deaddog@mandrake.org> 0.8.1-4mdk
