## START: Set by rpmautospec
## (rpmautospec version 0.3.0)
%define autorelease(e:s:pb:n) %{?-p:0.}%{lua:
    release_number = 33;
    base_release_number = tonumber(rpm.expand("%{?-b*}%{!?-b:1}"));
    print(release_number + base_release_number - 1);
}%{?-e:.%{-e*}}%{?-s:.%{-s*}}%{!?-n:%{?dist}}
## END: Set by rpmautospec

# Generated by go2rpm
%bcond_without check

%global min_llvm 14
%if %{fedora} >= 37
%global max_llvm 15
%else
%global max_llvm 14
%endif

# https://github.com/tinygo-org/go-llvm
%global goipath         tinygo.org/x/go-llvm
%global forgeurl        https://github.com/tinygo-org/go-llvm
%global commit          dcb078a262665943160fa7b6a8dd219c2e2fc990

%gometa

%global common_description %{expand:
This library provides bindings to a system-installed LLVM.}

%global golicenses      LICENSE.txt
%global godocs          README.markdown

Name:           %{goname}
Version:        0
Release:        %autorelease -p
Summary:        Go bindings to a system-installed LLVM

License:        ASL 2.0 and NCSA
URL:            %{gourl}
Source0:        %{gosource}
# Fedora specific
Patch0001:      0001-Make-LLVM-config-file-architecture-independent.patch

BuildRequires:  gcc-c++
BuildRequires:  make
%{lua:
local llvm_supported_versions = 'llvm_supported_versions'
for version=tonumber(rpm.expand('%min_llvm')),tonumber(rpm.expand('%max_llvm')) do
  print('BuildRequires: llvm-devel(major) = ' .. version .. '\n')
  llvm_supported_versions = llvm_supported_versions .. ' ' .. version
end
rpm.define(llvm_supported_versions)
}

%description
%{common_description}

%gopkg

%prep
%goprep
%autopatch -p1

# Set current LLVM paths.
rm llvm_config*.go
for version in %{llvm_supported_versions}; do
    # Extra checks because of https://bugzilla.redhat.com/show_bug.cgi?id=1871659
    if type llvm-config-${version}-%{__isa_bits}; then
        make config VERSION=${version}.0.0 CONFIG=llvm-config-${version}-%{__isa_bits} BUILDDIR=%{_prefix}
    elif type llvm-config-${version}; then
        make config VERSION=${version}.0.0 CONFIG=llvm-config-${version} BUILDDIR=%{_prefix}
    elif type llvm-config-%{__isa_bits}; then
        make config VERSION=${version}.0.0 CONFIG=llvm-config-%{__isa_bits} BUILDDIR=%{_prefix}
    elif type llvm-config; then
        make config VERSION=${version}.0.0 CONFIG=llvm-config BUILDDIR=%{_prefix}
    else
        echo "Unable to determine llvm-config for LLVM ${version}"
        exit 1
    fi
    mv llvm_config_linux.go llvm_config_linux_llvm${version}.go
done

%install
%gopkginstall

%if %{with check}
%global gotestflags %gocompilerflags -tags="${TAGS}"
%check
for version in %{llvm_supported_versions}; do
export TAGS=llvm${version}
%gocheck
done
%endif

%gopkgfiles

%changelog
* Mon Oct 24 2022 Elliott Sales de Andrade <quantum.analyst@gmail.com> 0-0.33
- Update to commit dcb078a262665943160fa7b6a8dd219c2e2fc990

* Sun Aug 07 2022 Elliott Sales de Andrade <quantum.analyst@gmail.com> 0-0.31
- Update to commit 86e76bb02d386095f0c0cb9edde38bc01903d916

* Sat May 07 2022 Elliott Sales de Andrade <quantum.analyst@gmail.com> 0-0.30
- Update to commit supporting LLVM 14

* Thu Jan 20 2022 Fedora Release Engineering <releng@fedoraproject.org> 0-0.29
- Rebuilt for https://fedoraproject.org/wiki/Fedora_36_Mass_Rebuild

* Tue Jan 04 2022 Elliott Sales de Andrade <quantum.analyst@gmail.com> 0-0.28
- Update to latest commit

