File json.spec of Package json

%define bname json
Name: %bname
Version: 0.1.0
Release: 1
Summary: A high level library for working with JSON in Erlang
License: MIT
Group: Development/Tools/Other
URL: https://github.com/talentdeficit/%bname
Source: %bname.tar.xz
Patch1: %bname-doc.patch
BuildArch: noarch
Provides: erlang-%bname = %version-%release

BuildRequires: rpm-macros-erlang rpm-build-erlang
BuildRequires: rebar >= 2.6.1-7
# check
BuildRequires: erlang-jsx erlang-jsonpointer erlang-jsonfilter

%description
%bname is a high level library for working with JSON in Erlang.


%package doc
Summary: Documentation of %bname
Group: Documentation/HTML
Provides: erlang-%bname-doc = %version-%release

%description doc
Documentation of %bname.


%prep
%setup -q -n %bname
%patch1 -p1


%build
erl -noshell -eval '
{ok, L} = file:consult("rebar.config"),
file:write_file("%bname.rebar.config",
                lists:map(fun(E) -> [io_lib:print(E), ".\n"] end,
                          [{erl_opts, [slim, inline, no_debug_info|lists:delete(debug_info, proplists:get_value(erl_opts, L, []))]}|lists:foldl(fun proplists:delete/2, L, [deps, erl_opts])]),
                [raw]),
init:stop().'
rebar -C %bname.rebar.config compile -v
rebar -C %bname.rebar.config doc -v


%install
install -d -m 0755 %buildroot%_otplibdir/%bname-%version/ebin
install -p -m 0644 ebin/* %buildroot%_otplibdir/%bname-%version/ebin/
install -d -m 0755 %buildroot%_otplibdir/%bname-%version/doc
install -p -m 0644 doc/*.{css,html,png} %buildroot%_otplibdir/%bname-%version/doc/
install -d -m 0755 %buildroot%_docdir/%name
ln -sf %_otplibdir/%name-%version/doc %buildroot%_docdir/%name/html
install -p -m 0644 *.md %buildroot%_docdir/%name/


%check
rebar -C %bname.rebar.config eunit


%files
%defattr(-,root,root)
%_otplibdir/*
%exclude %_otplibdir/%bname-*/doc


%files doc
%defattr(-,root,root)
%doc %_docdir/%name
%doc %dir %_otplibdir/%bname-*
%doc %_otplibdir/%bname-*/doc


%changelog
* Sat Jul 15 2017 Led <ledest@gmail.com> 0.1.0-1
- initial build