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

3
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin
gsell's avatar
gsell committed
4

5 6 7
shopt -s expand_aliases


8 9 10 11
declare -r  BUILDSCRIPT=$( cd $(dirname "$0") && pwd )/$(basename "$0")
declare -rx ARGS="$@"
declare -rx SHLIBDIR=$( cd $(dirname "$BASH_SOURCE") && pwd )
declare -r OS=$(uname -s)
gsell's avatar
gsell committed
12

13
# number of parallel make jobs
14
declare -i  JOBS=3
gsell's avatar
gsell committed
15 16 17

source "${SHLIBDIR}/lib.bash"

18 19 20 21 22 23 24 25 26 27
declare -rx BUILD_BASEDIR=$(abspath $SHLIBDIR/..)

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"

28
#declare -xr PSI_TEMPLATES_DIR='templates'
29

30 31 32
if [[ -z "${BUILD_CONFIGDIR}/families.d/"*.conf ]]; then
	die 1 "Default family configuration not set in ${BUILD_CONFIGDIR}/families.d"
fi
33

34 35 36
#for f in "${BUILD_CONFIGDIR}/families.d/"*.conf; do
#	source "${f}"
#done
37
source "${BUILD_CONFIGDIR}/Pmodules.conf"
38 39 40 41 42

declare -x  PREFIX=''
declare -x  DOCDIR=''
declare -x  MODULE_FAMILY=''
declare	-x  MODULE_RELEASE=''
43 44 45
declare     cur_module_release=''

declare     DEPEND_RELEASE=''
46 47 48 49 50 51 52 53 54
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

55 56 57 58 59 60
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
61

gsell's avatar
gsell committed
62

63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
function usage() {
	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.

86 87 88
-b | --bootstrap 
	Bootstrap Pmodules

89 90 91
--with=P/V
        Preload module P with version V. To preload multiple modules,
        use this option per module. Nete that order may matter.
92

93
--release=stable|unstable|deprecated
94 95 96 97 98

"
	exit 1
}

99

100 101
debug_on='no'
force_rebuild='no'
gsell's avatar
gsell committed
102
ENVIRONMENT_ARGS=''
103 104 105 106
dry_run='no'
bootstrap='no'

# array collecting all modules specified on the command line via '--with=module'
107
with_modules=()
108

gsell's avatar
gsell committed
109 110 111 112 113 114
while (( $# > 0 )); do
	case $1 in
	-j )
		JOBS=$2
		shift
		;;
115 116 117 118
	--jobs=[0-9]* )
		JOBS=${1/--jobs=}
		;;
	-v | --verbose)
119
		debug_on='yes'
gsell's avatar
gsell committed
120 121
		;;
	-f | --force-rebuild )
122 123 124 125 126
		force_rebuild='yes'
		;;
	-b | --bootstrap )
		bootstrap='yes'
		force_rebuild='yes'
gsell's avatar
gsell committed
127
		;;
128 129 130
	-? | -h | --help )
		usage
		;;
131
	--dry-run )
132
		dry_run='yes'
133
		;;
134 135 136
	--release=* )
		MODULE_RELEASE=${1/--release=}
		;;
