summarylogtreecommitdiffstats
path: root/test_optdepends.sh
blob: 09c2a8a79e3b99e93c752c2c00f07d76fe957afa (plain)
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
#!/bin/bash

# Test if external packages for PETSC are installed

# Fair attempt to find the directory of a header file
# example find_inc "head.h" "pack"
find_inc () {
    local INC;
    INC="$(find_so "$1")";
    # * Faster first
    if [ -f "${INC}" ]; then
        INC="${INC}";
    elif [ -f "${INC}"/"$1" ]; then
        # ** The header is inside INC (a directory) e.g.
        #    /usr/include/scotch
        #    /usr/include/scotch/scotch.h
        INC="${INC}"/"$1"
    elif [ -d "${INC}" ]; then
        # ** INC is a directory, and the header is deep inside
        #    (hopefully faster than `pacman')
        INC="$(find "${INC}" -name "$1" -print -quit)";
    elif [ ! "x$2" == "x" ]; then
        # ** May be there is a package?
        pacman -Qs "$2" 2>&1>/dev/null && \
            INC="$(pacman -Qlq "$2" | grep "/$1\$" || printf "")";
    fi;
    [[ -f "${INC}" ]] && dirname "${INC}"
}

# Find a shared object (library; .so extension)
#   example: find_so libboost_mpi
find_so () {
    whereis -b "$1" | cut -d' ' -f2
}

# Find directory where a pkg-config file is
#   example: find_pc glut
find_pc () {
    dirname "$(pkgconf --path "$1")"
}

ONLY_INC="--keep-system-cflags --cflags-only-I";

MPICC=$(type -p mpicc)
[[ -f ${MPICC} ]] && CONFOPTS+=" --with-cc=$(which mpicc)"
MPICXX=$(type -p mpicxx)
[[ -f ${MPICXX} ]] && CONFOPTS+=" --with-cxx=$(which mpicxx)"
MPIFORT=$(type -p mpifort)
[[ -f ${MPIFORT} ]] && CONFOPTS+=" --with-fc=$(which mpifort)"

# ADIOS (adios2)
if [ -f "$(find_so adios2)" ]; then
    CONFOPTS+=" --with-adios=1"
fi;

# Bison
# Tested by default

# BOOST: Free peer-reviewed portable C++ source libraries
if [ -f "$(find_so libboost_mpi.so)" ]; then
    CONFOPTS+=" --with-boost=1"
fi;

# CHOMBO

# CHACO

# CTETGEN

# CGNS: Recording and recovering computer data
CGNS_LIB="$(find_so libcgns.so)"
if [ -f "${CGNS_LIB}" ] && [ -n "$(nm -D /usr/lib/libcgns.so | grep cgp_open | cut -d" " -f3)" ]; then
    # CGNS_INC="$(find_inc "cgnslib.h" "cgns")"
    # CONFOPTS+=" -I${CGNS_INC}"
    # CONFOPTS+=" ${CGNS_LIB}"
	CONFOPTS+=" --with-cgns=1"
    # CONFOPTS+=" --with-cgns-lib=${CGNS_LIB}"
	# CONFOPTS+=" --with-cgns-include=${CGNS_INC}"
else
    CONFOPTS+=" --with-cgns=0"
fi

# CUDA: non-free
CONFOPTS+=" --with-cuda=0"

# eigen: Lightweight C++ template library for vector and
# matrix math
EIGEN_DIR="$(pkgconf --cflags-only-I eigen3)"
EIGEN_DIR="${EIGEN_DIR##-I}"
if [ -d "${EIGEN_DIR}" ]; then
	CONFOPTS+=" --with-eigen=1"
	CONFOPTS+=" --with-eigen-include=${EIGEN_DIR}"
fi

# fftw: Fast-Fourier Transform
if [ -f "$(find_so libfftw3_mpi.so)" ]; then
	CONFOPTS+=" --with-fftw=1"
fi

# GDB: GNU debugger
if [ -f "$(find_so gdb)" ]; then
	CONFOPTS+=" --with-debugger=gdb"
fi

# # GLUT (requires OpenGL)
# if [ -f "$(find_so libglut.so)" ]; then
# 	CONFOPTS+=" --with-glut=1"
#     CONFOPTS+=" --with-glut-pkg-config="
#     CONFOPTS+=" $(find_pc glut)"
# fi

# HDF5: large files
if [[ "$(h5stat -V)" ]]; then
	CONFOPTS+=" --with-hdf5=1 --with-hdf5-fortran-bindings=1"
fi

# hwloc: abstraction of hierarchical architectures
if [ -f "$(find_so libhwloc.so)" ]; then
	CONFOPTS+=" --with-hwloc=1"
    CONFOPTS+=" --with-hwloc-pkg-config="
    CONFOPTS="${CONFOPTS}$(find_pc hwloc)"
fi

