## START: Set by rpmautospec
## (rpmautospec version 0.3.0)
%define autorelease(e:s:pb:n) %{?-p:0.}%{lua:
    release_number = 2;
    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

# see https://luarocks.org/modules/siffiejoe/bit32/5.3.5-1
%global srcname lua-compat-5.3
%global srcver 0.10

%global lua_pkg_name bit32

%global lua51_version 5.1
%global lua51_libdir %{_libdir}/lua/%{lua51_version}
%global lua51_pkgdir %{_datadir}/lua/%{lua51_version}
%global lua51_builddir %{_builddir}/lua%{lua51_version}-%{lua_pkg_name}-%{version}-%{release}

Name:           lua-%{lua_pkg_name}
Version:        5.3.5.1
Release:        %autorelease
Summary:        Lua bit manipulation library

License:        MIT
URL:            https://luarocks.org/modules/siffiejoe/bit32
Source0:        https://github.com/keplerproject/%{srcname}/archive/v%{srcver}.tar.gz#/%{srcname}-%{srcver}.tar.gz

BuildRequires:  gcc
BuildRequires:  lua-devel >= 5.1
BuildRequires:  compat-lua-devel >= %{lua51_version}

%if 0%{?rhel} < 9
Requires:       lua(abi) = %{lua_version}
%endif

%global _description %{expand:
bit32 is a bit manipulation library, in the version from Lua
5.3; it is compatible with Lua 5.1 to 5.4.}

%description %{_description}

%package -n lua%{lua51_version}-%{lua_pkg_name}
Summary:        Lua 5.2 bit manipulation library
Provides:       compat-%{name}
Requires:       lua(abi) = %{lua51_version}

%description -n lua%{lua51_version}-%{lua_pkg_name} %{_description}


%prep
%autosetup -n %{srcname}-%{srcver}


%build
gcc %{optflags} $(pkg-config --cflags lua) -I./c-api -DLUA_COMPAT_BITLIB \
    lbitlib.c \
    -shared -fPIC -o lua-bit32.so $(pkg-config --libs lua)

gcc %{optflags} $(pkg-config --cflags lua-5.1) -I./c-api -DLUA_COMPAT_BITLIB \
    lbitlib.c \
    -shared -fPIC -o compat-lua-bit32.so $(pkg-config --libs lua-5.1)


%install
install -d -m 0755 %{buildroot}%{lua_libdir}
install -m 0755 lua-bit32.so %{buildroot}%{lua_libdir}/bit32.so

install -d -m 0755 %{buildroot}%{lua51_libdir}
install -m 0755 compat-lua-bit32.so %{buildroot}%{lua51_libdir}/bit32.so


%files
%license LICENSE
# README.md doesn't mention bit32
%{lua_libdir}/bit32.so

%files -n lua%{lua51_version}-%{lua_pkg_name}
%{lua51_libdir}/bit32.so


%changelog
* Thu Jul 21 2022 Fedora Release Engineering <releng@fedoraproject.org> 5.3.5.1-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_37_Mass_Rebuild

* Wed Mar 16 2022 Michel Alexandre Salim <salimma@fedoraproject.org> 5.3.5.1-1
- Update to 5.3.5.1

* Wed Mar 16 2022 Michel Alexandre Salim <salimma@fedoraproject.org> - 5.3.5-7
- Use lua macros
- Convert to rpmautospec

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

* Thu Jul 22 2021 Andreas Schneider <asn@redhat.com> - 5.3.5-4
- Also lua5.1-bit32 for neovim

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

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

* Mon Aug 31 2020 Michel Alexandre Salim <salimma@fedoraproject.org> - 5.3.5-1-1
- Update to 5.3.5

* Wed May 10 2017 Michel Alexandre Salim <salimma@fedoraproject.org> - 5.3.0-2
- Remove defattr

* Mon May 08 2017 Michel Alexandre Salim <salimma@fedoraproject.org> - 5.3.0-1
- Initial package