137 138 139
	--with=*/* )
		with_modules+=( ${1/--with=} )
		;;
140 141 142
	*=* )
		eval $1
		ENVIRONMENT_ARGS="${ENVIRONMENT_ARGS} $1"
143
		;;
gsell's avatar
gsell committed
144
	* )
145
		V=$1
gsell's avatar
gsell committed
146 147 148 149 150
		;;
	esac
	shift
done

151 152 153 154 155 156
if [[ ${debug_on} == yes ]]; then
	trap 'echo "$BASH_COMMAND"' DEBUG
fi

# while bootstraping the module command is not yet available
if [[ ${bootstrap} == no ]]; then
157 158
        source	"${PSI_PREFIX}/${PSI_CONFIG_DIR}/profile.bash"
	MODULECMD="${PMODULES_HOME}/bin/modulecmd"
159 160 161 162 163
	[[ -x ${MODULECMD} ]] || die 1 "${MODULECMD}: no such executable"
	module use unstable
	module purge
fi

164
P=$(basename $(dirname "${BUILDSCRIPT}"))
165 166 167
_P=$(echo $P | tr [:lower:] [:upper:])
_P=${_P//-/_}
_V=${_P}_VERSION
168 169 170

eval "${ENVIRONMENT_ARGS}"

171 172
if [[ -n ${PSI_RELEASES} ]]; then
        declare -r releases="${PSI_RELEASES}"
173 174 175 176
else
	# set defaults, if file doesn't exist or isn't readable
	declare -r releases=":unstable:stable:deprecated:"
fi
177

178 179
is_release () {
	[[ ${releases} =~ :$1: ]]
180
}
181

182 183
function em.set_release() {
	is_release "$1" || die 1 "$P: unknown release type: $1"
184
	[[ "$1" == "deprecated" ]] && die 0 "$P: is deprecated, we don't rebuild it."
185
	MODULE_RELEASE="$1"
gsell's avatar
gsell committed
186 187
}

188 189 190
function em.supported_os() {
	for os in "$@"; do
		[[ ${os} == ${OS} ]] && return 0
gsell's avatar
gsell committed
191
	done
192
	die 0 "${P}: Not available for ${OS}."
gsell's avatar
gsell committed
193 194
}

gsell's avatar
gsell committed
195
function em.add_to_family() {
gsell's avatar
gsell committed
196
	if [[ -z ${1} ]]; then
gsell's avatar
gsell committed
197
		die 42 "${FUNCNAME}: Missing family argument."
gsell's avatar
gsell committed
198
	fi
gsell's avatar
gsell committed
199
	if [[ ! -d ${PSI_PREFIX}/${PSI_TEMPLATES_DIR}/${1} ]]; then
200
		die 43 "${1}: family does not exist."
gsell's avatar
gsell committed
201
	fi
202
	MODULE_FAMILY=$1
gsell's avatar
gsell committed
203 204
}

205
function em.set_build_dependencies() {
206
	MODULE_BUILD_DEPENDENCIES=("$@")
207 208
}

gsell's avatar
gsell committed
209
function em.set_runtime_dependencies() {
210
	MODULE_DEPENDENCIES=("$@")
gsell's avatar
gsell committed
211 212
}

gsell's avatar
gsell committed
213
function em.set_supported_compilers() {
214
	MODULE_SUPPORTED_COMPILERS=("$@")
gsell's avatar
gsell committed
215 216 217
}

function em.set_docfiles() {
218
	MODULE_DOCFILES=("$@")
gsell's avatar
gsell committed
219 220
}

221
function module_is_available() {
222
	[[ -n $("${MODULECMD}" bash avail "$1" 2>&1 1>/dev/null) ]]
223 224
}

225
function _load_build_dependencies() {
226 227
	# :FIXME: merge this two loops, load only modules which are required
	#         this merge is not as easy as it looks like at a first glance!
228
	for m in "${with_modules[@]}"; do
229
		if module_is_available "$m"; then
230
			echo "Loading module: ${m}"
231 232 233 234
			module load "${m}"
		else
			die 44 "$m: module not available!"
		fi
235
	done
236
	for m in "${MODULE_BUILD_DEPENDENCIES[@]}"; do
237 238
		[[ -z $m ]] && continue
		if [[ ! $m =~ "*/*" ]]; then
gsell's avatar
gsell committed
239 240 241 242
			local _V=$(echo -n $m | tr [:lower:] [:upper:] )_VERSION
			if [[ -n ${!_V} ]]; then
		    		m=$m/${!_V}
			else
gsell's avatar
gsell committed
243
				echo "$m: warning: No version set, loading default ..."
gsell's avatar
gsell committed
244
			fi
245
		fi
