libpmodules.bash 20.6 KB
Newer Older
1
#!/bin/bash
gsell's avatar
gsell committed
2

3 4 5
# disable auto-echo feature of 'cd'
unset CDPATH

6
shopt -s expand_aliases
gsell's avatar
gsell committed
7 8
declare -rx ARGS="$@"

9 10


11 12
declare -r  BUILDSCRIPT_DIR=$( cd $(dirname "$0") && pwd )
declare -r  BUILDSCRIPT="${BUILDSCRIPT_DIR}"/$(basename "$0")
13
declare -rx SHLIBDIR=$( cd $(dirname "$BASH_SOURCE") && pwd )
gsell's avatar
gsell committed
14 15 16 17 18 19
source "${SHLIBDIR}/lib.bash"

declare -rx BUILD_BASEDIR=$(abspath $SHLIBDIR/..)



gsell's avatar
gsell committed
20
PATH=/usr/bin:/bin:/usr/sbin:/sbin
gsell's avatar
gsell committed
21

22
declare -r OS=$(uname -s)
gsell's avatar
gsell committed
23 24 25 26 27 28
if [[ "${OS}" == "Darwin" ]]; then
	# :FIXME: why do we need this?
	[[ -d "/opt/X11/bin" ]] && PATH+=':/opt/X11/bin'
fi


gsell's avatar
gsell committed
29

30
# number of parallel make jobs
31
declare -i  JOBS=3
gsell's avatar
gsell committed
32

33 34 35 36 37 38 39 40
source "$(readlink ${BUILD_BASEDIR}/config/environment.bash)"

declare -xr BUILD_CONFIGDIR="${BUILD_BASEDIR}/config"
declare -xr BUILD_SCRIPTSDIR="${BUILD_BASEDIR}/scripts"
declare -xr BUILD_TMPDIR="${BUILD_BASEDIR}/tmp"
declare -xr BUILD_DOWNLOADSDIR="${BUILD_BASEDIR}/Downloads"
declare -xr BUILD_VERSIONSFILE="${BUILD_CONFIGDIR}/versions.conf"

gsell's avatar
gsell committed
41
source "${BUILD_CONFIGDIR}/Pmodules.conf"
42 43 44

declare -x  PREFIX=''
declare -x  DOCDIR=''
gsell's avatar
gsell committed
45
declare -x  MODULE_GROUP=''
46
declare	-x  MODULE_RELEASE=''
47 48 49
declare     cur_module_release=''

declare     DEPEND_RELEASE=''
50 51 52 53 54 55 56 57 58
declare -x  MODULE_NAME=''

# these directories are module dependend
declare -x  MODULE_SRCDIR=''
declare -x  MODULE_BUILDDIR=''

declare -x  MODULE_BUILD_DEPENDENCIES
declare -x  MODULE_DEPENDENCIES

59 60 61 62 63 64
declare -x  C_INCLUDE_PATH
declare -x  CPLUS_INCLUDE_PATH
declare -x  CPP_INCLUDE_PATH
declare -x  LIBRARY_PATH
declare -x  LD_LIBRARY_PATH
declare -x  DYLD_LIBRARY_PATH
65

66 67
##############################################################################
#
gsell's avatar
gsell committed
68
usage() {
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
	error "
Usage: $0 [OPTIONS..] [VERSION] [ENV=VALUE...]

VERSION
        Version of module to compile.

ENV=VALUE
        Set environment variable ENV to VALUE. This can be used to
        overwrite default versions.

-? | -h | --help
        Print usage

-v | --verbose )
        Verbose output

-j N | --jobs=N
        Run N parallel make jobs

-f | --force-rebuild
        Force rebuild of module.

91 92 93
-b | --bootstrap 
	Bootstrap Pmodules

94 95 96
--with=P/V
        Preload module P with version V. To preload multiple modules,
        use this option per module. Nete that order may matter.
97

98
--release=stable|unstable|deprecated
99 100 101 102 103

"
	exit 1
}

104 105 106 107 108 109
##############################################################################
#
# test whether a the string passed in $1 is a valid release name
#
# $1: string to be tested
#
110 111
is_release () {
	[[ ${releases} =~ :$1: ]]
112
}
113

114 115
##############################################################################
#
gsell's avatar
gsell committed
116
# set supported OS
117
#
gsell's avatar
gsell committed
118
# $1: OS (as printed by 'uname -s')
119
#
gsell's avatar
gsell committed
120
pmodules.supported_os() {
121 122
	for os in "$@"; do
		[[ ${os} == ${OS} ]] && return 0
gsell's avatar
gsell committed
123
	done
124
	die 0 "${P}: Not available for ${OS}."
gsell's avatar
gsell committed
125 126
}

