%define version 5.1.22
%define name grace
# relative do datadir
%define type1fontdir fonts/default/Type1

Summary: Numerical Data Processing and Visualization Tool (grace)
Summary(ja): 数値データの処理および可視化を行うツール

Name: %{name}
Version: %{version}
Release: 1%{?_dist_release}
Group: Applications/Engineering
License: GPLv2+
URL: http://plasma-gate.weizmann.ac.il/Grace/
Source0: ftp://plasma-gate.weizmann.ac.il/pub/grace/src/%{name}-%{version}.tar.gz
Source1: %{name}.desktop
Source2: %{name}.png

#Icon: %{name}.gif
#Requires: pdflib, openMotif
#BuildPrereq: pdflib-devel, 
Buildroot: %{_tmppath}/%{name}-%{version}-root
BuildRequires: libjpeg-devel libpng-devel netcdf-devel
BuildRequires: fftw-devel gcc-gfortran
BuildRequires: openMotif-devel t1lib-devel
BuildRequires: libXmu-devel libXpm-devel
BuildRequires: desktop-file-utils
# to be able to generate FontDataBase
BuildRequires: urw-fonts

Requires: xdg-utils
# /usr/share/fonts/default/Type1/
Requires: urw-fonts
Requires(post): gtk2
Requires(postun): gtk2

Obsoletes: xmgr


%description
Grace is a Motif application for two-dimensional data visualization.
Grace can transform the data using free equations, FFT, cross- and
auto-correlation, differences, integrals, histograms, and much more. The
generated figures are of high quality.  Grace is a very convenient tool
for data inspection, data transformation, and and for making figures for
publications.

%description -l ja
Grace は 2次元データを可視化するMotif アプリケーションです.昔 xmgr と呼ば
れていたツールの子孫にあたります。利用には openMotif が必要です。

Grace では,FFT, 相互相関,自己相関,微分,積分,ヒストグラムその他,自由に
方程式を用いてデータを変換することができます.高品質の図の作成も行えます.
Grace はデータの解析や変換,出版向けの図の作成に大変便利です.

%prep
%setup -q 

%build
%configure \
    --enable-editres \
    --with-helpviewer="xdg-open %s" \
    --with-printcmd="lpr" \
    --enable-grace-home=%{_datadir}/%{name} \
    --disable-pdfdrv \
    --with-x \
    --with-f77=gfortran \
    --with-extra-incpath=%{_includedir}/netcdf \

make %{?_smp_mflags}

%install
rm -rf $RPM_BUILD_ROOT
make install DESTDIR=$RPM_BUILD_ROOT

#rm -f doc/*.1

mkdir -pm 755                               \
    $RPM_BUILD_ROOT%{_bindir}               \
    $RPM_BUILD_ROOT%{_includedir}           \
    $RPM_BUILD_ROOT%{_libdir}               \
    $RPM_BUILD_ROOT%{_datadir}/icons/hicolor/48x48/apps \
    $RPM_BUILD_ROOT%{_datadir}/applications  \
    $RPM_BUILD_ROOT%{_mandir}/man1           \
    $RPM_BUILD_ROOT%{_sysconfdir}/%{name}

##
# Let's have some sanity
#
pushd %{buildroot}%{_datadir}/%{name}
install -pm 755 bin/*   %{buildroot}%{_bindir}/
rm -rf bin
#ln -s %{_bindir} bin
ln -s ../../bin bin
cp -p lib/*   %{buildroot}%{_libdir}/
rm -rf lib
#ln -s %{_libdir} lib
ln -s ../../%_lib lib
install -pm 644 include/* %{buildroot}%{_includedir}/
rm -rf include
#ln -s %{_includedir} include
ln -s ../../include include
# use fonts from type1fontdir
rm -rf fonts/type1
ln -s ../../%{type1fontdir} fonts/type1
mv fonts/FontDataBase %{buildroot}%{_sysconfdir}/%{name}
#ln -s %{_sysconfdir}/%{name}/FontDataBase fonts/FontDataBase
ln -s ../../../../%{_sysconfdir}/%{name}/FontDataBase fonts/FontDataBase

# regenerate %{_sysconfdir}/%{name}/FontDataBase based on what is in
# type1fontdir and original FontDataBase content
FontDataBaseFile=%{buildroot}%{_sysconfdir}/%{name}/FontDataBase
rm -f $FontDataBaseFile.tmp
for file in %{_datadir}/%{type1fontdir}/*.pfb; do
  base=`basename $file .pfb`
  alias=
  if grep -qs $base $FontDataBaseFile; then
    # keep original aliases if the exist
    grep $base $FontDataBaseFile >> $FontDataBaseFile.tmp
  else
    # no original alias case. Use FullName from afm file and change space to -
    if [ -f %{_datadir}/%{type1fontdir}/$base.afm ]; then
      alias=`grep '^FullName' %{_datadir}/%{type1fontdir}/$base.afm | sed 's/^FullName *//' | sed 's/ *$//' | sed 's/ /-/g'`
    fi
    [ "z$alias" = 'z' ] && alias=$base
    echo "$alias $alias $base.pfb" >> $FontDataBaseFile.tmp
  fi
