# Reproducible build + test image for the planarity extension. Builds the vendored
# Boyer-Myrvold library together with the wrapper, enables the extension, and (by default)
# runs the .phpt suite. Useful on hosts without a phpize/autotools toolchain.
#
#   docker build -t php-planarity .
#   docker run --rm php-planarity                 # runs `make test` (the .phpt suite)
#   docker run --rm php-planarity php --ri planarity
#
# $PHPIZE_DEPS + docker-php-ext-enable come from the official php image. Valgrind is
# installed for the leak/UB proof (see README.md → Safety proofs).
FROM php:8.5-cli

RUN apt-get update \
 && apt-get install -y --no-install-recommends $PHPIZE_DEPS valgrind \
 && rm -rf /var/lib/apt/lists/*

COPY . /ext
WORKDIR /ext

# Strip any host build artifacts that rode in (they bake absolute host paths into the
# generated Makefile), then build cleanly in-image from the tracked sources.
RUN rm -rf Makefile Makefile.* config.h config.h.in config.log config.nice config.status \
      configure configure.ac libtool build .libs .deps modules autom4te.cache run-tests.php \
 && find . \( -name '*.lo' -o -name '*.la' -o -name '*.o' -o -name '*.dep' \) -delete \
 && phpize \
 && ./configure --enable-planarity \
 && make -j"$(nproc)" \
 && make install \
 && docker-php-ext-enable planarity \
 && php --ri planarity

CMD ["make", "test", "NO_INTERACTION=1"]