gsell's avatar
gsell committed
127 128 129 130 131 132 133
##############################################################################
#
# install module in given group
#
# $1: group
#
pmodules.add_to_group() {
gsell's avatar
gsell committed
134
	if [[ -z ${1} ]]; then
gsell's avatar
gsell committed
135
		die 42 "${FUNCNAME}: Missing group argument."
gsell's avatar
gsell committed
136
	fi
gsell's avatar
gsell committed
137 138
	if [[ ! -d ${PMODULES_ROOT}/${PMODULES_TEMPLATES_DIR}/${1} ]]; then
		die 43 "${1}: group does not exist."
gsell's avatar
gsell committed
139
	fi
gsell's avatar
gsell committed
140 141 142
	MODULE_GROUP=$1
}

gsell's avatar
gsell committed
143 144
##############################################################################
#
145
# set build-/runtime dependencies
gsell's avatar
gsell committed
146
#
147
# $@: dependencies
gsell's avatar
gsell committed
148 149
#
pmodules.set_build_dependencies() {
150
	MODULE_BUILD_DEPENDENCIES=("$@")
151 152
}

153 154 155 156 157 158 159 160 161 162
pmodules.set_runtime_dependencies() {
	MODULE_DEPENDENCIES=("$@")
}

##############################################################################
#
# set documentation file to be installed
#
# $@: documentation files relative to source
#
gsell's avatar
gsell committed
163 164
pmodules.set_docfiles() {
	MODULE_DOCFILES=("$@")
gsell's avatar
gsell committed
165 166
}

167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
##############################################################################
#
# set supported compilers
#
# $@: compilers
#
pmodules.set_supported_compilers() {
	MODULE_SUPPORTED_COMPILERS=("$@")
}

##############################################################################
#
# test availablity of a module
#
# $@: module
#
gsell's avatar
gsell committed
183 184
module_is_available() {
	[[ -n $("${MODULECMD}" bash avail "$1" 2>&1 1>/dev/null) ]]
gsell's avatar
gsell committed
185 186
}

gsell's avatar
gsell committed
187 188 189 190 191 192 193 194
##############################################################################
#
# test whether a module is loaded or not
#
# $1: module name
#
is_loaded() {
        [[ :${LOADEDMODULES}: =~ :$1: ]]
gsell's avatar
gsell committed
195 196
}

197

gsell's avatar
gsell committed
198
load_build_dependencies() {
199
	for m in "${MODULE_BUILD_DEPENDENCIES[@]}"; do
200 201
		[[ -z $m ]] && continue
		if [[ ! $m =~ "*/*" ]]; then
gsell's avatar
gsell committed
202 203 204 205
			local _V=$(echo -n $m | tr [:lower:] [:upper:] )_VERSION
			if [[ -n ${!_V} ]]; then
		    		m=$m/${!_V}
			else
gsell's avatar
gsell committed
206
				echo "$m: warning: No version set, loading default ..."
gsell's avatar
gsell committed
207
			fi
208
		fi
gsell's avatar
gsell committed
209
		is_loaded "$m" && continue
210 211
		if ! module_is_available "$m"; then
		        debug "${m}: module not available"
gsell's avatar
gsell committed
212
			local rels=( ${releases//:/ } )
213 214 215 216 217
			for rel in "${rels[@]}"; do
				debug "${m}: check release \"${rel}\""
				eval $("${MODULECMD}" bash use ${rel})
				if module_is_available "${m}"; then
					die 1 "${m}: module available with release \"${rel}\", add this release with \"module use ${rel}\" and re-run build script."
218 219
				fi
			done
220 221 222
			[[ ${dry_run} == yes ]] && {
				die 1 "${m}: module does not exist, cannot continue with dry run..."
				}
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

			echo "$m: module does not exist, trying to build it..."
			local args=( '' )
			set -- ${ARGS[@]}
			while (( $# > 0 )); do
				case $1 in
				-j )
					args+=( "-j $2" )
					shift
					;;
				--jobs=[0-9]* )
					args+=( $1 )
					;;
				-v | --verbose)
					args+=( $1 )
					;;
				--release=* )
					args+=( $1 )
					;;
				--with=*/* )
					args+=( $1 )
					;;
				*=* )
					args+=( $1 )
					;;
				esac
				shift
			done
251
			"${BUILD_SCRIPTSDIR}"/*/"${m/\/*}/build" ${args[@]}
252
			if [[ -z $(module avail "$m" 2>&1) ]]; then
gsell's avatar
gsell committed
253
				die 1 "$m: oops: build failed..."
254 255
			fi
		fi
gsell's avatar
gsell committed
256 257
		# :FIXME: this doesn't work any more!
		local modulepath_root="${PMODULES_ROOT}/${PMODULES_MODULEFILES_DIR}"
258 259
		local tmp=$( module display "${m}" 2>&1 | grep -m1 -- "${modulepath_root}" )
		tmp=${tmp/${modulepath_root}\/}
260 261 262
		tmp=${tmp%%/*}
		local _family=( ${tmp//./ } )
		if [[ ${_family[1]} == deprecated ]]; then
263 264
			# set module release to 'deprecated' if a build dependency
			# is deprecated
265
			DEPEND_RELEASE='deprecated'
266
		elif [[ ${_family[1]} == unstable ]] && [[ -z ${DEPEND_RELEASE} ]]; then
267 268
			# set module release to 'unstable' if a build dependency is
			# unstable and release not yet set
269
			DEPEND_RELEASE='unstable'
270
		fi
gsell's avatar
gsell committed
271 272

		
273 274
		echo "Loading module: ${m}"
		module load "${m}"
275 276 277
	done
}

278
if [[ ${bootstrap} == yes ]]; then
gsell's avatar
gsell committed
279
    load_build_dependencies() {
280 281 282 283
	    :
    }
fi

gsell's avatar
gsell committed
284
write_runtime_dependencies() {
gsell's avatar
gsell committed
285
	local -r fname="${PREFIX}/.dependencies"
286
	info "Writing run-time dependencies to ${fname}"
gsell's avatar
gsell committed
287 288
	local dep
	echo -n "" > "${fname}"
289
	for dep in "${MODULE_DEPENDENCIES[@]}"; do
gsell's avatar
gsell committed
290
		[[ -z $dep ]] && continue
291
		if [[ ! $dep =~ .*/.* ]]; then
