%define name gnuplot
%define version 3.7.1
%define prefix %{_prefix}
%define release 2
Name: %{name}
Summary: A program for plotting mathematical expressions and data.
Version: %{version}
Release: %{release}
Copyright: distributable
Group: Sciences/Other
BuildRequires: libpng-devel zlib-devel
Source: ftp://ftp.gnuplot.org/pub/gnuplot/%{name}-%{version}.tar.gz
Patch0: %{name}-%{version}-png.patch
URL: http://www.gnuplot.org/
BuildRoot: /var/tmp/%{name}-root
BuildPreReq: zlib-devel, libpng-devel

%ifarch ia64
  %define DEFCCIA cc
  %define DEFCC %{DEFCCIA}
%else
  %define DEFCC cc
%endif

%description
Gnuplot is a command-line driven, interactive function plotting program
especially suited for scientific data representation. Gnuplot can be used to
plot functions and data points in both two and three dimensions and in many
different formats.

Install gnuplot if you need a graphics package for scientific data
representation.

%prep
%setup -q
%patch0 -p0 -b .png

%build
# Use the default compiler for this platform - gcc otherwise
if [[ -z "$CC" ]]
then
    if test "X`type %{DEFCC} 2>/dev/null`" != 'X'; then
       export CC=%{DEFCC}
    else
       export CC=gcc
    fi
fi
if test "X$CC" != "Xgcc"
then
       export RPM_OPT_FLAGS=`echo $RPM_OPT_FLAGS | sed 's:-fsigned-char::'`
%ifarch ia64
       export CFLAGS=
%else
       export CFLAGS="$RPM_OPT_FLAGS"
%endif
fi

%configure --prefix=%{prefix} --with-readline --with-png
find . -type f -exec perl -pi -e 's/gdImageGif/gdImagePng/g' {} \;

%ifarch ia64
# Unset CFLAGS on term.o to workaround a compiler optimizer error.
CFLAGS= make -e term.o
%endif

make

cd docs
make doc2html
./doc2html gnuplot.doc > gnuplot.html

%install
rm -rf $RPM_BUILD_ROOT
%ifos linux
#mkdir -p $RPM_BUILD_ROOT/usr/{bin,share/gnuplot,man/man1,lib/menu}
#
#install -m 755 -s gnuplot_x11 $RPM_BUILD_ROOT/usr/bin/gnuplot_x11
#install -m 755 -s gnuplot $RPM_BUILD_ROOT/usr/bin/gnuplot
#install -m 644 docs/gnuplot.1 $RPM_BUILD_ROOT/usr/man/man1
#install -m 644 docs/gnuplot.gih $RPM_BUILD_ROOT/usr/share/gnuplot.gih
%endif

%makeinstall

