Blob Blame History Raw
%global ruby_sitearch %(ruby -rrbconfig -e 'puts Config::CONFIG["sitearchdir"] ')
%global gemdir %(ruby -rubygems -e 'puts Gem::dir' 2>/dev/null)
%global gemname gherkin
%global geminstdir %{gemdir}/gems/%{gemname}-%{version}
%global rubyabi 1.8

Summary: Fast Gherkin lexer/parser
Name: rubygem-%{gemname}
Version: 2.2.0
Release: 1%{?dist}
Group: Development/Languages
License: MIT
URL: http://github.com/aslakhellesoy/gherkin
Source0: http://rubygems.org/gems/%{gemname}-%{version}.gem
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
Requires: ruby(abi) = %{rubyabi} 
Requires: rubygems
Requires: rubygem(trollop)
BuildRequires: ruby(rubygems) 
BuildRequires: ruby-devel
Provides: rubygem(%{gemname}) = %{version}

%package doc
Summary: Documentation for %{name}
Group: Documentation
Requires:%{name} = %{version}-%{release}

%description doc
Documentation for %{name}


%description
A fast Gherkin lexer/parser based on the Ragel State Machine Compiler.


%prep
%setup -q -c -T 
mkdir -p ./%{gemdir}
gem install \
	--local \
	--install-dir ./%{gemdir} \
	--force \
	%{SOURCE0}
pushd %{_builddir}/%{name}-%{version}/%{geminstdir}/ext
# Fix trollop version
# TODO: Revert this to newer version once trollop will be upgraded
sed -i -e "s|1.16.2|1.15|" ../Rakefile
# Recompile all shared libraries using -O2 optimalization flag
rm -rf ../lib/*.so
for lexer_dir in */ ; do
  pushd $lexer_dir
  mkdir ext
  pushd ext
  ln -sf .. ${lexer_dir%/}
  popd
  sed -i 's/ -O0 / -O2 /' extconf.rb
  # Remove #line lines from C codes
  sed -ie 's/^#line .*$ / -O2 /' *.c
  CONFIGURE_ARGS="--with-cflags='%{optflags}'" ruby extconf.rb
  make clean && make RPM_OPT_FLAGS="$RPM_OPT_FLAGS"
  make install RUBYARCHDIR="../../lib"
  popd
done

%build

%install
rm -rf %{buildroot}
mkdir -p %{buildroot}%{ruby_sitearch}/%{gemname}
mkdir -p %{buildroot}%{gemdir}
mkdir -p %{buildroot}%{_prefix}
cp -a ./%{gemdir}/* %{buildroot}%{gemdir}
mv -f %{buildroot}%{geminstdir}/lib/*.so %{buildroot}%{ruby_sitearch}/
mv -f %{buildroot}%{gemdir}/bin %{buildroot}%{_prefix} 
find %{buildroot}%{geminstdir}/bin -type f | xargs chmod a+x
# Remove duplicate object files
rm -f %{buildroot}%{geminstdir}/ext/*/*.so
rm -f %{buildroot}%{geminstdir}/ext/*/*.o
rm -f %{buildroot}%{geminstdir}/ext/*/Makefile
# Remove git files
rm -f %{buildroot}%{geminstdir}/.gitattributes
rm -f %{buildroot}%{geminstdir}/.gitignore
rm -f %{buildroot}%{geminstdir}/.mailmap
rm -f %{buildroot}%{geminstdir}/.rspec
rm -f %{buildroot}%{geminstdir}/ikvm/.gitignore
rm -f %{buildroot}%{geminstdir}/java/.gitignore
rm -f %{buildroot}%{geminstdir}/java/src/main/java/gherkin/lexer/.gitignore
rm -f %{buildroot}%{geminstdir}/tasks/bench/generated/.gitignore
rm -f %{buildroot}%{geminstdir}/lib/gherkin/rb_lexer/.gitignore
rm -f %{buildroot}%{geminstdir}/java/src/main/resources/gherkin/.gitignore
rm -f %{buildroot}%{geminstdir}/lib/.gitignore
rm -f %{buildroot}%{geminstdir}/ragel/i18n/.gitignore
# Fix wrong executable flag on files
chmod -x %{buildroot}%{geminstdir}/tasks/ragel_task.rb
chmod -x %{buildroot}%{geminstdir}/tasks/compile.rake
# Fix DOS formatted line ends
sed -i -e "s|\r||" %{buildroot}%{geminstdir}/spec/gherkin/fixtures/dos_line_endings.feature
sed -i -e "s|\r||" %{buildroot}%{geminstdir}/spec/gherkin/fixtures/with_bom.feature
# Fix incompatible version of RSpec
# TODO: Update these packages in Fedora and remove this lines
sed -i -e "s|2.0.0.beta.17|1.3.0|" %{buildroot}%{geminstdir}/Rakefile
sed -i -e "s|1.16.2|1.15|" %{buildroot}%{geminstdir}/Rakefile
sed -i -e "s|2.0.0.beta.17|1.3.0|" %{buildroot}%{gemdir}/specifications/%{gemname}-%{version}.gemspec
sed -i -e "s|1.16.2|1.15|" %{buildroot}%{gemdir}/specifications/%{gemname}-%{version}.gemspec

%clean
rm -rf %{buildroot}

%files
%defattr(-, root, root, -)
%{_bindir}/%{gemname} 
%dir %{geminstdir}
%dir %{geminstdir}/bin
%{ruby_sitearch}/%{gemname}_*.so
%{geminstdir}/bin/gherkin
%{geminstdir}/lib
%{geminstdir}/ragel
%{geminstdir}/java
%{geminstdir}/ikvm
%{geminstdir}/json-simple-1.1.dll
%doc %{geminstdir}/features
%doc %{geminstdir}/spec
%doc %{geminstdir}/LICENSE
%doc %{geminstdir}/README.rdoc
%doc %{geminstdir}/History.txt
%doc %{geminstdir}/VERSION.yml
%doc %{geminstdir}/cucumber.yml
%{gemdir}/cache/%{gemname}-%{version}.gem
%{gemdir}/specifications/%{gemname}-%{version}.gemspec

%files doc
%defattr(-, root, root, -)
%{geminstdir}/Rakefile
%{geminstdir}/ext
%{geminstdir}/tasks
%{gemdir}/doc/%{gemname}-%{version}

%changelog
* Wed Sep 08 2010 Michal Fojtik <mfojtik@redhat.com> - 2.2.0-1
- Version bump

* Wed Jul 20 2010 Michal Fojtik <mfojtik@redhat.com> - 2.1.5-3
- Fixed rspec and trollop versions in gemspec files

* Wed Jul 20 2010 Michal Fojtik <mfojtik@redhat.com> - 2.1.5-2
- Added -doc subpackage
- Fixed debugging symbols issue (Thanks mtasaka)
- Fixed path for pushd in install section
- Fixed trollop version in gemspec
- Removed '#line foo' from C files

* Wed Jul 19 2010 Michal Fojtik <mfojtik@redhat.com> - 2.1.5-1
- Updated to latest version
- Fixed compiler flags
- Fixed directory ownership
- Removed unwanted versioning files
- Placed .so files on right place

* Wed Jul 14 2010 Michal Fojtik <mfojtik@redhat.com> - 2.1.3-1
- Initial package