#
# spec file for package rubygem-<%= spec.name %><%= config[:version_suffix] %>
#
# Copyright (c) <%= Time.now.year %> SUSE LINUX GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via http://bugs.opensuse.org/
#
<% if config && not(config.empty?) -%>


#
# This file was generated with a gem2rpm.yml and not just plain gem2rpm.
# All sections marked as MANUAL, license headers, summaries and descriptions
# can be maintained in that file. Please consult this file before editing any
# of those fields
#
<% end -%>

Name:           <%= config[:name] ? config[:name] : "rubygem-#{spec.name}#{config[:version_suffix]}"  %>
Version:        <%= spec.version %>
Release:        0
%define mod_name <%= spec.name %>
%define mod_full_name %{mod_name}-%{version}
<% if config[:version_suffix] -%>
%define mod_version_suffix <%= config[:version_suffix] %>
<% end -%>
<% if config[:preamble] -%>
# MANUAL
<%= config[:preamble] %>
# /MANUAL
<% end -%>
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
BuildRequires:  ruby-macros >= 5
<% for req in spec.required_ruby_version -%>
<%   unless req.empty? -%>
<%     if spec.extensions.empty? -%>
BuildRequires:  %{ruby <%= req %>}
<%     else -%>
BuildRequires:  %{rubydevel <%= req %>}
<%     end -%>
<%   else -%>
<%     if spec.extensions.empty? -%>
BuildRequires:  %{ruby}
<%     else -%>
BuildRequires:  %{rubydevel}
<%     end -%>
<%   end -%>
<% end -%>
<% for d in spec.runtime_dependencies -%>
<% if ['rdoc'].include? d.name.to_s -%>
# <%= d.name %> <%= d.__getobj__().requirement %>
<% for req in d.requirement -%>
BuildRequires:  %{rubygem <%= d.name %>  <%= req  %>}
<% end -%>
<% end -%>
<% end -%>
BuildRequires:  %{rubygem gem2rpm}
<% unless spec.rdoc_options.empty? || config[:disable_automatic_rdoc_dep] -%>
BuildRequires:  %{rubygem rdoc > 3.10}
<% end -%>
<% unless spec.executables.empty? -%>
BuildRequires:  update-alternatives
<% end -%>
<% unless spec.homepage.nil? || spec.homepage.empty? -%>
Url:            <%= spec.homepage %>
<% end -%>
<% if config[:sourceurl] -%>
Source:         <%= config[:sourceurl] %>
<% else -%>
Source:         https://rubygems.org/gems/%{mod_full_name}.gem
<% end -%>
<% if config[:sources]
     config[:sources].each_with_index do |src, i| -%>
Source<%= i+1 %>:        <%= src %>
<% end
 end -%>
<% if config[:patches] -%>
# MANUAL
<%   config[:patches].each_with_index do |patch,i| -%>
Patch<%= i %>:  <%= patch[0] %>
<%  end -%>
# /MANUAL
<% end -%>
Summary:        <%= config[:summary] or spec.summary %>
License:        <%= config[:license] or (spec.licenses and spec.licenses.join(" and ")) or 'CHECK(Ruby)' %>
Group:          Development/Languages/Ruby
<% unless spec.executables.empty? -%>
PreReq:         update-alternatives
<% end -%>

%description
<%= config[:description] or spec.description -%>

<% # TODO move into gem2rpm as gem_packages.sh also need this and we only leave it here for getting the docfiles list
   test_frameworks = Hash.new
   docdirfiles = []
   format.file_entries.each do |entry|
     # new rubygems version has it different
     if entry.kind_of?(Array)
       path=entry[0]['path']
     else
       path=entry
     end
     path.gsub!(%r{^\./}, '')
     %w(test spec).each { |framework|
       test_frameworks[framework] = 1 if path.index(framework + "/") == 0
     }
     %w(changes
        copying
        history
        legal
        licence
        license
        license-mit
        mit-license
        apache-license-2.0
        license-apache-2.0
        changelog
        news
        release_notes
        readme
       ).each { |file|
      bpath = path.downcase.gsub(%r{\.rdoc$}, '').gsub(%r{\.txt$}, '').gsub(%r{\.md$}, '').gsub(%r{\.markdown$}, '')
      #$stderr.puts "PATH #{path} #{bpath} #{file}"
      docdirfiles << path if bpath == file
     }
   end

   test_frameworks = test_frameworks.keys.sort
-%>
%prep
<% unless config[:patches].nil? or config[:patches].empty? -%>
%gem_unpack
<% config[:patches].each_with_index do |patch, i| -%>
%patch<%= i %> <%= patch[1] if patch[1] %>
<% end -%>
<% if config[:post_patch] -%>
# MANUAL
<%= config[:post_patch] %>
# /MANUAL
<% end -%>
find -type f -print0 | xargs -0 touch -r %{S:0}
%gem_build
<% end -%>

%build

%install
<% if config[:pre_install] -%>
# MANUAL
<%= config[:pre_install] %>
# /MANUAL
<% end -%>
%gem_install \
<% if config[:gem_install_args] -%>
<%= config[:gem_install_args] %> \
<% end -%>
<% if config[:disable_docs] -%>
  --no-rdoc --no-ri \
<% end -%>
<% unless spec.executables.empty? -%>
  --symlink-binaries \
<% end -%>
<% unless docdirfiles.empty? -%>
  --doc-files="<%= docdirfiles.join(' ') %>" \
<% end -%>
  -f
<% unless spec.extensions.empty? -%>
%gem_cleanup
<% end -%>
<% if config[:post_install] -%>
# MANUAL
<%= config[:post_install] %>
# /MANUAL

<% end -%>

<% if config[:testsuite_command] -%>
# MANUAL
%check
<%= config[:testsuite_command] %>
#/ MANUAL

<% end -%>
<% if config[:filelist] -%>
%files
%defattr(-,root,root,-)
<%= config[:filelist] %>

<% end -%>
<% if config[:scripts]
     if config[:scripts].is_a? Hash
       config[:scripts].each do |section, content| -%>
%<%= section %>
<%= content %>

<%     end
     else -%>
<%= config[:scripts] %>

<%   end
   end
-%>
<% if config[:custom_pkgs]
     config[:custom_pkgs].each do |custom_pkg_name, data|
-%>
%package <%= custom_pkg_name %><%= config[:version_suffix] %>
<% if data[:preamble] and data[:preamble] != '' -%>
<%= data[:preamble] %>
<% else %>
Summary:        <%= custom_pkg_name %> sub package for <%= spec.name %>
Group:          Development/Languages/Ruby
<% end %>
# Requires:      rubygem-<%= spec.name %><%= config[:version_suffix] %> = <%= spec.version %>
%description <%= custom_pkg_name %><%= config[:version_suffix] %>
<% if data[:description] and data[:description] != '' -%>
<%= data[:description] %>
<% else %>
<%= spec.description -%>

This package holds the <%= custom_pkg_name %> sub package for <%= spec.name -%>
<% end %>
%files <%= custom_pkg_name %><%= config[:version_suffix] %>
%defattr(-,root,root,-)
<%= data[:filelist] %>

<% if data[:scripts]
      if data[:scripts].is_a? Hash
        data[:scripts].each do |section, content| -%>
%<%=section %> <%=custom_pkg_name %>
<%= content %>

<%      end
      end
   end
-%>

<%   end
   end
-%>
%gem_packages

%changelog
