PORTNAME=	root
DISTVERSION=	6.38.00
PORTREVISION=	1
CATEGORIES=	devel science math parallel python
MASTER_SITES=	https://root.cern/download/
DISTFILES=	${PORTNAME}_v${DISTVERSION}.source${EXTRACT_SUFX}

MAINTAINER=	erik@tenku.dk
COMMENT=	Data analysis framework made at CERN
WWW=		https://root.cern/

LICENSE=	LGPL21
LICENSE_FILE=	${WRKSRC}/LGPL2_1.txt

BROKEN_i386=	std::uint64_t to std::size_t narrowing conversion issue introduced in version 6.34.02

BUILD_AND_RUN_DEPENDS=	bash:shells/bash \
		nlohmann-json>=3:devel/nlohmann-json
BUILD_DEPENDS=	${BUILD_AND_RUN_DEPENDS}
LIB_DEPENDS=	libfreetype.so:print/freetype2 \
		liblz4.so:archivers/liblz4 \
		libpcre2-8.so:devel/pcre2 \
		libxxhash.so:devel/xxhash \
		libzstd.so:archivers/zstd
RUN_DEPENDS=	${BUILD_AND_RUN_DEPENDS}

USES=		cmake desktop-file-utils iconv shebangfix

SHEBANG_FILES=	main/python/rootcp.py \
		main/python/rootdrawtree.py \
		main/python/rooteventselector.py \
		main/python/rootmkdir.py \
		main/python/rootmv.py \
		main/python/rootprint.py \
		main/python/rootrm.py \
		main/python/rootslimtree.py \
		config/rootssh \
		etc/dictpch/makepch.py \
		etc/pdg_table_update.py \
		etc/runfirefox.sh
# add a port-specific shebang to be replaced
python_OLD_CMD+=	"/usr/bin/env @python@"

# Flags and environment variables for building
CMAKE_ON=	builtin_civetweb builtin_clang builtin_cling builtin_llvm builtin_openui5 \
		fail-on-missing gnuinstall shared soversion thisroot_scripts
CMAKE_OFF=	arrow builtin_cfitsio builtin_cppzmq builtin_davix builtin_fftw3 \
		builtin_freetype builtin_ftgl builtin_gif builtin_gl2ps builtin_glew \
		builtin_gsl builtin_gtest builtin_jpeg builtin_lz4 builtin_lzma \
		builtin_nlohmannjson builtin_openssl builtin_pcre builtin_png builtin_tbb \
		builtin_unuran builtin_vc builtin_vdt builtin_veccore builtin_xrootd \
		builtin_xxhash builtin_zeromq builtin_zlib builtin_zstd cefweb check_connection \
		clad cocoa cuda daos dcache experimental_adaptivecpp experimental_genvectorx \
		fcgi geombuilder gviz libcxx llvm13_broken_tests macos_native memory_termination \
		minuit2_mpi minuit2_omp mpi pythia8 r roofit_multiprocess runtime_cxxmodules \
		shadowpw test_distrdf_dask test_distrdf_pyspark tmva-cudnn tmva-gpu tmva-rmva \
		tmva-sofie unuran uring use_gsl_cblas vc veccore vecgeom win_broken_tests \
		winrtdebug

# See https://root.cern/install/build_from_source/#all-build-options
OPTIONS_DEFINE=	DOCS ASIMAGE DATAFRAME DAVIX FFTW3 FITSIO FORTRAN GDML GEOM \
		HTTP IMT MATHMORE OPENGL PYROOT QT6WEB ROOFIT ROOT7 SPECTRUM \
		SQLITE SSL MLP TMVA UNFOLD VDT WEBGUI X11 XML XROOTD

OPTIONS_DEFAULT=	ASIMAGE DATAFRAME DAVIX FITSIO GDML GEOM HTTP IMT OPENGL PYROOT \
		ROOFIT ROOT7 SPECTRUM SQLITE SSL MLP TMVA UNFOLD VDT WEBGUI X11 XML XROOTD
OPTIONS_SUB=	yes

ASIMAGE_CMAKE_BOOL=	asimage asimage_tiff
ASIMAGE_DESC=		Enable support for image processing via libAfterImage
ASIMAGE_IMPLIES=	X11
ASIMAGE_LIB_DEPENDS=	libgif.so:graphics/giflib \
		libpng16.so:graphics/png \
		libtiff.so:graphics/tiff
