aboutsummaryrefslogtreecommitdiff
blob: 918fe718cd79a343346a6d31ac0d9eb7abc218f3 (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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
# Copyright 1999-2017 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

# @ECLASS: mpi-select.eclass
# @MAINTAINER:
# Michael Gilroy <michael.gilroy24@gmail.com>
# @BLURB: Allow mpi software to select mpi implementation of choice.

inherit multilib multilib-minimal flag-o-matic

EXPORT_FUNCTIONS src_configure src_compile src_test src_install

case ${EAPI:-0} in
  6) ;;
  5) ;;
  *) die "mpi-select.eclass does not support EAPI ${EAPI}"
esac

# @ECLASS-VARIABLE: IMPLEMENTATION_LIST
# @INTERNAL
# @DESCRIPTION:
# List of used MPI implementation
IMPLEMENTATION_LIST="mpich mpich2 openmpi openib-mvapich2"

# @ECLASS-VARIABLE: INSTALLED_IMPLEMENTATIONS
# @INTERNAL
# @DESCRIPTION:
# List of used MPI implementation
INSTALLED_IMPLEMENTATIONS=get_all_implementations

# @ECLASS-VARIABLE: MPI_DIR
# @INTERNAL
# @DESCRIPTION:
# Location in which mpi software should be installed
MPI_DIR="/usr/$(get_libdir)/mpi"

# @ECLASS-VARIABLE: MPI_TARGETS
# @INTERNAL
# @DESCRIPTION:
# List of implementations in make.conf.
MPI_TARGETS="${MPI_TARGETS}"

# @FUNCTION: mpi_dependencies
# Grabs $MPI_TARGETS to add to RDEPEND
mpi_dependencies()
{
	local impl ret

	for impl in "${MPI_TARGETS}"; do
			ret="${ret} =sys-cluster/${impl}"	
	done

	echo "${ret}"
}

# @FUNCTION: get_mpicc
# @DESCRIPTION:
# Fetches most recent version of mpicc installed
get_mpicc()
{
	echo "$(ls -dv /usr/$(get_libdir)/mpi/mpich-* | tail -n 1)" || die "could not get mpicc"
}

# @FUNCTION : mpi_pkg_cc
# @DESCRIPTION :
# Get location of C compiler from /usr/
mpi_pkg_cc()
{
	mpi_pkg_compiler "cc"
}

# @FUNCTION: mpi_pkg_compiler
# @DESCRIPTION :
# Returns correct path for the compiler
mpi_pkg_compiler
{
	local args
	for args in "${1}"; do
		if [ -f "/usr/lib64/mpi/mpich-3.2/install/usr/bin" ]; then
			die "hit!!"
			echo "$(get_mpicc)/install/usr/bin/mpi${args}"
			break
		fi
	done
}

# @FUNCTION: mpi_root
# @DESCRIPTION:
# Sets the root directory for the mpi pkg install
mpi_root
{
	echo "/usr/$(get_libdir)/mpi/${PF}"	
}

# @FUNCTION: _mpi_do
# @DESCRIPTION:
# mpi-sepecific build functions to be called from mpi pkg ebuilds
_mpi_do()
{
	local rc prefix d
	local cmd=${1}
	local ran=1
	local slash=/
	local mdir="$(mpi_root)"

	shift


	if [ "${cmd#do}" != "${cmd}" ]; then
		prefix="do"; cmd=${cmd#do}
	elif [ "${cmd#new}" != "${cmd}" ]; then
		prefix="new"; cmd=${cmd#new}
	else
		die "Unknown command passed to _mpi_do: ${cmd}"
	fi

	case ${cmd} in
		bin|lib|lib.a|lib.so|sbin)
			DESTTREE="${mdir}usr" ${prefix}${cmd} $*
			rc=$?
			;;
		doc)
			_E_DOCDESTTREE_="../../../../${mdir}usr/share/doc/${PF}/${_E_DOCDESTTREE_}" \
				${prefix}${cmd} $*
			rc=$?
			for d in "/share/doc/${P}" "/share/doc" "/share"; do
				rmdir ${D}/usr${d} &>/dev/null
			done
			;;
		html)
			_E_DOCDESTTREE_="../../../../${mdir}usr/share/doc/${PF}/www/${_E_DOCDESTTREE_}" \
			${prefix}${cmd} $*
			rc=$?
			for d in "/share/doc/${P}/html" "/share/doc/${P}" "/share/doc" "/share"; do
				rmdir ${D}/usr${d} &>/dev/null
			done
			;;
		exe)
			_E_EXEDESTTREE_="${mdir}${_E_EXEDESTTREE_}" ${prefix}${cmd} $*
			rc=$?
			;;
		man|info)
			"${D}"usr/share/${cmd} ] && mv "${D}"usr/share/${cmd}{,-orig}
			[ ! -d "${D}"${mdir}usr/share/${cmd} ] \
				&& install -d "${D}"${mdir}usr/share/${cmd}
			[ ! -d "${D}"usr/share ] \
				&& install -d "${D}"usr/share

			ln -snf ../../${mdir}usr/share/${cmd} ${D}usr/share/${cmd}
			${prefix}${cmd} $*
			rc=$?
			rm "${D}"usr/share/${cmd}
			[ -d "${D}"usr/share/${cmd}-orig ] \
				&& mv "${D}"usr/share/${cmd}{-orig,}
			[ "$(find "${D}"usr/share/)" == "${D}usr/share/" ] \
			rmdir "${D}usr/share"
			;;
		dir)
			dodir "${@/#${slash}/${mdir}${slash}}"; rc=$?
			;;
		hard|sym)
			${prefix}${cmd} "${mdir}$1" "${mdir}/$2"; rc=$?
			;;
		ins)
			INSDESTTREE="${mdir}${INSTREE}" ${prefix}${cmd} $*; rc=$?
			;;
		*)
			rc=0
			;;
	esac

	[[ ${ran} -eq 0 ]] && die "mpi_do passed unknown command: ${cmd}"
	return ${rc}
}