292
		    local _V=$(echo -n $dep | tr [:lower:] [:upper:] )_VERSION
gsell's avatar
gsell committed
293 294 295 296 297 298
		    dep=$dep/${!_V}
		fi
		echo "${dep}" >> "${fname}"
	done
}

gsell's avatar
gsell committed
299
write_build_dependencies() {
gsell's avatar
gsell committed
300
	local -r fname="${PREFIX}/.build_dependencies"
301
	info "Writing build dependencies to ${fname}"
gsell's avatar
gsell committed
302 303
	local dep
	echo -n "" > "${fname}"
304
	for dep in "${MODULE_BUILD_DEPENDENCIES[@]}"; do
gsell's avatar
gsell committed
305 306
		[[ -z $dep ]] && continue
		if [[ ! $dep =~ "*/*" ]]; then
307
		    local _V=$(echo -n $dep | tr [:lower:] [:upper:] )_VERSION
gsell's avatar
gsell committed
308 309 310 311 312 313
		    dep=$dep/${!_V}
		fi
		echo "${dep}" >> "${fname}"
	done
}

314 315 316 317
##############################################################################
# 
# cleanup environment
#
gsell's avatar
gsell committed
318
pmodules.cleanup_env() {
319

gsell's avatar
gsell committed
320 321 322 323 324 325 326
	C_INCLUDE_PATH=''
	CPLUS_INCLUDE_PATH=''
	CPP_INCLUDE_PATH=''
	LIBRARY_PATH=''
	LD_LIBRARY_PATH=''
	DYLD_LIBRARY_PATH=''

327 328 329 330 331
	CFLAGS=''
	CPPFLAGS=''
	CXXFLAGS=''
	LIBS=''
	LDFLAGS=''
332 333 334 335 336 337 338 339
}

##############################################################################
#
# load default versions
#
 _setup_env1() {
	local varname=''
340 341 342 343
	while read _name _version; do
		[[ -z ${_name} ]] && continue
		[[ -z ${_version} ]] && continue
		[[ "${_name:0:1}" == '#' ]] && continue
344 345 346 347 348
		var_name=$(echo ${_name} | tr [:lower:] [:upper:])_VERSION
		# don't set version, if already set
		if [[ -z ${!var_name} ]]; then
			eval ${var_name}="${_version}"
		fi
349 350 351 352
	done < "${BUILD_VERSIONSFILE}"

}

gsell's avatar
gsell committed
353 354 355 356 357 358
#
# find tarball 
# $1: download directory
# $2: name without version
# $3: version
#
gsell's avatar
gsell committed
359
find_tarball() {
gsell's avatar
gsell committed
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383
	local -r dir=$1
	local -r name=$2
	local -r version=$3

	TARBALL=""
	local ext
	for ext in tar tar.gz tgz tar.bz2 tar.xz; do
		local fname="${dir}/${name}-${OS}-${version}.${ext}"
		if [[ -r "${fname}" ]]; then
			TARBALL="${fname}"
			break
		fi
		local fname="${dir}/${name}-${version}.${ext}"
		if [[ -r "${fname}" ]]; then
			TARBALL="${fname}"
			break
		fi
	done
	if [[ -z ${TARBALL} ]]; then
		error "tar-ball for $P/$V not found."
		exit 43
	fi
}