done
fontcount=`wc -l $FontDataBaseFile.tmp`
echo $fontcount | sed 's:%{buildroot}.*::' > $FontDataBaseFile
cat $FontDataBaseFile.tmp >> $FontDataBaseFile
rm $FontDataBaseFile.tmp

install -pm 644 doc/*.1 %{buildroot}%{_mandir}/man1/
# doc and example directories are removed from GRACE_HOME and put in %doc
rm -rf doc
#ln -s %{_docdir}/%{name}-%{version}/doc doc
ln -s ../doc/%{name}-%{version}/doc doc
rm -rf examples
#ln -s %{_docdir}/%{name}-%{version}/examples examples
ln -s ../doc/%{name}-%{version}/examples examples
# the convcal source file shouldn't be installed, it is removed here
rm -f auxiliary/convcal.c
# move config files to %{_sysconfdir} and do symlinks
for conf in gracerc templates gracerc.user; do
    mv $conf %{buildroot}%{_sysconfdir}/%{name}
    #ln -s %{_sysconfdir}/%{name}/$conf $conf
    ln -s ../../../%{_sysconfdir}/%{name}/$conf $conf
done
popd

##
# Desktop stuff
#
install -pm 644 %{SOURCE2} %{buildroot}%{_datadir}/icons/hicolor/48x48/apps/%{name}.png
desktop-file-install \
    --dir %{buildroot}%{_datadir}/applications          \
    %{SOURCE1}

# clean up docs
rm -rf __dist_doc
mkdir __dist_doc
cp -a doc __dist_doc
rm __dist_doc/doc/Makefile __dist_doc/doc/*.sgml

%clean
rm -rf $RPM_BUILD_ROOT

%post
touch --no-create %{_datadir}/icons/hicolor || :
if [ -x %{_bindir}/gtk-update-icon-cache ]; then
   %{_bindir}/gtk-update-icon-cache --quiet %{_datadir}/icons/hicolor || :
fi

%postun
touch --no-create %{_datadir}/icons/hicolor || :
if [ -x %{_bindir}/gtk-update-icon-cache ]; then
   %{_bindir}/gtk-update-icon-cache --quiet %{_datadir}/icons/hicolor || :
fi


%files
%defattr(-,root,root)
%doc ChangeLog CHANGES COPYRIGHT DEVELOPERS LICENSE README
%doc examples/ __dist_doc/doc/
%config(noreplace) %{_sysconfdir}/%{name}/
%{_bindir}/*
%{_datadir}/%{name}
%{_datadir}/applications/*
%{_datadir}/icons/hicolor/*/*/*
%{_mandir}/man*/*

%{_includedir}/*
#{_datadir}/%{name}/include
%{_libdir}/libgrace_np.a
#{_datadir}/%{name}/lib


%changelog 
* Fri Mar 20 2009 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 5.1.22-1
- applied new versioning policy, spec in UTF-8
- updated to 5.1.22
- changed Group to Applications/Engineering
- used xdg-utils, gfortran

* Mon Jun  2 2003 Jun Nishii <jun@vinelinux.org> 5.1.12-0vl1
- ver.up and build with openMotif

* Wed Sep 18 2002 Jun Nishii <jun@vinelinux.org> 5.1.10-0vl1
- ver.up

* Fri Aug 16 2002 Jun Nishii <jun@vinelinux.org> 5.1.9-0vl1
- ver.up

* Sun Mar  3 2002 Jun Nishii <jun@vinelinux.org> 5.1.6-0vl1
- ver.up

* Mon Jan 21 2002 Jun Nishii <jun@vinelinux.org> 5.1.5-0vl1
- ver.up
- added BuildPrereq: lesstif-devel to get xmgrace

* Wed Aug 29 2001 MATSUBAYASHI Kohji <shaolin@vinelinux.org> 5.1.4-0vl2
- remove ExclusiveArch

* Mon Aug 27 2001 Jun Nishii <jun@vinelinux.org> 5.1.4-0vl1
- ver.up

* Fri Apr 20 2001 Jun Nishii <jun@vinelinux.org>
- 5.1.3-0vl1
- ver.up

* Sat Nov 11 2000 Masato Bito <masato@nets.ce.hiroshima-cu.ac.jp>
- 5.1.1-0vl2
- added ExclusiveArch: sparc

* Wed Sep 27 2000 Jun Nishii <jun@vinelinux.org>
- 5.1.1-0vl1
- build for Vine Linux 2.1