* Tue Sep 07 2021 Elliott Sales de Andrade <quantum.analyst@gmail.com> 0-0.27
- Make LLVM config file architecture independent

* Mon Sep 06 2021 Elliott Sales de Andrade <quantum.analyst@gmail.com> 0-0.26
- Add support for LLVM 13

* Mon Sep 06 2021 Elliott Sales de Andrade <quantum.analyst@gmail.com> 0-0.25
- Fully test against all supported LLVM

* Mon Aug 02 2021 Elliott Sales de Andrade <quantum.analyst@gmail.com> 0-0.24
- Build with LLVM 12.

* Mon Aug 02 2021 Elliott Sales de Andrade <quantum.analyst@gmail.com> 0-0.23
- Update to commit e7b85195e81cf864a886c203c928997658c6f83a

* Thu Jul 22 2021 Fedora Release Engineering <releng@fedoraproject.org> - 0-0.17.20201119git570e7a6
- Rebuilt for https://fedoraproject.org/wiki/Fedora_35_Mass_Rebuild

* Tue Jan 26 2021 Fedora Release Engineering <releng@fedoraproject.org> - 0-0.16.20201119git570e7a6
- Rebuilt for https://fedoraproject.org/wiki/Fedora_34_Mass_Rebuild

* Thu Nov 19 2020 Elliott Sales de Andrade <quantum.analyst@gmail.com> - 0-0.15.20201119git570e7a6
- Update to 570e7a6841d9b3ae1c357ac08ff38fe43b55e9c3
- Drop compatibility with EOL Fedora 31

* Sat Sep 19 2020 Elliott Sales de Andrade <quantum.analyst@gmail.com> - 0-0.14.20200919git70c5585
- Switch to llvm11 branch

* Sun Aug 23 2020 Elliott Sales de Andrade <quantum.analyst@gmail.com> - 0-0.13.20200818git345b294
- Simplify LLVM dependency

* Tue Aug 18 2020 Elliott Sales de Andrade <quantum.analyst@gmail.com> - 0-0.12.20200818git345b294
- Update to latest commit

* Tue Jul 28 2020 Fedora Release Engineering <releng@fedoraproject.org> - 0-0.11.20200419git8d12088
- Rebuilt for https://fedoraproject.org/wiki/Fedora_33_Mass_Rebuild

* Sun Apr 19 2020 Elliott Sales de Andrade <quantum.analyst@gmail.com> - 0-0.10.20200419git8d12088
- Update to latest commit

* Tue Feb 11 2020 Elliott Sales de Andrade <quantum.analyst@gmail.com> - 0-0.9.20200207git1ff21df
- Add support for LLVM 10

* Fri Feb 07 2020 Elliott Sales de Andrade <quantum.analyst@gmail.com> - 0-0.8.20200207git1ff21df
- Update to latest commit

* Wed Jan 29 2020 Fedora Release Engineering <releng@fedoraproject.org> - 0-0.7.20190925git95bc4ff
- Rebuilt for https://fedoraproject.org/wiki/Fedora_32_Mass_Rebuild

* Wed Sep 25 2019 Elliott Sales de Andrade <quantum.analyst@gmail.com> - 0-0.6.20190925git95bc4ff
- Update to latest commit

* Thu Jul 25 2019 Fedora Release Engineering <releng@fedoraproject.org> - 0-0.5.20190604git0713e35
- Rebuilt for https://fedoraproject.org/wiki/Fedora_31_Mass_Rebuild

* Thu Jul 04 01:54:04 CEST 2019 Robert-André Mauchin <zebob.m@gmail.com> - 0-0.4.20190604git0713e35
- Update to new macros

* Fri Jun 07 2019 Elliott Sales de Andrade <quantum.analyst@gmail.com> - 0-0.3.20190604git0713e35
- Update to latest commit
- Add gcc-c++ to Requires

* Sat Apr 27 2019 Elliott Sales de Andrade <quantum.analyst@gmail.com> - 0-0.2.20190427git7707ae5
- Add llvm-devel to Requires

* Thu Apr 18 2019 Elliott Sales de Andrade <quantum.analyst@gmail.com> - 0-0.1.20190427git7707ae5
- First package for Fedora