ASIMAGE_USES=	jpeg

# TODO: clad can only be included in ROOT's configure stage
# with network access, however, a port of clad is available -- patch
#CLAD_CMAKE_BOOL=	clad
#CLAD_DESC=		Build clad, the cling automatic differentiation plugin
#CLAD_LIB_DEPENDS=	libclad.so:math/clad
#CLAD_CMAKE_ON=	-DCLAD_SOURCE_DIR=

DATAFRAME_CMAKE_BOOL=	dataframe
DATAFRAME_DESC=			Enable ROOT RDataFrame

DAVIX_CMAKE_BOOL=	davix
DAVIX_DESC=		Enable support for Davix (HTTP/WebDAV access)
DAVIX_LIB_DEPENDS=	libdavix.so:www/davix
DAVIX_USES=	pkgconfig

# TODO
#EXPERIMENTALADAPTIVECPP_CMAKE_BOOL=	experimental_adaptivecpp

# TODO
#EXPERIMENTALGENVECTORX_CMAKE_BOOL=	experimental_genvectorx

# TODO
#FCGI_CMAKE_BOOL=	fcgi

FFTW3_CMAKE_BOOL=	fftw3
FFTW3_DESC=		Enable support for FFTW3
FFTW3_LIB_DEPENDS=	libfftw3.so:math/fftw3

FITSIO_CMAKE_BOOL=	fitsio
FITSIO_DESC=		Enable support for reading FITS images
FITSIO_LIB_DEPENDS=	libcfitsio.so:astro/cfitsio \
		libcurl.so:ftp/curl

FORTRAN_CMAKE_BOOL=	fortran
FORTRAN_DESC=		Build Fortran components of ROOT
FORTRAN_USES=		fortran

GDML_CMAKE_BOOL=	gdml
GDML_DESC=		Enable support for GDML (Geometry Description Markup Language)
GDML_IMPLIES=		GEOM

GEOM_CMAKE_BOOL=	geom
GEOM_DESC=	Enable support for the geometry library

# TODO: Missing include in TGeoParaEditor.cxx in upstream; wait for fix
#GEOMBUILDER_CMAKE_BOOL=	geombuilder
#GEOMBUILDER_DESC=	Enable support for the geombuilder library
#GEOMBUILDER_IMPLIES=	GEOM

# TODO
#GVIZ_CMAKE_BOOL=	gviz

HTTP_CMAKE_BOOL=	http
HTTP_DESC=		Enable support for HTTP server
HTTP_IMPLIES=	ROOT7 WEBGUI

IMT_CMAKE_BOOL=	imt
IMT_DESC=		Enable support for implicit multi-threading via Intel® Thread Building Blocks (TBB)
IMT_LIB_DEPENDS=	libtbb.so:devel/onetbb

MATHMORE_CMAKE_BOOL=	mathmore
MATHMORE_DESC=		Build libMathMore extended math library
MATHMORE_LIB_DEPENDS=	libgsl.so:math/gsl

# TODO
#MINUIT2MPI_CMAKE_BOOL=	minuit2_mpi

# TODO
#MINUIT2OMP_CMAKE_BOOL=	minuit2_omp

MLP_CMAKE_BOOL=	mlp
MLP_DESC=		Enable support for TMultilayerPerceptron classes' federation
MLP_IMPLIES=	TMVA MATHMORE

# TODO
#MPI_CMAKE_BOOL=	mpi

OPENGL_CMAKE_BOOL=	opengl
OPENGL_DESC=		Enable support for OpenGL
OPENGL_IMPLIES=	X11 ASIMAGE
OPENGL_LIB_DEPENDS=	libftgl.so:graphics/ftgl \
		libgl2ps.so:print/gl2ps
OPENGL_USES=	gl
OPENGL_USE=		gl=glew,glu,opengl

PYROOT_CMAKE_BOOL=	pyroot tpython tmva-pymva
PYROOT_DESC=		Enable bindings between Python and C++ with PyROOT
PYROOT_BUILD_DEPENDS=	${PYNUMPY}
PYROOT_USES=		python:build,run
PYROOT_USES_OFF=	python:build

