%define       _noVersionedDependencies        1
%define       prereq_ge()   %(LC_ALL="C" rpm -q --queryformat 'PreReq:%%{NAME} >= %%{VERSION}' %1| grep -v "is not")
%define       emacsen_pkgdir /usr/lib/emacsen-common/packages
%define       origname      psgml
%define       origver       1.2.5
%define       release       6%{?_dist_release}

Summary:      A GNU emacs major mode for editing SGML documents.
name:         %{origname}
Version:      %{origver}
Release:      %{release}
Distribution: Vine Linux
Vendor:       Project Vine
Conflicts:    %{origname}-el

PreReq:       emacsen
PreReq:       sgml-common
Requires:     emacsen
%prereq_ge emacsen-common

License: GPL
Source: ftp://ftp.lysator.liu.se/pub/sgml/%{origname}-%{version}.tar.gz
Source1: psgml-install.sh
Source2: psgml-remove.sh
Group: Applications/Editors/Emacs
BuildRoot: %{_tmppath}/%{name}-%{version}-root
BuildArch: noarch
Prefix: /usr

#%define psgmldir %{prefix}/share/emacs/site-lisp/psgml/

%description
Emacs is an advanced and extensible editor. An Emacs major mode
customizes Emacs for editing particular types of text documents. PSGML
is a major mode for SGML (a markup language) documents.  PSGML
provides several functionalities for editing SGML documents:
indentation according to element nesting depth and identification of
structural errors (but it is not a validating SGML parser); menus and
commands for inserting tags with only the contextually valid tags;
attribute values can be edited in a separate window with information
about types and defaults; structure based editing includes movement
and killing; and also several commands for folding editing.

%description -l ja
Emacs は拡張性に優れたエディターです．Emacs メジャーモードは特定の
テキスト文書を入力する時に Emacs をカスタマイズします．PSGML は
SGML (マークアップ言語)文書用のメジャーモードです．PSGML は SGML 文書を
入力ための機能を持っています。例えば，階層構造にネストしている
エレメントに従ってインデントさせたり，構造エラーを(SGML パーサで
検証しなくても)確認できます．また，文脈から正しいタグだけを挿入する
メニューやコマンド，属性値は型(type) や deaults に関する情報を別
ウィンドウで編集できます．また、movement や killing を含む編集を
ベースにした構造、編集を保持するコマンドもあります．

%prep
rm -rf ${RPM_BUILD_DIR}/%{origname}-%{origver}

%setup -q -n %{origname}-%{origver}

%build
%configure
# make sure we "find" etags in the installed place...
#cat > psgml-init.el << __ELISP__
#;(setq load-path (append load-path '("%{psgmldir}")))
#
#(autoload 'sgml-mode "psgml" "Major mode for editing SGML." t)
#(autoload 'xml-mode "psgml" "Major mode for editing XML." t)
#(if (not (getenv "SGML_CATALOG_FILES"))
#   (defvar sgml-catalog-files '("CATALOG" "catalog" "%{_sysconfdir}/sgml/catalog" "%{_libdir}/sgml/CATALOG" "%{_libdir}/sgml-tools/dtd/catalog"))
#  "*List of catalog entry files.
#The files are in the format defined in the SGML Open Draft Technical
#Resolution on Entity Management.")
#(put 'sgml-catalog-files 'sgml-type 'list)
#
#__ELISP__


%install
[ "${RPM_BUILD_ROOT}" != "/" ] && rm -rf ${RPM_BUILD_ROOT}
[ "${RPM_BUILD_ROOT}" != "/" ] && mkdir -p ${RPM_BUILD_ROOT}

mkdir -p $RPM_BUILD_ROOT%{_datadir}/emacs/site-lisp/%{origname}
#mkdir -p $RPM_BUILD_ROOT%{_libdir}/emacsen-common/packages/install
#mkdir -p $RPM_BUILD_ROOT%{_libdir}/emacsen-common/packages/remove
mkdir -p $RPM_BUILD_ROOT%{emacsen_pkgdir}/install
mkdir -p $RPM_BUILD_ROOT%{emacsen_pkgdir}/remove
mkdir -p $RPM_BUILD_ROOT%{_prefix}/lib/sgml/cdtd
mkdir -p $RPM_BUILD_ROOT%{_infodir}
#touch $RPM_BUILD_ROOT%{_infodir}/dir

#
# install el files
# 
cp -a Makefile install-sh mkinstalldirs iso88591.map install-sh \
      psgml*.el ${RPM_BUILD_ROOT}%{_datadir}/emacs/site-lisp/%{origname}

#
#  build & install info
#
make EMACS=emacs infodir=${RPM_BUILD_ROOT}%{_infodir} install-info


#
# install  script( bytecompile el and install elc , remove )   
#
%_installemacsenscript %{origname} %{SOURCE1} 

%_removeemacsenscript  %{origname} %{SOURCE2}


#
#mkdir -p ${RPM_BUILD_ROOT}%{psgmldir}
#mkdir -p ${RPM_BUILD_ROOT}%{_infodir}

#touch ${RPM_BUILD_ROOT}/usr/info/dir

#make install infodir=${RPM_BUILD_ROOT}%{_infodir} \
#  prefix=${RPM_BUILD_ROOT}%{prefix} \
#  psgmldir=${RPM_BUILD_ROOT}%{psgmldir} \
#  lispdir=${RPM_BUILD_ROOT}%{psgmldir}

#make install-info infodir=${RPM_BUILD_ROOT}%{_infodir}

#gzip ${RPM_BUILD_ROOT}/usr/info/*.info