mpi_dobin()     { _mpi_do "dobin"        $*; }
mpi_newbin()    { _mpi_do "newbin"       $*; }
mpi_dodoc()     { _mpi_do "dodoc"        $*; }
mpi_newdoc()    { _mpi_do "newdoc"       $*; }
mpi_doexe()     { _mpi_do "doexe"        $*; }
mpi_newexe()    { _mpi_do "newexe"       $*; }
mpi_dohtml()    { _mpi_do "dohtml"       $*; }
mpi_dolib()     { _mpi_do "dolib"        $*; }
mpi_dolib.a()   { _mpi_do "dolib.a"      $*; }
mpi_newlib.a()  { _mpi_do "newlib.a"     $*; }
mpi_dolib.so()  { _mpi_do "dolib.so"     $*; }
mpi_newlib.so() { _mpi_do "newlib.so"    $*; }
mpi_dosbin()    { _mpi_do "dosbin"       $*; }
mpi_newsbin()   { _mpi_do "newsbin"      $*; }
mpi_doman()     { _mpi_do "doman"        $*; }
mpi_newman()    { _mpi_do "newman"       $*; }
mpi_doinfo()    { _mpi_do "doinfo"       $*; }
mpi_dodir()     { _mpi_do "dodir"        $*; }
mpi_dohard()    { _mpi_do "dohard"       $*; }
mpi_doins()     { _mpi_do "doins"        $*; }
mpi_dosym()     { _mpi_do "dosym"        $*; }


