Commit 6a3d1b52 authored by Simon Braß's avatar Simon Braß
Browse files

Add getopts and add self-documenting help; FORCE_ROOT env

parent 7373507a
Pipeline #9249 failed with stage
in 14 minutes and 7 seconds
#!/usr/bin/env bash
## Bootstrap WHIZARD and environment
##
## with recommanded packages enabled as default.
##
## Environment variables:
## - FORCE [False|True] Force build of autotools, although the underlying system provides them.
## - BUILD [Path] Path to build directory, defaults to the current working directory.
## - PREFIX [Path] Path to installation directory, defaults to $HOME/local.
## - NPROC [N] Number of parallel processes, defaults to (cores - 1).
## - CMAKE_GENERATOR [Ninja|Unix Makefiles] Use Ninja per default, fallback to Unix Makefiles.
## - DEBUG [False|True] Developer option.
##
## Author: Simon Braß <simon.brass@desy.de>
## Last modified: 2. Juni 2020
##
## CAUTION: We take no garantue for correct useage or indentation of this script.
## USE AT YOUR OWN RISK! → READ AND UNDERSTAND the following lines of bash code.
## USE AT YOUR OWN RISK! → READ AND UNDERSTAND the following lines.
##
## Requirements: Bash (>5), Unix-System
## Unsupported: Mac OS - I do not care enough to provide such support.
......@@ -34,7 +46,6 @@
##
## TODO:
## - CMake
## - WHIZARD/make check
## - Compiler FLAGS (FC, CC, CXX) and CFLAGS, CXXFLAGS, FCFLAGS (at least)
test -z "${FORCE}" && FORCE=False
......@@ -90,7 +101,7 @@ url_hepmc3="https://hepmc.web.cern.ch/hepmc/releases/HepMC3-3.2.1.tar.gz"
url_lhapdf="https://lhapdf.hepforge.org/downloads/?f=LHAPDF-6.2.3.tar.gz"
url_fastjet="http://fastjet.fr/repo/fastjet-3.3.4.tar.gz"
url_openloops="https://openloops.hepforge.org/downloads?f=OpenLoops-2.1.1.tar.gz"
url_pythia8="http://home.thep.lu.se/~torbjorn/pythia8/pythia8244.tgz"
url_pythia8="http://home.thep.lu.se/~torbjorn/pythia8/pythia8303.tgz"
url_delphes="https://github.com/delphes/delphes/archive/3.4.2.tar.gz"
# WHIZARD
......@@ -174,7 +185,7 @@ build_generic () {
test -d "${name}" || download_untar_pkg "${url}"
pushd "${name}" && \
make_make_install "${config}" && \
popd
popd || return
}
# $1 : Download-URL
......@@ -187,7 +198,7 @@ build_cmake_generic () {
mkdir -p "${name}-build" &&
pushd "${name}-build" && \
cmake_make_install "${config}" "../${name}" && \
popd
popd || return
}
build_hepmc2 () {
......@@ -198,7 +209,7 @@ build_hepmc2 () {
mkdir -p "${name}-build" && \
pushd "${name}-build" && \
cmake_make_install "${config}" "../${name}"
popd
popd || return
}
build_ocaml () {
......@@ -354,7 +365,7 @@ build_and_log_rivet () {
fi
}
########################################################################
# #######################################################################
write_script () {
......@@ -364,43 +375,26 @@ write_script () {
rm -f "${name}" && touch "${name}"
cat <<EOF > "${name}"
#!/bin/bash
########################################################################
# #######################################################################
# WHIZARD build environment
# Date: ${date}
# Created by: ${myself}
########################################################################
# #######################################################################
export PATH=${PREFIX}/bin:\${PATH}
export LD_LIBRARY_PATH=${PREFIX}/lib:${PREFIX}/OpenLoops/lib:\${LD_LIBRARY_PATH}
########################################################################
# #######################################################################
EOF
chmod 755 "${name}"
}
########################################################################
# #######################################################################
function help() {
echo "Bootstrap WHIZARD"
echo
echo "with recommanded packages enabled as default."
echo
echo "Build WHIZARD's dependencies:"
echo " - Autotools [default]"
echo " - Make [default]"
echo " - OCaml"
echo " - HepMC2 [default]"
echo " - LHAPDF6 [default]"
echo " - FastJet [default]"
echo " - OpenLoops [default]"
echo " - Pythia8 [default]"
echo " - Rivet"
echo " - whizard-config : Print WHIZARD configuration flags."
echo
echo "Environment variables:"
echo " - FORCE [False|True] Force build of autotools, although the underlying system provides them."
echo " - DEBUG [False|True]"
sed -n 's/^##//p' "${BASH_SOURCE[0]}" >&2
exit 1
}
########################################################################
# #######################################################################
HEPMC2_CONFIG=(
-DCMAKE_INSTALL_PREFIX="${PREFIX}"
......@@ -423,8 +417,7 @@ FASTJET_CONFIG=(
)
PYTHIA8_CONFIG=(
--enable-64bit
--enable-shared
--enable-debug
--with-fastjet3="${PREFIX}"
--with-lhapdf6="${PREFIX}"
--with-hepmc2="${PREFIX}"
......@@ -495,7 +488,7 @@ function main() {
if test $# -eq 0 || test "$@" == ""; then
local modes=(autotools hepmc3 lhapdf fastjet pythia8 openloops whizard bin)
else
local modes=${@}
local modes=("${@}")
fi
for mode in "${modes[@]}"; do
case $mode in
......@@ -530,14 +523,18 @@ function main() {
cmake_and_log "ROOT" "${url_root}" "${ROOT_CONFIG[*]}"
;;
hepmc3)
if ! test -d "${ROOT_DIR}/cmake" || ! test -f "${ROOT_DIR}/cmake/ROOTConfig.cmake"; then
cmake_and_log "ROOT" "${url_root}" "${ROOT_CONFIG[*]}"
if test "${FORCE_ROOT}" = true; then
if ! test -d "${ROOT_DIR}/cmake" || ! test -f "${ROOT_DIR}/cmake/ROOTConfig.cmake"; then
cmake_and_log "ROOT" "${url_root}" "${ROOT_CONFIG[*]}"
fi
fi
cmake_and_log "HepMC3" "${url_hepmc3}" "${HEPMC3_CONFIG[*]}"
;;
delphes)
if test -z "${ROOT_DIR}" && ! test -f "${ROOT_DIR}/cmake/ROOTConfig.cmake"; then
cmake_and_log "ROOT" "${url_root}" "${ROOT_CONFIG[*]}"
if test "${FORCE_ROOT}" = true; then
if test -z "${ROOT_DIR}" && ! test -f "${ROOT_DIR}/cmake/ROOTConfig.cmake"; then
cmake_and_log "ROOT" "${url_root}" "${ROOT_CONFIG[*]}"
fi
fi
cmake_and_log "Delphes" "${url_delphes}" "${DELPHES_CONFIG[*]}"
;;
......@@ -557,7 +554,7 @@ function main() {
bin)
# Secure that the bin directory exists
mkdir -p "${PREFIX}/bin"
write_script ${PREFIX}/bin/whizard-build-env.sh
write_script "${PREFIX}/bin/whizard-build-env.sh"
;;
help)
help
......@@ -569,5 +566,30 @@ function main() {
done
}
FORCE_ROOT=false
## Command-line options:
## -h : print help message (or when none argument is presented)
## -r : force build of ROOT
while getopts ":hr" opt; do
case "${opt}" in
h)
help
;;
r)
FORCE_ROOT=true
;;
\?)
echo "Invalid option: -${OPTARG}" >&2
exit 1
;;
:)
echo "Option -${OPTARG} requires an argument." >&2
exit 1
;;
esac
done
shift $((OPTIND - 1))
main "$@"
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment