# Maintainer: Trevor SANDY <trevor[dot]sandy[at]gmail[dot]com>
#  Last Update: June 3, 2025
#  Copyright (C) 2017 - 2025 by Trevor SANDY
pkgname=lpub3d-ci
pkgver=2.4.9.4556
pkgrel=1
pkgdesc="An LDraw Building Instruction Editor"
url="https://trevorsandy.github.io/lpub3d"
arch=('x86_64' 'i686')
license=('GPL3')
makedepends=('cmake' 'elfutils' 'gcc' 'glu' 'libdrm' 'libglvnd' 'libunwind' 'libx11' 'libxdamage' 'libxml2' 'libxrandr' 'libxshmfence' 'libxxf86vm' 'make' 'meson' 'python-mako' 'python-packaging' 'valgrind' 'wayland' 'wayland-protocols' 'xorgproto')
depends=('boost' 'boost-libs' 'freeglut' 'gl2ps' 'libelf' 'libjpeg-turbo' 'libpng' 'libtiff' 'llvm' 'llvm-libs' 'mesa' 'mesa-libgl' 'minizip' 'openexr' 'qt5-base' 'qt5-tools' 'sdl2' 'unzip' 'xorg-util-macros')
conflicts=()
replaces=()
backup=()
source=(
	'lpub3d-ci-git.tar.gz'
	'version.info'
	'povray.tar.gz'
	'ldview.tar.gz'
	'ldglite.tar.gz'
	'mesa-21.3.9.tar.xz'
	'glu-9.0.1.tar.xz'
	'zstd-1.5.7.tar.gz'
	'complete.zip'
	'lpub3dldrawunf.zip'
	'tenteparts.zip'
	'vexiqparts.zip')
noextract=(
	'povray.tar.gz'
	'ldview.tar.gz'
	'ldglite.tar.gz'
	'mesa-21.3.9.tar.xz'
	'glu-9.0.1.tar.xz'
	'zstd-1.5.7.tar.gz'
	'complete.zip'
	'lpub3dldrawunf.zip'
	'tenteparts.zip'
	'vexiqparts.zip')
sha256sums=(
	SKIP
	SKIP
	'2793182e702750daa9c3dea19b167c78d004846e44c4ad73b9c3ec34566e1dcb'
	'e9e95a91e9d3cd0ae813210893a4d5ef6b5115bbc6e402a89124ec26d656a9d2'
	'c2ad5e45bc391db634db6d0ed47d317c0268dccf4d1aa37ff5c780731ff5a8ca'
	'91fe6f20339884e37a7c47bfba42fb1cd397512c9ed5ad423de369f047cd8b5c'
	'fb5a4c2dd6ba6d1c21ab7c05129b0769544e1d68e1e3b0ffecb18e73c93055bc'
	'eb33e51f49a15e023950cd7825ca74a4a2b43db8354825ac24fc1b7ee09e6fa3'
	'a4ab15366d22ae0589901ec15bcc465fd5bb5b6057661b91b89b810f98a56c06'
	'a22da755a9c10cecf37928f4c951be00be9149146914de2a2b7a526906fdfd0e'
	'95b65664c455f4895f480ab8e3ed9e96046ca69ee1b296922d76a369e2cf2846'
	'e2f4114c8ff6bfe7e5a43b6c88fb47f32328ddb147578456ec0825aa76803b20')

prepare() {
	# location is /usr/src/packages/BUILD/lpub3d-ci/src
	export WD="$PWD"
	export LDRAWDIR="${HOME}/ldraw"
	export PLATFORM_PRETTY="Arch Linux"
	export PLATFORM_VER="2025"
	export LPUB3D="${pkgname}"
	export TARGET_CPU="$(uname -m)"
	export LP3D_LOG_PATH="${WD}"
	export LP3D_CPU_CORES="$(nproc)"
	export LP3D_3RD_DIST_DIR="lpub3d_linux_3rdparty"
	cd ${pkgname}-git
	# location is .../src/${pkgname}-git
	# move ldraw archive libraries to extras
	for LDrawLibFile in \
		../complete.zip \
		../lpub3dldrawunf.zip \
		../tenteparts.zip \
		../vexiqparts.zip; do
		if [ -f "${LDrawLibFile}" ]; then
			[ "$(basename ${LDrawLibFile})" = "complete.zip" ] && LIB_CMD=cp || LIB_CMD=mv
			${LIB_CMD} -f ${LDrawLibFile} mainApp/extras/
		fi
	done
	# Build Mesa-amber 21.3.9
	export build_osmesa=1
	# LLVM not needed for default Mesa 21.3.9 configuration
	export llvm_not_used=1
	# Until LDView converts to tinyxml2, build tinyxml from source 
	export build_tinyxml=1
	# copy version.info to utilities
	[ -f "../version.info" ] && export OBS=true; cp -f ../version.info builds/utilities/ || :
	# build 3rd-party renderers
	chmod a+x builds/utilities/CreateRenderers.sh && ./builds/utilities/CreateRenderers.sh
	# set qmake and generate Makefiles
	export QT_SELECT=qt5
	if [ -x /usr/bin/qmake ] ; then
		QMAKE_EXEC=qmake
	elif [ -x /usr/bin/qmake-qt5 ] ; then
		QMAKE_EXEC=qmake-qt5
	fi
	${QMAKE_EXEC} -makefile CONFIG+=release CONFIG+=build_check CONFIG-=debug_and_release CONFIG+=pkg
}

build() {
	cd ${pkgname}-git
	export TARGET_VENDOR="Arch Linux"
	export PLATFORM_CODE="ar"
	export PLATFORM_VER="2025"
	export TARGET_CPU="$(uname -m)"
	make clean
	make -j$(nproc)
	# check lpub3d dependencies
	[[ "${TARGET_CPU}" = "x86_64" || "${TARGET_CPU}" = "aarch64" ]] && \
	LP3D_RELEASE="64bit_release" || LP3D_RELEASE="32bit_release"
	LP3D_SUFFIX=$(cat builds/utilities/version.info | cut -d " " -f 1-2 | sed s/" "//g)
	LP3D_EXE="mainApp/${LP3D_RELEASE}/lpub3d${LP3D_SUFFIX}"
	[ -f "${LP3D_EXE}" ] && ldd ${LP3D_EXE} 2>/dev/null || :
}

package() {
	cd ${pkgname}-git
	make INSTALL_ROOT=${pkgdir} install
}
