1#!/bin/sh
2
3# Shell script with one argument (path of an OpenMP executable) that exits
4# with status 0 if the OpenMP test program should be run and that exits with
5# status 1 if the OpenMP test program should not be run.
6
7test -e "$1" || exit $?
8
9./supported_libpthread || exit $?
10
11# Do not accept any statically linked executable.
12if /usr/bin/file "$1" | grep -q 'statically linked'; then
13  exit 1
14fi
15
16if [ "$(uname)" = Linux ]; then
17
18  # Let the dynamic linker/loader print the path of libgomp. See also man ld.so
19  libgomp_path="$(LD_TRACE_LOADED_OBJECTS=1 "$1" \
20    | while read soname arrow path offset; \
21   do if [ "${soname#libgomp.so}" != "${soname}" ]; then echo $path; fi; done)"
22
23  # Inspect the output of nm. If nm does not find any symbol information,
24  # echo 1. If the symbol gomp_barrier_init is found, echo 0. Otherwise echo
25  # nothing. The second case occurs if gcc has been compiled with 
26  # --disable-linux-futex, and the last case occurs if gcc has been compiled
27  # with --enable-linux-futex.
28  rc="$(nm "${libgomp_path}" 2>&1 \
29        |
30        while read line
31        do
32          if [ "${line%: no symbols}" != "${line}" ]; then
33            echo 1
34            break
35          elif [ "${line% gomp_barrier_init}" != "${line}" ]; then
36            echo 0
37            break
38          fi
39        done)"
40  exit ${rc:-1}
41
42fi
43