%define ruby    /usr/bin/ruby
%define rdoc    /usr/bin/rdoc
%define gemdir  %{_localstatedir}/lib/gems/%(%{ruby} -r rbconfig -e 'print File.basename(Config::CONFIG["rubylibdir"])')

Summary: packaging system for Ruby application or library
Summary(ja): Rubyアプリケーションやライブラリのためのパッケージシステム
Name: rubygems
Version: 1.3.7
Release: 1%{?_dist_release}
License: distributable
Group: Development/Tools
Source0: rubygems-%{version}.tgz
Patch1: rubygems-1.3.7-default-dir.patch
URL: http://www.rubygems.org/
BuildArch: noarch
BuildRoot: %{_tmppath}/%{name}-%{version}-root
BuildPreReq: ruby ruby-devel rdoc
Requires: ruby ruby-devel rdoc

%description
RubyGems is the name of the project that developed the gem packaging
system and the gem command.
* Easy Installation and removal of RubyGems packages and their
  dependents.
* Management and control of local packages
* Package dependency management
* Query, search and list local and remote packages
* Multiple version support for installed packages
* Web-based interface to view the documentation for your installed
  gems
* Easy to use interface for building gem packages
* Simple server for distributing your own gem packages

%description -l ja

%prep

%setup -q

%patch1 -p1

%install
rm -rf ${RPM_BUILD_ROOT}
mkdir -p ${RPM_BUILD_ROOT}%{rbindir}
mkdir -p ${RPM_BUILD_ROOT}%{rlibdir}

#%{ruby} -I${RPM_BUILD_ROOT}%{rlibdir} \
%{ruby} -I%{rlibdir} setup.rb install --destdir=${RPM_BUILD_ROOT}%{rlibdir} --prefix=/

# fix install path
mkdir -p %{buildroot}%{_bindir}
mv %{buildroot}%{rlibdir}/bin/gem %{buildroot}%{_bindir}/gem
rm -rf %{buildroot}%{rlibdir}/bin
mv %{buildroot}%{rlibdir}/lib/* %{buildroot}%{rlibdir}/.

%{rdoc} --op html \
  --main README . README LICENSE.txt GPL.txt
%{rdoc} --ri --op ${RPM_BUILD_ROOT}%{gemdir}/doc/%{name}-%{version} \
  --main README . README LICENSE.txt GPL.txt
rm -f ${RPM_BUILD_ROOT}%{gemdir}/doc/rubygems-%{version}/created.rid

cd pkgs/sources
GEM_HOME=${RPM_BUILD_ROOT}%{gemdir} \
%{ruby} -I${RPM_BUILD_ROOT}%{rlibdir} \
  -rrubygems -rrubygems/builder -rrubygems/installer -e '
load("./sources.gemspec")
spec = Gem.sources_spec
gem = Gem::Builder.new(spec).build
Gem::Installer.new(gem).install()
'
cd ../..


%clean
rm -rf ${RPM_BUILD_ROOT}
rm -rf html

%pre
if [ `grep rubygems %{_sysconfdir}/group | wc -l` = 0 ]; then
  %{_sbindir}/groupadd rubygems
fi


%files
%defattr(-, root, root)
%doc ChangeLog
%doc GPL.txt
%doc LICENSE.txt
%doc README
%doc TODO
%doc html
%{rbindir}/*
%{rlibdir}/*
%defattr(664,root,rubygems,775)
%{gemdir}

%changelog
* Thu Sep 16 2010 IWAI, Masaharu <iwai@alib.jp> 1.3.7-1
- new upstream release
- update default dir patch (Patch1)

* Mon Dec 14 2009 Daisuke SUZUKI <daisuke@linux.or.jp> 1.3.5-1
- new upstream release

* Sat Mar  7 2009 IWAI, Masaharu <iwai@alib.jp> 1.3.1-1
- new upstream release
- apply new versioning policy
- spec in UTF-8
- update URL
- update default dir patch (Patch1)
- drop fix shebang patch (Patch2)
- drop postinst patch (Patch3)
- add install dir patch (Patch4)
- update %%install section
- create rubygems group for %%{gemdir}

* Mon Mar 19 2007 akira yamada <akira@vinelinux.org> 0.9.2-0vl1
- initial packaging.
