1#!/usr/bin/env bash
2# Compile a source file with '-funparse-with-symbols' and verify
3# we get the right symbols in the output, i.e. the output should be
4# the same as the input, except for the copyright comment.
5# Change the compiler by setting the F18 environment variable.
6
7F18_OPTIONS="-funparse-with-symbols"
8srcdir=$(dirname $0)
9source $srcdir/common.sh
10[[ ! -f $src ]] && echo "File not found: $src" && exit 1
11
12src1=$temp/1.f90
13src2=$temp/2.f90
14src3=$temp/3.f90
15diffs=$temp/diffs
16
17# Strip out blank lines and all comments except "!DEF:", "!REF:", and "!$omp"
18sed -e 's/!\([DR]EF:\)/KEEP \1/' -e 's/!\($omp\)/KEEP \1/' \
19  -e 's/!\($acc\)/KEEP \1/' -e 's/!.*//' -e 's/ *$//' -e '/^$/d' \
20  -e 's/KEEP \([DR]EF:\)/!\1/' -e 's/KEEP \($omp\)/!\1/' \
21  -e 's/KEEP \($acc\)/!\1/' \
22  $src > $src1
23egrep -v '![DR]EF:' $src1 > $src2  # strip out DEF and REF comments
24# compile, inserting comments for symbols:
25( cd $temp; $F18 $F18_OPTIONS $(basename $src2) ) > $src3
26
27if diff -w -U999999 $src1 $src3 > $diffs; then
28  echo PASS
29else
30  sed '1,/^\@\@/d' $diffs
31  echo
32  echo FAIL
33  exit 1
34fi
35