# Supported Fedora releases: 40 41
FROM registry.fedoraproject.org/fedora:41 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
# updates disabled for a stable environment
RUN sed -i -e "s:^enabled=.$:enabled=0:g" /etc/yum.repos.d/*updates*.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 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 \
  dwz \
  fsverity-utils fsverity-utils-devel \
  pandoc \
  libasan \
  libubsan
# If updates to specific packages are needed, do it here
# RUN dnf --enablerepo=updates update ...
RUN 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

# Self-destruct stock rpm
RUN if which dnf5; then \
	# Fedora 41+ \
	rpm -e --nodeps --nodb \
	    rpm-plugin-ima; \
    else \
	# Fedora 40 \
	rpm -e --nodeps --nodb \
	    rpm-sign-libs \
	    python3-rpm; \
    fi; \
    rpm -e --nodeps --nodb \
	rpm \
	rpm-libs \
	rpm-build-libs

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 \
	-DENABLE_TESTSUITE=ON \
	-DMKTREE_BACKEND=rootfs \
	../rpm
RUN make -j$(nproc) tree

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