384
#setup module specific environment
gsell's avatar
gsell committed
385
setup_env2() {
gsell's avatar
gsell committed
386 387
	if [[ -z ${MODULE_GROUP} ]]; then
		die 1 "$P: group not set."
gsell's avatar
gsell committed
388 389 390
	fi

	# overwrite environment variables with values we got on the cmd line
gsell's avatar
gsell committed
391
	eval "${ENVIRONMENT_ARGS}"
gsell's avatar
gsell committed
392

393 394
	# this allows us to specify the version as PKGNAME_VERSION=1.2.3 on
	# the cmd-line
gsell's avatar
gsell committed
395 396 397 398 399 400 401 402
        if [[ -z $V ]]; then
		V=$(eval echo \$${_P}_VERSION)
	fi

	# oops, we need a version
	if [[ -z $V ]]; then
		die 1 "$P: Missing version."
	fi
403
	MODULE_SRCDIR="${BUILD_TMPDIR}/src/${P/_serial}-$V"
404
	MODULE_BUILDDIR="${BUILD_TMPDIR}/build/$P-$V"
gsell's avatar
gsell committed
405 406

	# build module name
407 408
	# :FIXME: the MODULE_PREFIX should be derived from MODULE_NAME
	# :FIXME: this should be read from a configuration file
gsell's avatar
gsell committed
409
	case ${MODULE_GROUP} in
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 451 452
		Tools )
			MODULE_RPREFIX="${P}/${V}"
			MODULE_NAME="${P}/${V}"
			;;
		Programming )
			MODULE_RPREFIX="${P}/${V}"
			MODULE_NAME="${P}/${V}"
			;;
		Libraries )
			MODULE_RPREFIX="${P}/${V}"
			MODULE_NAME="${P}/${V}"
			;;
		System )
			MODULE_RPREFIX="${P}/${V}"
			MODULE_NAME="${P}/${V}"
			;;
		Compiler )
			MODULE_RPREFIX="${P}/${V}"
			MODULE_RPREFIX+="/${COMPILER}/${COMPILER_VERSION}"
			
			MODULE_NAME="${COMPILER}/${COMPILER_VERSION}/"
			MODULE_NAME+="${P}/${V}"
			;;
		MPI )
			MODULE_RPREFIX="${P}/${V}/"
			MODULE_RPREFIX+="${MPI}/${MPI_VERSION}/"
			MODULE_RPREFIX+="${COMPILER}/${COMPILER_VERSION}"
			
			MODULE_NAME="${COMPILER}/${COMPILER_VERSION}/"
			MODULE_NAME+="${MPI}/${MPI_VERSION}/"
			MODULE_NAME+="${P}/${V}"
			;;
		HDF5 )
			MODULE_RPREFIX="${P}/${V}"
			MODULE_RPREFIX+="/${HDF5}/${HDF5_VERSION}"
			MODULE_RPREFIX+="/${MPI}/${MPI_VERSION}"
			MODULE_RPREFIX+="/${COMPILER}/${COMPILER_VERSION}"
			
			MODULE_NAME="${COMPILER}/${COMPILER_VERSION}/"
			MODULE_NAME+="${MPI}/${MPI_VERSION}/"
			MODULE_NAME+="${HDF5}/${HDF5_VERSION}/"
			MODULE_NAME+="${P}/${V}"
			;;
453 454 455 456 457 458 459 460 461 462 463
		OPAL )
			MODULE_RPREFIX="${P}/${V}"
			MODULE_RPREFIX+="/${OPAL}/${OPAL_VERSION}"
			MODULE_RPREFIX+="/${MPI}/${MPI_VERSION}"
			MODULE_RPREFIX+="/${COMPILER}/${COMPILER_VERSION}"
			
			MODULE_NAME="${COMPILER}/${COMPILER_VERSION}/"
			MODULE_NAME+="${MPI}/${MPI_VERSION}/"
			MODULE_NAME+="${OPAL}/${OPAL_VERSION}/"
			MODULE_NAME+="${P}/${V}"
			;;