QT6WEB_CMAKE_BOOL=	qt6web
QT6WEB_DESC=		Enable support for Qt6 web-based display
QT6WEB_IMPLIES=	WEBGUI OPENGL
QT6WEB_USES=	qt:6
QT6WEB_USE=	qt=base,declarative,positioning,webchannel,webengine

ROOFIT_CMAKE_BOOL=	roofit
ROOFIT_DESC=		Build the advanced fitting package RooFit, and RooStats for statistical tests

ROOT7_CMAKE_BOOL=	root7
ROOT7_DESC=		Build ROOT 7 components of ROOT

SPECTRUM_CMAKE_BOOL=	spectrum
SPECTRUM_DESC=		Enable support for TSpectrum

SQLITE_CMAKE_BOOL=	sqlite
SQLITE_DESC=		Enable support for SQLite
SQLITE_USES=		sqlite

SSL_CMAKE_BOOL=	ssl
SSL_DESC=		Enable support for SSL encryption via OpenSSL
SSL_USES=		ssl

TMVA_CMAKE_BOOL=	tmva tmva-cpu
TMVA_DESC=		Build TMVA multi variate analysis library, including TMVA with CPU support for deep learning
TMVA_IMPLIES=	IMT MATHMORE
TMVA_LIB_DEPENDS=	libopenblas.so:math/openblas

UNFOLD_CMAKE_BOOL=	unfold
UNFOLD_DESC=	Enable the unfold package
UNFOLD_IMPLIES=	XML

# TODO
#UNURAN_CMAKE_BOOL=	unuran

VDT_CMAKE_BOOL=	vdt
VDT_DESC=		Enable support for VDT (fast and vectorisable mathematical functions)
VDT_LIB_DEPENDS=	libvdt.so:math/vdt

# TODO
#VECCORE_CMAKE_BOOL=	veccore

# TODO
#VECGEOM_CMAKE_BOOL=	vecgeom

WEBGUI_CMAKE_BOOL=	webgui
WEBGUI_DESC=		Build Web-based UI components of ROOT
WEBGUI_IMPLIES=	HTTP ROOT7

X11_CMAKE_BOOL=	x11
X11_DESC=		Enable support for X11/Xft
X11_USES=		xorg
X11_USE=		xorg=ice,sm,x11,xau,xaw,xcb,xcomposite,xcursor,xdamage,xdmcp,xext \
		xorg=xfixes,xfont,xfont2,xft,xi,xinerama,xkbfile,xmu,xpm,xrandr,xrender \
		xorg=xres,xscrnsaver,xt,xv,xxf86vm

XML_CMAKE_BOOL=		xml
XML_DESC=		Enable support for XML
XML_USES=		gnome
XML_USE=		gnome=libxml2

XROOTD_CMAKE_BOOL=	xrootd
XROOTD_DESC=		Enable support for XRootD file server and client
XROOTD_LIB_DEPENDS=	libXrdCl.so:databases/xrootd

.include <bsd.port.options.mk>

ROOT_CLANG_VER=	20

PLIST_SUB+=	PYVER="${PYTHON_VER:S/./_/}" \
		ROOT_CLANG_VER="${ROOT_CLANG_VER}" \
		SHLIB_SHVER="${DISTVERSION:R}" \
		SHLIB_VER="${DISTVERSION}"

# A few headers are only installed on aarch64
.if ${OPSYS} == FreeBSD && ${ARCH} == "aarch64"
PLIST_SUB+=	ONLY_INSTALLED_ON_AARCH64=""
.else
PLIST_SUB+=	ONLY_INSTALLED_ON_AARCH64="@comment "
.endif

# Files in ${PREFIX}/lib/root/__pycache__ have links into WRKDIR and should not be staged
# Files in wrkdirs are generated during build of libAfterImage and should not be staged
post-install:
	${RM} -r ${STAGEDIR}${PREFIX}/lib/root/__pycache__
	${RM} -r ${STAGEDIR}/wrkdirs
.if ${PORT_OPTIONS:MPYROOT}
	${STRIP_CMD} ${STAGEDIR}${PREFIX}/lib/root/cppyy/libcppyy.so.${DISTVERSION}
	${STRIP_CMD} ${STAGEDIR}${PREFIX}/lib/root/ROOT/libROOTPythonizations.so
.endif

.include <bsd.port.mk>