246 247
		if ! module_is_available "$m"; then
		        debug "${m}: module not available"
gsell's avatar
gsell committed
248
			local rels=( ${releases//:/ } )
249 250 251 252 253
			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."
254 255
				fi
			done
256 257 258
			[[ ${dry_run} == yes ]] && {
				die 1 "${m}: module does not exist, cannot continue with dry run..."
				}
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

			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
287
			"${BUILD_SCRIPTSDIR}"/*/"${m/\/*}/build" ${args[@]}
288
			if [[ -z $(module avail "$m" 2>&1) ]]; then
gsell's avatar
gsell committed
289
				die 1 "$m: oops: build failed..."
290 291
			fi
		fi
292 293 294
		local modulepath_root="${PSI_PREFIX}/${PSI_MODULES_ROOT}"
		local tmp=$( module display "${m}" 2>&1 | grep -m1 -- "${modulepath_root}" )
		tmp=${tmp/${modulepath_root}\/}
295 296 297
		tmp=${tmp%%/*}
		local _family=( ${tmp//./ } )
		if [[ ${_family[1]} == deprecated ]]; then
298 299
			# set module release to 'deprecated' if a build dependency
			# is deprecated
300
			DEPEND_RELEASE='deprecated'
301
		elif [[ ${_family[1]} == unstable ]] && [[ -z ${DEPEND_RELEASE} ]]; then
302 303
			# set module release to 'unstable' if a build dependency is
			# unstable and release not yet set
304
			DEPEND_RELEASE='unstable'
305 306 307
		fi
		echo "Loading module: ${m}"
		module load "${m}"
308 309 310
	done
}

311 312 313 314 315 316
if [[ ${bootstrap} == yes ]]; then
    function _load_build_dependencies() {
	    :
    }
fi

gsell's avatar
gsell committed
317 318
function _write_runtime_dependencies() {
	local -r fname="${PREFIX}/.dependencies"
319
	info "Writing run-time dependencies to ${fname}"
gsell's avatar
gsell committed
320 321
	local dep
	echo -n "" > "${fname}"
322
	for dep in "${MODULE_DEPENDENCIES[@]}"; do
gsell's avatar
gsell committed
323
		[[ -z $dep ]] && continue
324
		if [[ ! $dep =~ .*/.* ]]; then
325
		    local _V=$(echo -n $dep | tr [:lower:] [:upper:] )_VERSION
gsell's avatar
gsell committed
326 327 328 329 330 331 332 333
		    dep=$dep/${!_V}
		fi
		echo "${dep}" >> "${fname}"
	done
}

function _write_build_dependencies() {
	local -r fname="${PREFIX}/.build_dependencies"
334
	info "Writing build dependencies to ${fname}"
gsell's avatar
gsell committed
335 336
	local dep
	echo -n "" > "${fname}"
337
	for dep in "${MODULE_BUILD_DEPENDENCIES[@]}"; do
gsell's avatar
gsell committed
338 339
		[[ -z $dep ]] && continue
		if [[ ! $dep =~ "*/*" ]]; then
340
		    local _V=$(echo -n $dep | tr [:lower:] [:upper:] )_VERSION
gsell's avatar
gsell committed
341 342 343 344 345 346
		    dep=$dep/${!_V}
		fi
		echo "${dep}" >> "${fname}"
	done
}

347
# setup general environment
348
function _setup_env1() {
gsell's avatar
gsell committed
349 350 351 352 353 354 355
	C_INCLUDE_PATH=''
	CPLUS_INCLUDE_PATH=''
	CPP_INCLUDE_PATH=''
	LIBRARY_PATH=''
	LD_LIBRARY_PATH=''
	DYLD_LIBRARY_PATH=''

356 357 358 359 360 361
	CFLAGS=''
	CPPFLAGS=''
	CXXFLAGS=''
	LIBS=''
	LDFLAGS=''
	
362 363 364 365 366 367 368 369 370 371
	while read _name _version; do
		[[ -z ${_name} ]] && continue
		[[ -z ${_version} ]] && continue
		[[ "${_name:0:1}" == '#' ]] && continue
		_NAME=$(echo ${_name} | tr [:lower:] [:upper:])
		eval ${_NAME}_VERSION=$_version 
	done < "${BUILD_VERSIONSFILE}"

}

