FROM registry.fedoraproject.org/fedora:40 AS base
MAINTAINER rpm-maint@lists.rpm.org

RUN echo -e "deltarpm=0\ninstall_weak_deps=0\ntsflags=nodocs" >> /etc/dnf/dnf.conf
RUN rpm --quiet -q fedora-repos-modular && rpm -e fedora-repos-modular ||:
RUN sed -i -e "s:^enabled=.$:enabled=0:g" /etc/yum.repos.d/*openh264.repo
# dummy for controlling per-repo gpgcheck via Semaphore setup
RUN sed -i -e "s:^gpgcheck=.$:gpgcheck=1:g" /etc/yum.repos.d/*.repo
RUN dnf -y update
RUN dnf -y install \
  autoconf \
  bubblewrap \
  cmake \
  gettext-devel \
  debugedit \
  doxygen \
  make \
  gcc \
  git-core \
  glibc-gconv-extra \
  zlib-devel \
  bzip2-devel \
  xz-devel \
  libzstd-devel \
  elfutils-libelf-devel \
  elfutils-devel \
  openssl-devel \
  libgcrypt-devel \
  rpm-sequoia-devel \
  file-devel \
  popt-devel \
  libarchive-devel \
  sqlite-devel \
  libselinux-devel \
  ima-evm-utils-devel \
  libcap-devel \
  libacl-devel \
  audit-libs-devel \
  lua-devel readline-devel \
  python3-devel \
  dbus-devel \
  which \
  elfutils binutils \
  findutils sed grep gawk diffutils file patch \
  tar unzip gzip bzip2 cpio xz p7zip \
  pkgconfig \
  /usr/bin/systemd-sysusers \
  gdb-headless-14.2 \
  dwz \
  fsverity-utils fsverity-utils-devel \
  pandoc \
  libasan \
  libubsan \
  && dnf clean all
RUN echo "%_dbpath $(rpm --eval '%_dbpath')" > /root/.rpmmacros

# Workaround for pkgconf(1)'s unlisted dependency on rpm.
# This is needed for cmake to work without an rpm installation.
RUN ln -sf $(rpm --eval '%{_target_platform}%{?_gnu}')-pkg-config \
           /usr/bin/pkg-config

RUN rpm -e --nodeps --nodb \
	rpm \
	rpm-libs \
	rpm-build-libs \
	rpm-sign-libs \
	python3-rpm

WORKDIR /
CMD /bin/bash

FROM base AS full

WORKDIR /srv/rpm
COPY . .
RUN chmod -R a-w .

WORKDIR /srv/build
ENV CFLAGS="-Og -g"
RUN cmake \
	-DENABLE_WERROR=ON \
	-DENABLE_ASAN=ON \
	-DENABLE_UBSAN=ON \
	-DENABLE_BDB_RO=ON \
	-DWITH_FSVERITY=ON \
	-DWITH_IMAEVM=ON \
	-DWITH_DOXYGEN=ON \
	-DMKTREE_BACKEND=rootfs \
	../rpm
RUN make -j$(nproc) tree

RUN rm -rf /srv/{rpm,build}
