%define _noVersionedDependencies        1
%define prereq_ge()  %(LC_ALL="C" rpm -q --queryformat 'Requires(post):%%{NAME} >= %%{VERSION}' %1| grep -v "is not")

%define texmf           %{_datadir}/texmf
%define build_texmf     %{buildroot}%{texmf}

%define exec_texhash	[ -x %{_bindir}/texhash ] && %{_bindir}/env - %{_bindir}/texhash 2> /dev/null
%define exec_updmap	[ -x %{_bindir}/updmap-sys ] && %{_bindir}/env - %{_bindir}/updmap-sys --nostop 2> /dev/null

#% define emacs_sitelisp  %{_datadir}/emacs/site-lisp
#% define xemacs_sitelisp %{_datadir}/xemacs/site-packages/lisp

%define emacspkg asy-mode

Name:           asymptote
Version:        1.70
Release:        5%{?_dist_release}
Summary:        Descriptive vector graphics language
Summary(ja):    MetaPost に触発されたスクリプトベースのベクターグラフィック言語

Group:          Applications/Publishing
License:        GPLv3+
URL:            http://asymptote.sourceforge.net/
Source0:        http://dl.sourceforge.net/sourceforge/asymptote/asymptote-%{version}.src.tgz
Source1:	asy.gif
Source2:	xasy.desktop

Source11:	%{emacspkg}-install.sh
Source12:	%{emacspkg}-remove.sh
#Source13:	%{name}-init.el

#Patch0:         asymptote-1.29-settings.patch
Patch0:         asymptote-1.70-settings-vine.patch
Patch1:		asymptote-1.63-gcc44.patch
BuildRoot:      %{_tmppath}/%{name}-%{version}-root

BuildRequires:  ncurses-devel
BuildRequires:  readline-devel
BuildRequires:  fftw3-devel >= 3.0
BuildRequires:  gc-devel >= 6.8
BuildRequires:  gsl-devel
BuildRequires:  texlive
BuildRequires:  ghostscript
BuildRequires:  texinfo
BuildRequires:  ImageMagick
BuildRequires:  desktop-file-utils
BuildRequires:  freeglut-devel
BuildRequires:  zlib-devel

Requires:       tetex

Requires(post): desktop-file-utils
Requires(postun): desktop-file-utils

# for /usr/bin/texhash and /sbin/install-info
Requires(post): tetex, info
Requires(postun): tetex, info

%define texpkgdir   %{texmf}/tex/latex/%{name}

%description
Asymptote is a powerful descriptive vector graphics language for technical
drawings, inspired by MetaPost but with an improved C++-like syntax.
Asymptote provides for figures the same high-quality level of typesetting
that LaTeX does for scientific text.

This package is custmized for Japanese. 

%description -l ja
Asymptote は MetaPost に触発されているが，C++ のような構文に改良された，
テクニカルな図面のための強力な記述ベクターグラフィックス言語です．
Asymptote は科学的なテキストに対して LaTeX がしている組版のと
同じくらい高品質なレベルの図を提供します．

このパッケージは日本語向けにカスタマイズされています．


%package gui
Summary: A graphical interface for Asymptote
Summary(ja): Asymptote のためのグラフィカルインターフェース
Group: Applications/Graphics
Requires: %{name} = %{version}-%{release}
Requires:       tkinter
Requires:	python-imaging

%description gui
A graphical interface for Asymptote


%package -n %{emacspkg}
Summary: Emacs mode for editing Asymptote source code
Summary(ja): Asymptote ソースコードを編集するための Emacs モード
Group: Applications/Editors/Emacs
Requires: %{name} = %{version}-%{release}
BuildRequires: emacsen
%prereq_ge     emacsen-common

%description -n %{emacspkg}
Emacs mode for editing Asymptote source code


%prep
%setup -q
%patch0 -p1
%patch1 -p1 -b .gcc44
%{__sed} -i 's/\r//' doc/CAD1.asy

# convert to UTF-8
iconv -f iso-8859-1 -t utf-8 -o examples/interpolate1.asy{.utf8,}
mv examples/interpolate1.asy{.utf8,}

