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

%define origname        auctex
%define emacspkg        preview-latex

%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


Summary:	Enhanced TeX modes for Emacsen
Name:		%{origname}
Version:	11.86
Release:	3%{?_dist_release}
Group: 		Applications/Editors/Emacs
License:	GPLv3+
URL:		http://www.gnu.org/software/auctex/
Source: 	http://ftp.gnu.org/pub/gnu/auctex/auctex-%{version}.tar.gz
Source1:       	%{origname}-install.sh
Source2:       	%{origname}-remove.sh
Source3:       	%{origname}-init.el
Source4:       	vine-default-%{origname}.el

Source5:       	%{emacspkg}-install.sh
Source6:       	%{emacspkg}-remove.sh
Source7:       	%{emacspkg}-init.el
Source8:       	vine-default-%{emacspkg}.el

Patch: 		auctex-11.85-vine.patch

Requires:       %{emacspkg} = %{version}-%{release}
BuildRequires:  texinfo
%if %{?_dist_release} == "vl5"
BuildRequires:  tetex
%else
BuildRequires:  texlive
%endif
## Note: "BR: emacs >= 23.1" need to build auctex
BuildRequires:  emacs >= 23.1

%prereq_ge      emacsen emacsen-common
Requires(post): /sbin/install-info

Obsoletes:	auctex-emacs auctex-xemacs

BuildArch:      noarch
BuildRoot:	%{_tmppath}/%{name}-%{version}-root

Vendor:         Project Vine
Distribution:   Vine Linux
Packager:	munepi


%description
AUCTeX is an extensible package that supports writing and formatting TeX files
for most variants of Emacs.  

AUCTeX supports many different TeX macro packages, including AMS-TeX, LaTeX,
Texinfo and basic support for ConTeXt.  Documentation can be found under
/usr/share/doc, e.g. the reference card (tex-ref.pdf) and the FAQ.  The AUCTeX
manual is available in Emacs info (C-h i d m AUCTeX RET).  On the AUCTeX home
page, we provide manuals in various formats.

This version of AUCTeX comes with preview-latex, an addictive productivity
tool providing a fine-grained interactive folding WYSIWYG display in the
source buffer. 

If you are AUCTeX user and you install both yatex and auctex on your system, 
you may add the following configure in your emacs init file 
%if %{?_dist_release} == "vl5"
~/.emacs.el: 
%else
~/.emacs.d/emacsXX-vine-default.el (XX: emacs major version): 
%endif

;; I am AUCTeX user!!!
(setq vine-default-yatex nil)


%package -n %{emacspkg}
Summary:        Emacs/LaTeX inline preview
Group:          Applications/Editors/Emacs
Requires(post):       %{origname} = %{version}-%{release}
BuildRequires:  emacsen
%prereq_ge      emacsen-common

%description -n %{emacspkg}
AUCTeX is an extensible package that supports writing and formatting TeX files
for most variants of Emacs.  

AUCTeX supports many different TeX macro packages, including AMS-TeX, LaTeX,
Texinfo and basic support for ConTeXt.  Documentation can be found under
/usr/share/doc, e.g. the reference card (tex-ref.pdf) and the FAQ.  The AUCTeX
manual is available in Emacs info (C-h i d m AUCTeX RET).  On the AUCTeX home
page, we provide manuals in various formats.

This version of AUCTeX comes with preview-latex, an addictive productivity
tool providing a fine-grained interactive folding WYSIWYG display in the
source buffer.

Does your neck hurt from turning between previewer windows and the
source too often? This Elisp/LaTeX package will render your displayed
LaTeX equations right into the editing window where they belong. 


%prep
%setup -q -n %{origname}-%{version}
%patch -p1 -b .vine

%build
%configure --with-emacs INSTALL_INFO=: --without-texmf-dir
%__make