372
#setup module specific environment
373
function _setup_env2() {
374
	if [[ -z ${MODULE_FAMILY} ]]; then
gsell's avatar
gsell committed
375
		die 1 "$P: family not set."
gsell's avatar
gsell committed
376 377 378
	fi

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

381 382
	# this allows us to specify the version as PKGNAME_VERSION=1.2.3 on
	# the cmd-line
gsell's avatar
gsell committed
383 384 385 386 387 388 389 390
        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
391
	MODULE_SRCDIR="${BUILD_TMPDIR}/src/${P/_serial}-$V"
392
	MODULE_BUILDDIR="${BUILD_TMPDIR}/build/$P-$V"
gsell's avatar
gsell committed
393 394

	# build module name
395 396
	# :FIXME: the MODULE_PREFIX should be derived from MODULE_NAME
	# :FIXME: this should be read from a configuration file
397
	case ${MODULE_FAMILY} in
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 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}"
			;;
		HDF5_serial )
			MODULE_RPREFIX="${P}/${V}"
			MODULE_RPREFIX+="/hdf5_serial/${HDF5_SERIAL_VERSION}"
			MODULE_RPREFIX+="/${COMPILER}/${COMPILER_VERSION}"
			
			MODULE_NAME="${COMPILER}/${COMPILER_VERSION}/"
			MODULE_NAME+="hdf5_serial/${HDF5_VERSION}/"
			MODULE_NAME+="${P}/${V}"
			;;
		* )
			die 1 "$P: oops: unknown family: ${MODULE_FAMILY}"
			;;
gsell's avatar
gsell committed
453 454
	esac

gsell's avatar
gsell committed
455
	# set PREFIX of module
456
	PREFIX="${PSI_PREFIX}/${MODULE_FAMILY}/${MODULE_RPREFIX}"
gsell's avatar
gsell committed
457

458 459
	# get module release if already installed
	local saved_modulepath=${MODULEPATH}
