Warning, /tools/build_options/linux_arm64_gfortran is written in an unsupported language. File is not indexed.
view on githubraw file Latest commit 726aa03a on 2024-10-10 20:35:24 UTC
726aa03a13 Gael*0001 #!/bin/bash
0002
0003 # Build options for gfortran compiler (GNU) for Linux on ARM64 hardware (e.g., in VMs or containers)
0004 # note: this optfile shares many similarities with "linux_amd64_gfortran"
0005 #
0006 # Was tested on Macbook air (M3 generation) in a Ubuntu Docker container (ECCO-Docker v0.2.2)
0007 #
0008 # Gael Forget. (2024). gaelforget/ECCO-Docker: update to latest MITgcm.jl , Climatology.jl ,
0009 # and Dockerfile (v0.2.2). Zenodo. https://doi.org/10.5281/zenodo.12581248
0010
0011 if test "x$MPI" = xtrue ; then
0012 CC=${CC:=mpicc}
0013 FC=${FC:=mpif77}
0014 F90C=${F90C:=mpif90}
0015 else
0016 CC=gcc
0017 FC=gfortran
0018 F90C=gfortran
0019 fi
0020
0021 DEFINES='-DWORDLENGTH=4 -DNML_TERMINATOR'
0022 EXTENDED_SRC_FLAG='-ffixed-line-length-132'
0023 F90FIXEDFORMAT='-ffixed-form'
0024 GET_FC_VERSION="--version"
0025 OMPFLAG='-fopenmp'
0026
0027 NOOPTFLAGS='-O0'
0028 NOOPTFILES=''
0029
0030 CFLAGS='-O0'
0031
0032 #- for setting specific options, check compiler version:
0033 fcVers=`$CC -dumpversion | head -n 1 | sed 's/^[^0-9]* //;s/\..*$//'`
0034 if ! [[ $fcVers =~ ^[0-9]+$ ]] ; then
0035 echo " un-recognized Compiler-version '$fcVers' ; ignored (-> set to 0)" ; fcVers=0 ;
0036 else echo " get Compiler-version: '$fcVers'" ; fi
0037
0038 if [ $fcVers -ge 10 ] ; then
0039 FFLAGS="$FFLAGS -fallow-argument-mismatch"
0040 fi
0041 #- Requires gfortran from 2006 onwards for -fconvert=big-endian
0042 FFLAGS="$FFLAGS -fconvert=big-endian -fimplicit-none"
0043 #- for big setups, compile & link with "-fPIC" or set memory-model to "small":
0044 #CFLAGS="$CFLAGS -fPIC"
0045 #FFLAGS="$FFLAGS -fPIC"
0046 #- with FC 19, need to use this without -fPIC (which cancels -mcmodel option):
0047 #- NOTES: The following option is not supported yet for this type of processor (arm64):
0048 # CFLAGS="$CFLAGS -mcmodel=medium"
0049 # FFLAGS="$FFLAGS -mcmodel=medium"
0050 #- might want to use '-fdefault-real-8' for fizhi pkg:
0051 #FFLAGS="$FFLAGS -fdefault-real-8 -fdefault-double-8"
0052
0053 if test "x$IEEE" = x ; then #- with optimisation:
0054 #- full optimisation
0055 FOPTIM='-O3 -funroll-loops'
0056 NOOPTFILES="$NOOPTFILES ini_masks_etc.F"
0057 #- can use -O2 (safe optimisation) to avoid Pb with some gcc version of -O3:
0058 #FOPTIM='-O2 -funroll-loops'
0059 else
0060 # these may also be useful, but require specific gfortran versions:
0061 # -Wnonstd-intrinsics for gfortran <= 4.3
0062 # -Wintrinsics-std for gfortran >= 4.4
0063 # -Wno-tabs for gfortran >= 4.3
0064 # -Wno-unused-dummy-argument for gfortran >= 4.6
0065 #FFLAGS="$FFLAGS -Waliasing -Wampersand -Wsurprising -Wline-truncation"
0066 #- or simply:
0067 FFLAGS="$FFLAGS -Wall"
0068 if [ $fcVers -ge 10 ] ; then
0069 FFLAGS="$FFLAGS -Wno-unused-dummy-argument"
0070 fi
0071 #- to get plenty of warnings: -Wall -Wextra (older form: -Wall -W) or:
0072 #FFLAGS="$FFLAGS -Wconversion -Wimplicit-interface -Wunused-labels"
0073 if test "x$DEVEL" = x ; then #- no optimisation + IEEE :
0074 FOPTIM='-O0'
0075 else #- development/check options:
0076 FOPTIM='-O0 -g -fbounds-check'
0077 FOPTIM="$FOPTIM -ffpe-trap=invalid,zero,overflow -finit-real=inf"
0078 fi
0079 fi
0080
0081 F90FLAGS=$FFLAGS
0082 F90OPTIM=$FOPTIM
0083
0084 INCLUDEDIRS=''
0085 INCLUDES=''
0086 LIBS=''
0087
0088 if [ "x$NETCDF_ROOT" != x ] ; then
0089 INCLUDEDIR="${NETCDF_ROOT}/include"
0090 INCLUDES="-I${NETCDF_ROOT}/include"
0091 LIBDIR="${NETCDF_ROOT}/lib"
0092 LIBS="-L${NETCDF_ROOT}/lib"
0093 elif [ "x$NETCDF_HOME" != x ]; then
0094 INCLUDEDIR="${NETCDF_HOME}/include"
0095 INCLUDES="-I${NETCDF_HOME}/include"
0096 LIBDIR="${NETCDF_HOME}/lib"
0097 LIBS="-L${NETCDF_HOME}/lib"
0098 elif [ "x$NETCDF_INC" != x -a "x$NETCDF_LIB" != x ]; then
0099 NETCDF_INC=`echo $NETCDF_INC | sed 's/-I//g'`
0100 NETCDF_LIB=`echo $NETCDF_LIB | sed 's/-L//g'`
0101 INCLUDEDIR="${NETCDF_INC}"
0102 INCLUDES="-I${NETCDF_INC}"
0103 LIBDIR="${NETCDF_LIB}"
0104 LIBS="-L${NETCDF_LIB}"
0105 elif [ "x$NETCDF_INCDIR" != x -a "x$NETCDF_LIBDIR" != x ]; then
0106 INCLUDEDIR="${NETCDF_INCDIR}"
0107 INCLUDES="-I${NETCDF_INCDIR}"
0108 LIBDIR="${NETCDF_LIBDIR}"
0109 LIBS="-L${NETCDF_LIBDIR}"
0110 elif [[ -n $( nf-config --includedir 2> /dev/null ) && ($? == 0) ]] ; then
0111 # NETCDF env variables are not set, trying nf-config instead
0112 INCLUDEDIR=$( nf-config --includedir )
0113 INCLUDES="-I$INCLUDEDIR"
0114 LIBS=$( nf-config --flibs )
0115 elif test -d /usr/include/netcdf-3 ; then
0116 INCLUDES='-I/usr/include/netcdf-3'
0117 LIBS='-L/usr/lib/netcdf-3 -L/usr/lib64/netcdf-3'
0118 elif test -d /usr/include/netcdf ; then
0119 INCLUDES='-I/usr/include/netcdf'
0120 elif test -d /usr/local/netcdf ; then
0121 INCLUDES='-I/usr/local/netcdf/include'
0122 LIBS='-L/usr/local/netcdf/lib'
0123 elif test -d /usr/local/include/netcdf.inc ; then
0124 INCLUDES='-I/usr/local/include'
0125 LIBS='-L/usr/local/lib64'
0126 elif test -d /usr/include/netcdf.inc ; then
0127 INCLUDES='-I/usr/include'
0128 LIBS='-L/usr/lib64'
0129 fi
0130
0131 if [ -n "$MPI_HOME" -a -z "$MPI_INC_DIR" ]; then
0132 MPI_INC_DIR="$MPI_HOME/include"
0133 fi
0134
0135 if [ "x$MPI" = xtrue ] ; then
0136 if [ -z "$MPI_INC_DIR" ] ; then
0137 # MPI env variables are not set, trying pkg-config insteal
0138 if [[ -n $( pkg-config --cflags-only-I ompi ) && ($? == 0) ]] ; then
0139 MPI_INC_DIR=$(pkg-config --cflags-only-I ompi | awk '{ print $1 }' | sed -e "s/-I//" )
0140 else
0141 echo MPI_HOME is not set and pkg-config not available, aborting
0142 exit 1
0143 fi
0144 fi
0145 if [ -n "$MPI_INC_DIR" ] ; then
0146 # only fill this if we can find MPI, otherwise triggers netcdf error
0147 INCLUDES+=" -I$MPI_INC_DIR"
0148 INCLUDEDIRS+=" $MPI_INC_DIR"
0149 #- used for parallel (MPI) DIVA
0150 MPIINCLUDEDIR="$MPI_INC_DIR"
0151 else
0152 echo could not set MPI_INC_DIR, aborting
0153 exit 1
0154 fi
0155 fi