File relx.spec of Package relx

%define bname relx
Name: %bname
Version: 3.24.4
Release: 1
Summary: A release assembler for Erlang
License: Apache-2.0
Group: Development/Tools/Other
URL: https://github.com/erlware/%bname
Source: %bname-%version.tar.xz
#Patch0: %bname-%version-git.patch
Patch1: %bname-3.24.3-doc.patch
Patch2: %bname-3.22.1-fix-templates.patch
Provides: erlang-%bname = %version-%release
BuildArch: noarch

BuildRequires: rpm-macros-erlang rpm-build-erlang
BuildRequires: erlang-otp-devel erlang-common_test-devel
BuildRequires: erlang-erlware_commons-devel >= 1.0.4
BuildRequires: erlang-providers >= 1.7.0
BuildRequires: erlang-providers-devel >= 1.7.0
BuildRequires: rebar >= 2.6.1-7

%description
Relx assembles releases for an Erlang/OTP release. Given a release specification
and a list of directories in which to search for OTP applications it will
generate a release output. That output depends heavily on what plugins available
and what options are defined, but usually it is simply a well configured release
directory.
The release-specification-file is optional but otherwise contains additional
specification information for releases.


%package devel
Summary: Headers of %bname
Group: Development/Tools/Other
Provides: erlang-%bname-devel = %version-%release
Conflicts: %bname < 3.23.1-2

%description devel
Headers of %bname.


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

%description doc
Documentation of %bname.


%prep
%setup -q -n %bname-%version
#patch0 -p1
%patch1 -p1
%patch2 -p1
erl -noshell -eval '
{ok, [{application, %bname, L}]} = file:consult("src/%bname.app.src"),
file:write_file("src/%bname.app.src",
                io_lib:format("{application, %bname, ~p}.~n", [lists:keyreplace(vsn, 1, L, {vsn, "%version"})]), [raw]),
init:stop().'


%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,
                          lists:keystore(eunit_opts, 1, lists:keydelete(deps, 1, L),
                                         {eunit_opts,
                                          [nowarn_deprecated_function|proplists:get_value(eunit_opts, L, [])]})),
                [raw]),
init:stop().'
ERL_COMPILER_OPTIONS="[inline,nowarn_deprecated_function,nowarn_export_all,verbose]" rebar %{?_smp_mflags} -C %bname.rebar.config compile -v
rebar %{?_smp_mflags} -C %bname.rebar.config doc -v

cat > %bname.escript <<__EOF__
#!%__escript
%%%%
%%%%!-noinput +sbtu +A0
main(X) -> relx:main(X).
__EOF__


%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/include
install -p -m 0644 include/* %buildroot%_otplibdir/%bname-%version/include/
install -d -m 0755 %buildroot%_otplibdir/%bname-%version/priv/templates
for i in priv/templates/*; do
	head -1 $i | grep '^#!' && m="0755" || m="0644"
	install -p -m $m $i %buildroot%_otplibdir/%bname-%version/priv/templates/
done
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%_otplibdir/%bname-%version/examples
install -p -m 0644 examples/* %buildroot%_otplibdir/%bname-%version/examples/
install -d -m 0755 %buildroot%_docdir/%name
ln -sf %_otplibdir/%bname-%version/doc %buildroot%_docdir/%name/html
install -p -m 0644 README* CONTRIBUTING* %buildroot%_docdir/%name/
install -pD -m 0755 %bname.escript %buildroot%_bindir/%bname


%check
ERL_COMPILER_OPTIONS="[inline,nowarn_deprecated_function,nowarn_export_all,verbose]" rebar -C %bname.rebar.config eunit -v


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


%files devel
%defattr(-,root,root)
%dir %_otplibdir/%bname-*
%_otplibdir/%bname-*/include


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


%changelog
* Sat Feb 10 2018 Led <ledest@gmail.com> 3.24.4-1
- 3.24.4

* Thu Dec 07 2017 Led <ledest@gmail.com> 3.24.3-2
- update BuildRequires

* Sun Nov 26 2017 Led <ledest@gmail.com> 3.24.3-1
- 3.24.3

* Fri Nov 24 2017 Led <ledest@gmail.com> 3.23.1-2
- update BuildRequires
- move headers and docs to separate packages

* Sun Jul 16 2017 Led <ledest@gmail.com> 3.23.1-1
- 3.23.1
- update patches:
  + relx-3.23.1-doc.patch

* Wed May 31 2017 Led <ledest@gmail.com> 3.23.0-1
- 3.23.0

* Sun May 21 2017 Led <ledest@gmail.com> 3.22.3-4
- revert BuildRequires

* Sat May 20 2017 Led <ledest@gmail.com> 3.22.3-3
- update BuildRequires

* Sun Mar 26 2017 Led <ledest@gmail.com> 3.22.3-2
- fix script

* Sun Mar 26 2017 Led <ledest@gmail.com> 3.22.3-1
- 3.22.3

* Sun Jan 01 2017 Led <ledest@gmail.com> 3.22.1-1
- 3.22.1
- add patches:
  + relx-3.22.1-fix-templates.patch

* Mon Dec 12 2016 Led <ledest@gmail.com> 3.21.1-2
- git c305c89
- add nowarn_export_all compile option

* Thu Oct 20 2016 Led <ledest@gmail.com> 3.21.1-1
- 3.21.1
- git 53a87ed

* Fri Aug 26 2016 Led <ledest@gmail.com> 3.21.0-1
- 3.21.0

* Mon Jul 25 2016 Led <ledest@gmail.com> 3.20.0-1
- 3.20.0

* Sat Apr 02 2016 Led <ledest@gmail.com> 3.18.0-1
- 3.18.0
- git 1e15397

* Sat Apr 02 2016 Led <ledest@gmail.com> 3.17.0-1
- 3.17.0
- clean up and update BuildRequires

* Sun Feb 14 2016 Led <ledest@gmail.com> 3.15.0-1
- 3.15.0

* Sun Jan 17 2016 Led <ledest@gmail.com> 3.13.0-1
- 3.13.0
- add patches:
  + relx-3.13.0-git.patch

* Sun Nov 29 2015 Led <ledest@gmail.com> 3.9.0-1
- 3.9.0
- remove patches:
  + relx-3.7.1-git.patch

* Sun Oct 11 2015 Led <ledest@gmail.com> 3.7.1-1
- 3.7.1

* Fri Sep 04 2015 Led <ledest@gmail.com> 3.5.0-1
- 3.5.0
- add patches:
  + relx-3.5.0-git.patch

* Sat Jul 04 2015 Led <ledest@gmail.com> 3.1.0-1
- 3.1.0
- fix changelog

* Sat Jul 04 2015 Led <ledest@gmail.com> 2.1.0-1
- 2.1.0

* Thu Jul 02 2015 Led <ledest@gmail.com> 2.0.0-2
- fix build with Erlang 18

* Sun May 31 2015 Led <ledest@gmail.com> 2.0.0-1
- initial build