%define _build_id_links none
%global debug_package %{nil}

Name:           syft
Version:        1.19.0
Release:        1%{?dist}
Summary:        A CLI tool for generating SBOMs (Software Bill of Materials)

%global go_version 1.23.5

License:        Apache-2.0

URL:            https://github.com/anchore/%{name}/releases
Source0:        https://github.com/anchore/%{name}/archive/refs/tags/v%{version}.tar.gz

BuildRequires:  coreutils
BuildRequires:  make
BuildRequires:  git
BuildRequires:  gcc
BuildRequires:  wget

# Python 3.9 is not generally available for Redhat 8
%if 0%{?rhel} == 8
BuildRequires:  python39
%else
BuildRequires:  python3 >= 3.9
%endif

%description
Syft is a CLI tool and library for generating a Software Bill of Materials
(SBOM) from container images and filesystems.


%prep
%autosetup -c


%build
# Some architecture replacements (equal "replacements" included to remind myself that I didn't forget them)
ARCH=%{_arch}
ARCH=${ARCH/x86_64/amd64}
ARCH=${ARCH/aarch64/arm64}
ARCH=${ARCH/ppc64le/ppc64le}
ARCH=${ARCH/s390x/s390x}

# get current go version, which is required to build syft
wget -O go.tar.gz https://go.dev/dl/go%{go_version}.linux-${ARCH}.tar.gz
tar -xzf go.tar.gz
rm go.tar.gz
GOBIN=$(pwd)/go/bin/go

cd %{name}-%{version}

$GOBIN version
$GOBIN mod tidy
GOOS=linux GOARCH=$ARCH $GOBIN build -gcflags="all=-N -l" -o build/%{name} cmd/%{name}/main.go


%install
mkdir -p %{buildroot}/%{_bindir}
mkdir -p %{buildroot}%{_docdir}/%{name}

cd %{name}-%{version}

%{__install} -m 755 build/%{name} %{buildroot}/%{_bindir}/%{name}
%{__install} -m 644 LICENSE %{buildroot}%{_docdir}/%{name}/LICENSE
%{__install} -m 644 README.md %{buildroot}%{_docdir}/%{name}/README.md
%{buildroot}/%{_bindir}/%{name} help


%files
%{_bindir}/%{name}

%doc %{_docdir}/%{name}/README.md
%license %{_docdir}/%{name}/LICENSE


%changelog
* Thu Jan 23 2025 Christian Vonderstein <copr234@vonderste.in> - 1.19.0-1
- Initial packaging for Syft 1.19.0