FROM --platform=$BUILDPLATFORM tonistiigi/xx AS xx
FROM --platform=$BUILDPLATFORM alpine:3.21

ARG BUILD_PACKAGES="\
	clang \
	make \
	cmake \
	lld \
	curl \
	pkgconfig"

RUN	apk add --no-cache ${BUILD_PACKAGES}

ARG	LMS_BUILD_PACKAGES=" \
	gcc \
	g++ \
	alsa-lib-dev \
	benchmark-dev \
	boost-dev \
	ffmpeg-dev \
	gtest-dev \
	libarchive-dev \
	libconfig-dev \
	musl-dev \
	pugixml-dev \
	pulseaudio-dev \
	stb \
	taglib-dev \
	wt-dev \
	xxhash-dev"

COPY --from=xx / /

ARG TARGETPLATFORM
RUN	xx-apk add --no-scripts --no-cache ${LMS_BUILD_PACKAGES}

# LMS
COPY . /tmp/lms/
ARG LMS_BUILD_TYPE="Release"
RUN \
	DIR=/tmp/lms/build && mkdir -p ${DIR} && cd ${DIR}  && \
		xx-info is-cross && export BUILD_TESTS=OFF || export BUILD_TESTS=ON && \
		PKG_CONFIG_PATH=/$(xx-info)/usr/lib/pkgconfig cmake /tmp/lms/ -DCMAKE_INCLUDE_PATH=/$(xx-info)/usr/include -DCMAKE_UNITY_BUILD=ON -DCMAKE_BUILD_TYPE=${LMS_BUILD_TYPE} $(xx-clang --print-cmake-defines) -DCMAKE_PREFIX_PATH=/$(xx-info)/usr/lib/cmake -DBUILD_TESTING=${BUILD_TESTS} -DBUILD_BENCHMARKS=ON && \
		VERBOSE=1 make -j$(nproc) && \
		xx-verify src/lms/lms && \
		(xx-info is-cross || make test)