464 465 466 467 468 469
		HDF5_serial )
			MODULE_RPREFIX="${P}/${V}"
			MODULE_RPREFIX+="/hdf5_serial/${HDF5_SERIAL_VERSION}"
			MODULE_RPREFIX+="/${COMPILER}/${COMPILER_VERSION}"
			
			MODULE_NAME="${COMPILER}/${COMPILER_VERSION}/"
gsell's avatar
gsell committed
470
			MODULE_NAME+="hdf5_serial/${HDF5_SERIAL_VERSION}/"
471 472 473
			MODULE_NAME+="${P}/${V}"
			;;
		* )
gsell's avatar
gsell committed
474
			die 1 "$P: oops: unknown group: ${MODULE_GROUP}"
475
			;;
gsell's avatar
gsell committed
476 477
	esac

gsell's avatar
gsell committed
478
	# set PREFIX of module
gsell's avatar
gsell committed
479
	PREFIX="${PMODULES_ROOT}/${MODULE_GROUP}/${MODULE_RPREFIX}"
gsell's avatar
gsell committed
480

481 482
	# get module release if already installed
	local saved_modulepath=${MODULEPATH}
483 484 485
	rels=( ${releases//:/ } )
	for rel in "${rels[@]}"; do
		eval $("${MODULECMD}" bash unuse ${rel})
486
	done
487 488 489
	for rel in "${rels[@]}"; do
		eval $("${MODULECMD}" bash use ${rel})
		if module_is_available "${P}/${V}"; then
490
			cur_module_release=${rel}
491
			info "${P}/${V}: already available and released as \"${rel}\""
492 493 494 495 496 497 498 499 500 501
			break
		fi
	done
	MODULEPATH=${saved_modulepath}

	# set release of module
	# release is deprecated
	#   - if a build-dependency is deprecated or 
	#   - the module already exists and is deprecated or
	#   - is forced to be deprecated by setting this on the command line
502 503 504 505
	if [[ "${depend_release}" == 'deprecated' ]] || \
		[[ "${cur_module_release}" == 'deprecated' ]] \
		|| [[ "${MODULE_RELEASE}" == 'deprecated' ]]; then
		MODULE_RELEASE='deprecated'
506 507 508 509 510
		info "${P}/${V}: will be released as \"deprecated\""
	#
	# release is stable
	#   - if all build-dependency are stable or
	#   - the module already exists and is stable
511 512
	#   - an unstable release of the module exists and the release is
	#     changed to stable on the command line
513 514 515 516
	elif [[ "${depend_release}" == 'stable' ]] \
		|| [[ "${cur_module_release}" == 'stable' ]] \
		|| [[ "${MODULE_RELEASE}" == 'stable' ]]; then
		MODULE_RELEASE='stable'
517 518 519 520
		info "${P}/${V}: will be released as \"stable\""
	#
	# release is unstable
	#   - if a build-dependency is unstable or 
521 522
	#   - if the module does not exists and no other release-type is
	#     given on the command line
523 524
	#   - and all the cases I didn't think of
	else
525
		MODULE_RELEASE='unstable'
526 527
		info "${P}/${V}: will be released as \"unstable\""
	fi
528 529

	# directory for README's, license files etc
gsell's avatar
gsell committed
530 531
	DOCDIR="${PREFIX}/share/doc/$P"

532
	# set tar-ball and flags for tar
gsell's avatar
gsell committed
533
	find_tarball "${BUILD_DOWNLOADSDIR}" "${P/_serial}" "${V}"
534

gsell's avatar
gsell committed
535 536
}

537
# redefine function for bootstrapping
gsell's avatar
gsell committed
538
setup_env2_bootstrap() {
gsell's avatar
gsell committed
539 540
	if [[ -z ${MODULE_GROUP} ]]; then
		die 1 "$P: group not set."
541
	fi
542

543
        if [[ -z $V ]]; then
544
		V=$(eval echo \$${_P}_VERSION)
545
	fi
546

547 548
	# oops, we need a version
	if [[ -z $V ]]; then
549
		die 1 "$P: Missing version."
550 551 552
	fi
	MODULE_SRCDIR="${BUILD_TMPDIR}/src/${P/_serial}-$V"
	MODULE_BUILDDIR="${BUILD_TMPDIR}/build/$P-$V"
gsell's avatar
gsell committed
553
	MODULE_GROUP='Tools'
554 555
	MODULE_NAME="Pmodules/${PMODULES_VERSION}"
	# set PREFIX of module
gsell's avatar
gsell committed
556
	PREFIX="${PMODULES_ROOT}/${MODULE_GROUP}/${MODULE_NAME}"
557 558 559 560 561 562 563 564
	
	MODULE_RELEASE='unstable'
	info "${MODULE_NAME}: will be released as \"${MODULE_RELEASE}\""

	# directory for README's, license files etc
	DOCDIR="${PREFIX}/share/doc/$P"

	# set tar-ball and flags for tar
gsell's avatar
gsell committed
565 566
	find_tarball "${BUILD_DOWNLOADSDIR}" "${P/_serial}" "${V}"

567 568 569 570 571 572 573 574 575
	C_INCLUDE_PATH="${PREFIX}/include"
	CPLUS_INCLUDE_PATH="${PREFIX}/include"
	CPP_INCLUDE_PATH="${PREFIX}/include"
	LIBRARY_PATH="${PREFIX}/lib"
	LD_LIBRARY_PATH="${PREFIX}/lib"
	DYLD_LIBRARY_PATH="${PREFIX}/lib"

	PATH+=":${PREFIX}/bin"
}
576

gsell's avatar
gsell committed
577
prep() {
gsell's avatar
gsell committed
578 579

	# untar sources
580 581
	if [[ ! -d ${MODULE_SRCDIR} ]]; then
		mkdir -p "${BUILD_TMPDIR}/src"
582
		(cd "${BUILD_TMPDIR}/src" && tar xvf "${TARBALL}")
gsell's avatar
gsell committed
583 584 585
	fi

	# create build directory
586
	mkdir -p "${MODULE_BUILDDIR}"
gsell's avatar
gsell committed
587 588 589

}

gsell's avatar
gsell committed
590
pmodules.pre_configure() {
gsell's avatar
gsell committed
591 592 593
	:
}

gsell's avatar
gsell committed
594
pmodules.configure() {
595
	${MODULE_SRCDIR}/configure \
gsell's avatar
gsell committed
596 597 598
		--prefix="${PREFIX}"
}

gsell's avatar
gsell committed
599
pmodules.build() {
gsell's avatar
gsell committed
600 601 602
	make -j${JOBS}
}

gsell's avatar
gsell committed
603
pmodules.install() {
gsell's avatar
gsell committed
604 605 606
	make install
}

gsell's avatar
gsell committed
607
pmodules.post_install() {
gsell's avatar
gsell committed
608 609 610
	:
}

gsell's avatar
gsell committed
611
pmodules.install_doc() {
612
	info "Installing documentation to ${DOCDIR}"
613
	install -m 0755 -d "${DOCDIR}"
614
	install -m0444 "${MODULE_DOCFILES[@]/#/${MODULE_SRCDIR}/}" "${BUILDSCRIPT}" "${DOCDIR}"
gsell's avatar
gsell committed
615 616
}

gsell's avatar
gsell committed
617
set_legacy_link() {
gsell's avatar
gsell committed
618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636
	local -r link_name="${PMODULES_ROOT}/${PMODULES_MODULEFILES_DIR}/${MODULE_GROUP}/${MODULE_NAME}"
	local -r dir_name=${link_name%/*}
	local -r release_file="${dir_name}/.release-${MODULE_NAME##*/}"
	if [[ ! -e "${_path}" ]]; then
	    (
		    info "Setting new sym-link \"${link_name}\" ..."
		    mkdir -p "${dir_name}"
		    cd "${dir_name}"
		    local x
		    IFS='/' x=( ${dir_name/${PMODULES_ROOT}\/${PMODULES_MODULEFILES_DIR}\/} )
		    local n=${#x[@]}
		    local -r _target="../"$(eval printf "../%.s" {1..${n}})${PMODULES_TEMPLATES_DIR##*/}/"${MODULE_GROUP}/${P}/modulefile"
		    ln -fs "${_target}" "${MODULE_NAME##*/}"
	    )
	fi
	info "${MODULE_NAME}: set release to '${MODULE_RELEASE}'"
	echo "${MODULE_RELEASE}" > "${release_file}"
}

gsell's avatar
gsell committed
637
set_link() {
gsell's avatar
gsell committed
638
	local -r link_name="${PMODULES_ROOT}/${MODULE_GROUP}/${PMODULES_MODULEFILES_DIR}/${MODULE_NAME}"
639 640 641 642 643 644 645 646
	local -r dir_name=${link_name%/*}
	local -r release_file="${dir_name}/.release-${MODULE_NAME##*/}"
	if [[ ! -e "${_path}" ]]; then
	    (
		    info "Setting new sym-link \"${link_name}\" ..."
		    mkdir -p "${dir_name}"
		    cd "${dir_name}"
		    local x
gsell's avatar
gsell committed
647
		    IFS='/' x=( ${dir_name/${PMODULES_ROOT}\/${MODULE_GROUP}\/} )
648
		    local n=${#x[@]}
gsell's avatar
gsell committed
649
		    local -r _target="../"$(eval printf "../%.s" {1..${n}})${PMODULES_TEMPLATES_DIR##*/}/"${MODULE_GROUP}/${P}/modulefile"
650 651
		    ln -fs "${_target}" "${MODULE_NAME##*/}"
	    )
652
	fi
653 654
	info "${MODULE_NAME}: set release to '${MODULE_RELEASE}'"
	echo "${MODULE_RELEASE}" > "${release_file}"
gsell's avatar
gsell committed
655 656
}

gsell's avatar
gsell committed
657
pmodules.cleanup_build() {
658 659 660 661 662 663 664 665
	[[ -n "${MODULE_BUILDDIR}" ]]     \
		|| die 1 "Oops: internal error: MODULE_BUILDDIR is set to empty string..."
	[[ "${MODULE_BUILDDIR}" == "/" ]] \
		&& die 1 "Oops: internal error: MODULE_BUILDDIR is set to '/'..."
	[[ -d "/${MODULE_BUILDDIR}" ]]    \
		|| die 1 "Oops: internal error: MODULE_BUILDDIR=${MODULE_BUILDDIR} is not a directory..."
	echo "Cleaning up '/${MODULE_BUILDDIR}'..."
	rm -rf  "/${MODULE_BUILDDIR}"
gsell's avatar
gsell committed
666 667
}

gsell's avatar
gsell committed
668
pmodules.cleanup_src() {
669
    (
670 671
	[[ -d /${MODULE_SRCDIR} ]] || return 0
	cd "/${MODULE_SRCDIR}/..";
672 673
	if [[ $(pwd) != / ]]; then
		echo "Cleaning up $(pwd)"
674
		rm -rf ${MODULE_SRCDIR##*/}
675 676
	fi
    );
677
	return 0
678 679
}

gsell's avatar
gsell committed
680
check_compiler() {
681 682
	test -z ${MODULE_SUPPORTED_COMPILERS} && return 0
	for cc in ${MODULE_SUPPORTED_COMPILERS[@]}; do
gsell's avatar
gsell committed
683 684 685 686 687 688
		if [[ ${COMPILER}/${COMPILER_VERSION} =~ ${cc} ]]; then
			return 0
		fi
	done
	die 0 "Package cannot be build with ${COMPILER}/${COMPILER_VERSION}."
}
689

690
# unfortunatelly we need sometime an OS depended post-install
gsell's avatar
gsell committed
691
post_install_linux() {
692 693 694
	cd "${PREFIX}"
	# solve multilib problem with LIBRARY_PATH on 64bit Linux
	[[ -d "lib" ]] && [[ ! -d "lib64" ]] && ln -s lib lib64
695
	return 0
696 697
}

gsell's avatar
gsell committed
698
post_install() {
699
	info "Run post-installation for ${OS} ..."
gsell's avatar
gsell committed
700
	[[ "${OS}" == "Linux" ]] && post_install_linux
701
	info "Post-installation done ..."
gsell's avatar
gsell committed
702
	return 0
703
}
704

gsell's avatar
gsell committed
705
pmodules.make_all() {
gsell's avatar
gsell committed
706
	local building='no'
707
	echo "${P}:"
708
	_setup_env1
gsell's avatar
gsell committed
709
	load_build_dependencies
710
	# setup module specific environment
711
	if [[ ${bootstrap} == no ]]; then
gsell's avatar
gsell committed
712
		setup_env2
713
	else
gsell's avatar
gsell committed
714
		setup_env2_bootstrap
715
	fi
716

717
	if [[ ! -d "${PREFIX}" ]] || [[ ${force_rebuild} == 'yes' ]]; then
gsell's avatar
gsell committed
718
		building='yes'
719
 		echo "Building $P/$V ..."
720
		[[ ${dry_run} == yes ]] && die 0 ""
gsell's avatar
gsell committed
721 722
		check_compiler
		prep
723
		cd "${MODULE_SRCDIR}"
gsell's avatar
gsell committed
724
		pmodules.pre_configure
725
		cd "${MODULE_BUILDDIR}"
gsell's avatar
gsell committed
726 727 728 729 730 731
		pmodules.configure
		pmodules.build
		pmodules.install
		pmodules.post_install
		pmodules.install_doc
		post_install
732
		if [[ ${bootstrap} == 'no' ]]; then
gsell's avatar
gsell committed
733 734
			write_runtime_dependencies
			write_build_dependencies
735
		fi
gsell's avatar
gsell committed
736 737
		[[ ${enable_cleanup_build} == yes ]] && pmodules.cleanup_build
		[[ ${enable_cleanup_src} == yes ]] && pmodules.cleanup_src
738
		
gsell's avatar
gsell committed
739
	else
740
 		echo "Not rebuilding $P/$V ..."
gsell's avatar
gsell committed
741
	fi
742
	if [[ ${bootstrap} == 'no' ]]; then
gsell's avatar
gsell committed
743
		if [[ -d "${PMODULES_ROOT}/${PMODULES_MODULEFILES_DIR}" ]]; then
gsell's avatar
gsell committed
744
			set_legacy_link
gsell's avatar
gsell committed
745
		fi
gsell's avatar
gsell committed
746
		set_link
747
	fi
gsell's avatar
gsell committed
748
	return 0
gsell's avatar
gsell committed
749 750
}

751 752 753 754 755 756 757
##############################################################################
#
debug_on='no'
force_rebuild='no'
ENVIRONMENT_ARGS=''
dry_run='no'
bootstrap='no'
gsell's avatar
gsell committed
758 759
enable_cleanup_build='yes'
enable_cleanup_src='no'
760

gsell's avatar
gsell committed
761
pmodules.cleanup_env
762

763 764 765
# array collecting all modules specified on the command line via '--with=module'
with_modules=()

766 767 768 769
if [[ -r "${BUILDSCRIPT_DIR}/with_modules" ]]; then
	with_modules+=( $(cat "${BUILDSCRIPT_DIR}/with_modules") )
fi

770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791
while (( $# > 0 )); do
	case $1 in
	-j )
		JOBS=$2
		shift
		;;
	--jobs=[0-9]* )
		JOBS=${1/--jobs=}
		;;
	-v | --verbose)
		debug_on='yes'
		;;
	-f | --force-rebuild )
		force_rebuild='yes'
		;;
	-b | --bootstrap )
		bootstrap='yes'
		force_rebuild='yes'
		;;
	-? | -h | --help )
		usage
		;;
gsell's avatar
gsell committed
792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807
	--disable-cleanup )
		enable_cleanup_build='no'
		enable_cleanup_src='no'
		;;
	--enable-cleanup-build )
		enable_cleanup_build='yes'
		;;
	--disable-cleanup-build )
		enable_cleanup_build='no'
		;;
	--enable-cleanup-src )
		enable_cleanup_src='yes'
		;;
	--disable-cleanup-src )
		enable_cleanup_src='no'
		;;
