Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
Restructured scripts to consolidate variable definitions and argument…
Browse files Browse the repository at this point in the history
… parsing into one place.
  • Loading branch information
daminton committed Aug 17, 2023
1 parent 170360d commit efda5c2
Show file tree
Hide file tree
Showing 11 changed files with 129 additions and 449 deletions.
3 changes: 1 addition & 2 deletions buildscripts/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
!*.sh
!*.yml
!*.sh
87 changes: 87 additions & 0 deletions buildscripts/_build_getopts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/bin/bash
# This script will gets the arguments common to all the dependency build scripts
#
# Copyright 2023 - David Minton
# This file is part of Swiftest.
# Swiftest is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
# Swiftest is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along with Swiftest.
# If not, see: https://www.gnu.org/licenses.
set -a
SCRIPT_DIR=$(realpath $(dirname $0))
ROOT_DIR=$(realpath ${SCRIPT_DIR}/..)

# Parse arguments
USTMT="Usage: ${0} <-d /path/to/dependency/source> [-p /prefix/path|{/usr/local}] [-m MACOSX_DEPLOYMENT_TARGET|{13}]"
PREFIX=/usr/local
DEPENDENCY_DIR="${ROOT_DIR}/_dependencies"
MACOSX_DEPLOYMENT_TARGET=13
while getopts ":d:p:m:h" ARG; do
case "${ARG}" in
d)
DEPENDENCY_DIR=$(realpath ${OPTARG})
;;
p)
PREFIX="${OPTARG}"
;;
m)
MACOSX_DEPLOYMENT_TARGET="${OPTARG}"
;;
:)
printf "Error: -${OPTARG} requires an argument.\n"
printf "$USTMT\n"
exit 1
;;
h)
printf "$USTMT\n"
exit 1
;;
*)
;;
esac
done
read -r OS ARCH < <($SCRIPT_DIR/get_platform.sh)
case $OS in
MacOSX)
COMPILER="GNU-Mac"
;;
Linux)
COMPILER="GNU-Linux"
;;
*)
printf "This script is not tested for ${OS}-${ARCH}\n"
;;
esac

if [ -z ${DEPENDENCY_ENV_VARS+x} ]; then
CMD="${SCRIPT_DIR}/set_compilers.sh -c $COMPILER"
read -r CC CXX FC F77 CPP < <($CMD)
unset CMD

LD_LIBRARY_PATH="${PREFIX}/lib"
CPPFLAGS="-isystem ${PREFIX}/include"
LDFLAGS="-L${PREFIX}/lib -fPIE"
CPATH="${PREFIX}/include}"
CFLAGS="-Wno-unused-but-set-variable -fPIC"
LIBS="-lgomp"

if [ $COMPILER = "GNU-Mac" ]; then
LDFLAGS="${LDFLAGS} -Wl,-no_compact_unwind"
CFLAGS="${CFLAGS} -Wno-deprecated-non-prototype"
fi

HDF5_ROOT="${PREFIX}"
HDF5_LIBDIR="${HDF5_ROOT}/lib"
HDF5_INCLUDE_DIR="${HDF5_ROOT}/include"
HDF5_PLUGIN_PATH="${HDF5_LIBDIR}/plugin"
NCDIR="${PREFIX}"
NFDIR="${PREFIX}"
NETCDF_FORTRAN_HOME=${NFDIR}
NETCDF_HOME=${NCDIR}

DEPENDENCY_ENV_VARS=true
fi

mkdir -p ${DEPENDENCY_DIR}
59 changes: 6 additions & 53 deletions buildscripts/build_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,59 +11,12 @@
# You should have received a copy of the GNU General Public License along with Swiftest.
# If not, see: https://www.gnu.org/licenses.


# Determine the platform and architecture
set -a
SCRIPT_DIR=$(realpath $(dirname $0))
ROOT_DIR=$(realpath ${SCRIPT_DIR}/..)
DEPENDENCY_DIR="${ROOT_DIR}/_dependencies"
PREFIX=/usr/local

# Parse arguments
USTMT="Usage: ${0} [-d /path/to/dependancy/build] [-p {/usr/local}|/prefix/path]"
COMPILER=""
while getopts ":d:p:" ARG; do
case "${ARG}" in
d)
DEPENDENCY_DIR="${OPTARG}"
;;
p)
PREFIX="${OPTARG}"
;;
:)
echo "Error: -${OPTARG} requires an argument."
echo $USTMT
exit 1
;;
*)
;;
esac
done

read -r OS ARCH < <($SCRIPT_DIR/get_platform.sh)

# Determine if we are in the correct directory (the script can either be run from the Swiftest project root directory or the
# buildscripts directory)
if [ ! -f "${ROOT_DIR}/setup.py" ]; then
echo "Error: setup.py not found"
exit 1
fi
cd ${ROOT_DIR}
VERSION=$( cat version.txt )