%build
%configure \
    --enable-gc=system \
    --with-docdir=%{_defaultdocdir}/%{name}-%{version}/ \
    --with-latex=%{texmf}/tex/latex
%__make %{?_smp_mflags}
cd doc/
%__make asymptote.pdf

%install
%__rm -rf $RPM_BUILD_ROOT
%__make install-all DESTDIR=$RPM_BUILD_ROOT

%__install -p -m 644 BUGS ChangeLog LICENSE README ReleaseNotes TODO \
    $RPM_BUILD_ROOT%{_defaultdocdir}/%{name}-%{version}/

# # Emacs mode and init files
# install -dm 755 $RPM_BUILD_ROOT%{emacs_sitelisp}/site-start.d
# cd $RPM_BUILD_ROOT%{emacs_sitelisp}
# ln -s ../../%{name}/asy-{mode,keywords}.el .
# cd $RPM_BUILD_ROOT%{emacs_sitelisp}/site-start.d
# ln -s ../../../%{name}/asy-init.el .

# # Xemacs mode and init files
# install -dm 755 $RPM_BUILD_ROOT%{xemacs_sitelisp}/site-start.d
# cd $RPM_BUILD_ROOT%{xemacs_sitelisp}
# ln -s ../../../%{name}/asy-{mode,keywords}.el .
# cd $RPM_BUILD_ROOT%{xemacs_sitelisp}/site-start.d
# ln -s ../../../../%{name}/asy-init.el .

# # Vim syntax file
# for vimver in 63 64 70 71 ; do
#     install -dm 755 $RPM_BUILD_ROOT%{_datadir}/vim/vim$vimver/syntax
#     cd $RPM_BUILD_ROOT%{_datadir}/vim/vim$vimver/syntax
#     ln -s ../../../%{name}/asy.vim .
# done

# copy icon to pixmaps dir
mkdir -p $RPM_BUILD_ROOT%{_datadir}/pixmaps/
cp %{SOURCE1} $RPM_BUILD_ROOT%{_datadir}/pixmaps/

mkdir -p $RPM_BUILD_ROOT%{_datadir}/applications
desktop-file-install --vendor "vine"                  \
        --dir $RPM_BUILD_ROOT%{_datadir}/applications   \
        %{SOURCE2}

# Clean up symlink
rm -rf $RPM_BUILD_ROOT%{_bindir}/xasy
cd $RPM_BUILD_ROOT%{_bindir}
ln -s ../share/%{name}/GUI/xasy.py xasy


## <asy-mode>
%__mkdir_p $RPM_BUILD_ROOT%{_datadir}/emacs/site-lisp/%{name}
%__mkdir_p ${RPM_BUILD_ROOT}%{_prefix}/lib/emacsen-common/packages/install
%__mkdir_p ${RPM_BUILD_ROOT}%{_prefix}/lib/emacsen-common/packages/remove

#
# install el files
#

# install -dm 755 $RPM_BUILD_ROOT%{emacs_sitelisp}/site-start.d
# cd $RPM_BUILD_ROOT%{emacs_sitelisp}
# ln -s ../../%{name}/asy-{mode,keywords}.el .
# cd $RPM_BUILD_ROOT%{emacs_sitelisp}/site-start.d
# ln -s ../../../%{name}/asy-init.el .

%__mv $RPM_BUILD_ROOT%{_datadir}/%{name}/asy-{init,mode,keywords}.el \
    $RPM_BUILD_ROOT%{_datadir}/emacs/site-lisp/%{name}/


#
# install script (bytecompile el and install elc, remove)
#

%_installemacsenscript %{name} %{SOURCE11}

%_removeemacsenscript  %{name} %{SOURCE12}

## </asy-mode>


%clean
%__rm -rf $RPM_BUILD_ROOT


%post
/sbin/install-info %{_infodir}/%{name}.info.gz %{_infodir}/dir 2>/dev/null || :
/sbin/install-info %{_infodir}/asy-faq.info.gz %{_infodir}/dir 2>/dev/null || :
%{exec_texhash}
%{exec_updmap}


%post -n %{emacspkg}
if [ "$1" = 2 ]; then

  %_emacsenPackageRemove %{name}

fi

%_addemacsenlist %{name}

%_emacsenPackageInstall %{name}
      

