| 1 | #!/bin/sh |
| 2 | # autopkgtest check: Build and link against a simple shared library, to test |
| 3 | # basic binutils compile-time and run-time linking functionality. |
| 4 | # |
| 5 | # (C) 2012 Canonical Ltd. |
| 6 | # Author: Martin Pitt <[email protected]> |
| 7 | |
| 8 | set -e |
| 9 | |
| 10 | WORKDIR=$(mktemp -d) |
| 11 | trap "rm -rf $WORKDIR" 0 INT QUIT ABRT PIPE TERM |
| 12 | cd $WORKDIR |
| 13 | cat <<EOF > testlib.c |
| 14 | |
| 15 | int ultimate_answer() |
| 16 | { |
| 17 | return 42; |
| 18 | } |
| 19 | EOF |
| 20 | |
| 21 | gcc -fuse-ld=gold -Wall -Werror -shared -o libultimate.so testlib.c |
| 22 | echo "library build: OK" |
| 23 | |
| 24 | # should export the symbol |
| 25 | nm -D libultimate.so | grep -q 'T ultimate_answer' |
| 26 | |
| 27 | # link it against a program |
| 28 | cat <<EOF > testprog.c |
| 29 | #include <assert.h> |
| 30 | |
| 31 | int ultimate_answer(); |
| 32 | |
| 33 | int main() |
| 34 | { |
| 35 | assert (ultimate_answer() == 42); |
| 36 | return 0; |
| 37 | } |
| 38 | EOF |
| 39 | |
| 40 | gcc -fuse-ld=gold -Wall -Werror -L . -o testprog testprog.c -lultimate |
| 41 | echo "program build: OK" |
| 42 | [ -x testprog ] |
| 43 | LD_LIBRARY_PATH=. ./testprog |
| 44 | echo "run: OK" |