Warning, /tools/build_options/darwin_arm64_gfortran is written in an unsupported language. File is not indexed.
view on githubraw file Latest commit 626c6ac9 on 2025-11-05 20:20:29 UTC
fefbff5637 Mart*0001 #!/bin/bash
0002 #
0003 # tested on MacBook Pro with macOS Monterey
0004 # uname -a
0005 # Darwin bkli04m056 21.3.0 Darwin Kernel Version 21.3.0: Wed Jan 5 21:37:58 PST 2022; root:xnu-8019.80.24~20/RELEASE_ARM64_T6000 arm64
0006 # gcc, gfortran, netcdf/netcdf-fortran, and openmpi obtained from
0007 # https://www.macports.org
0008 # sudo port install gcc11
0009 # sudo port select --set gcc mp-gcc11
0010 # similar results can be achieved using homebrew
0011
0012 # Note: at the time of creating this file (Mar2022), the
0013 # gfortran-build of http://hpc.sourceforge.net does not work with
0014 # testreport (also: cannot compile like the "etime" test and leads to
0015 # multile warnings at the link step), because the model compiled with
0016 # this gfortran does not print the last line before the stop statement
0017 # without an additional flush-statement.
0018
0019 if test "x$MPI" = xtrue ; then
0020 CC=mpicc
0021 FC=mpif77
0022 F90C=mpif90
0023 LINK=$F90C
0024 else
0025 CC=gcc
0026 FC=gfortran
0027 F90C=gfortran
0028 LINK=$F90C
0029 fi
0030
626c6ac944 Jean*0031 ABSOLUTE_ROOTDIR=$(cd $(dirname $0) && cd ../ && pwd)
0032 TAPENADECMD="docker container run --rm -u $(stat -f '%u:%g' ./) \
0033 -v \${PWD}:\${PWD} -v ${ABSOLUTE_ROOTDIR}:${ABSOLUTE_ROOTDIR} -w \${PWD} \
0034 registry.gitlab.inria.fr/tapenade/tapenade"
0035
fefbff5637 Mart*0036 FC_NAMEMANGLE="#define FC_NAMEMANGLE(X) X ## _"
0037 S64='$(TOOLSDIR)/set64bitConst.sh'
0038 DEFINES='-DWORDLENGTH=4 -DNML_TERMINATOR'
0039 CPP='/usr/bin/cpp -traditional -P'
0040 GET_FC_VERSION="--version"
0041 EXTENDED_SRC_FLAG='-ffixed-line-length-132'
0042 OMPFLAG='-fopenmp'
0043
0044 #MAKEDEPEND=tools_xmakedepend
0045
0046 NOOPTFLAGS='-O0'
0047 NOOPTFILES=''
0048
0049 FFLAGS="$FFLAGS -fconvert=big-endian"
e2eee4773e mjlo*0050 # needed for big objects (e.g., to compile and run TAF AD of
0051 # global_ocean.cs32x15), but requires larger stack sizes (set with
0052 # ulimit -s) in other cases, so we leave this commented out:
0053 # man gfortran: Allow indirect recursion by forcing all local arrays
0054 # to be allocated on the stack.
0055 #FFLAGS="$FFLAGS -frecursive"
fefbff5637 Mart*0056 #- might want to use '-fdefault-real-8' for fizhi pkg:
0057 #FFLAGS="$FFLAGS -fdefault-real-8 -fdefault-double-8"
0058
0059 #- for setting specific options, check compiler version:
0060 fcVers=`$FC -dumpversion | head -n 1 | sed 's/^[^0-9]* //;s/\..*$//'`
0061 if ! [[ $fcVers =~ ^[0-9]+$ ]] ; then
0062 echo " un-recognized Compiler-version '$fcVers' ; ignored (-> set to 0)" ; fcVers=0 ;
0063 else echo " get Compiler-version: '$fcVers'" ; fi
0064
0065 if [ $fcVers -ge 10 ] ; then
0066 FFLAGS="$FFLAGS -fallow-argument-mismatch"
0067 fi
0068
0069 # For IEEE, use the "-ffloat-store" option
0070 if test "x$IEEE" = x ; then
0071 FFLAGS="$FFLAGS -Wunused -Wuninitialized"
0072 FOPTIM='-O3 -ftree-vectorize -funroll-loops'
0073 NOOPTFLAGS='-O2 -funroll-loops'
0074 # NOOPTFILES='gad_c4_adv_x.F gad_u3_adv_x.F'
0075 else
0076 FFLAGS="$FFLAGS -Wall"
0077 if test "x$DEVEL" = x ; then #- no optimisation + IEEE :
0078 FOPTIM='-O0'
0079 else #- development/check options:
0080 FOPTIM='-O0 -g -fbounds-check'
0081 FOPTIM="$FOPTIM -ffpe-trap=invalid,zero,overflow -finit-real=inf"
0082 fi
0083 fi
0084
c7a06a2c29 Mart*0085 # add undocumented flag -x f95 to force gfortran to interpret any
0086 # suffix as a f90-freeformat file, add -ffree-form to suppress the
0087 # associated warning
0088 F90FLAGS="$FFLAGS -x f95 -ffree-form"
fefbff5637 Mart*0089 F90OPTIM=$FOPTIM
0090
0091 INCLUDEDIRS=''
0092 INCLUDES=''
0093 LIBS=''
0094
0095 if [ "x$NETCDF_ROOT" != x ] ; then
0096 INCLUDEDIR="${NETCDF_ROOT}/include"
0097 INCLUDES="-I${NETCDF_ROOT}/include"
0098 LIBDIR="${NETCDF_ROOT}/lib"
0099 LIBS="-L${NETCDF_ROOT}/lib -lnetcdf -lcurl"
0100 elif [ "x$NETCDF_HOME" != x ]; then
0101 INCLUDEDIR="${NETCDF_HOME}/include"
0102 INCLUDES="-I${NETCDF_HOME}/include"
0103 LIBDIR="${NETCDF_HOME}/lib"
0104 LIBS="-L${NETCDF_HOME}/lib"
0105 elif [ "x$NETCDF_INC" != x -a "x$NETCDF_LIB" != x ]; then
0106 NETCDF_INC=`echo $NETCDF_INC | sed 's/-I//g'`
0107 NETCDF_LIB=`echo $NETCDF_LIB | sed 's/-L//g'`
0108 INCLUDEDIR="${NETCDF_INC}"
0109 INCLUDES="-I${NETCDF_INC}"
0110 LIBDIR="${NETCDF_LIB}"
0111 LIBS="-L${NETCDF_LIB}"
0112 elif [ "x$NETCDF_INCDIR" != x -a "x$NETCDF_LIBDIR" != x ]; then
0113 INCLUDEDIR="${NETCDF_INCDIR}"
0114 INCLUDES="-I${NETCDF_INCDIR}"
0115 LIBDIR="${NETCDF_LIBDIR}"
0116 LIBS="-L${NETCDF_LIBDIR}"
0117 elif [[ -n $( nf-config --includedir ) && ($? == 0) ]] ; then
0118 # NETCDF env variables are not set, trying nf-config instead
0119 INCLUDEDIR=$( nf-config --includedir )
0120 INCLUDES="-I$INCLUDEDIR"
0121 # although this would is the best option, the resulting -arch arm64 is
0122 # not supported by gfortran from hpc.sourceforge.net
0123 LIBS=$( nf-config --flibs )
0124 # if FC=gfortran from hpc.sourceforge.net, then this works:
0125 # LIBDIR=$( nf-config --prefix )/lib
0126 # LIBS="-L$LIBDIR"
0127 elif test -d /opt/local/include ; then
0128 # if netcdf has been install by macports, this is where it is:
0129 INCLUDES='-I/opt/local/include'
0130 LIBS='-L/opt/local/lib'
0131 elif test -d /usr/include/netcdf-3 ; then
0132 INCLUDES='-I/usr/include/netcdf-3'
0133 LIBS='-L/usr/lib/netcdf-3 -L/usr/lib64/netcdf-3'
0134 elif test -d /usr/include/netcdf ; then
0135 INCLUDES='-I/usr/include/netcdf'
0136 elif test -d /usr/local/netcdf ; then
0137 INCLUDES='-I/usr/local/netcdf/include'
0138 LIBS='-L/usr/local/netcdf/lib'
0139 elif test -d /usr/local/include/netcdf.inc ; then
0140 INCLUDES='-I/usr/local/include'
0141 LIBS='-L/usr/local/lib64'
0142 elif test -d /usr/include/netcdf.inc ; then
0143 INCLUDES='-I/usr/include'
0144 LIBS='-L/usr/lib64'
0145 fi
0146
0147 if [ -n "$MPI_HOME" -a -z "$MPI_INC_DIR" ]; then
0148 MPI_INC_DIR="$MPI_HOME/include"
0149 fi
0150
0151 if [ "x$MPI" = xtrue ] ; then
0152 if [ -z "$MPI_INC_DIR" ] ; then
0153 # MPI env variables are not set, trying pkg-config insteal
0154 # this works for macport installs of openmpi
0155 if [[ -n $( pkg-config --cflags-only-I mpich ) && ($? == 0) ]] ; then
0156 MPI_INC_DIR=$(pkg-config --cflags-only-I mpich | awk '{ print $1 }' | sed -e "s/-I//" )
0157 else
0158 echo MPI_HOME is not set and pkg-config not available, aborting
0159 exit 1
0160 fi
0161 fi
0162 if [ -n "$MPI_INC_DIR" ] ; then
0163 # only fill this if we can find MPI, otherwise triggers netcdf error
0164 INCLUDES+=" -I$MPI_INC_DIR"
0165 INCLUDEDIRS+=" $MPI_INC_DIR"
0166 #- used for parallel (MPI) DIVA
0167 MPIINCLUDEDIR="$MPI_INC_DIR"
0168 else
0169 echo could not set MPI_INC_DIR, aborting
0170 exit 1
0171 fi
0172 fi