## output auctex.el
%__cp -a auctex.el auctex.el.vine
cat>auctex.el<<EOF
;;; auctex.el
;;
;; This can be used for starting up AUCTeX.  The following somewhat
;; strange trick causes tex-site.el to be loaded in a way that can be
;; safely undone using (unload-feature 'tex-site).
;;
;; (autoload 'TeX-load-hack
;;   "/some/where/tex-site.el")
;; (TeX-load-hack)

;; 
;; No any settings provide in this file. 
;; 
EOF

## remove all *.elc
find . -type f -name "*.elc" -exec rm -f {} ';'


%install

[ "${RPM_BUILD_ROOT}" != "/" ] && rm -rf ${RPM_BUILD_ROOT}

## install preview package
pushd preview
%__make install-texmf \
    previewtexmfdir=%{build_texmf}/tex/latex/preview \
    previewdocdir=%{build_texmf}/doc/latex/preview
%__rm -f %{build_texmf}/doc/latex/preview/preview.dvi
%__install -p -m0644 latex/preview.pdf %{build_texmf}/doc/latex/preview/
popd


%__mkdir_p ${RPM_BUILD_ROOT}%{_datadir}/emacs/site-lisp/%{name}
%__mkdir_p ${RPM_BUILD_ROOT}%{_datadir}/emacs/site-lisp/%{emacspkg}
%__mkdir_p $RPM_BUILD_ROOT/%{emacsen_pkgdir}/install
%__mkdir_p $RPM_BUILD_ROOT/%{emacsen_pkgdir}/remove
%__mkdir_p ${RPM_BUILD_ROOT}%{_infodir}


#
# install el files
#

## <auctex>
%__install -p -m0644 *.el \
    ${RPM_BUILD_ROOT}/%{_datadir}/emacs/site-lisp/%{name}/
%__cp -ra images style \
    ${RPM_BUILD_ROOT}%{_datadir}/emacs/site-lisp/%{name}/

%__install -p -m0644 %{SOURCE3} %{SOURCE4} \
    ${RPM_BUILD_ROOT}/%{_datadir}/emacs/site-lisp/%{name}/
## </auctex>

## <preview-latex>
pushd preview
%__install -p -m0644 *.el \
    ${RPM_BUILD_ROOT}/%{_datadir}/emacs/site-lisp/%{emacspkg}/
%__cp -ra images \
    ${RPM_BUILD_ROOT}/%{_datadir}/emacs/site-lisp/%{emacspkg}/
popd

%__install -p -m0644 %{SOURCE7} %{SOURCE8} \
    ${RPM_BUILD_ROOT}/%{_datadir}/emacs/site-lisp/%{emacspkg}/
## </preview-latex>


#
# install info files
#

%__install -p -m 0644 doc/%{origname}.info doc/%{emacspkg}.info \
    ${RPM_BUILD_ROOT}%{_infodir}/


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

%_installemacsenscript %{origname} %{SOURCE1} 

%_removeemacsenscript  %{origname} %{SOURCE2}

%_installemacsenscript %{emacspkg} %{SOURCE5} 

%_removeemacsenscript  %{emacspkg} %{SOURCE6}


%clean 
[ "${RPM_BUILD_ROOT}" != "/" ] && %__rm -rf ${RPM_BUILD_ROOT}


%post
#
# bytecompile and install
#

if [ "$1" = 2 ]; then

%_emacsenPackageRemove %{origname}

fi

%_addemacsenlist %{origname}

%_emacsenPackageInstall %{origname}

/sbin/install-info %{_infodir}/%{origname}.info.gz %{_infodir}/dir \
  --section="A much enhanced LaTeX mode for GNU Emacs"


%post -n %{emacspkg}
#
# bytecompile and install
#

if [ "$1" = 2 ]; then

    %_emacsenPackageRemove %{emacspkg}

fi

%_addemacsenlist %{emacspkg}

%_emacsenPackageInstall %{emacspkg}

/sbin/install-info \
    %{_infodir}/%{emacspkg}.info.gz %{_infodir}/dir \
    --section="A much enhanced LaTeX mode for GNU Emacs"


%preun
if [ "$1" = 0 ]; then
    %_emacsenPackageRemove %{origname}

    %_removeemacsenlist %{origname}

    /sbin/install-info --delete \
	%{_infodir}/%{origname}.info.gz %{_infodir}/dir \
	--section="A much enhanced LaTeX mode for GNU Emacs"
fi


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

    %_emacsenPackageRemove %{emacspkg}

    %_removeemacsenlist %{emacspkg}

    /sbin/install-info --delete \
	%{_infodir}/preview-latex.info.gz %{_infodir}/dir \
	--section="A much enhanced LaTeX mode for GNU Emacs"
fi


%files
%defattr(-,root,root)
%doc CHANGES COPYING ChangeLog FAQ INSTALL README RELEASE TODO doc/*.{tex,pdf}
%{_infodir}/%{origname}*
%{_datadir}/emacs/site-lisp/%{origname}/
%{emacsen_pkgdir}/install/%{origname}
%{emacsen_pkgdir}/remove/%{origname}


%files -n %{emacspkg}
%defattr(-,root,root)
%doc preview/COPYING preview/ChangeLog{,.1}
%{_infodir}/%{emacspkg}*
%{texmf}/doc/latex/preview/preview.pdf
%{texmf}/tex/latex/preview/*
%{_datadir}/emacs/site-lisp/%{emacspkg}/
%{emacsen_pkgdir}/install/%{emacspkg}
%{emacsen_pkgdir}/remove/%{emacspkg}



%changelog
* Tue Feb 22 2011 Munehiro Yamamoto <munepi@vinelinux.org> 11.86-3
- updated auctex-init.el and preview-latex-init.el
  - output "Loading vine-default-xxxxx ..." to the buffer *Messages*

* Mon Jan 03 2011 Munehiro Yamamoto <munepi@vinelinux.org> 11.86-2
- fixed requirements
  - set BuildRequires: emacs >= 23.1
  - set BuildRequires: texlive (for vl6)

* Sun Mar 28 2010 Munehiro Yamamoto <munepi@vinelinux.org> 11.86-1
- new versioning release

* Sun Sep 13 2009 Munehiro Yamamoto <munepi@vinelinux.org> 11.85-1
- new versioning release
- dropped old version patches
- changed to GPLv3+ in License tag
- changed to http://www.gnu.org/software/auctex/ in URL tag
- download from http://ftp.gnu.org/pub/gnu/auctex in Source0
- added preview-latex package
- setup vine-default

* Sun Sep 14 2008 Shu KONNO <owa@bg.wakwak.com> 11.13-1vl5
- applied new versioning policy, spec in utf-8
- added macro %%emacsen_pkgdir

* Tue Sep 12 2006 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 11.13-0vl2
- changed Group to Appliations/Editors/Emacs <BTS:VineLinux:163>
- s/Copyright/License/

* Wed Dec 25 2002 Jun Nishii <jun@vinelinux.org> 11.13-0vl1
- ver.up

* Mon Apr 22 2002 Jun Nishii <jun@vinelinux.org> 10.0g-0vl3
- minor fix of tex-jp.el

* Wed Mar  6 2002 Jun Nishii <jun@vinelinux.org> 10.0g-0vl2
- emasenize

* Tue Apr 24 2001 Jun Nishii <jun@vinelinux.org>
- 10.0g-0vl1

* Thu Sep 21 2000 Jun Nishii <jun@vinelinux.org>
- 9.10p-0vl2
- minor modification of spec file

* Fri Jan 14 2000 Jun Nishii <jun@vinelinux.org>
- 9.10p-0vl1
- change directories
- minor customization

* Wed Dec 22 1999 Jun Nishii <jun@vinelinux.org>
- 9.10p

* Thu Dec 16 1999 Jun Nishii <jun@vinelinux.org>
- build auctex for emacs

* Fri Feb 19 1999 Jun Nishii <jun@vinelinux.org>
- updated to 9.9p

* Sat Nov 14 1998 Jun Nishii <jun@vinelinux.org>
- first release for 9.8l