# Hypre: Large and sparse linear with massive parallel
# computing
HYPRE_SO="$(find_so libHYPRE.so)"
if [ -f "${HYPRE_SO}" ]; then
	CONFOPTS+=" --with-hypre=1"
	CONFOPTS+=" --with-hypre-lib=${HYPRE_SO}"
    HYPRE_INC="$(find_inc "HYPRE.h" "hypre")"
	CONFOPTS+=" --with-hypre-include=${HYPRE_INC}"

	# CONFOPTS+=" --with-hypre=1 --download-hypre=1"

    # CONFOPTS+=" --with-hypre=0"
fi

# MED: Data Modelization and Exchanges (meshes)
if [ -f "$(find_so libmed.so)" ]; then
	CONFOPTS+=" --with-med=1"
fi

# METIS: Automatic meshing partitioning
if [ -f "$(find_so libmetis.so)" ]; then
	CONFOPTS+=" --with-metis=1"
fi

# # MPI4Py
# if [ -n "$(pacman -Qsq mpi4py)" ]; then
#     mpi4py_inc="$(pacman -Ql python-mpi4py | awk '/mpi4py.h$/{print $NF}')"
# 	CONFOPTS+=" --with-mpi4py=1"
#     CONFOPTS+=" --with-mpi4py-include="
#     CONFOPTS+=" $(dirname "${mpi4py_inc}")"
#     CONFOPTS+=" --with-mpi4py-lib="
#     CONFOPTS+=" $(pacman -Ql python-mpi4py | awk '/.*\.so$/{print $NF}' | tr ' \n' ',')"
# fi

# MUMPS: Sparse solver library
if [ -f "$(find_so libmumps_common.so)" ]; then
	CONFOPTS+=" --with-mumps=1"
fi

# NetCDF
if [ -f "$(find_so libnetcdf.so)" ]; then
	CONFOPTS+=" --with-netcdf=1"
    CONFOPTS+=" --with-netcdf-pkg-config="
    CONFOPTS="${CONFOPTS}$(find_pc netcdf)"
fi

# ParMETIS (non-free)
CONFOPTS=+" --with-parmetis=0"

# PNG
if [ -f "$(find_so libpng.so)" ]; then
	CONFOPTS+=" --with-png=1"
    CONFOPTS+=" --with-png-pkg-config="
    CONFOPTS="${CONFOPTS}$(find_pc libpng)"
fi

# PNetCDF
if [ -f "$(find_so libpnetcdf.so)" ]; then
	CONFOPTS+=" --with-pnetcdf=1"
    CONFOPTS+=" --with-pnetcdf-pkg-config="
    CONFOPTS="${CONFOPTS}$(find_pc pnetcdf)"
fi

# OpenBLAS: Linear algebra libraries
BLAS_SO="$(find_so libblas.so)"
OPENBLAS_SO="$(find_so libopenblas.so)"
LAPACK_SO="$(find_so liblapack.so)"
if [ -f "${BLAS_SO}" ] && [ -f "${OPENBLAS_SO}" ] \
       && [ -f "${LAPACK_SO}" ]; then
    # With help from Satish Balay
    # @ 3.15.4.33.g0bac13e0fe9 2021-09-21
    #  nm -AoD /usr/lib64/libopenblas.so | grep dgetrs_
    CONFOPTS+=" --with-blaslapack-lib=[${LAPACK_SO},${BLAS_SO}]"
fi

# OpenCL: GPU computing
# Check header files
# (from opencl-headers package; how to do this in a consistent way?)
OPENCL_INC="/usr/include/CL/cl.h"
[[ -f ${OPENCL_INC} ]] ||
    OPENCL_INC=$(find_inc "cl.h" "opencl-clhpp")
[[ -z ${OPENCL_INC} ]] &&
    OPENCL_INC=$(find_inc "cl.h" "opencl-headers")
[[ -z ${OPENCL_INC} ]] &&
    OPENCL_INC=$(find_inc "cl.h" "gegl")
# Check library (find libOpenCL.so)
OPENCL_SO="$(find_so libOpenCL.so)"
if [ -f "${OPENCL_SO}" ] && [ -f "${OPENCL_INC}" ]; then
	CONFOPTS+=" --with-opencl=1"
fi

# # OpenGL (mesa)
# deprecated (VULKAN)

# OpenMP: 64 bits blas and lapack, multi-threaded
if [ -f "$(find_so libomp.so)" ]; then
	CONFOPTS+=" --with-openmp=1"
fi

# # OpenMPI (dependency; should be found by pacman)
# MPILIBDIR=$(dirname "$(pacman -Qlq openmpi | grep 'libmpi.so$')")
# MPIINC="$(pacman -Qlq openmpi | grep 'mpi.h$')"
# if [ -d "${MPILIBDIR}" ]; then
# 	CONFOPTS+=" --with-mpi=1"
#     CONFOPTS+=" --with-mpi-dir=/usr/"
# fi

