%global commit 3149960f8acc8a87adac6722138d06527bb71230
%global gitdate 20190209
%global shortcommit %(c=%{commit}; echo ${c:0:7})

Name:      srelay
Version:   0.4.8p3
Release:   0.%{gitdate}.git%{shortcommit}%{?dist}.9sunshine
Summary:   A SOCKS 4/5 protocol proxy server

Group:     Utilities/System
# unknown
License:   GPLv2+
URL:       https://socks-relay.sourceforge.io/
# NAME=%%{name}; COMMIT=%%{commit}
# git clone git://git.code.sf.net/p/socks-relay/srelay $NAME
# (cd $NAME && git checkout $COMMIT)
# tar czvvpf $NAME-g$COMMIT.tar.gz $NAME
Source0:   %{name}-g%{commit}.tar.gz
# some warnings aren't supported by older gcc
Patch0:    srelay-0.4.8-no_extra_warnings.patch
# more platforms need to be accepted as Linux
Patch1:    srelay-linux-arm-s390.patch
# improve the man page
Patch2:    srelay-man.patch
# fix configure not defining a preprocessor
Patch3:    srelay-configure.patch

BuildRequires: gcc
# for Patch0:
BuildRequires: autoconf
%if 0%{?fedora} >= 12
# for Patch3, autoreconf
BuildRequires: automake
%endif

%description
Srelay is a socks 4/5 protocol proxy server. 
Supports socks connect/bind request in the protocol v4, v4a, and v5.
Supports socks server chaining with both v4 and v5 servers.
Supports Username/Password authentication in v5 (not recommended).
Supports IPv6 as well as IPv4.

%prep
%setup -q -n %{name}
%if 0%{?fedora} && 0%{?fedora} < 12
%patch -P 0 -p1 -b .no_extra_warnings
%endif
%patch -P 1 -p1 -b .arm
%patch -P 2 -p1 -b .man
%if 0%{?fedora} >= 12
%patch -P 3 -p1 -b .configure
%endif

%build
%if 0%{?fedora} >= 12
autoreconf
%endif
autoconf
%configure --without-libwrap
make %{?_smp_mflags}

%install
rm -rf %{buildroot}
install -d %{buildroot}%{_bindir}
install -p -m755 %{name} %{buildroot}%{_bindir}
install -d %{buildroot}%{_mandir}/man8
install -p -m644 %{name}.8 %{buildroot}%{_mandir}/man8

%files
%doc README Changes srelay.conf srelay.passwd
%{_bindir}/%{name}
%{_mandir}/man8/%{name}.8*

%changelog
* Thu Apr 20 2023 Moritz Barsnick <moritz+rpm@barsnick.net> 0.4.8p3-0.20190209.git688764b.9sunshine
- update patch to allow building on further architectures to s390, s390x

* Thu Apr 20 2023 Moritz Barsnick <moritz+rpm@barsnick.net> 0.4.8p3-0.20190209.git688764b.8sunshine
- apply warnings patch only on old Fedora
- add a patch for configure not properly finding some headers due to missing cpp
- use %%patch macro instead of %%patchN

* Thu Jun 18 2020 Moritz Barsnick <moritz+rpm@barsnick.net> 0.4.8p3-0.20190209.git688764b.7sunshine
- add a patch to improve the man page and fix paths in it

* Sun Apr 26 2020 Moritz Barsnick <moritz+rpm@barsnick.net> 0.4.8p3-0.20190209.git688764b.6sunshine
- add a patch to allow building on further architectures (notably Linux armv7, aarch64)

* Sun Apr 26 2020 Moritz Barsnick <moritz+rpm@barsnick.net> 0.4.8p3-0.20190209.git688764b.5sunshine
- avoid macros in comments (stupid newer rpmbuild feature)

* Sun Apr 26 2020 Moritz Barsnick <moritz+rpm@barsnick.net> 0.4.8p3-0.20190209.git688764b.4sunshine
- use newer git version from upstream, integrating my patch
- drop my patch for error reporting

* Thu Feb 07 2019 Moritz Barsnick <moritz+rpm@barsnick.net> 0.4.8p3-0.20181224.git688764b.3sunshine
- add a patch for better error reporting

* Tue Jan 15 2019 Moritz Barsnick <moritz+rpm@barsnick.net> 0.4.8p3-0.20181224.git688764b.2sunshine
- build without libwrap support, tcp_wrappers-devel is dropped in newer Fedoras

* Tue Jan 15 2019 Moritz Barsnick <moritz+rpm@barsnick.net> 0.4.8p3-0.git688764b.1sunshine
- initial RPM