%define build_compat32 %{?_with_compat32:1}%{!?_with_compat32:0}
%define _unpackaged_files_terminate_build 1

%define freetype_version 2.10.1

Summary: Font configuration and customization library
Summary(ja): フォント設定/カスタマイズライブラリ
Name: fontconfig
Version: 2.13.1
Release: 1%{?_dist_release}
Group: System Environment/Libraries
Vendor: Project Vine
Distribution: Vine Linux

License: MIT
URL: https://fontconfig.org/
Source: https://fontconfig.org/release/fontconfig-%{version}.tar.bz2
Source10: 70-prefer-ja-font.conf
Source11: 59-morisawa-font-alias.conf
Source100: ChangeLog.fedora

# from fedora
# https://bugzilla.redhat.com/show_bug.cgi?id=140335
Patch0:         fontconfig-2.8.0-sleep-less.patch

# vine
Patch4: fontconfig-2.3.2-subst-ja-font.patch
Patch10: fontconfig-2.13.1-vine.patch


BuildRoot: %{_tmppath}/%{name}-%{version}-root
BuildRequires: gawk
BuildRequires: expat-devel
BuildRequires: freetype2-devel >= %{freetype_version}
BuildRequires: perl
#BuildRequires: itstool
BuildRequires: libuuid-devel
BuildRequires: gperf

Requires(pre): freetype2 >= %{freetype_version}, coreutils
Conflicts: XOrg-libs <= 6.9.0
Obsoletes: XOrg-libs <= 6.9.0
Conflicts: XOrg-font-utils <= 6.9.0
Obsoletes: XOrg-font-utils <= 6.9.0

%description
Fontconfig is designed to locate fonts within the
system and select them according to requirements specified by 
applications.

%description -l ja
Fontconfig は、システム内のフォントを把握し、アプリケーション
が指定した要求に応じてそれらを選択するためのライブラリです。

%package devel
Summary: Development files for %{name}
Summary(ja): Fontconfig の開発ファイル
Group: Development/Libraries
Requires: fontconfig = %{version}-%{release}
Requires: freetype2-devel >= %{freetype_version}
Requires: expat-devel
Requires: pkgconfig
Conflicts: XOrg-devel <= 6.9.0
Obsoletes: XOrg-devel <= 6.9.0

%description devel
The fontconfig-devel package includes the header files,
and developer docs for the fontconfig package.

%description -l ja devel
fontconfig-devel パッケージには fontconfig を使ったソフトウエア
を開発するために必要なヘッダファイルやライブラリ、開発用ドキュメ
ントが含まれています。

# compat32
%package -n compat32-%{name}
Summary: Font configuration and customization library
Summary(ja): フォント設定/カスタマイズライブラリ
Group: System Environment/Libraries

%description -n compat32-%{name}
Fontconfig is designed to locate fonts within the
system and select them according to requirements specified by 
applications.

%description -l ja -n compat32-%{name}
Fontconfig は、システム内のフォントを把握し、アプリケーション
が指定した要求に応じてそれらを選択するためのライブラリです。

%package -n compat32-%{name}-devel
Summary: Font configuration and customization library
Group: Development/Libraries
Requires: compat32-%{name} = %{version}-%{release}
Requires: %{name}-devel = %{version}-%{release}
Requires: compat32-freetype2-devel >= %{freetype_version}
Requires: compat32-expat-devel

%description -n compat32-%{name}-devel
The fontconfig-devel package includes the header files,
and developer docs for the fontconfig package.

%description -l ja -n compat32-%{name}-devel
fontconfig-devel パッケージには fontconfig を使ったソフトウエア
を開発するために必要なヘッダファイルやライブラリ、開発用ドキュメ
ントが含まれています。

%prep
%setup -q

%patch0 -p1 -b .sleep-less

#patch4 -p1 -b .subst-ja-font
%patch10 -p1 -b .vine

%build

# We don't want to rebuild the docs, but we want to install the included ones.
export HASDOCBOOK=no

%configure \
  --with-add-fonts=/usr/share/X11/fonts/Type1,/usr/share/X11/fonts/TTF,/usr/local/share/fonts

%__make %{?_smp_mflags}

%install
rm -rf $RPM_BUILD_ROOT

%__make install DESTDIR=$RPM_BUILD_ROOT

ln -s %{_datadir}/fontconfig/conf.avail/25-unhint-nonlatin.conf $RPM_BUILD_ROOT%{_sysconfdir}/fonts/conf.d
install -m664 %{SOURCE10} %{SOURCE11} $RPM_BUILD_ROOT/%{_datadir}/fontconfig/conf.avail/
for i in 70-prefer-ja-font.conf 59-morisawa-font-alias.conf
do
  ln -sf %{_datadir}/fontconfig/conf.avail/$i $RPM_BUILD_ROOT/%{_sysconfdir}/fonts/conf.d/
done