460 461 462
	rels=( ${releases//:/ } )
	for rel in "${rels[@]}"; do
		eval $("${MODULECMD}" bash unuse ${rel})
463
	done
464 465 466
	for rel in "${rels[@]}"; do
		eval $("${MODULECMD}" bash use ${rel})
		if module_is_available "${P}/${V}"; then
467
			cur_module_release=${rel}
468
			info "${P}/${V}: already available and released as \"${rel}\""
469 470 471 472 473 474 475 476 477 478
			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
479 480 481 482
	if [[ "${depend_release}" == 'deprecated' ]] || \
		[[ "${cur_module_release}" == 'deprecated' ]] \
		|| [[ "${MODULE_RELEASE}" == 'deprecated' ]]; then
		MODULE_RELEASE='deprecated'
483 484 485 486 487
		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
488 489
	#   - an unstable release of the module exists and the release is
	#     changed to stable on the command line
490 491 492 493
	elif [[ "${depend_release}" == 'stable' ]] \
		|| [[ "${cur_module_release}" == 'stable' ]] \
		|| [[ "${MODULE_RELEASE}" == 'stable' ]]; then
		MODULE_RELEASE='stable'
494 495 496 497
		info "${P}/${V}: will be released as \"stable\""
	#
	# release is unstable
	#   - if a build-dependency is unstable or 
498 499
	#   - if the module does not exists and no other release-type is
	#     given on the command line
500 501
	#   - and all the cases I didn't think of
	else
502
		MODULE_RELEASE='unstable'
503 504
		info "${P}/${V}: will be released as \"unstable\""
	fi
505 506

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

509
	# set tar-ball and flags for tar
510 511 512 513 514 515 516 517 518
	TARBALL="${BUILD_DOWNLOADSDIR}/${P/_serial}"
	if [[ -r "${TARBALL}-${V}.tar.gz" ]]; then
		TARBALL+="-${V}.tar.gz"
	elif [[ -r "${TARBALL}-${OS}-${V}.tar.gz" ]]; then
		TARBALL+="-${OS}-${V}.tar.gz"
	elif [[ -r "${TARBALL}-${V}.tar.bz2" ]]; then
		TARBALL+="-${V}.tar.bz2"
	elif [[ -r "${TARBALL}-${OS}-${V}.tar.bz2" ]]; then
		TARBALL+="-${OS}-${V}.tar.bz2"
gsell's avatar
gsell committed
519
	else
520
		error "tar-ball for $P/$V not found."
gsell's avatar
gsell committed
521 522
		exit 43
	fi
523

gsell's avatar
gsell committed
524 525
}

526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543
if [[ ${bootstrap} == yes ]]; then
    # redefine function for bootstrapping
    function _setup_env2() {
	    if [[ -z ${MODULE_FAMILY} ]]; then
		die 1 "$P: family not set."
	    fi

            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
	    MODULE_SRCDIR="${BUILD_TMPDIR}/src/${P/_serial}-$V"
	    MODULE_BUILDDIR="${BUILD_TMPDIR}/build/$P-$V"
	    MODULE_FAMILY='Tools'
544
	    MODULE_NAME="Pmodules/${PMODULES_VERSION}"
545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578
	    # set PREFIX of module
	    PREFIX="${PSI_PREFIX}/${MODULE_FAMILY}/${MODULE_NAME}"
	    
	    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
	    TARBALL="${BUILD_DOWNLOADSDIR}/${P/_serial}"
	    if [[ -r "${TARBALL}-${V}.tar.gz" ]]; then
		    TARBALL+="-${V}.tar.gz"
	    elif [[ -r "${TARBALL}-${OS}-${V}.tar.gz" ]]; then
		    TARBALL+="-${OS}-${V}.tar.gz"
	    elif [[ -r "${TARBALL}-${V}.tar.bz2" ]]; then
		    TARBALL+="-${V}.tar.bz2"
	    elif [[ -r "${TARBALL}-${OS}-${V}.tar.bz2" ]]; then
		    TARBALL+="-${OS}-${V}.tar.bz2"
	    else
		    error "tar-ball for $P/$V not found."
		    exit 43
	    fi
	    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"
    }
fi

579
function _prep() {
gsell's avatar
gsell committed
580 581

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

	# create build directory
588
	mkdir -p "${MODULE_BUILDDIR}"
gsell's avatar
gsell committed
589 590 591 592 593 594 595 596

}

function em.pre_configure() {
	:
}

function em.configure() {
597
	${MODULE_SRCDIR}/configure \
gsell's avatar
gsell committed
598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613
		--prefix="${PREFIX}"
}

function em.build() {
	make -j${JOBS}
}

function em.install() {
	make install
}

function em.post_install() {
	:
}

function em.install_doc() {
614
	info "Installing documentation to ${DOCDIR}"
615
	install -m 0755 -d "${DOCDIR}"
616
	install -m0444 "${MODULE_DOCFILES[@]/#/${MODULE_SRCDIR}/}" "${BUILDSCRIPT}" "${DOCDIR}"
gsell's avatar
gsell committed
617 618 619
}

function _set_link() {
620 621 622 623 624 625 626 627 628 629 630
	local -r link_name="${PSI_PREFIX}/${PSI_MODULES_ROOT}/${MODULE_FAMILY}/${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/${PSI_PREFIX}\/${PSI_MODULES_ROOT}\/} )
		    local n=${#x[@]}
631
		    local -r _target="../"$(eval printf "../%.s" {1..${n}})${PSI_TEMPLATES_DIR##*/}/"${MODULE_FAMILY}/${P}/modulefile"
632 633
		    ln -fs "${_target}" "${MODULE_NAME##*/}"
	    )
634
	fi
635 636
	info "${MODULE_NAME}: set release to '${MODULE_RELEASE}'"
	echo "${MODULE_RELEASE}" > "${release_file}"
gsell's avatar
gsell committed
637 638
}

639
function em.cleanup_build() {
gsell's avatar
gsell committed
640
    (
641 642
	[[ -d /${MODULE_BUILDDIR} ]] || return 0
	cd "/${MODULE_BUILDDIR}/..";
gsell's avatar
gsell committed
643
	if [[ $(pwd) != / ]]; then
gsell's avatar
gsell committed
644
		echo "Cleaning up $(pwd)/${COMPILER_VERSION}"
gsell's avatar
gsell committed
645 646 647 648 649
		rm -rf *
	fi
    );
}

650 651
function em.cleanup_src() {
    (
652 653
	[[ -d /${MODULE_SRCDIR} ]] || return 0
	cd "/${MODULE_SRCDIR}/..";
654 655
	if [[ $(pwd) != / ]]; then
		echo "Cleaning up $(pwd)"
656
		rm -rf ${MODULE_SRCDIR##*/}
657 658
	fi
    );
659
	return 0
660 661
}

gsell's avatar
gsell committed
662
function _check_compiler() {
663 664
	test -z ${MODULE_SUPPORTED_COMPILERS} && return 0
	for cc in ${MODULE_SUPPORTED_COMPILERS[@]}; do
gsell's avatar
gsell committed
665 666 667 668 669 670
		if [[ ${COMPILER}/${COMPILER_VERSION} =~ ${cc} ]]; then
			return 0
		fi
	done
	die 0 "Package cannot be build with ${COMPILER}/${COMPILER_VERSION}."
}
671

672 673 674 675 676
# unfortunatelly we need sometime an OS depended post-install
function _post_install_linux() {
	cd "${PREFIX}"
	# solve multilib problem with LIBRARY_PATH on 64bit Linux
	[[ -d "lib" ]] && [[ ! -d "lib64" ]] && ln -s lib lib64
677
	return 0
678 679 680
}

function _post_install() {
681
	info "Run post-installation for ${OS} ..."
682
	[[ "${OS}" == "Linux" ]] && _post_install_linux
683
	info "Post-installation done ..."
gsell's avatar
gsell committed
684
	return 0
685
}
686

687 688
function em.make_all() {
	echo "${P}:"
689
	_setup_env1
690
	_load_build_dependencies
691
	# setup module specific environment
692 693
	_setup_env2

694
	if [[ ! -d "${PREFIX}" ]] || [[ ${force_rebuild} == 'yes' ]]; then
695
 		echo "Building $P/$V ..."
696
		[[ ${dry_run} == yes ]] && die 0 ""
gsell's avatar
gsell committed
697
		_check_compiler
698
		_prep
699
		cd "${MODULE_SRCDIR}"
gsell's avatar
gsell committed
700
		em.pre_configure
701
		cd "${MODULE_BUILDDIR}"
gsell's avatar
gsell committed
702 703 704 705 706
		em.configure
		em.build
		em.install
		em.post_install
		em.install_doc
707
		_post_install
708 709 710 711
		if [[ ${bootstrap} == 'no' ]]; then
			_write_runtime_dependencies
			_write_build_dependencies
		fi
712
		
gsell's avatar
gsell committed
713
	else
714
 		echo "Not rebuilding $P/$V ..."
gsell's avatar
gsell committed
715
	fi
716 717 718 719
	if [[ ${bootstrap} == 'no' ]]; then
		_set_link
	fi
	em.cleanup_build
gsell's avatar
gsell committed
720 721
}

722 723 724 725 726
# Local Variables:
# mode: sh
# sh-basic-offset: 8
# tab-width: 8
# End: