Summary: SmartCard library with support for Spanish fnmt card (%(echo $CFGDIST))
Name: libpkcs11-%(echo $CFGDIST)
Version: %(echo $CFGMAJOR).%(echo $CFGMINOR).%(echo $CFGFIX)
Release: 1%{?dist}
License: commercial
Group: System Environment/Libraries
Source: libpkcs11-%(echo $CFGDIST).tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
Requires: pcsc-lite pinentry-gtk2

%description
SmartCard library with support for %(echo $CFGDISTUPPER) card
This package contains the necessary libraries for %(echo $CFGDISTUPPER) card.
These libraries allow programs to access data, such as
cryptographic keys, on specific PKCS#15 %(echo $CFGDISTUPPER) smart card.

%prep
%define is_fnmt %(test %(echo $CFGDIST) == fnmt && echo 1 || echo 0)
%define is_dnie %(test %(echo $CFGDIST) == dnie && echo 1 || echo 0)
%define is_tif %(test %(echo $CFGDIST) == tif && echo 1 || echo 0)
%define is_fnmtdnie %(test %(echo $CFGDIST) == fnmtdnie && echo 1 || echo 0)

%setup -q

if test -f Makefile; then
  make distclean
fi
rm -rf *~ *.cache *.m4 config.guess config.log \
	config.status config.sub depcomp ltmain.sh

autoreconf --verbose --install --force

%build
%if %is_fnmt
export CFLAGS="-D_CFG_FNMT_CERES_"
export CPPFLAGS="-D_CFG_FNMT_CERES_"
%endif
%if %is_dnie 
export CFLAGS="-D_CFG_DNI_"
export CPPFLAGS="-D_CFG_DNI_"
%endif
%if %is_tif
export CFLAGS="-D_CFG_TIF_REAL_"
export CPPFLAGS="-D_CFG_TIF_REAL_"
%endif
%if %is_fnmtdnie 
export CFLAGS=""
export CPPFLAGS=""
%endif

%ifarch i386
CFLAGS="$CFLAGS %optflags -march=i486"
CXXFLAGS="%optflags -march=i486"
%endif

%configure --disable-static --with-libassuan-prefix=./libassuan_2_0_0_dist/
 
make 

%install
make install DESTDIR=$RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT/usr/share/libpkcs11-%(echo $CFGDIST)
mkdir -p $RPM_BUILD_ROOT/usr/share/libpkcs11-%(echo $CFGDIST)/instal_%(echo $CFGDIST)
mkdir -p $RPM_BUILD_ROOT/usr/share/applications

cp card-%(echo $CFGDIST)/postinst                  $RPM_BUILD_ROOT/usr/share/libpkcs11-%(echo $CFGDIST)/
cp card-%(echo $CFGDIST)/postrm                    $RPM_BUILD_ROOT/usr/share/libpkcs11-%(echo $CFGDIST)/
cp card-%(echo $CFGDIST)/message.htm               $RPM_BUILD_ROOT/usr/share/libpkcs11-%(echo $CFGDIST)/
cp card-%(echo $CFGDIST)/message.css               $RPM_BUILD_ROOT/usr/share/libpkcs11-%(echo $CFGDIST)/

cp card-%(echo $CFGDIST)/instal_%(echo $CFGDIST)/*    			$RPM_BUILD_ROOT/usr/share/libpkcs11-%(echo $CFGDIST)/instal_%(echo $CFGDIST)/.
cp card-%(echo $CFGDIST)/*.crt		                   		$RPM_BUILD_ROOT/usr/share/libpkcs11-%(echo $CFGDIST)/
cp card-%(echo $CFGDIST)/libpkcs11-%(echo $CFGDIST).desktop             $RPM_BUILD_ROOT/usr/share/applications/

find $RPM_BUILD_ROOT%{_libdir} -type f -name "*.la" | xargs rm

%clean
rm -rf $RPM_BUILD_ROOT

%post
/usr/bin/perl /usr/share/libpkcs11-%(echo $CFGDIST)/postinst



%preun
if [ "$1" = "0" ] ; then #removing
/usr/bin/perl /usr/share/libpkcs11-%(echo $CFGDIST)/postrm
fi

%files
%defattr(-,root,root,-)
%{_libdir}/lib*
/usr/share/libpkcs11-%(echo $CFGDIST)/
/usr/share/applications/libpkcs11-%(echo $CFGDIST).desktop
%exclude /usr/bin/lib*

%changelog
* Thu Aug 01 2013 FNMT <tarjetas@fnmt.es> - 1.1.0
1.1.0 New code Version.

* Mon Dec 17 2012 FNMT <tarjetas@fnmt.es> - 1.0.0
1.0.0 Initial Release.