%postun
if [ $1 = 0 ]; then
    /sbin/install-info --delete %{name} %{_infodir}/dir 2>/dev/null || :
    /sbin/install-info --delete asy-faq %{_infodir}/dir 2>/dev/null || :
    %{exec_texhash}
    %{exec_updmap}
fi


%preun -n %{emacspkg}
if [ "$1" = 0 ]; then

  %_emacsenPackageRemove %{name}

  %_removeemacsenlist %{name}

fi


%files
%defattr(-,root,root,-)
%doc %{_defaultdocdir}/%{name}-%{version}/
%{_bindir}/asy
%{_datadir}/%{name}/
%exclude %{_datadir}/asymptote/GUI/
%{texpkgdir}/
%{_mandir}/man*/asy.*
%{_infodir}/*.info*
#%{_datadir}/vim/vim*/syntax/asy.vim
# Strictly speaking, we shouldn't own these dirs.
# However, we don't require emacs/xemacs, we just enhance them.
# Thus, its ok for dual ownership.
#%{_datadir}/emacs*
#%{_datadir}/xemacs/


%files gui
%{_bindir}/xasy
%{_datadir}/applications/vine-xasy.desktop
%{_datadir}/pixmaps/asy.gif
%{_datadir}/asymptote/GUI/
%{_mandir}/man*/xasy.*


%files -n %{emacspkg}
%defattr(-,root,root)
%{_datadir}/emacs/site-lisp/%{name}
%{_prefix}/lib/emacsen-common/packages/install/%{name}
%{_prefix}/lib/emacsen-common/packages/remove/%{name}


%changelog
* Sun Aug 08 2010 Munehiro Yamamoto <munepi@vinelinux.org> - 1.70-5
- TeX Live 2009

* Tue Feb 23 2010 Ryoichi INAGAKI <ryo1@bc.wakwak.com> - 1.70-4
- rebuilt with new toolchain, libsigsegv-2.8
- appled Patch1 again

* Tue Jun 16 2009 MATSUBAYASHI Kohji <shaolin@vinelinux.org> - 1.70-3
- don't apply Patch1 until gcc44 comes to VineSeed

* Fri May 15 2009 Munehiro Yamamoto <munepi@cg8.so-net.ne.jp> 1.70-2
- separated Xasy to gui subpackage

* Thu May 14 2009 Munehiro Yamamoto <munepi@cg8.so-net.ne.jp> 1.70-1
- initial build based on Fedora Development (fc11) package
- applied asymptote-1.70-settings-vine.patch

* Mon Apr 13 2009 Tom "spot" Callaway <tcallawa@redhat.com> - 1.70-1
- update to 1.70

* Tue Apr  7 2009 Tom "spot" Callaway <tcallawa@redhat.com> - 1.69-1
- update to 1.69

* Wed Mar 25 2009 Tom "spot" Callaway <tcallawa@redhat.com> - 1.68-1
- update to 1.68

* Thu Mar 19 2009 Tom "spot" Callaway <tcallawa@redhat.com> - 1.67-1
- update to 1.67

* Fri Feb 27 2009 Tom "spot" Callaway <tcallawa@redhat.com> - 1.66-1
- update to 1.66

* Mon Feb 23 2009 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 1.63-5
- Rebuilt for https://fedoraproject.org/wiki/Fedora_11_Mass_Rebuild

* Wed Feb 18 2009 Tom "spot" Callaway <tcallawa@redhat.com> - 1.63-4
- more gcc44 fixes with BIG_ENDIAN platforms

* Wed Feb 18 2009 Tom "spot" Callaway <tcallawa@redhat.com> - 1.63-3
- fix gcc44 issue with BIG_ENDIAN platforms

* Wed Feb 18 2009 Tom "spot" Callaway <tcallawa@redhat.com> - 1.63-2
- forgot to put in new source

* Wed Feb 18 2009 Tom "spot" Callaway <tcallawa@redhat.com> - 1.63-1
- 1.63

* Fri Jan 30 2009 Tom "spot" Callaway <tcallawa@redhat.com> - 1.60-1
- 1.60

* Mon Jan 19 2009 Tom "spot" Callaway <tcallawa@redhat.com> - 1.59-1
- 1.59

