%bcond_without check
%bcond_without staging
%bcond_without static

%global         libbuild2_load_version                  0.14.0-a.0.bbf3c05a0827
%global         libbuild2_kconfig_version               0.1.0
%global         libbuild2_kconfig_pkgrel                1

%if %{with staging}
%global         libbuild2_kconfig_datetime              20210108084836
%global         libbuild2_kconfig_short_revision        3687e4b95226
%global         libbuild2_kconfig_prerel                a.0.
%global         libbuild2_kconfig_snapshot              %{libbuild2_kconfig_prerel}%{libbuild2_kconfig_datetime}.%{libbuild2_kconfig_short_revision}
%global         libbuild2_kconfig_release               %{libbuild2_kconfig_pkgrel}.%{libbuild2_kconfig_snapshot}%{?dist}
%global         libbuild2_kconfig_version_snapshot      %{libbuild2_kconfig_version}-%{libbuild2_kconfig_snapshot}
%global         libbuild2_kconfig_version_prerel_rev    %{libbuild2_kconfig_version}-%{libbuild2_kconfig_prerel}%{libbuild2_kconfig_short_revision}
%else
%global         libbuild2_kconfig_release               %{libbuild2_kconfig_pkgrel}.%{?dist}
%global         libbuild2_kconfig_version_snapshot      %{libbuild2_kconfig_version}
%endif

Name:           libbuild2-kconfig
Version:        %{libbuild2_kconfig_version}
Release:        %{libbuild2_kconfig_release}
Summary:        Kconfig build system module for build2

License:        GPLv2
URL:            https://github.com/build2/libbuild2-kconfig
%if %{with staging}
Source0:        https://stage.build2.org/1/build2/%{name}-%{libbuild2_kconfig_version_snapshot}.tar.gz
Source1:        https://stage.build2.org/1/build2/%{name}-tests-%{libbuild2_kconfig_version_snapshot}.tar.gz
%else
Source0:        https://pkg.cppget.org/1/alpha/build2/%{name}-%{version}.tar.gz
Source1:        https://pkg.cppget.org/1/alpha/build2/%{name}-tests-%{version}.tar.gz
%endif

BuildRequires:  gcc-c++
BuildRequires:  build2
BuildRequires:  build2-rpm-macros
BuildRequires:  pkgconfig(libbuild2)

%description
Linux kernel configuration system (Kconfig) build system module for build2. For
details on Kconfig and its support in build2 see The build2 Kconfig Module. For
a complete example that demonstrates key features of Kconfig-based configuration
management see kconfig-hello.

%package -n     %{name}-doc
Summary:        %{name} documentation
BuildArch:      noarch

%description -n %{name}-doc
This package contains the %{name} documentation.

%package -n     %{name}-devel
Summary:        Development files for %{name} library
Requires:       %{name}%{?_isa} = %{version}-%{release}
Requires:       pkgconfig

%description -n %{name}-devel
The %{name}-devel package contains libraries and header files for
developing applications that use %{name}.

%if %{with static}
%package -n     %{name}-static
Summary:        Static libraries for %{name} library
Requires:       %{name}-devel%{?_isa} = %{version}-%{release}

%description -n %{name}-static
The %{name}-static package contains static libraries for developing
applications that use %{name}.
%endif

%prep
%setup -q -c -n %{name}-%{version} -a 1

%build
%build2                                                                                 \
  %{name}-%{libbuild2_kconfig_version_snapshot}/                                        \
  %{name}-tests-%{libbuild2_kconfig_version_snapshot}/                                  \
%if %{with static}
  config.bin.lib=both                                                                   \
%endif
  '!config.import.libbuild2_kconfig=%{name}-%{libbuild2_kconfig_version_snapshot}/'

%install
%build2_install %{name}-%{libbuild2_kconfig_version_snapshot}/                          \
%if %{with static}
  config.bin.lib=both
%endif

%check
%if %{with check}
export LD_LIBRARY_PATH=$PWD/%{name}-%{libbuild2_kconfig_version_snapshot}/libbuild2/kconfig:${LD_LIBRARY_PATH}
%build2_test %{name}-tests-%{libbuild2_kconfig_version_snapshot}/
%endif

%files
%dir %{_defaultlicensedir}/%{name}
%license %{_defaultlicensedir}/%{name}/AUTHORS
%license %{_defaultlicensedir}/%{name}/COPYRIGHT
%license %{_defaultlicensedir}/%{name}/LICENSE
%{_libdir}/%{name}-%{libbuild2_load_version}-%{libbuild2_kconfig_version_prerel_rev}.so

%files -n       %{name}-doc
%dir %{_docdir}/%{name}
%doc %{_docdir}/%{name}/README.md
%doc %{_docdir}/%{name}/build2-kconfig-manual.xhtml
%doc %{_docdir}/%{name}/manifest

%files -n       %{name}-devel
%{_includedir}/libbuild2/kconfig
%{_libdir}/%{name}{,-%{libbuild2_load_version}}.so
%{_libdir}/pkgconfig/%{name}{,.shared}.pc

%if %{with static}
%files -n       %{name}-static
%{_libdir}/%{name}.a
%{_libdir}/pkgconfig/%{name}.static.pc
%endif

%changelog
* Wed Jan 20 2021 Matthew Krupcale <mkrupcale@matthewkrupcale.com> - 0.1.0-1
- Initial package