# Generated by go2rpm 1.9.0
%bcond_without check

%global libsofedbasever 0.n
%global libsomajor 1
%global libsoversion %{libsofedbasever}.%{libsomajor}

# https://github.com/SUSE/connect-ng
%global goipath         github.com/SUSE/connect-ng
Version:                1.4.0

%gometa -f


%global common_description %{expand:
SUSEConnect is a command line tool for connecting a client system
to the SUSE Customer Center. It will connect the system to your
product subscriptions and enable the product repositories/services
locally.}

%global golicenses      LICENSE LICENSE.LGPL
%global godocs          DIFFERENCES.md README.md\\\
                        man/SUSEConnect.5.md man/SUSEConnect.8.md\\\
                        suseconnect/migrationUsage.txt\\\
                        suseconnect/searchPackagesUsage.txt\\\
                        suseconnect/connectUsage.txt

Name:           suseconnect-ng
Release:        3%{?dist}
Summary:        Utility to register a system with the SUSE Customer Center

License:        LGPL-2.1-or-later
URL:            %{gourl}
Source:         %{gosource}

# Fix tests
## From: https://github.com/SUSE/connect-ng/pull/189
Patch:          suseconnect-ng-PR189.patch

BuildRequires:  go-rpm-macros
BuildRequires:  systemd-rpm-macros
# Original name
Provides:       SUSEConnect = %{version}-%{release}
# Alternative name
Provides:       SUSEConnect-ng = %{version}-%{release}

%description %{common_description}

%package -n libsuseconnect
Summary:        Library to interface with the SUSE Customer Center

%description -n libsuseconnect %{common_description}
This package provides the library for applications to
interface with the SUSE Customer Center.

%package -n libsuseconnect-devel
Summary:        Development files to use libsuseconnect
Requires:       libsuseconnect%{?_isa} = %{version}-%{release}

%description -n libsuseconnect-devel %{common_description}
This package provides the development files for applications
to use the library to interface with the SUSE Customer Center.

%gopkg

%prep
%goprep
%autopatch -p1
echo "%{version}-%{release}" > internal/connect/version.txt

%generate_buildrequires
%go_generate_buildrequires

%build
# build the library
for cmd in libsuseconnect; do
  %define gocompilerflags -buildmode=c-shared -compiler gc
  %define __golang_extldflags -Wl,-soname,$(basename $cmd).so.%{libsoversion}
  %gobuild -o %{gobuilddir}/lib/$(basename $cmd).so.%{libsoversion} %{goipath}/$cmd
  ln -sr %{gobuilddir}/lib/$(basename $cmd).so.%{libsoversion} %{gobuilddir}/lib/$(basename $cmd).so
  mv %{gobuilddir}/lib/$(basename $cmd).so.%{libsofedbasever}.h %{gobuilddir}/lib/$(basename $cmd).h
done
# build the binary
for cmd in suseconnect; do
  %define gocompilerflags -buildmode=pie -compiler gc
  %define __golang_extldflags %{nil}
  %gobuild -o %{gobuilddir}/bin/$(basename $cmd) %{goipath}/$cmd
done

# Set up aliases
ln -sr %{gobuilddir}/bin/suseconnect %{gobuilddir}/bin/SUSEConnect

%install
%gopkginstall
# binaries
install -m 0755 -vd                       %{buildroot}%{_bindir}
cp -av %{gobuilddir}/bin/*                %{buildroot}%{_bindir}/
# libraries
install -m 0755 -vd                       %{buildroot}%{_libdir}
cp -av %{gobuilddir}/lib/*.so*            %{buildroot}%{_libdir}/
# headers
install -m 0755 -vd                       %{buildroot}%{_includedir}
install -m 0644 -vp %{gobuilddir}/lib/*.h %{buildroot}%{_includedir}/
# systemd units
install -m 0755 -vd                       %{buildroot}%{_unitdir}
install -m 0644 -vp *.service *.timer     %{buildroot}%{_unitdir}/



%if %{with check}
%check
%gocheck
%endif

%post
%systemd_post suseconnect-keepalive.timer

%preun
%systemd_preun suseconnect-keepalive.timer

%postun
%systemd_postun_with_restart suseconnect-keepalive.timer

%files
%license LICENSE LICENSE.LGPL
%doc DIFFERENCES.md README.md man/SUSEConnect.5.md
%doc man/SUSEConnect.8.md
%doc suseconnect/migrationUsage.txt suseconnect/searchPackagesUsage.txt
%doc suseconnect/connectUsage.txt
%{_bindir}/suseconnect
%{_bindir}/SUSEConnect
%{_unitdir}/suseconnect-keepalive.*

%files -n libsuseconnect
%license LICENSE LICENSE.LGPL
%{_libdir}/libsuseconnect.so.%{libsoversion}

%files -n libsuseconnect-devel
%{_libdir}/libsuseconnect.so
%{_includedir}/libsuseconnect.h

%gopkgfiles

%changelog
* Sat Jan 27 2024 Fedora Release Engineering <releng@fedoraproject.org> - 1.4.0-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild

* Mon Oct 16 2023 Neal Gompa <ngompa@fedoraproject.org> - 1.4.0-2
- Fix compiled in soname for library

* Thu Oct 12 2023 Neal Gompa <ngompa@opensuse.org> - 1.4.0-1
- Update to 1.4.0

* Fri Sep 29 2023 Neal Gompa <ngompa@opensuse.org> - 1.3.0-1
- Initial package