case $OS in
MacOSX)
COMPILER="GNU-Mac"
;;
Linux)
COMPILER="GNU-Linux"
;;
*)
echo "This script is not tested for ${OS}-${ARCH}"
;;
esac

${SCRIPT_DIR}/build_dependencies.sh -p ${PREFIX} -d ${DEPENDENCY_DIR}
${SCRIPT_DIR}/build_swiftest.sh -c $COMPILER -p ${PREFIX}


. ${SCRIPT_DIR}/_build_getopts.sh

ARGS=$@
set -e
${SCRIPT_DIR}/build_dependencies.sh ${ARGS}
${SCRIPT_DIR}/build_swiftest.sh ${ARGS}
69 changes: 8 additions & 61 deletions buildscripts/build_dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,55 +13,9 @@

# Determine the platform and architecture
SCRIPT_DIR=$(realpath $(dirname $0))
ROOT_DIR=$(realpath ${SCRIPT_DIR}/..)
DEPENDENCY_DIR="${ROOT_DIR}/_dependencies"
PREFIX=/usr/local

# Parse arguments
USTMT="Usage: ${0} [-d /path/to/dependancy/build] [-p {/usr/local}|/prefix/path]"
COMPILER=""
while getopts ":d:p:" ARG; do
case "${ARG}" in
d)
DEPENDENCY_DIR="${OPTARG}"
;;
p)
PREFIX="${OPTARG}"
;;
:)
echo "Error: -${OPTARG} requires an argument."
echo $USTMT
exit 1
;;
*)
;;
esac
done

mkdir -p ${DEPENDENCY_DIR}
read -r OS ARCH < <($SCRIPT_DIR/get_platform.sh)

# Determine if we are in the correct directory (the script can either be run from the Swiftest project root directory or the
# buildscripts directory)
if [ ! -f "${ROOT_DIR}/setup.py" ]; then
echo "Error: setup.py not found"
exit 1
fi
cd ${ROOT_DIR}
VERSION=$( cat version.txt )
echo "Building Swiftest version ${VERSION} for ${OS}-${ARCH}"

case $OS in
MacOSX)
COMPILER="GNU-Mac"
;;
Linux)
COMPILER="GNU-Linux"
;;
*)
echo "This script is not tested for ${OS}-${ARCH}"
;;
esac
set -a
. ${SCRIPT_DIR}/_build_getopts.sh
ARGS=$@

printf "*********************************************************\n"
printf "* FETCHING DEPENCENCY SOURCES *\n"
Expand All @@ -77,22 +31,15 @@ wget -qO- https://github.com/Unidata/netcdf-fortran/archive/refs/tags/v4.6.1.tar
printf "*********************************************************\n"
printf "* STARTING DEPENDENCY BUILD *\n"
printf "*********************************************************\n"
CMD="${SCRIPT_DIR}/set_compilers.sh -c $COMPILER"
read -r CC CXX FC F77 CPP < <($CMD)
export CC=${CC}
export CXX=${CXX}
export FC=${FC}
export F77=${F77}
export CPP=${CPP}

printf "Using ${COMPILER} compilers:\nFC: ${FC}\nCC: ${CC}\nCXX: ${CXX}\n"
printf "Installing to ${PREFIX}\n"
printf "\n"

${SCRIPT_DIR}/build_zlib.sh -c $COMPILER -p $PREFIX -d $DEPENDENCY_DIR
${SCRIPT_DIR}/build_hdf5.sh -c $COMPILER -p $PREFIX -d $DEPENDENCY_DIR
${SCRIPT_DIR}/build_netcdf-c.sh -c $COMPILER -p $PREFIX -d $DEPENDENCY_DIR
${SCRIPT_DIR}/build_netcdf-fortran.sh -c $COMPILER -p $PREFIX -d $DEPENDENCY_DIR
set -e
${SCRIPT_DIR}/build_zlib.sh ${ARGS}
${SCRIPT_DIR}/build_hdf5.sh ${ARGS}
${SCRIPT_DIR}/build_netcdf-c.sh ${ARGS}
${SCRIPT_DIR}/build_netcdf-fortran.sh ${ARGS}

printf "\n"
printf "*********************************************************\n"
Expand Down
55 changes: 2 additions & 53 deletions buildscripts/build_hdf5.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,59 +11,8 @@
# You should have received a copy of the GNU General Public License along with Swiftest.
# If not, see: https://www.gnu.org/licenses.
SCRIPT_DIR=$(realpath $(dirname $0))

