summaryrefslogtreecommitdiff
path: root/science/cp2k/Makefile
blob: 50458ec12b805fd6c84fc03784fe150086dd8c00 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
PORTNAME=	cp2k
DISTVERSIONPREFIX=	v
DISTVERSION=	2022.2
CATEGORIES=	science

MAINTAINER=	yuri@FreeBSD.org
COMMENT=	Quantum chemistry and solid state physics software package
WWW=		https://www.cp2k.org/

LICENSE=	GPLv2+
LICENSE_FILE=	${WRKSRC}/LICENSE

.if !exists(/usr/include/omp.h)
BROKEN=		requires OpenMP support that is missing on this architecture
.endif

BUILD_DEPENDS=	fypp:devel/py-fypp@${PY_FLAVOR}
LIB_DEPENDS=	libblas.so:math/blas \
		libfftw3.so:math/fftw3 \
		liblapack.so:math/lapack
RUN_DEPENDS=	cp2k-data>0:science/cp2k-data
TEST_DEPENDS=	bash:shells/bash

USES=		fortran gmake localbase:ldflags python:build shebangfix tar:bz2

USE_GITHUB=	yes
GH_TUPLE=	cp2k:dbcsr:c134996:cp2k_dbcsr/exts/dbcsr \
		pseewald:fprettify:71781aa:pseewald_fprettify/tools/prettify/fprettify

SHEBANG_FILES=	tools/regtesting/do_regtest

GCC_VERSION=	${GCC_DEFAULT} # ${_USE_GCC}

MAKE_ARGS=	XARCH=FreeBSD-gfortran VERSION=${VERSION} FC=gfortran${GCC_VERSION} CC=${CC} LD=gfortran${GCC_VERSION} \
		DATA_DIR=${DATADIR}

BINARY_ALIAS=	python=${PYTHON_CMD} python3=${PYTHON_CMD} make=${GMAKE} # make - only for tests

OPTIONS_DEFINE=		LIBINT
OPTIONS_SINGLE=		MULTIPROCESSING
OPTIONS_SINGLE_MULTIPROCESSING=		SERIAL OPENMP MPI OPENMP_MPI # for the complete list see https://github.com/cp2k/cp2k/blob/master/INSTALL.md
OPTIONS_DEFAULT=	LIBINT OPENMP
MULTIPROCESSING_DESC=	Multiprocessing

LIBINT_DESC=		Use libint to evaluate integrals
LIBINT_LIB_DEPENDS=	libint.so:science/libint

SERIAL_DESC=		Single core (no multiprocessing)
SERIAL_VARS=		VERSION=sopt EFFECTIVE_VERSION=ssmp # now is a flavor of ssmp with NUM_THEADS=1
SERIAL_CFLAGS=		${OPENMP_CFLAGS}
SERIAL_CXXFLAGS=	${OPENMP_CXXFLAGS}
SERIAL_LDFLAGS=		${OPENMP_LDFLAGS}
SERIAL_PLIST_FILES=	${EXECUTABLES_CORE:C/(.*)/bin\/\1.${VERSION}/} # symlinks

OPENMP_VARS=		VERSION=ssmp EFFECTIVE_VERSION=ssmp
OPENMP_CFLAGS=		-fopenmp
OPENMP_CXXFLAGS=	-fopenmp
OPENMP_LDFLAGS=		/usr/lib/libgomp.so

MPI_VARS=		VERSION=popt EFFECTIVE_VERSION=psmp # now is a flavor of psmp with NUM_THEADS=1
MPI_LIB_DEPENDS=	libmpich.so:net/mpich \
			libscalapack.so:math/scalapack
MPI_LDFLAGS=		-lmpifort
MPI_PLIST_FILES=	${EXECUTABLES_CORE:C/(.*)/bin\/\1.${VERSION}/} # symlinks
MPI_BROKEN=		https://github.com/cp2k/cp2k/issues/2128

OPENMP_MPI_DESC=	Enable both OpenMP and MPI
OPENMP_MPI_VARS=	VERSION=psmp EFFECTIVE_VERSION=psmp
OPENMP_MPI_CFLAGS=	${OPENMP_CFLAGS}
OPENMP_MPI_CXXFLAGS=	${OPENMP_CXXFLAGS}
OPENMP_MPI_LDFLAGS=	${OPENMP_LDFLAGS}
OPENMP_MPI_LIB_DEPENDS=	${MPI_LIB_DEPENDS}
OPENMP_MPI_LDFLAGS=	${MPI_LDFLAGS}
OPENMP_MPI_BROKEN=	https://github.com/cp2k/cp2k/issues/2128

EXECUTABLES_CORE=	cp2k cp2k_shell
EXECUTABLES_EXTRA=	dumpdcd graph grid_miniapp xyz2dcd
EXECUTABLES=		${EXECUTABLES_CORE} ${EXECUTABLES_EXTRA}

PLIST_FILES=		${EXECUTABLES:C/(.*)/bin\/\1.${EFFECTIVE_VERSION}/}

.include <bsd.port.options.mk>

.if ${PORT_OPTIONS:MOPENMP} || ${PORT_OPTIONS:MOPENMP_MPI}
pre-configure:
	@if [ ! -e ${LOCALBASE}/lib/libfftw3_omp.so ] ; then \
	  ${ECHO_MSG} "The OPENMP and OPENMP_MPI options require math/fftw3" ; \
	  ${ECHO_MSG} "to be built and installed with the OPENMP option ON" ; \
	  exit 1; \
	fi
.endif

post-patch:
	@${REINPLACE_CMD} -i '' 's|LIBS.*=.*|& ${LDFLAGS}|; s|^FCFLAGS.*=.*|& -I${LOCALBASE}/include|; s| -march=native||' ${WRKSRC}/arch/FreeBSD-*

xpre-build:
	@${ECHO} ${PORTVERSION} > ${WRKSRC}/REVISION

do-install:
.for e in ${EXECUTABLES}
	${INSTALL_PROGRAM} ${WRKSRC}/exe/*/${e}.${EFFECTIVE_VERSION} ${STAGEDIR}${PREFIX}/bin
.endfor

do-install-SERIAL-on:
.for e in ${EXECUTABLES_CORE}
	cd ${STAGEDIR}${PREFIX}/bin && ${LN} -s ${e}.${EFFECTIVE_VERSION} ${e}.${VERSION}
.endfor

do-test: # fails to run: some Linux-only commands are present, also /usr/local/bin/ar: invalid option -- /
	@cd ${WRKSRC} && \
		${TOUCH} arch/local.${EFFECTIVE_VERSION} && \
		${SETENV} ${MAKE_ENV} ./tools/regtesting/do_regtest -maxtasks 8

.include <bsd.port.pre.mk>

.  if ${GCC_DEFAULT} >= 10 # only needed when MPI is on, but flags aren't passed into DBCSR sub-project, see https://github.com/cp2k/cp2k/issues/2128
FCFLAGS+=	-fallow-argument-mismatch
.  endif

# build instructions: https://github.com/cp2k/cp2k/blob/master/INSTALL.md

.include <bsd.port.post.mk>