# @ECLASS-FUNCTION: mpi-select_detect_installs
# @DESCRIPTION:
# See what MPI software is installed on the system
get_all_implemenetations()
{
    for dir in "${MPI_DIR}"/*
    do
        INSTALLED_IMPLEMENTATIONS="${INSTALLED_IMPLEMENTATIONS} ${dir}"
    done

    echo "${INSTALLED_IMPLEMENTATIONS}"
}

# @ECLASS-FUNCTION: mpi_foreach_implementation
# @DESCRIPTION:
# Iterates through each given implementation and repeats commands for each implementation
mpi_foreach_implementation()
{
	debug-print-function ${FUNCNAME} "${@}"	

	# [[ -z "${INSTALLED_IMPLEMENTATIONS}" ]] \
	#			die "No mpi implementations detected"

	local status=0

	for implementation in "${@}"
	do
		# iterate through implementations, repeat same commands for each variant
		if [[ "${IMPLEMENTATION_LIST}" == *"${implementation}"* ]]; then
			local BUILD_DIR="${WORKDIR}/build"
			einfo ${BUILD_DIR}
			
			# modeling after multibuild for testing & learning
			_mpi_run()
			{
				local i=1
				while [[ ${!1} == _* ]];do
					i+=1
				done

				[[ ${i} -le ${#} ]]
				einfo ${@}
				echo ${@}
			}

			_mpi_run "${@}"
		else
			die "invalid implementation!"
		fi

	
	done

	echo "${status}"
}





# @ECLASS-FUNCTION: mpi_wrapper
# @DESCRIPTION:
# Helper function for setting up environment
mpi_wrapper()
{
	export BUILD_DIR="${PF}-${ABI}"

	export LD_LIBRARY_PATH="/usr/$(get_libdir)/mpi/mpich-3.2/install/usr/bin:${LD_LIBRARY_PATH}"

	echo ${impl}

}

# @ECLASS-FUNCTION: mpi-select_get_implementation
# @DESCRIPTION:
# Helper function for getting the current implementation in use
mpi-select_get_implementation()
{
	echo "${PN}"
}

# @FUCNTION: mpi-select_mpi_pkg_set_env
# @DESCRIPTION:
# Set environment variables specificly for mpi
mpi-select_mpi_pkg_set_env()
{
	_mpi_oCC=${CC}
	_mpi_oCXX=${CXX}
	_mpi_oF77=${FF}
	_mpi_oFC=${FC}
	_mpi_oPCP=${PKG_CONFIG_PATH}
	_mpi_oLLP=${LD_LIBRARY_PATH}
	export CC=$(mpi_pkg_cc)
	export CXX=$(mpi_pkg_cxx)
	export F77=$(mpi_pkg_f77)
	export FC=$(mpi_pkg_fc)
	export PKG_CONFIG_PATH="$(mpi_root)$(get_libdir)/pkgconfig:${PKG_CONFIG_PATH}"
	export LD_LIBRARY_PATH="/usr/$(get_libdir)/mpi/mpich-3.2/install/usr/bin:${LD_LIBRARY_PATH}"
}

# @FUCNTION: mpi-select_mpi_pkg_restore_env
# @DESCRIPTION:
# Set envrionment variables to what they were before mpi_pkg_set_env
mpi-select_mpi_pkg_set_env()
{
	export CC=${_mpi_oCC}
	export CXX=$_mpi_oCXX
	export F77=$_mpi_oF77
	export FC=$_mpi_oFC
	export PKG_CONFIG_PATH=${_mpi_oPCP}
}

# @ECLASS-FUNCTION: mpi-select_bindir
# @DESCRIPTION:
# Helper function for getting the directory for binaries to be installed to
mpi-select_bindir()
{
	echo "${D}/usr/bin/${PF}/"
}

# @ECLASS-FUNCTION: mpi-select_libdir
# @DESCRIPTION:
# Helper function for getting the directory for libraries to be installed to
mpi-select_libdir()
{
	echo "${D}/usr/$(get_libdir)/mpi/${PF}/"
}

# @ECLASS-FUNCTION: mpi-select_etcdir
# @DESCRIPTION:
# Helper function for getting the directory for /etc* to be installed to
mpi-select_etcdir()
{
	echo "${D}/etc/${PF}/"
}

###########################
# MPI SRC PHASE FUNCTIONS #
###########################

mpi-select_src_configure()
{
	append-cflags -std=gnu89

	mpi_wrapper

	if [[ "${imp}" == "mpich" ]]; then
		einfo "hit mpich"
	elif [[ "${imp}" == "openmpi" ]]; then
		einfo "hit openmpi"
	fi

	mpi-select_src_configure()
	{
		mkdir -p "${BUILD_DIR}" || die
		pushd "${BUILD_DIR}" > /dev/null || die
		if declare -f multilib_src_configure > /dev/null ; then
			multilib_src_configure
		else
			default_src_configure
		fi

		popd > /dev/null || die
	}

	multilib_foreach_variant mpi-select_src_configure
}

mpi-select_src_compile()
{
	local imp=$(mpi-select_get_implementation)

	if [[ "${imp}" == "mpich" ]]; then
		einfo "hit mpich"
	elif [[ "${imp}" == "openmpi" ]]; then
		einfo "hit openmpi"
	fi

	mpi-select_src_compile()
	{
		mkdir -p "${BUILD_DIR}" || die
		pushd "${BUILD_DIR}" > /dev/null || die
		if declare -f multilib_src_compile > /dev/null ; then
			multilib_src_compile
		else
			default_src_compile
		fi

		popd > /dev/null || die
	}

	multilib_foreach_variant mpi-select_src_compile
}

mpi-select_src_test()
{
	emake -j1 check

	mpi-select_src_test()
	{
		mkdir -p "${BUILD_DIR}" || die
		pushd "${BUILD_DIR}" > /dev/null || die
		if declare -f multilib_src_test > /dev/null ; then
			multilib_src_test
		else
			default_src_test
		fi

		popd > /dev/null || die
	}

	multilib_foreach_variant mpi-select_src_test
}

mpi-select_src_install()
{
	emake DESTDIR="${D}" install

	dodir $(mpi-select_bindir)
	mv "${D}"/usr/bin/* $(mpi-select_bindir)

	dodir $(mpi-select_libdir)
	mv "${D}"/usr/$(get_libdir)/* $(mpi-select_libdir)

	dodir $(mpi-select_etcdir)
	local i
	for i in "${D}/etc/"*; do
		[ "${i}" == $(mpi-select_etcdir) ] && continue
		mv "${i}" $(mpi-select_etcdir) || die "failed to mv"
	done

	find . -type d -empty -delete || die "could not delete empty directories"

	mpi-select_src_install()
	{
		mkdir -p "${BUILD_DIR}" || die
		pushd "${BUILD_DIR}" > /dev/null || die
		if declare -f multilib_src_test > /dev/null ; then
			multilib_src_install
		else
			default_src_test
		fi
		
		popd > /dev/null || die
	}

	multilib_foreach_variant mpi-select_src_install

	
	# TODO: proper conditional for einstalldocs
	einstalldocs
}