github.com/riscv/riscv-go@v0.0.0-20200123204226-124ebd6fcc8e/misc/cgo/fortran/test.bash (about)

     1  #!/usr/bin/env bash
     2  # Copyright 2016 The Go Authors. All rights reserved.
     3  # Use of this source code is governed by a BSD-style
     4  # license that can be found in the LICENSE file.
     5  
     6  # This directory is intended to test the use of Fortran with cgo.
     7  
     8  set -e
     9  
    10  FC=$1
    11  
    12  goos=$(go env GOOS)
    13  
    14  libext="so"
    15  if [ "$goos" == "darwin" ]; then
    16  	libext="dylib"
    17  fi
    18  
    19  case "$FC" in
    20  *gfortran*)
    21    libpath=$(dirname $($FC -print-file-name=libgfortran.$libext))
    22    export CGO_LDFLAGS="$CGO_LDFLAGS -Wl,-rpath,$libpath -L $libpath"
    23    ;;
    24  esac
    25  
    26  if ! $FC helloworld/helloworld.f90 -o main.exe >& /dev/null; then
    27    echo "skipping Fortran test: could not build helloworld.f90 with $FC"
    28    exit 0
    29  fi
    30  rm -f main.exe
    31  
    32  status=0
    33  
    34  if ! go test; then
    35    echo "FAIL: go test"
    36    status=1
    37  fi
    38  
    39  exit $status