File rebar.spec of Package rebar

%define bname rebar
Name: %bname
Version: 2.6.1
Release: 12
Summary: A sophisticated build-tool for Erlang projects that follows OTP principles
License: Apache-2.0
Group: Development/Tools/Other
URL: https://github.com/rebar/%bname
Source: %bname-%version.tar.xz
Source9: %name-rpmlintrc
Patch0: %bname-%version-git.patch
Patch1: %bname-2.6.1-fix-link-drv.patch
BuildArch: noarch
Requires: erlang
Requires: erl_interface
Requires: /usr/sbin/update-alternatives
Provides: erlang-rebar = %version-%release
Provides: %bname-reltool = %version-%release
Obsoletes: %bname-reltool < %version-%release

BuildRequires: rpm-macros-erlang >= 0.9.1 rpm-build-erlang >= 0.10.0
BuildRequires: erlang erlang-tools erlang-otp-devel erl_interface erlang-syntax_tools
BuildRequires: erlang-edoc
BuildRequires: /usr/sbin/update-alternatives
BuildRequires: erlang-crypto erlang-eunit erlang-diameter

%description
%bname is an Erlang build tool that makes it easy to compile and test Erlang
applications, port drivers and releases. %bname is a self-contained Erlang script,
so it's easy to distribute or even embed directly in a project. Where possible,
%bname uses standard Erlang/OTP conventions for project structures, thus
minimizing the amount of build configuration work. %bname also provides dependency
management, enabling application writers to easily re-use common libraries from a
variety of locations (git, hg, etc).


%package static
Summary: A sophisticated build-tool for Erlang projects that follows OTP principles
Group: Development/Tools/Other
Provides: %name-bundle = %version-%release
Requires: erlang
Requires: erlang-otp-base erlang-syntax_tools

%description static
%bname is an Erlang build tool that makes it easy to compile and test Erlang
applications, port drivers and releases. %bname is a self-contained Erlang script,
so it's easy to distribute or even embed directly in a project. Where possible,
%bname uses standard Erlang/OTP conventions for project structures, thus
minimizing the amount of build configuration work. %bname also provides dependency
management, enabling application writers to easily re-use common libraries from a
variety of locations (git, hg, etc).


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

sed -i 's/"All\( 2 tests passed"\)/"\1/g' test/rebar_eunit_tests.erl


%build
erl -noshell -eval '
{ok, L} = file:consult("rebar.config"),
file:write_file("rebar.config",
                lists:map(fun(E) -> io_lib:format("~p.~n", [E]) end,
                          [{erl_opts, [inline, slim, no_debug_info|lists:delete(debug_info, proplists:get_value(erl_opts, L, []))]},
                           {edoc_opts, [{preprocess, true}|proplists:get_value(edoc_opts, L, [])]},
                           {escript_shebang, "#!%_bindir/escript\n"}, {escript_comment, ""}, {escript_emu_args, ""}
                           |lists:foldl(fun proplists:delete/2, L, [erl_opts, edoc_opts])])),
halt().'

./bootstrap
./rebar doc

cat > %bname.escript <<__EOF__
#!/usr/bin/escript
%%%%
main(A) -> rebar:main(A).
__EOF__


