File cowboy1.spec of Package cowboy1

%def_with doc

%define oname cowboy
%define bname %{oname}1
Name: %bname
Version: 1.2.3
Release: 1
Summary: Small, fast and modular HTTP server written in Erlang
License: ISC
Group: Development/Tools/Other
#URL: https://github.com/ninenines/%oname
URL: https://github.com/Ledest/%oname
Source0: %oname-%version.tar.xz
Source1: %{bname}_pt.erl
BuildArch: noarch
Provides: erlang-%bname = %version-%release

BuildRequires: rpm-macros-erlang rpm-build-erlang >= 0.9.9
BuildRequires: erlang erlang-otp-base-devel
BuildRequires: erlang-cowlib-devel >= 2.0.0
BuildRequires: fdupes
%if_with doc
# docs
BuildRequires: erlang-edoc erlang-ezdoc
%endif

%description
Cowboy is a small, fast and modular HTTP server written in Erlang.
Cowboy aims to provide a complete HTTP stack in a small code base. It is
optimized for low latency and low memory usage, in part because it uses binary
strings.
Cowboy provides routing capabilities, selectively dispatching requests to
handlers written in Erlang.
Because it uses Ranch for managing connections, Cowboy can easily be embedded in
any other application.
No process dictionary. Clean Erlang code.


%package devel
Summary: Behaviour modules of %bname
Group: Development/Tools/Other
Provides: erlang-%bname-devel = %version-%release

%description devel
Cowboy is a small, fast and modular HTTP server written in Erlang.
Cowboy aims to provide a complete HTTP stack in a small code base. It is
optimized for low latency and low memory usage, in part because it uses binary
strings.
This package contains behaviour modules of %bname.


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

%description doc
Cowboy is a small, fast and modular HTTP server written in Erlang.
Cowboy aims to provide a complete HTTP stack in a small code base. It is
optimized for low latency and low memory usage, in part because it uses binary
strings.
This package contains documentation of %bname.


%prep
%setup -q -n %oname-%version
sed -i 's/\r$//' examples/websocket/priv/static/jquery.min.js
sed -i '/^docs:/s/ build-doc-deps//' Makefile
sed -i 's/cowboy/&1/g' Makefile
sed -i 's/cowboy/&1/g' doc/src/*/*.ezdoc

cd doc/src/manual
for i in %{oname}*; do
	mv $i %bname${i#%oname}
done
cd - > /dev/null

cd src
for i in *.erl *.app.src; do
	mv $i %bname${i#%oname}
done
cd -

erl -noshell -eval '
F = fun(X) ->
        case atom_to_list(X) of
            "%oname" ++ T -> list_to_atom("%bname" ++ T);
            _ -> X
        end
    end,
{ok, [{application, %oname, L}]} = file:consult("src/%bname.app.src"),
file:write_file("src/%bname.app.src",
                io_lib:format("{application, %bname, ~81p}.~n",
                              [lists:map(fun({registered, [_|_] = Ms}) ->
                                             {registered, lists:map(fun(M) when is_atom(M) -> F(M);
                                                                       (M) -> M
                                                                    end, Ms)};
                                            ({mod, {M, A}}) -> {mod, {F(M), A}};
                                            (E) -> E
                                         end, L)]),
                [raw]),
init:stop().'


%build
install -d -m 0755 ebin
%__erlc -o ebin -Werror +debug_info +warn_export_all +warn_export_vars +warn_shadow_vars +warn_obsolete_guard +inline %{S:1}
make %{?_smp_mflags} SKIP_DEPS=1 \
	ERL_COMPILER_OPTIONS="[{parse_transform,%{bname}_pt},no_error_module_mismatch,inline,verbose%{?cowboy_websocket_compress_level:,{d,'WS_COMPRESS_LEVEL',%cowboy_websocket_compress_level}}]" \
	EDOC_OPTS="{preprocess, true}" \
	V=1 all %{?_with_doc:docs}
erl -noshell -eval '
{ok, [{application, %bname, L}]} = file:consult("ebin/%bname.app"),
{_, Ms} = lists:keyfind(modules, 1, L),
file:write_file("ebin/%bname.app",
                io_lib:format("{application, %bname, ~81p}.~n",
                              [lists:keystore(modules, 1, L, {modules, lists:delete(%{bname}_pt, Ms)})]),
                [raw]),
init:stop().'


%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%_docdir/%name
install -p -m 0644 AUTHORS *.md %buildroot%_docdir/%name/
cp -a examples %buildroot%_docdir/%name/
%if_with doc
install -d -m 0755 %buildroot%_docdir/%name/guide %buildroot%_docdir/%name/manual
install -p -m 0644 doc/markdown/guide/* %buildroot%_docdir/%name/guide/
install -p -m 0644 doc/markdown/manual/* %buildroot%_docdir/%name/manual/
install -d -m 0755 %buildroot%_mandir/man3 %buildroot%_mandir/man7
install -p -m 0644 doc/man3/* %buildroot%_mandir/man3/
install -p -m 0644 doc/man7/* %buildroot%_mandir/man7/
%endif

erl -noshell -eval '
lists:foreach(fun(F) ->
                  {ok, {M, [{exports, Fs}]}} = beam_lib:chunks(F, [exports]),
                  lists:sort(Fs) =:= [{behaviour_info, 1}, {module_info, 0}, {module_info, 1}] andalso
                      io:fwrite("%_otplibdir/%bname-%version/ebin/~s.beam~n", [M])
              end, filelib:wildcard("./ebin/*.beam")),
init:stop().' | tee behaviours.list | sed 's/^/%%exclude /' > behaviours-exclude.list
[ -s behaviours.list ] && sed -i '1i%%dir %_otplibdir/%bname-%version/ebin' behaviours.list ||:

%fdupes %buildroot%_docdir/%name/examples


%files -f behaviours-exclude.list
%defattr(-,root,root)
%_otplibdir/*
%exclude %_otplibdir/*/ebin/%{bname}_pt.beam