# Parse arguments
USTMT="Usage: ${0} <-c Intel|GNU-Linux|GNU-Mac> <-d /path/to/dependency/source> [-p {/usr/local}|/prefix/path] "
PREFIX=/usr/local
COMPILER=""
DEPENCENCY_DIR=""
CARG=""
while getopts ":c:p:d:" ARG; do
case "${ARG}" in
c)
COMPILER="${OPTARG}"
;;
p)
PREFIX="${OPTARG}"
;;
d)
DEPENDENCY_DIR="${OPTARG}"
;;
:)
echo "Error: -${OPTARG} requires an argument."
echo $USTMT
exit 1
;;
*)
;;
esac
done

CMD="${SCRIPT_DIR}/set_compilers.sh -c $COMPILER"
read -r CC CXX FC F77 CPP < <($CMD)
export CC=${CC}
export CXX=${CXX}
export FC=${FC}
export F77=${F77}
export CPP=${CPP}

export HDF5_ROOT="${PREFIX}"
export HDF5_LIBDIR="${HDF5_ROOT}/lib"
export HDF5_INCLUDE_DIR="${HDF5_ROOT}/include"
export HDF5_PLUGIN_PATH="${HDF5_LIBDIR}/plugin"
export NCDIR="${PREFIX}"
export NFDIR="${PREFIX}"
export LD_LIBRARY_PATH="${PREFIX}/lib:${LD_LIBRARY_PATH}"
export CPPFLAGS="${CPPFLAGS} -isystem ${PREFIX}/include"
export LDFLAGS="${LDFLAGS} -L${PREFIX}/lib"
export CPATH="${PREFIX}/include:${CPATH}"
export CFLAGS="${CFLAGS} -Wno-unused-but-set-variable"

if [ $COMPILER = "GNU-Mac" ]; then
export MACOSX_DEPLOYMENT_TARGET=13
export LDFLAGS="${LDFLAGS} -Wl,-no_compact_unwind"
export CFLAGS="${CFLAGS} -Wno-deprecated-non-prototype"
fi
set -a
. ${SCRIPT_DIR}/_build_getopts.sh

printf "\n"
printf "*********************************************************\n"
Expand Down
54 changes: 2 additions & 52 deletions buildscripts/build_netcdf-c.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,58 +12,8 @@
# If not, see: https://www.gnu.org/licenses.
SCRIPT_DIR=$(realpath $(dirname $0))

# Parse arguments
USTMT="Usage: ${0} <-c Intel|GNU-Linux|GNU-Mac> <-d /path/to/dependency/source> [-p {/usr/local}|/prefix/path] "
PREFIX=/usr/local
COMPILER=""
DEPENCENCY_DIR=""
CARG=""
while getopts ":c:p:d:" ARG; do
case "${ARG}" in
c)
COMPILER="${OPTARG}"
;;
p)
PREFIX="${OPTARG}"
;;
d)
DEPENDENCY_DIR="${OPTARG}"
;;
:)
echo "Error: -${OPTARG} requires an argument."
echo $USTMT
exit 1
;;
*)
;;
esac
done

CMD="${SCRIPT_DIR}/set_compilers.sh -c $COMPILER"
read -r CC CXX FC F77 CPP < <($CMD)
export CC=${CC}
export CXX=${CXX}
export FC=${FC}
export F77=${F77}
export CPP=${CPP}

export HDF5_ROOT=${HDF5_ROOT:-$PREFIX}
export HDF5_LIBDIR="${HDF5_ROOT}/lib"
export HDF5_INCLUDE_DIR="${HDF5_ROOT}/include"
export HDF5_PLUGIN_PATH="${HDF5_LIBDIR}/plugin"
export NCDIR="${PREFIX}"
export NFDIR="${PREFIX}"
export LD_LIBRARY_PATH="${PREFIX}/lib:${HDF5_LIBDIR}:${LD_LIBRARY_PATH}"
export CPPFLAGS="${CPPFLAGS} -isystem ${PREFIX}/include -isystem ${HDF5_INCLUDE_DIR}"
export LDFLAGS="${LDFLAGS} -L${PREFIX}/lib -L${HDF5_LIBDIR}"
export CPATH="${PREFIX}/include:${CPATH}"
export CFLAGS="${CFLAGS} -Wno-unused-but-set-variable"

if [ $COMPILER = "GNU-Mac" ]; then
export MACOSX_DEPLOYMENT_TARGET=13
export LDFLAGS="${LDFLAGS} -Wl,-no_compact_unwind"
export CFLAGS="${CFLAGS} -Wno-deprecated-non-prototype"
fi
set -a
. ${SCRIPT_DIR}/_build_getopts.sh

printf "\n"
printf "*********************************************************\n"
Expand Down
Loading

0 comments on commit efda5c2

Please sign in to comment.