%install
install -pD -m 0755 %bname %buildroot%_bindir/%bname-bundle
ln -sf %bname-bundle %buildroot%_bindir/%bname-static
for d in ebin priv/templates; do
	install -d -m 0755 %buildroot%_otplibdir/%bname-%version/$d
	install -p -m 0644 $d/* %buildroot%_otplibdir/%bname-%version/$d/
done
install -pD %bname.escript -m 0755 %buildroot%_bindir/%bname-otp
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/%bname-%version/doc %buildroot%_docdir/%name/html
install -p -m 0644 CONTRIBUTING* README* RELEASE-NOTES* THANKS* %buildroot%_docdir/%name/

# completion
install -pD -m 0644 priv/shell-completion/bash/%bname %buildroot%_sysconfdir/bash_completion.d/%bname.sh

# alternatives
install -d -m 0755 %buildroot%_sysconfdir/alternatives
touch %buildroot%_sysconfdir/alternatives/%bname
ln -sf %_sysconfdir/alternatives/%bname %buildroot%_bindir/%bname

# RPM macros
install -d -m 0755 %buildroot%_rpmmacrosdir
cat > %buildroot%_rpmmacrosdir/macros.%bname <<__EOF__
%__rebar env REBAR_DEPS_PREFER_LIBS=1 %_bindir/%bname
%__rebar_compile %__rebar compile
%__rebar_doc %__rebar doc
%__rebar_eunit %__rebar eunit
__EOF__

%add_erlang_req_beam_skiplist dialyzer
%add_erlang_req_beam_skiplist reltool reltool_server
%add_erlang_req_beam_skiplist abnfc
%add_erlang_req_beam_skiplist erlydtl
%add_erlang_req_beam_skiplist lfe_comp
%add_erlang_req_beam_skiplist neotoma
%add_erlang_req_beam_skiplist protobuffs_compile
%add_erlang_req_beam_skiplist eflame
%add_erlang_req_beam_skiplist gpb_compile
%add_erlang_req_beam_skiplist diameter_codegen diameter_dict_util
%add_erlang_req_app_skiplist dialyzer reltool


%post
%_sbindir/update-alternatives --install %_bindir/%bname %bname %_bindir/%bname-otp 10

%preun
[ "$1" != 0 ] || %_sbindir/update-alternatives --remove %bname %_bindir/%bname-otp


%post static
%_sbindir/update-alternatives --install %_bindir/%bname %bname %_bindir/%bname-bundle 5

%preun static
[ "$1" != 0 ] || %_sbindir/update-alternatives --remove %bname %_bindir/%bname-bundle


%check
./rebar eunit


%files
%defattr(-,root,root)
%doc %_docdir/%name
%_bindir/%bname-otp
%_otplibdir/*
%_sysconfdir/bash_completion.d/*
%ghost %_bindir/%bname
%ghost %_sysconfdir/alternatives/*
%_rpmmacrosdir


%files static
%defattr(-,root,root)
%doc CONTRIBUTING* README* RELEASE-NOTES* THANKS*
%_bindir/%bname-bundle
%_bindir/%bname-static
%ghost %_bindir/%bname
%ghost %_sysconfdir/alternatives/*


%changelog
* Tue Jun 21 2016 Led <ledest@gmail.com> 2.6.1-12
- ignore requires of diameter

* Sat Jun 18 2016 Led <ledest@gmail.com> 2.6.1-11
- git f695144

* Sat May 14 2016 Led <ledest@gmail.com> 2.6.1-10
- git 9281b84
- remove patches:
  + rebar-2.6.1-find-deps-locally-first.patch
- add erlang-diameter to BuildRequires (for tests)
- add macro.rebar

* Mon Mar 21 2016 Led <ledest@gmail.com> 2.6.1-9
- ignore requires of reltool_server

* Mon Mar 21 2016 Led <ledest@gmail.com> 2.6.1-8
- remove rebar-reltool subpackage

* Thu Mar 17 2016 Led <ledest@gmail.com> 2.6.1-7
- add requires erl_interface
- change alternatives for compatibility

* Thu Mar 17 2016 Led <ledest@gmail.com> 2.6.1-6
- enable find deps locally first by default

* Mon Mar 07 2016 Led <ledest@gmail.com> 2.6.1-5
- don't remove rebar_reltool from rebar.app
- skip requires of dialyzer

* Mon Mar 07 2016 Led <ledest@gmail.com> 2.6.1-4
- add bash completion
- add patches:
  + rebar-2.6.1-find-deps-locally-first.patch

* Sun Jan 17 2016 Led <ledest@gmail.com> 2.6.1-3
- fix URL

* Mon Nov 30 2015 Led <ledest@gmail.com> 2.6.1-2
- update patches:
  + rebar-2.6.1-fix-link-drv.patch

* Tue Oct 20 2015 Led <ledest@gmail.com> 2.6.1-1
- 2.6.1
- update patches:
  + rebar-2.6.1-fix-link-drv.patch

* Sun Sep 27 2015 Led <ledest@gmail.com> 2.6.0-5
- fix build docs
- fix tests for Erlang 18.1

* Sat Jul 04 2015 Led <ledest@gmail.com> 2.6.0-4
- ignore requires of reltool app

* Fri Jun 26 2015 Led <ledest@gmail.com> 2.6.0-3
- fix test on Erlang 18

* Sun Jun 21 2015 Led <ledest@gmail.com> 2.6.0-2
- build docs
- ignore requires of eflame and gpb_compile modules

* Sat Jun 20 2015 Led <ledest@gmail.com> 2.6.0-1
- 2.6.0

* Sun May 31 2015 Led <ledest@gmail.com> 2.5.1-14
- remove rebar_reltool entry in rebar.app

* Sun Apr 12 2015 Led <ledest@gmail.com> 2.5.1-13
- update patches:
  + rebar-2.5.1-fix-link-drv.patch

* Sun Apr 12 2015 Led <ledest@gmail.com> 2.5.1-12
- cosmetic fixes

* Sun Apr 12 2015 Led <ledest@gmail.com> 2.5.1-11
- add patches:
  + rebar-2.5.1-fix-link-drv.patch

* Sun Apr 05 2015 Led <ledest@gmail.com> 2.5.1-10
- add erl_opts
- add %%check

* Sun Mar 22 2015 Led <ledest@gmail.com> 2.5.1-9
- use alternatives

* Sat Feb 21 2015 Led  <ledest@gmail.com> 2.5.1-8
- add rebar-reltool subpackage

* Thu Jan 29 2015 Led <ledest@gmail.com> 2.5.1-7
- ignore requires of protobuffs_compile module

* Thu Jan 29 2015 Led <ledest@gmail.com> 2.5.1-6
- ignore requires of neotoma module

* Thu Jan 29 2015 Led <ledest@gmail.com> 2.5.1-5
- ignore requires of lfe_comp module

* Thu Jan 29 2015 Led <ledest@gmail.com> 2.5.1-4
- ignore requires of erlydtl module

* Thu Jan 29 2015 Led <ledest@gmail.com> 2.5.1-3
- ignore requires of abnfc module

* Thu Jan 29 2015 Led <ledest@gmail.com> 2.5.1-2
- add %%name-static subpackage

* Fri Jan 16 2015 Led <ledest@gmail.com> 2.5.1-1
- 2.5.1
- fixed License
- updated BuildRequires
- updated Requires
- updated Provides

* Sat Mar 03 2012 Led <led@massivesolutions.co.uk> 2-2
- spec:
  + added Buildroot
  + updated BuildRequires

* Mon Feb 13 2012 Led <led@massivesolutions.co.uk> 2-1
- removed erlang-common_test from Requires

* Mon Feb 06 2012 Led <led@massivesolutions.co.uk> 2-0
- initial build for openSUSE
openSUSE Build Service is sponsored by