File: trylibs.sh

package info (click to toggle)
dq 20251001-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,376 kB
  • sloc: ansic: 13,644; python: 651; makefile: 382; sh: 336
file content (52 lines) | stat: -rwxr-xr-x 984 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/sh

# version 20241109

scriptname="`basename $0`"

if [ x"${CC}" = x ]; then
  echo "usage: env CC=<compiler> ${scriptname} -l<library> -l<library> ..."
  echo '$CC not set'
  exit 1
fi

if [ x"$1" = x ]; then
  echo "usage: env CC=<compiler> ${scriptname} -l<library> -l<library> ..."
  echo 'missing -l<library> argument'
  exit 1
fi

# temporary
name="${scriptname}"
tryname="${name}.tmp.C"
binname="${tryname}.tmp.bin"
logname="${tryname}.tmp.log"

cleanup() {
  ex=$?
  rm -f "${binname}" "${tryname}" "${logname}"
  exit "${ex}"
}
trap "cleanup" EXIT TERM INT

cat <<EOF > "${tryname}"
int main(int argc, char **argv) {
    (void) argc;
    (void) argv;
    return 0;
}
EOF

while true; do
  [ x"$1" = x ] && break
  "${CC}" -O0 -o "${binname}" "${tryname}" "$1" 1>"${logname}" 2>&1
  if [ $? -eq 0 ]; then
    echo "${scriptname}: '$1' detected" >&2
    echo "$1"
  else
    echo "${scriptname}: '$1' not detected" >&2
    cat "${logname}" >&2
  fi
  shift
done
exit 0