%files -f behaviours.list devel
%defattr(-,root,root)
%dir %_otplibdir/%bname-*
%_otplibdir/*/ebin/%{bname}_pt.beam


%files doc
%defattr(-,root,root)
%doc %_docdir/%name
%if_with doc
%_mandir/man3/*
%_mandir/man7/*
%endif


%changelog
* Sun Jul 09 2023 Led <ledest@gmail.com> 1.2.3-1
- rename to cowboy1
- add cowboy1_pt

* Sat Aug 21 2021 Led <ledest@gmail.com> 1.2.3-1
- 1.2.3

* Tue Nov 12 2019 Led <ledest@gmail.com> 1.2.2-1
- 1.2.2

* Sat Aug 10 2019 Led <ledest@gmail.com> 1.2.1-1
- 1.2.1
- update URL
- remove patches
- clean up %%build

* Tue Aug 06 2019 Led <ledest@gmail.com> 1.1.2-22
- update patches:
  + 0011-Use-cow_ws-for-the-Websocket-parsing-code.patch
- revert behaviour-only to cowboy.app's modules

* Thu Jul 25 2019 Led <ledest@gmail.com> 1.1.2-21
- clean up %%files

* Tue Jul 23 2019 Led <ledest@gmail.com> 1.1.2-20
- generate behaviour-only module list

* Tue Jul 23 2019 Led <ledest@gmail.com> 1.1.2-19
- remove optional alternate cowboy_websocket module

* Fri Jul 05 2019 Led <ledest@gmail.com> 1.1.2-18
- remove cow_uri module (already in cowlib >= 2.0.0-pre.1)
- update BuildRequires

* Mon Jul 01 2019 Led <ledest@gmail.com> 1.1.2-17
- add patches:
  + cowboy-1.1.2-stacktrace.patch

* Sun Jun 30 2019 Led <ledest@gmail.com> 1.1.2-16
- add patches:
  + cowboy_websocket-get-compress-level-from-env.patch
- update patches:
  + cowboy-1.1.2-ws-compress-level.patch

* Sat Jun 29 2019 Led <ledest@gmail.com> 1.1.2-15
- add patches:
  + cowboy_websocket-update-extensions-definition-in-state-record.patch

* Sat Jun 29 2019 Led <ledest@gmail.com> 1.1.2-14
- add patches:
  + 0012-Update-Cowlib-to-1.2.0-adds-Websocket-permessage-def.patch
- update patches:
  + cowboy-1.1.2-ws-compress-level.patch

* Sat Jun 29 2019 Led <ledest@gmail.com> 1.1.2-13
- fix Group for doc subpackage
- add patches:
  + 0011-Use-cow_ws-for-the-Websocket-parsing-code.patch
- update patches:
  + cowboy-1.1.2-ws-compress-level.patch

* Sat Jun 29 2019 Led <ledest@gmail.com> 1.1.2-12
- revert cowboy_websocket.erl

* Sat Jun 29 2019 Led <ledest@gmail.com> 1.1.2-11
- add patches:
  + 0001-Use-cowlib-master.patch
- update BuildRequires
- remove cowboy_websocket.erl

* Mon Dec 17 2018 Led <ledest@gmail.com> 1.1.2-10
- add patches:
  + cowboy-1.1.2-ws-compress-level.patch

* Mon Dec 17 2018 Led <ledest@gmail.com> 1.1.2-9
- update cowboy_websocket.erl

* Sun Dec 16 2018 Led <ledest@gmail.com> 1.1.2-8
- add cowboy_websocket.erl
- without alt_ws

* Sun Dec 16 2018 Led <ledest@gmail.com> 1.1.2-7
- move behaviour modules to devel subpackage

* Sun Dec 16 2018 Led <ledest@gmail.com> 1.1.2-6
- remove patches:
  + 0001-Use-cowlib-master.patch
  + 0011-Use-cow_ws-for-the-Websocket-parsing-code.patch
  + 0012-Adds-Websocket-permessage-deflate.patch
- add Provides

* Sat Dec 15 2018 Led <ledest@gmail.com> 1.1.2-5
- add patches:
  + 0011-Use-cow_ws-for-the-Websocket-parsing-code.patch
  + 0012-Adds-Websocket-permessage-deflate.patch

* Sat Dec 15 2018 Led <ledest@gmail.com> 1.1.2-4
- remove patches:
  + cowboy-1.1.2-cowlib-compat.patch
- add patches:
  + 0001-Use-cowlib-master.patch

* Sat Dec 15 2018 Led <ledest@gmail.com> 1.1.2-3
- add patches:
  + cowboy-1.1.2-cowlib-compat.patch
- update BuildRequires

* Tue Aug 21 2018 Led <ledest@gmail.com> 1.1.2-2
- update %%build

* Thu Oct 12 2017 Led <ledest@gmail.com> 1.1.2-1
- 1.1.2
- remove patches:
  + cowboy-1.0.3-integer_to_binary.patch
- fix License
- add doc subpackage

* Fri Aug 25 2017 Led <ledest@gmail.com> 1.0.4-4
- remove slim option

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

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

* Sun Nov 29 2015 Led <ledest@gmail.com> 1.0.4-1
- 1.0.4

* Sun Sep 27 2015 Led <ledest@gmail.com> 1.0.3-2
- fix build on Erlang R15
- add patches:
  + cowboy-1.0.3-integer_to_binary.patch

* Sun Aug 09 2015 Led <ledest@gmail.com> 1.0.3-1
- 1.0.3

* Sat Jul 04 2015 Led <ledest@gmail.com> 1.0.2-2
- fix BuildRequires

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

* Mon Apr 13 2015 Led <ledest@gmail.com> 1.0.1-4
- update BuildRequires

* Sun Apr 12 2015 Led <ledest@gmail.com> 1.0.1-3
- clean up BuildRequires

* Wed Apr 01 2015 Led <ledest@gmail.com> 1.0.1-2
- build docs

* Wed Apr 01 2015 Led <ledest@gmail.com> 1.0.1-1
- initial build
openSUSE Build Service is sponsored by