* Mon Jan 12 2009 Tom "spot" Callaway <tcallawa@redhat.com> - 1.58-1
- 1.58

* Mon Dec 15 2008 Tom "spot" Callaway <tcallawa@redhat.com> - 1.57-1
- 1.57

* Tue Dec  9 2008 Tom "spot" Callaway <tcallawa@redhat.com> - 1.56-1
- 1.56

* Tue Dec  2 2008 Tom "spot" Callaway <tcallawa@redhat.com> - 1.54-1
- 1.54

* Tue Nov 25 2008 Tom "spot" Callaway <tcallawa@redhat.com> - 1.52-1
- 1.52

* Tue Nov 11 2008 Tom "spot" Callaway <tcallawa@redhat.com> - 1.51-1
- update to 1.51

* Mon Nov  3 2008 Tom "spot" Callaway <tcallawa@redhat.com> - 1.49-1
- update to 1.49

* Sun Oct 26 2008 Tom "spot" Callaway <tcallawa@redhat.com> - 1.47-1
- update to 1.47

* Mon Oct 20 2008 Tom "spot" Callaway <tcallawa@redhat.com> - 1.46-1
- update to 1.46

* Mon Oct  6 2008 Tom "spot" Callaway <tcallawa@redhat.com> - 1.44-2
- add missing BuildRequires

* Mon Oct  6 2008 Tom "spot" Callaway <tcallawa@redhat.com> - 1.44-1
- update to 1.44

* Fri Jun 13 2008 Tom "spot" Callaway <tcallawa@redhat.com> - 1.43-1
- update to 1.43

* Fri Apr 25 2008 Tom "spot" Callaway <tcallawa@redhat.com> - 1.42-3
- explicitly call "make asymptote.pdf" in doc/

* Fri Apr  4 2008 Tom "spot" Callaway <tcallawa@redhat.com> - 1.42-2
- fix build failure (use _POSIX_ARG_MAX) resolves bz 440799

* Thu Feb 28 2008 Tom "spot" Callaway <tcallawa@redhat.com> - 1.42-1
- update to 1.42

* Wed Feb  6 2008 Tom "spot" Callaway <tcallawa@redhat.com> - 1.41-1
- update to 1.41
- enable desktop file for xasy

* Thu Jan  3 2008 Tom "spot" Callaway <tcallawa@redhat.com> - 1.37-1
- bump to 1.37
- fix gcc43 failures
- drop triggers

* Wed Aug 29 2007 Fedora Release Engineering <rel-eng at fedoraproject dot org> - sh: kpsewhich: command not found
- Rebuild for selinux ppc32 issue.

* Sun Jul 29 2007 Jose Pedro Oliveira <jpo at di.uminho.pt> - 1.33-1
- Update 1.33.