# Scalapack: Parallel memory linear algebra
if [ -f "$(find_so libscalapack.so)" ]; then
	CONFOPTS+=" --with-scalapack=1"
fi

# Scotch: Partitioning with sparse matrices
# TODO: general (non-pacman) way
PTSCOTCH_SO="$(find_so libptscotch.so)"
if [ -f "${PTSCOTCH_SO}" ]; then
	CONFOPTS+=" --with-ptscotch=1"
    SCOTCH_LIBS=$(pacman -Qlq scotch | grep '.so$'| tr '\n' ',')
    # Check if libscotch was compiled with bz2
    if [ ! -z "$(nm -D $(find_so libscotch.so) | grep bz)" ]; then
        SCOTCH_LIBS="${SCOTCH_LIBS}$(find_so libbz2.so)"
    else
        # Remove trailing ,
        SCOTCH_LIBS="${SCOTCH_LIBS%%,}"
    fi;
    CONFOPTS+=" --with-ptscotch-lib=[${SCOTCH_LIBS}]"
    CONFOPTS+=" --with-ptscotch-include="
    CONFOPTS="${CONFOPTS}$(find_inc ptscotch.h scotch)"
fi

# SuiteSparse: Sparse matrix library
if [ -f "$(find_so libsuitesparseconfig.so)" ]; then
	CONFOPTS+=" --with-suitesparse=1"
fi

# SuperLU: Subroutines for sparsse linear systems
# TODO: programatic way
SUPERLU_DIR="/usr/include/superlu"
if [ -d "${SUPERLU_DIR}" ]; then
	CONFOPTS+=" --with-superlu=1"
	CONFOPTS+=" --with-superlu-lib=-lsuperlu"
	CONFOPTS+=" --with-superlu-include=${SUPERLU_DIR}"
fi

# YAML: configuration files
# Check library (find libyaml.so)
YAML_SO="$(find_so libyaml.so)"
if [ -f "${YAML_SO}" ]; then
	CONFOPTS+=" --with-yaml=1"
fi

# X: to enable ksp_xmonitor
LIBX11_SO="$(find_so libX11.so)"
LIBX11_DIR="$(dirname ${LIBX11_SO})"
if [ -f "${LIBX11_SO}" ]; then
    LIBX11_INC="$(pkgconf ${ONLY_INC} x11)";
    LIBX11_INC="${LIBX11_INC//-I/}";
	CONFOPTS+=" --with-x-lib=[${LIBX11_DIR}/";
    # As per X11.pc, it seems that xcb.so is needed
    CONFOPTS="${CONFOPTS}libX11-xcb.so,${LIBX11_SO}]"
    CONFOPTS+=" --with-x-include=${LIBX11_INC}"
fi

# ZLIB
if [ -f "$(find_so libzlib.so)" ] || [ -f "$(find_so libz.so)" ]; then
	CONFOPTS+=" --with-zlib=1"
    CONFOPTS+=" --with-zlib-pkg-config="
    CONFOPTS="${CONFOPTS}$(find_pc zlib)"
fi

# TetGen
TETGEN_SO="$(find_so libtet.so)"
if [ -f "${TETGEN_SO}" ]; then
	CONFOPTS+=" --with-tetgen=1"
    CONFOPTS+=" --with-tetgen-lib=${TETGEN_SO}"
    CONFOPTS+=" --with-tetgen-include=$(find_inc tetgen.h tetgen)"
fi

# # trilinos support
#
# if [ "${TRILINOS_DIR}" ]; then
# 	CONFOPTS+=" --with-ml-dir=${TRILINOS_DIR}"
# 	# boost support (may be useful for trilinos)
# 	CONFOPTS+=" --with-boost=1"
# fi

# Incompatible with complex
# # sundials support
# SUNDIALS_DIR="/usr/include/sundials/"
# if [ -d "${SUNDIALS_DIR}" ]; then
# 	CONFOPTS+=" --with-sundials=1"
# 	CONFOPTS+=" --with-sundials-include=${SUNDIALS_DIR}"
# fi

# # pastix support (non-free)
# PASTIX_CONF=$(which pastix-conf)
# if [ -f "${PASTIX_CONF}" ]; then
# 	PASTIX_DIR="$($PASTIX_CONF --incs | sed 's/-I//')"
# 	if [ ! -d ${PASTIX_DIR} ]; then
# 		PASTIX_DIR="[]"
# 	fi
# 	#PASTIX_LIBS="$($PASTIX_CONF --libs)"
# 	PASTIX_LIBS="[libpastix.a,librt.so,libhwloc.so,libpthread.a]"
# 	CONFOPTS+=" --with-pastix=1"
# 	CONFOPTS+=" --with-pastix-lib=${PASTIX_LIBS}"
# 	CONFOPTS+=" --with-pastix-include=${PASTIX_DIR}"
# fi

echo "${CONFOPTS}"