%define name mpich
%define version 1.2.3
%define release 1%{?_dist_release}

Summary: A Portable Implementation of the Message-Passing Interface Standard
Name: %{name}
Version: %{version}
Release: %{release}
License: Freely Distributable
Group: Development/Libraries
Source: ftp://ftp.mcs.anl.gov/pub/mpi/mpich-%{version}.tar.gz
Source1: ftp://ftp.mcs.anl.gov/pub/mpi/mpich-docs.tgz
Source100: RSHCOMMAND
Source101: RSHCOMMAND.ja
Source102: RSHCOMMAND.en
%define lang ja

BuildRequires: xorg-x11-devel
BuildRoot: %{_tmppath}/%{name}-%{version}-root

# note
# jumpshot is written for jdk 1.x
# java is not locatable with a packge.
# Therefore, jumpshot is not included in this package, yet.
# jumpshot is commented out with #java#.

%package mpi
Summary: Message-Passing Interface Standard
Summary(ja): Message-Passing Interface Standard
Group: Development/Libraries

%package mpe
Summary: MPE
Requires: mpich-mpi = %{version}-%{release} XFree86-devel, tk
Group: Development/Libraries

%package doc
Summary: MPE
Group: Development/Libraries

%description
MPICH is an open-source, portable implementation of the Message-Passing
Interface Standard.

MPICH is a virtual package for MPI, MPE, and doc.

%description mpi
It contains a complete implementation of version 1.2 of
the MPI Standard and also significant parts of MPI-2, particularly in the
area of parallel I/O.

%description mpe
The Multi-Processing Environment (MPE) attempts to provide programmers with
a complete suite of performance analysis tools for their MPI programs based
on post processing approach.  These tools include a set of profiling libraries,
a set of utility programs, and a set of graphical tools.

The first set of tools to be used with user MPI programs is profiling libraries
which provide a collection of routines that create log files.  These log files
can be created manually by inserting MPE calls in the MPI program, or
automatically by linking with the appropriate MPE libraries, or by combining
the above two methods.  Currently, the MPE offers the following 3 profiling
libraries: Tracing Library, Animation Libraries, and Logging Libraries.


%description doc
Documentation for MPI and MPE. 

%prep
%setup -q -a 1

# as of version 1.2.2.3, use of mktemp is only in c files in mpe and mpid.
## as of version 1.2.3, configure checks use of mkstemp.
##find mpe mpid -type f -name \*.c \
##	-exec perl -p -i -e "s|mktemp|mkstemp|g;" {} \;

%build
export RSHCOMMAND=%{_sysconfdir}/%{name}/RSHCOMMAND
CFLAGS="$RPM_OPT_FLAGS" ./configure -prefix=$RPM_BUILD_ROOT/usr \
	--enable-sharedlib=$RPM_BUILD_ROOT%{_libdir} \
	--disable-doc \
	--libdir=$RPM_BUILD_ROOT%{_libdir} \
	--mandir=$RPM_BUILD_ROOT%{_mandir}
#	--with-comm=shared # for SMP
#	--enable-debug # enables TotalView(c) debugger

make 

%install
rm -rf $RPM_BUILD_ROOT

# this installs everything as specified at configure time.
make install

# set datadir=/etc/mpich.
find $RPM_BUILD_ROOT{%{_sbindir},%{_bindir}} -type f \
	-exec perl -p -i -e \
	"s|(datadir=.*)$RPM_BUILD_ROOT/usr/share|\1/etc/%{name}|g;" {} \;

# remove $RPM_BUILD_ROOT except lib*{a,so}.
find $RPM_BUILD_ROOT -type f -not -path '*lib*' \
	-exec perl -p -i -e "s|$RPM_BUILD_ROOT||g;" {} \;

# put a sample Makefile in /etc/mpich.
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/%{name}
mv $RPM_BUILD_ROOT/usr/share/Makefile.sample \
	$RPM_BUILD_ROOT%{_sysconfdir}/%{name}

# set up the list of servers -- only localhost for the package.
sed -e "/^[^#]/d" $RPM_BUILD_ROOT/usr/share/machines.LINUX >> \
	$RPM_BUILD_ROOT%{_sysconfdir}/%{name}/machines.LINUX
echo "localhost" >> $RPM_BUILD_ROOT%{_sysconfdir}/%{name}/machines.LINUX

# make RSHCOMMAND setting easy.
install -m 755 %{SOURCE100}.%{lang} \
	$RPM_BUILD_ROOT%{_sysconfdir}/%{name}/RSHCOMMAND

# make care of upshot and jumpshot.
mkdir -p $RPM_BUILD_ROOT%{_datadir}/%{name}
#java#mv $RPM_BUILD_ROOT/usr/share/{upshot,jump-shot-3} \
mv $RPM_BUILD_ROOT/usr/share/upshot \
	$RPM_BUILD_ROOT%{_datadir}/%{name}

ln -sf %{_datadir}/%{name}/upshot/bin/upshot $RPM_BUILD_ROOT/%{_bindir}/upshot
#java#ln -sf %{_datadir}/%{name}/upshot/bin/jumpshot \
#java#	$RPM_BUILD_ROOT/%{_bindir}/jumpshot

perl -p -i -e "s|%{_datadir}|%{_datadir}/%{name}|g;" \
	$RPM_BUILD_ROOT%{_datadir}/%{name}/upshot/bin/*
#java#	$RPM_BUILD_ROOT%{_datadir}/%{name}/{upshot,jump-short-3}/bin/*

%clean
rm -rf $RPM_BUILD_ROOT

%files
%defattr(-,root,root)

%files mpi
%defattr(-,root,root)
%config(noreplace) %{_sysconfdir}/%{name}*
%{_sbindir}/*
%{_bindir}/mpi*
%{_bindir}/serv_p4
%{_bindir}/tarch
%{_bindir}/tdevice
%{_includedir}/*mpi*
%{_libdir}/*mpich*
%{_mandir}/man1/MPI.1*
%{_mandir}/man1/mpi*
%{_mandir}/man1/chp4_servs.1*
%{_mandir}/man1/cleanipcs.1*
%{_mandir}/man1/tstmachines.1*
%{_mandir}/man3/MPI*
%{_mandir}/man3/Constants.3*

%files mpe
%defattr(-,root,root)
%{_bindir}/mpe*
%{_includedir}/basex11.h
%{_includedir}/mpe*
%{_includedir}/protofix.h
%{_libdir}/*mpe*
%{_mandir}/man4/MPE*
%{_bindir}/clog*
%{_bindir}/slog*
%{_bindir}/logviewer*
%{_bindir}/upshot
%{_mandir}/man1/Jumpshots.1*
%{_mandir}/man4/CLOG*
%{_datadir}/%{name}

%files doc
%defattr(-,root,root)
%doc COPYRIGHT KnownBugs README doc docs www
%doc mpe/contrib examples installtest


%changelog
* Mon Sep 08 2008 Shu KONNO <owa@bg.wakwak.com> 1.2.3-1vl5
- applied new versioning policy, spec in utf-8
- added libdir option to configure

* Fri Feb 08 2002 Yoshihiro Ota <ota@j.email.ne.jp>
- Separated into subpackages -- mpi, mpe, and doc - 1.2.3-0vl3

* Sun Feb 03 2002 Yoshihiro Ota <ota@j.email.ne.jp>
- Version up to mpich-1.2.3

* Fri Jan 25 2002 Yoshihiro Ota <ota@j.email.ne.jp>
- Created spec file for mpich-1.2.2.3