* Sat Jun 30 2007 Jose Pedro Oliveira <jpo at di.uminho.pt> - 1.32-1
- Update to 1.32.
- vim-common triggers: correction and improvements (#246131).

* Wed Jun 27 2007 Jose Pedro Oliveira <jpo at di.uminho.pt> - 1.31-1
- Update to 1.31.

* Sat Jun 16 2007 Jose Pedro Oliveira <jpo at di.uminho.pt> - 1.30-1
- Update to 1.30.

* Sat Jun 16 2007 Jose Pedro Oliveira <jpo at di.uminho.pt> - 1.29-3
- Using "evince" as the default PS and PDF viewers (#244151).
  (patch file: asymptote-1.29-settings.patch)
- Use relative symbolic links in the {emacs,xemacs}-common triggers (#155750).
- Use relative symbolic links in the vim-common triggers.

* Sat Jun  2 2007 Jose Pedro Oliveira <jpo at di.uminho.pt> - 1.29-2
- Add asy-faq to install-info (#155750).
- Add support for vim 7.1.

* Mon May 21 2007 Jose Pedro Oliveira <jpo at di.uminho.pt> - 1.29-1
- Update to 1.29.

* Tue May  8 2007 Jose Pedro Oliveira <jpo at di.uminho.pt> - 1.28-1
- Update to 1.28.

* Sat May  5 2007 Jose Pedro Oliveira <jpo at di.uminho.pt> - 1.27-1
- Update to 1.27.

* Wed Apr 25 2007 Jose Pedro Oliveira <jpo at di.uminho.pt> - 1.26-1
- Update to 1.26.

* Tue Apr 10 2007 Jose Pedro Oliveira <jpo at di.uminho.pt> - 1.25-1
- Update to 1.25.

* Sun Apr  1 2007 Jose Pedro Oliveira <jpo at di.uminho.pt> - 1.24-1
- Update to 1.24.

* Sun Mar 11 2007 Jose Pedro Oliveira <jpo at di.uminho.pt> - 1.23-1
- Update to 1.23.

* Tue Mar  6 2007 Jose Pedro Oliveira <jpo at di.uminho.pt> - 1.22-1
- Update to 1.22.

* Sat Mar  3 2007 Jose Pedro Oliveira <jpo at di.uminho.pt> - 1.21-1
- Update to 1.21.

* Fri Dec 29 2006 Jose Pedro Oliveira <jpo at di.uminho.pt> - 1.20-1
- Update to 1.20.

* Sat Dec 23 2006 Jose Pedro Oliveira <jpo at di.uminho.pt> - 1.19-1
- Update to 1.19.

* Sun Nov  5 2006 Jose Pedro Oliveira <jpo at di.uminho.pt> - 1.18-1
- Update to 1.18.

* Wed Nov  1 2006 Jose Pedro Oliveira <jpo at di.uminho.pt> - 1.17-1
- Update to 1.17.

* Wed Oct 25 2006 Jose Pedro Oliveira <jpo at di.uminho.pt> - 1.16-1
- Update to 1.16.

* Sun Oct 22 2006 Jose Pedro Oliveira <jpo at di.uminho.pt> - 1.15-1
- Update to 1.15.

* Wed Sep  6 2006 Jose Pedro Oliveira <jpo at di.uminho.pt> - 1.13-1
- Update to 1.13.

* Thu Aug  3 2006 Jose Pedro Oliveira <jpo at di.uminho.pt> - 1.12-1
- Update to 1.12.

* Thu Jul  6 2006 Jose Pedro Oliveira <jpo at di.uminho.pt> - 1.11-1
- Update to 1.11.

* Wed Jun 28 2006 Jose Pedro Oliveira <jpo at di.uminho.pt> - 1.10-1
- Update to 1.10.

* Fri Jun 23 2006 Jose Pedro Oliveira <jpo at di.uminho.pt> - 1.09-1
- Update to 1.09.

* Thu Jun 22 2006 Jose Pedro Oliveira <jpo at di.uminho.pt> - 1.08-1
- Update to 1.08.
- Also installs the info file.

* Mon May 29 2006 Jose Pedro Oliveira <jpo at di.uminho.pt> - 1.06-5
- Fedora Core 6: the texinfo package has been splitted (texinfo + texinfo-tex).

* Sat May 27 2006 Jose Pedro Oliveira <jpo at di.uminho.pt> - 1.06-4
- Group: Development/Tools -> Applications/Publishing (#193154).

* Sat May 27 2006 Jose Pedro Oliveira <jpo at di.uminho.pt> - 1.06-3
- Emacs/Xemacs init file (#193154 comment 6).

* Fri May 26 2006 Jose Pedro Oliveira <jpo at di.uminho.pt> - 1.06-2
- Directories ownership (#193154).

* Wed May 24 2006 Jose Pedro Oliveira <jpo at di.uminho.pt> - 1.06-1
- Update to 1.06.
- Using triggers to install the Vim syntax file and the Emacs/Xemacs mode file.

* Mon May 22 2006 Jose Pedro Oliveira <jpo at di.uminho.pt> - 1.05-1
- Update to 1.05.

* Sun May  7 2006 Jose Pedro Oliveira <jpo at di.uminho.pt> - 1.04-1
- Update to 1.04.

* Fri Mar 31 2006 Jose Pedro Oliveira <jpo at di.uminho.pt> - 1.03-1
- Update to 1.03.

* Thu Mar 23 2006 Jose Pedro Oliveira <jpo at di.uminho.pt> - 1.02-1
- First build.

# vim:set ai ts=4 sw=4 sts=4 et:
