File fluent-bit.spec of Package fluent-bit

%define realname fluent-bit
%define realver  3.2.6
%define srcext   tar.gz

%bcond_without ninja
%bcond_with postgres

# turn off the generation of debuginfo rpm  (RH9) ??
%global debug_package %{nil}

# Common info
Name:          %{realname}
Version:       %{realver}
Release:       wiz%{?extraver:0.}1%{?dist}
License:       Apache-2.0
Group:         System/Monitoring
URL:           https://fluentbit.io/
Summary:       Fast and Lightweight Logs and Metrics processor

# Build-time parameters
BuildRequires: gcc-c++
BuildRequires: cmake >= 3.12
BuildRequires: pkg-config
%if %{with ninja}
BuildRequires: ninja
%endif
BuildRequires: pkgconfig(libsystemd) pkgconfig(systemd)
BuildRequires: flex bison
BuildRequires: pkgconfig(libnghttp2) >= 1.0.0
BuildRequires: pkgconfig(libcares) >= 1.18.0
BuildRequires: pkgconfig(libevent)
BuildRequires: pkgconfig(openssl)
BuildRequires: pkgconfig(jemalloc) >= 5.0.0
BuildRequires: pkgconfig(libsasl2)
BuildRequires: pkgconfig(zlib)
BuildRequires: pkgconfig(yaml-0.1)
BuildRequires: pkgconfig(jansson)
BuildRequires: pkgconfig(libxml-2.0)
### BuildRequires: pkgconfig(luajit) >= 2.1.0
%if %{with postgres}
BuildRequires: pkgconfig(libpq)
%endif
BuildRequires: pkgconfig(libedit)
Source0:       https://codeload.github.com/fluent/fluent-bit/%{srcext}/refs/tags/v%{realver}#/%{realname}-%{realver}%{?extraver}.%{srcext}

%description
Fluent Bit is a fast Log Processor and Forwarder for Linux, Windows, Embedded
Linux, MacOS and BSD family operating systems. It's part of the Graduated
Fluentd Ecosystem and a CNCF sub-project.

Fluent Bit allows to collect log events or metrics from different sources,
process them and deliver them to different backends such as Fluentd,
Elasticsearch, Splunk, DataDog, Kafka, New Relic, Azure services, AWS services,
Google services, NATS, InfluxDB or any custom HTTP end-point.

Fluent Bit comes with full SQL Stream Processing capabilities: data manipulation
and analytics using SQL queries.

%package devel
License:       Apache-2.0
Group:         Development/Languages/C and C++
Summary:       Developent stuff for %{name}
Requires:      %{name} = %{version}-%{release}

%description devel
Fluent Bit is a fast Log Processor and Forwarder.

This package contains developent stuff for %{name}.

# Preparation step (unpackung and patching if necessary)
%prep
%setup -q -n %{realname}-%{realver}%{?extraver}

%build
_CFLAGS='%{optflags} %{?gcc_lto} -D_GNU_SOURCE'
_LDFLAGS='-Wl,--as-needed -Wl,--strip-all -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,now -Wl,-z,relro %{?gcc_lto}'
cmake -B build -S . \
%if %{with ninja}
 -G Ninja \
%endif
 -Wno-dev \
 -DCMAKE_INSTALL_PREFIX=%{_prefix} \
 -DCMAKE_INSTALL_LIBDIR=%{_libdir} \
 -DCMAKE_INSTALL_SYSCONFDIR=%{_sysconfdir} \
 -DCMAKE_BUILD_TYPE=Release \
 -DCMAKE_C_FLAGS_RELEASE="$_CFLAGS" \
 -DCMAKE_CXX_FLAGS_RELEASE="$_CFLAGS" \
 -DCMAKE_EXE_LINKER_FLAGS_RELEASE="$_LDFLAGS" \
 -DCMAKE_MODULE_LINKER_FLAGS_RELEASE="$_LDFLAGS" \
 -DCMAKE_SHARED_LINKER_FLAGS_RELEASE="$_LDFLAGS" \
 -DCMAKE_SKIP_RPATH=YES \
 -DCMAKE_VERBOSE_MAKEFILE=YES \
 \
 -DFLB_DEBUG=NO \
 -DFLB_RELEASE=YES \
 -DFLB_IPO=YES \
 \
 -DFLB_JEMALLOC=YES \
 -DFLB_TLS=YES \
 -DFLB_EXAMPLES=NO \
 -DFLB_SHARED_LIB=NO \
 -DFLB_WASM=NO \
 \
 -DFLB_PREFER_SYSTEM_LIBS=YES \
 \
 -DFLB_IN_UNIX_SOCKET=YES \
 -DFLB_OUT_CLOUDWATCH_LOGS=NO \
 \
 -DFLB_EVENT_LOOP_LIBEVENT=YES \
%if %{with postgres}
 -DFLB_OUT_PGSQL=YES \
%endif
 \
 -DFLB_GIT_HASH=v%{version}
%if %{with ninja}
ninja -C build -v %{?_smp_mflags}
%else
%{__make} -C build %{?_smp_mflags}
%endif

%install
%if %{with ninja}
DESTDIR=%{buildroot} ninja -v -C build install
%else
%{__make} -C build install DESTDIR=%{buildroot}
%endif
%{__mkdir_p} %{buildroot}%{_localstatedir}/lib/%{name}
%{__sed} -ri -e '1i\@SET datadir=%{_localstatedir}/lib/%{name}\n' -e '/storage\.path/ s|/tmp/storage|${datadir}|' %{buildroot}%{_sysconfdir}/fluent-bit/fluent-bit.conf
%{__install} -d -m0755 %{buildroot}%{_libdir}/fluent-bit

%clean
[ "%{buildroot}" != "/" ] && %{__rm} -rf %{buildroot}

%files
%defattr(-,root,root)
%license LICENSE
%doc CHUNKS.md MAINTAINERS.md README.md SECURITY.md
%doc conf/
%dir %{_sysconfdir}/fluent-bit
%config(noreplace) %{_sysconfdir}/fluent-bit/*.conf
%{_bindir}/fluent-bit
%{_unitdir}/fluent-bit.service
%dir %{_libdir}/fluent-bit
%dir %{_localstatedir}/lib/%{name}
%exclude %{_bindir}/luajit

%files devel
%defattr(-,root,root)
%license LICENSE
%doc CODE_OF_CONDUCT.md CONTRIBUTING.md CONTRIBUTING_DOCS.md DEVELOPER_GUIDE.md GOVERNANCE.md
%{_includedir}/fluent-bit/
%exclude %{_libdir}/*.a
%exclude %{_includedir}/*.h
%exclude %{_includedir}/luajit/
%exclude %{_includedir}/monkey/

%if 0%{?suse_version}

%pre
%{service_add_pre %{name}.service}

%post
%{service_add_post %{name}.service}

%preun
%{service_del_preun %{name}.service}

%postun
%{service_del_postun %{name}.service}

%endif

%changelog
openSUSE Build Service is sponsored by