808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833
	--dry-run )
		dry_run='yes'
		;;
	--release=* )
		MODULE_RELEASE=${1/--release=}
		;;
	--with=*/* )
		with_modules+=( ${1/--with=} )
		;;
	*=* )
		eval $1
		ENVIRONMENT_ARGS="${ENVIRONMENT_ARGS} $1"
		;;
	* )
		V=$1
		;;
	esac
	shift
done

if [[ ${debug_on} == yes ]]; then
	trap 'echo "$BASH_COMMAND"' DEBUG
fi

# while bootstraping the module command is not yet available
if [[ ${bootstrap} == no ]]; then
gsell's avatar
gsell committed
834
        source	"${PMODULES_ROOT}/${PMODULES_CONFIG_DIR}/profile.bash"
835 836 837 838 839 840 841 842 843 844 845 846
	MODULECMD="${PMODULES_HOME}/bin/modulecmd"
	[[ -x ${MODULECMD} ]] || die 1 "${MODULECMD}: no such executable"
	module use unstable
	module purge
	for m in "${with_modules[@]}"; do
		if module_is_available "$m"; then
			echo "Loading module: ${m}"
			module load "${m}"
		else
			die 44 "$m: module not available!"
		fi
	done
gsell's avatar
gsell committed
847
else
gsell's avatar
gsell committed
848
	read_versions "${BUILD_BASEDIR}/scripts/Bootstrap/Pmodules_version.conf"
gsell's avatar
gsell committed
849 850
	unset PMODULES_HOME
	source "/opt/psi/config/environment.bash"
851 852 853
fi

P=$(basename $(dirname "${BUILDSCRIPT}"))
gsell's avatar
gsell committed
854
P=${P%.*}
855 856 857 858 859 860
_P=$(echo $P | tr [:lower:] [:upper:])
_P=${_P//-/_}
_V=${_P}_VERSION

eval "${ENVIRONMENT_ARGS}"

gsell's avatar
gsell committed
861 862
if [[ -n ${PMODULES_DEFINED_RELEASES} ]]; then
        declare -r releases="${PMODULES_DEFINED_RELEASES}"
863 864 865 866 867
else
	# set defaults, if file doesn't exist or isn't readable
	declare -r releases=":unstable:stable:deprecated:"
fi

868 869 870 871 872
# Local Variables:
# mode: sh
# sh-basic-offset: 8
# tab-width: 8
# End: