2019-12-09 15:49:37 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
2021-12-15 02:30:48 +01:00
|
|
|
set -e
|
|
|
|
|
|
|
|
# Show the usage screen
|
|
|
|
show_help(){
|
|
|
|
cat <<EOF
|
|
|
|
Usage: $0 [OPTION]... [VAR=VALUE]...
|
|
|
|
|
|
|
|
To assign environment variables (e.g., FC, FFLAGS...), specify them as
|
|
|
|
VAR=VALUE. Defaults for the options are specified in brackets.
|
|
|
|
|
|
|
|
Options:
|
|
|
|
-h, --help display this help and exit
|
|
|
|
--prefix=PREFIX install files in PREFIX [/usr/local]
|
2024-10-09 18:09:15 +02:00
|
|
|
--with-compiler=PROG use PROG as Fortran compiler [automatically detect]
|
2021-12-15 02:30:48 +01:00
|
|
|
--enable-static statically link programs and libraries [no]
|
|
|
|
--disable-static dynamically link programs and libraries [yes]
|
2023-10-13 13:58:47 +02:00
|
|
|
--enable-deterministic try to make a bit-for-bit deterministic build [no]
|
2021-12-15 02:30:58 +01:00
|
|
|
--with-katex=PATH specify path to the KaTeX library [automatically downloaded]
|
2021-12-15 02:30:48 +01:00
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
# Check whether a command exists
|
|
|
|
check() {
|
|
|
|
test -z "$1" && return 1
|
|
|
|
printf 'checking for %s... ' "$1"
|
|
|
|
command -v "$1" || (echo 'not found'; exit 1)
|
|
|
|
return $?
|
|
|
|
}
|
|
|
|
|
2021-12-15 02:30:58 +01:00
|
|
|
# Truncate the current configuration
|
|
|
|
: > configure.mk
|
|
|
|
|
2021-12-15 02:30:48 +01:00
|
|
|
# Parse command line options
|
|
|
|
for arg in "$@"; do
|
|
|
|
case "$arg" in
|
|
|
|
-h|--help) show_help; exit 0 ;;
|
|
|
|
--prefix=*)
|
|
|
|
PREFIX="${arg#*=}"
|
|
|
|
printf 'install prefix set to %s\n' "$PREFIX"
|
|
|
|
;;
|
2024-10-09 18:09:15 +02:00
|
|
|
--with-compiler=*) FC="${arg#*=}" ;;
|
2021-12-15 02:30:48 +01:00
|
|
|
--enable-static) printf 'STATIC=1\n' >> configure.mk ;;
|
|
|
|
--disable-static) ;;
|
2023-10-13 13:58:47 +02:00
|
|
|
--enable-deterministic) printf 'DETERMINISTIC=1\n' >> configure.mk ;;
|
2021-12-15 02:30:58 +01:00
|
|
|
--with-katex=*) printf 'KATEX_URL==file://%s/\n' "${arg#*=}" >> configure.mk ;;
|
2021-12-15 02:30:48 +01:00
|
|
|
*=*)
|
|
|
|
printf '%s\n' "${arg?}" >> configure.mk
|
|
|
|
printf 'set %s\n' "$arg"
|
|
|
|
;;
|
|
|
|
*) show_help; exit 1 ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
# Platform information
|
2021-12-15 02:30:45 +01:00
|
|
|
printf 'Running on '
|
|
|
|
case $(uname -s) in
|
|
|
|
Linux*) echo 'Linux' ;;
|
2023-11-25 18:11:52 +01:00
|
|
|
Darwin*)
|
|
|
|
echo 'macOS'
|
|
|
|
# static libc is not available on macOS
|
|
|
|
printf 'SEMISTATIC=1\n' >> configure.mk ;;
|
2021-12-15 02:30:45 +01:00
|
|
|
CYGWIN*|MSYS*|MINGW*) echo 'Windows' ;;
|
|
|
|
*) echo 'unknown OS' ;;
|
2019-12-09 15:49:37 +01:00
|
|
|
esac
|
|
|
|
|
2021-12-15 02:30:45 +01:00
|
|
|
os=$(uname -r)
|
|
|
|
printf 'OS version %s\n' "$os"
|
2019-12-09 15:49:37 +01:00
|
|
|
|
2021-12-15 02:30:48 +01:00
|
|
|
# Architecture information
|
2021-12-15 02:30:45 +01:00
|
|
|
arch=$(uname -m)
|
|
|
|
printf 'Processor architecture %s\n' "$arch"
|
2019-12-09 15:49:37 +01:00
|
|
|
|
2021-12-15 02:30:48 +01:00
|
|
|
# Variables with a default
|
|
|
|
printf '%s=%s\n' PREFIX "${PREFIX:-/usr/local}" >> configure.mk
|
2019-12-09 15:49:37 +01:00
|
|
|
|
2021-12-15 02:30:48 +01:00
|
|
|
# Detect the Fortran compiler
|
2024-10-09 18:09:15 +02:00
|
|
|
for FC in "$FC" ifx ifort gfortran f77; do
|
2021-12-15 02:30:48 +01:00
|
|
|
check "$FC" && break
|
2019-12-09 15:49:37 +01:00
|
|
|
done
|
2021-12-15 02:30:45 +01:00
|
|
|
# shellcheck disable=SC2181
|
2019-12-09 15:49:37 +01:00
|
|
|
if [ $? -ne 0 ]; then
|
2021-12-15 02:30:48 +01:00
|
|
|
printf 'Fortran compiler not found: cannot proceed\n'
|
2019-12-09 15:49:37 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
2021-12-15 02:30:48 +01:00
|
|
|
printf 'using %s as Fortran compiler\n' "$FC"
|
|
|
|
printf '%s=%s\n' FC "$FC" >> configure.mk
|
2023-10-13 13:58:47 +02:00
|
|
|
|
2024-10-09 18:09:15 +02:00
|
|
|
case $FC in
|
|
|
|
ifx|ifort) echo 'INTEL=1' >> configure.mk ;;
|
|
|
|
gfortran|f77) echo 'GNU=1' >> configure.mk ;;
|
|
|
|
esac
|
|
|
|
|
2023-10-13 13:58:47 +02:00
|
|
|
# Check whether ar is deterministic by default
|
|
|
|
if ar h | grep -q '\[D\].*(default)' 2>/dev/null; then
|
|
|
|
printf 'AR_DEFAULT_DETERMINISTIC=1\n' >> configure.mk
|
|
|
|
fi
|