# move installed doc files back to build directory to package themm
# in the right place
mv $RPM_BUILD_ROOT%{_docdir}/fontconfig/* .
rmdir $RPM_BUILD_ROOT%{_docdir}/fontconfig/

# All font packages depend on this package, so we create
# and own /usr/share/fonts
mkdir -p $RPM_BUILD_ROOT%{_datadir}/fonts

# Remove unpackaged files
find $RPM_BUILD_ROOT -name '*.la' -exec rm -f {} \;
find $RPM_BUILD_ROOT -name '*.a' -exec rm -f {} \;

# remove locales (zh only)
rm -rf %{buildroot}%{_datadir}/locale

%clean
rm -rf $RPM_BUILD_ROOT

%post
/sbin/ldconfig
umask 0022
# Remove stale caches
rm -f %{_localstatedir}/cache/fontconfig/????????????????????????????????-*.cache-2
HOME=/root /usr/bin/fc-cache -f -s >& /dev/null


%postun -p /sbin/ldconfig

%post -n compat32-%{name} -p /sbin/ldconfig

%postun -n compat32-%{name} -p /sbin/ldconfig

%files
%defattr(-, root, root)
%license COPYING 
%doc README AUTHORS
%doc fontconfig-user.txt fontconfig-user.html
%doc %{_sysconfdir}/fonts/conf.d/README
%{_libdir}/libfontconfig.so.*
%{_bindir}/fc-cache
%{_bindir}/fc-conflist
%{_bindir}/fc-list
%{_bindir}/fc-match
%{_bindir}/fc-cat
%{_bindir}/fc-query
%{_bindir}/fc-scan
%{_bindir}/fc-pattern
%{_bindir}/fc-validate
%dir %{_datadir}/fonts
%{_datadir}/%{name}
%{_datadir}/xml/%{name}/fonts.dtd
%config %{_sysconfdir}/fonts/fonts.conf
%config(noreplace) %{_sysconfdir}/fonts/conf.d/*.conf
%dir %{_localstatedir}/cache/fontconfig

%{_mandir}/man1/*
%{_mandir}/man5/*

%files devel
%defattr(-, root, root)
%doc fontconfig-devel.txt fontconfig-devel
%{_libdir}/libfontconfig.so
%dir %{_datadir}/gettext
%dir %{_datadir}/gettext/its
%{_datadir}/gettext/its/*
%{_libdir}/pkgconfig/*
%{_includedir}/fontconfig
%{_mandir}/man3/*

# compat32
%if %{build_compat32}
%files -n compat32-%{name}
%defattr(-, root, root)
%{_libdir}/libfontconfig.so.*

%files -n compat32-%{name}-devel
%defattr(-, root, root)
%{_libdir}/libfontconfig.so
%endif

%changelog
* Fri Apr 10 2020 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 2.13.1-1
- new upstream release.
- disabled Patch4.
- updated Patch10.
- truncated %%changelog: old logs are ChangeLog.fedora.

* Fri Jan 05 2018 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 2.12.6-1
- new upstream release.
- added BR:gperf.

* Fri Mar 28 2014 Yoji TOYODA <bsyamato@sea.plala.or.jp> 2.11.1-1
- new upstream release

* Mon Dec 30 2013 Yoji TOYODA <bsyamato@sea.plala.or.jp> 2.11.0-1
- new upstream release
- remove Patch1,2

* Tue May 07 2013 Daisuke SUZUKI <daisuke@linux.or.jp> 2.10.92-2
- install/enable 70-prefer-ja-font.conf and 59-morisawa-font-alias.conf (again)
- enable 25-unhint-nonlatin.conf (again)
- add patch0-2 from fedora package
  - patch0: less sleep in fc-cache
  - patch1: fix font matching issue
  - patch2: fix web font issue in firefox

* Wed Apr 17 2013 Yoji TOYODA <bsyamato@sea.plala.or.jp> 2.10.92-1
- new upstream release
- remove Patch1 (fontconfig-2.2.1-AppleRoman-DynaFont.patch)

* Fri Dec 24 2010 Yoji TOYODA <bsyamato@sea.plala.or.jp> 2.8.0-3
- rebuild with freetype2-2.4.8
- add Requires: expat-devel (-devel package)

* Tue Sep 21 2010 IWAI, Masaharu <iwai@alib.jp> 2.8.0-2
- build with rpm-4.8.1-1 for pkg-config file

* Fri Jan 08 2010 Daisuke SUZUKI <daisuke@linux.or.jp> 2.8.0-1
- new upstream release
- remove static libs

* Sun Aug 16 2009 Daisuke SUZUKI <daisuke@linux.or.jp> 2.7.1-3
- update %%post

* Thu Aug 06 2009 Daisuke SUZUKI <daisuke@linux.or.jp> 2.7.1-2
- add translated summary and description

* Wed Aug 05 2009 Daisuke SUZUKI <daisuke@linux.or.jp> 2.7.1-1
- new upstream release

* Mon Jul 20 2009 Daisuke SUZUKI <daisuke@linux.or.jp> 2.7.0-2
- add fc-query and fc-scan to %%files

* Mon Jul 20 2009 Daisuke SUZUKI <daisuke@linux.or.jp> 2.7.0-1
- new upstream release
- update 59-morisawa-font-alias.conf

* Sun May 03 2009 NAKAMURA Kenta <kenta@vinelinux.org> 2.6.0-3
- added compat32 package for x86_64 arch support

* Tue Jan 06 2009 Daisuke SUZUKI <daisuke@linux.or.jp> 2.6.0-2
- update 59-morisawa-font-alias.conf
  - add FutoMin, FutoGo, Jun alias

* Thu Jun 12 2008 Daisuke SUZUKI <daisuke@linux.or.jp> 2.6.0-1
- new upstream release
- rename 10-prefer-ja-font.conf to 70-prefer-ja-font.conf

* Thu May 29 2008 Daisuke SUZUKI <daisuke@linux.or.jp> 2.5.0-3
- add 10-prefer-ja-font.conf to prefer Japanese fonts.
- add 59-morisawa-font-alias.conf
  - bind Ryumin to serif and GothicBBB to sans-serif

* Mon May 12 2008 Daisuke SUZUKI <daisuke@linux.or.jp> 2.5.0-2
- add legacy font path for compatibility

* Thu Apr 17 2008 Daisuke SUZUKI <daisuke@linux.or.jp> 2.5.0-1
- add Conflits/Obsoletes: XOrg-font-utils <= 6.9.0

* Mon Dec 10 2007 Daisuke SUZUKI <daisuke@linux.or.jp> 2.5.0-0vl1
- initial build for Vine Linux
  - splitted from XOrg package.