strip $RPM_BUILD_ROOT%{prefix}/bin/* || :

( cd $RPM_BUILD_ROOT
    mkdir -p usr/bin
    cd usr/bin
    ln -sf ../..%{prefix}/bin/* .
    cd -
)

%clean
rm -rf $RPM_BUILD_ROOT

%files
%defattr(-,root,root)
%doc Copyright docs/gnuplot.html docs/psdoc
%doc demo gnuplot-mode/dotemacs gnuplot-mode/gpelcard.pdf 0README 0FAQ
%{_bindir}/gnuplot_x11
%{_bindir}/gnuplot
%{_mandir}/man1/*
%{_datadir}/gnuplot.gih
/usr/bin/*

%changelog
* Thu Jan 31 2008 Reza Arbab <arbab@austin.ibm.com> 3.7.1-2
- Rebuild against newer libpng: libpng.a(libpng.so.3)

* Wed May 16 2001 David Clissold <cliss@austin.ibm.com>
- Modify to build for AIX.

* Sun May 06 2001 Geoffrey Lee <snailtalk@mandrakesoft.com> 3.7.1-15mdk
- s/gdImageGif/gdImagePng/g; (Not --without-gd because if we use
  set terminal gif then it gives us a segfault.)
  
* Mon Jan 22 2001 Guillaume Cottenceau <gc@mandrakesoft.com> 3.7.1-14mdk
- fix URL following suggestion by <vgeloven@dds.nl>

* Sun Aug 27 2000 Guillaume Cottenceau <gc@mandrakesoft.com> 3.7.1-13mdk
- now should also compile on non x86 arch, /me sucks

* Fri Aug 25 2000 Guillaume Cottenceau <gc@mandrakesoft.com> 3.7.1-12mdk
- removed -ffast-math option to improve reliability

* Wed Aug 23 2000 Guillaume Cottenceau <gc@mandrakesoft.com> 3.7.1-11mdk
- automatically added packager tag

* Mon Aug 07 2000 Frederic Lepied <flepied@mandrakesoft.com> 3.7.1-10mdk
- automatically added BuildRequires

* Thu Jul 20 2000 Guillaume Cottenceau <gc@mandrakesoft.com> 3.7.1-9mdk
- BM
- macroweruivieruweiovjzations

* Fri Apr 28 2000 Guillaume Cottenceau <gc@mandrakesoft.com> 3.7.1-8mdk
- fixed menu entry adding 32x32 icon

* Fri Apr 28 2000 Giuseppe Ghibò <ghibo@mandrakesoft.com> 3.7.1-7mdk
- added XFree86-devel in BuildPreReq for X11.
- removed bzip2 man pages (done by spec_helper).
- removed gnu-readline and put back minimal-readline otherwise the
  Boer's patch doesn't work.

* Mon Apr 17 2000 Guillaume Cottenceau <gc@mandrakesoft.com> 3.7.1-6mdk
- fix directory owns.
- now uses gnu readline library instead of minimal built-in readline.

* Mon Apr 10 2000 Guillaume Cottenceau <gc@mandrakesoft.com> 3.7.1-5mdk
- added icon.

* Thu Mar 23 2000 Guillaume Cottenceau <gc@mandrakesoft.com> 3.7.1-4mdk
- new groups.
- menu entry.

* Thu Nov 11 1999 Giuseppe Ghibò <ghibo@linux-mandrake.com>
- added Pieter de Boer's patch <ptdeboer@cs.utwent.nl> for splot X11
  interactive rotations.
- added gnuplot-mode documentation.

* Tue Nov  9 1999 Giuseppe Ghibò <ghibo@linux-mandrake.com>
- updated to 3.7.1.
- added gnuplot-faq.html.
- added PDF documentation.

* Mon Nov  8 1999 Chmouel Boudjnah <chmouel@mandrakesoft.com>
- 3.7.0.2.
- fix license.
- add emacs-mode.
- add some documentation.

* Fri Oct 1 1999 Giuseppe Ghibò <ghibo@linux-mandrake.com>
- Changed the 3.7.0->3.7.0.1 patch to a more recent version because
the previous version has broken the postscript terminal.

* Tue Jul 20 1999 Chmouel Boudjnah <chmouel@mandrakesoft.com>
- Rebuild without svgalib.

* Wed Jun 30 1999 Chmouel Boudjnah <chmouel@mandrakesoft.com>
- Update to 3.7.0.1.

* Tue May 11 1999 Chmouel Boudjnah <chmouel@mandrakesoft.com>
- Mandrake adaptations.

* Sun Mar 21 1999 Cristian Gafton <gafton@redhat.com> 
- auto rebuild in the new build environment (release 2)

* Tue Feb  2 1999 Jeff Johnson <jbj@redhat.com>
- update to 3.7.

* Thu Dec 17 1998 Michael Maher <mike@redhat.com>
- built package for 6.0

* Fri Sep 11 1998 Jeff Johnson <jbj@redhat.com>
- update to 2.6beta347

* Sat Aug 15 1998 Jeff Johnson <jbj@redhat.com>
- build root

* Thu May 07 1998 Prospector System <bugs@redhat.com>
- translations modified for de, fr, tr

* Mon Oct 20 1997 Donnie Barnes <djb@redhat.com>
- spec file cleanups

* Thu Jul 10 1997 Erik Troan <ewt@redhat.com>
- built against glibc