#rm ${RPM_BUILD_ROOT}%{_infodir}/dir

#cp psgml-init.el ${RPM_BUILD_ROOT}%{prefix}/share/emacs/site-lisp/

%post
#
# bytecompile and install 
#

if [ "$1" = 2 ]; then

%_emacsenPackageRemove %{origname}

fi

%_addemacsenlist %{origname}

%_emacsenPackageInstall %{origname}

/sbin/install-info %{_infodir}/psgml.info.gz %{_infodir}/dir \
        --section="Emacs"
/sbin/install-info %{_infodir}/psgml-api.info.gz %{_infodir}/dir \
        --section="Emacs"

#SS=%{prefix}/share/emacs/site-lisp/site-start.el
## must version the load since the old postun runs *after* the new post...
#V=%{version}-%{release}
#if grep -q psgml-auto-setup-$V $SS 2>/dev/null
#then
#  :
#else
#  echo '(load "psgml-init") ;; psgml-auto-setup-'"$V" >> $SS
#fi

%preun
if [ "$1" = 0 ]; then

%_emacsenPackageRemove %{origname}

%_removeemacsenlist %{origname}

/sbin/install-info --delete %{_infodir}/psgml.info.gz %{_infodir}/dir \
        --section="Emacs"
/sbin/install-info --delete %{_infodir}/psgml-api.info.gz %{_infodir}/dir \
        --section="Emacs"

fi

%postun


#SS=%{prefix}/share/emacs/site-lisp/site-start.el
#V=%{version}-%{release}
#if [ "$1" = 0 ] ; then
#  install-info --info-dir=%{_infodir} --delete %{_infodir}/psgml.info
#  install-info --info-dir=%{_infodir} --delete %{_infodir}/psgml-api.info
#  if grep -q psgml-auto-setup-1 $SS 2>/dev/null
#  then
#    grep -v psgml-auto-setup-1 $SS > $SS.new 2>/dev/null
#    mv $SS.new $SS
#  fi
#fi
#if grep -q psgml-auto-setup-$V $SS
#then
#  grep -v psgml-auto-setup-$V $SS > $SS.new 2>/dev/null
#  mv $SS.new $SS
#fi

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

rm -rf ${RPM_BUILD_DIR}/%{origname}-%{origver}



%files
%defattr(-,root,root)
%doc psgml.ps README.psgml
%dir %{_prefix}/lib/sgml/cdtd
#%{prefix}/share/emacs/site-lisp/psgml/*
#%{prefix}/share/emacs/site-lisp/psgml-init.el
%{_infodir}/psgml*
/usr/share/emacs/site-lisp/%{origname}/
#/usr/lib/emacsen-common/packages/install/%{origname}
#/usr/lib/emacsen-common/packages/remove/%{origname}
%{emacsen_pkgdir}/install/%{origname}
%{emacsen_pkgdir}/remove/%{origname}

%changelog
* Fri Oct 10 2008 Shu KONNO <owa@bg.wakwak.com> 1.2.5-6vl5
- applied new versioning policy, spec in utf-8
- added macro %%emacsen_pkgdir

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

* Mon Mar 17 2003 IWAI Masaharu <iwai@alib.jp> 1.2.5-5vl2
- rebuild

* Sun Jul 21 2002 IWAI Masaharu <iwai@alib.jp> 1.2.5-5vl1
- upstream release

* Thu Jan  3 2002 IWAI Masaharu <iwaim@cc.mbn.or.jp> 1.2.4-5vl1
- upstream release
- eliminated Patch1 for Emacs21 (obsoleted)
- updated psgml-install.sh

* Tue Jan  1 2002 IWAI Masaharu <iwaim@cc.mbn.or.jp> 1.2.2-5vl2
- emacsenize
- package name changed psgml-el -> psgml again
- added patch for Emacs21
     ( /emacs-21.0.104.xtar.gz:emacs-21.0.104/etc/PROBLEMS )
- stopped creating psgml-init.el

* Fri Aug 31 2001 IWAI, Masaharu <iwaim@cc.mbn.or.jp>
- 1.2.2-5vl1
- upstream release
- build on Vine Seed
- use rpm macros
- package name changed psgml -> psgml-el

* Mon Feb 28 2000 MACHINO, Satoshi <mac@netfort.gr.jp>
- 1.2.1-5vl1
- build on Vine Linux 2.0β2
- added description -l ja
 
* Wed Feb 16 2000 Bill Nottingham <notting@redhat.com>
- look in old sgml-tools dirs for catalogs, to catch linuxdoc

* Thu Feb  3 2000 Bill Nottingham <notting@redhat.com>
- handle compressed man pages

* Wed Jan  5 2000 Bill Nottingham <notting@redhat.com>
- clean up spec file some

* Wed Nov 24 1999 Tim Powers <timp@redhat.com>
- came in on my day off to buld this package, feel special?
- updated to 1.2.1

* Mon Aug 30 1999 Tim Powers <timp@redhat.com>
- changed group
- changed buildroot toe be in /var/tmp
- added %defattr

* Tue Jul 21 1999 Tim Powers <timp@redhat.com>
- rebuilt for 6.1

* Fri Apr 23 1999 Michael K. Johnson <johnsonm@redhat.com>
- PATH hack to protect "make install" from install-info
- %doc path fixed
- protect postun from uninstall
- Moved $V outside of '' so that it gets interpolated

* Thu Apr 22 1999 Owen Taylor <otaylor@redhat.com>
- Upgrade to psgml-1.0.3
- Made noarch

