%define svnrevision 950
%define templates_japanese 1
%define templates_japanese_version 20110626

%define _qt4_qmake		%{_libdir}/qt4/bin/qmake

## Summary/Description adopted from Debian with modification

Name:           texworks
Version:        0.5
Release:        1%{?svnrevision:.svn%svnrevision}%{?_dist_release}
Summary:        An environment for authoring TeX (LaTeX, ConTeXt, etc) documents
Summary(ja):    TeX ドキュメント制作のための総合環境

Group:          Applications/Editors
License:        GPLv2+
URL:            http://tug.org/texworks/
Source0:        http://texworks.googlecode.com/files/%{name}-%{version}%{?svnrevision:.svn%svnrevision}.tar.%{?svnrevision:bz2}%{!?svnrevision:gz}
#Source0:        http://texworks.googlecode.com/files/%{name}-%{version}-r858.tar.gz
# Desktop file adopted from Debian with modification
Source1:        %{name}.desktop

## vine
Source10:       texworks-snapshot.sh
%if %{templates_japanese}
Source50:       texworks-templates-japanese-%{templates_japanese_version}.tar.xz
%endif
Source100:      pdfplatex.sh
Source101:      pdfeplatex.sh

## vine
Patch100:       texworks-0.4.1-ptex-vine-vl6.patch
Patch101:       texworks-0.5.svn950-vine-vl7.patch

BuildRequires:  hunspell-devel
BuildRequires:  dbus-devel
BuildRequires:  poppler-qt4-devel
BuildRequires:  desktop-file-utils
BuildRequires:  texlive-common
Requires:       texlive-common

BuildRoot:	%{_tmppath}/%{name}-%{version}-%{release}-root

Distribution:	Vine
Vendor:		Project Vine
Packager:	munepi


%description
TeXworks is an environment for authoring TeX (LaTeX, ConTeXt, etc) documents, 
with a Unicode-based, TeX-aware editor, integrated PDF viewer, and a clean, 
simple interface accessible to casual and non-technical users.

You may install the texlive-* packages to make this program useful.

%description -l ja
TeXworks は TeX (LaTeX, ConTeXt, etc) ドキュメント制作のための総合環境です。
ユニコードベースで編集する TeX に特化したエディタに、
PDF プレビュアーが統合されており、不慣れな非技術系のユーザへの
簡潔で操作しやすいインタフェースを備えています。

TeXworks を利用するためには、TeX 環境が必要です。


%prep
%setup -q

%if %{?_dist_release} == "vl6"
%patch100 -p1 -b .vine
%endif
%if %{?_dist_release} == "vl7"
%patch101 -p1 -b .vine
%endif

## added some Japanese templates
%if %{templates_japanese}
%__tar xf %{SOURCE50}
%__cp -ra "texworks-templates-japanese-%{templates_japanese_version}/Japanese documents" res/resfiles/templates/ || exit 1
patch -p1 -b -z .vine < texworks-templates-japanese-%{templates_japanese_version}/texworks-0.4.1-templates-japanese.patch || exit 1
%endif

%build
%_qt4_qmake INSTALL_PREFIX=%{_prefix} DOCS_DIR=%{_docdir}/%{name}-%{version}
%__make %{?_smp_mflags}


%install
%__rm -rf %{buildroot}
%__make install INSTALL_ROOT=%{buildroot}

## support platex/eplatex via dvipdfmx
## [ ]: TeX distribution and its version, ( ): typesetting engine
## vl5 [teTeX-3.0]:     platex (ptex) 
## vl6 [TeX Live 2009]: platex (ptex), eplatex (eptex)
## vl7 [TeX Live 2011]: platex (eptex)
%__install -m755 -D %{SOURCE100} %{buildroot}%{_bindir}/pdfplatex
%if %{?_dist_release} == "vl6"
%__install -m755 -D %{SOURCE101} %{buildroot}%{_bindir}/pdfeplatex
%endif


%clean
%__rm -rf %{buildroot}

%post
update-desktop-database &> /dev/null || :

%postun
update-desktop-database &> /dev/null || :

%files
%defattr(-,root,root,-)
%{_docdir}/%{name}-%{version}/
%{_bindir}/%{name}
%{_bindir}/pdfplatex
%if %{?_dist_release} == "vl6"
%{_bindir}/pdfeplatex
%endif
%{_datadir}/applications/%{name}.desktop
%{_datadir}/pixmaps/*
# %dir %{_datadir}/texworks-help
# %{_datadir}/texworks-help/*
%{_mandir}/man1/texworks.1.gz

%changelog
* Sun Dec  4 2011 Munehiro Yamamoto <munepi@vinelinux.org> 0.5-1.svn950
- source snapshot r950
- updated pdfplatex.sh
  - support SyncTeX
- TeX Live 2011

* Fri Jul 01 2011 Munehiro Yamamoto <munepi@vinelinux.org> 0.4.3-1
- new upstream release
- added BuildRequires: texlive-common
- added Requires: texlive-common

* Sat Jun 25 2011 Munehiro Yamamoto <munepi@vinelinux.org> 0.4.1-2
- added some Japanese templates

* Sat Jun 18 2011 Munehiro Yamamoto <munepi@vinelinux.org> 0.4.1-1
- new upstream release

* Wed Mar 30 2011 Munehiro Yamamoto <munepi@vinelinux.org> 0.4.0-1
- new upstream release

* Fri Dec 17 2010 Munehiro Yamamoto <munepi@vinelinux.org> 0.3-1.svn724
- source snapshot r724

* Sat Oct 02 2010 Munehiro Yamamoto <munepi@vinelinux.org> 0.3-1.svn671
- source snapshot r671
  - dropped obsolete/upstreamed patches
- added texworks-snapshot.sh

* Sat Aug 07 2010 Munehiro Yamamoto <munepi@vinelinux.org> 0.2.3-1
- initial build

* Sat Apr 24 2010 Robin Lee <robinlee.sysu@gmail.com> - 0.2.3-3
- Move to menu category 'Office'
- License tag revised to 'GPLv2+'
- Initial import to Fedora repositories

* Thu Apr 22 2010 Robin Lee <robinlee.sysu@gmail.com> - 0.2.3-2
- Fix some strange characters in README
- Patch TeXworks.pro to use qmake mechanism to install files and fix DSO linking
  problem

* Sun Apr 11 2010 Robin Lee <robinlee.sysu@gmail.com> - 0.2.3-1
- Initial packaging
