| 1 | #!/bin/sh |
| 2 | # autopkgtest check: Build and run a program against SDL, to verify that the |
| 3 | # headers and pkg-config file are installed correctly |
| 4 | # |
| 5 | # Based on glib2.0's debian/tests/build |
| 6 | # (C) 2012 Canonical Ltd. |
| 7 | # (C) 2018 Simon McVittie |
| 8 | # Authors: Martin Pitt, Simon McVittie |
| 9 | |
| 10 | set -eux |
| 11 | |
| 12 | # Ideally this test could be re-run with mode=static. However, statically |
| 13 | # linking libSDL2 doesn't actually work, because there is no libasound.a |
| 14 | # in libasound-dev (since 1.0.27-3 in 2013). |
| 15 | mode=dynamic |
| 16 | |
| 17 | WORKDIR=$(mktemp -d) |
| 18 | trap 'rm -rf "$WORKDIR"' 0 INT QUIT ABRT PIPE TERM |
| 19 | |
| 20 | if [ -n "${DEB_HOST_GNU_TYPE:-}" ]; then |
| 21 | CROSS_COMPILE="$DEB_HOST_GNU_TYPE-" |
| 22 | else |
| 23 | CROSS_COMPILE= |
| 24 | fi |
| 25 | |
| 26 | export SDL2COMPAT_DEBUG_LOGGING=1 |
| 27 | |
| 28 | cd "$WORKDIR" |
| 29 | cat <<EOF > use-sdl.c |
| 30 | #undef NDEBUG |
| 31 | #include <assert.h> |
| 32 | |
| 33 | #include <SDL_version.h> |
| 34 | |
| 35 | int main(void) |
| 36 | { |
| 37 | SDL_version compiled; |
| 38 | SDL_version linked; |
| 39 | |
| 40 | SDL_VERSION(&compiled); |
| 41 | SDL_GetVersion(&linked); |
| 42 | |
| 43 | assert(compiled.major == 2); |
| 44 | assert(linked.major == 2); |
| 45 | |
| 46 | return 0; |
| 47 | } |
| 48 | EOF |
| 49 | |
| 50 | for tool in pkg-config sdl2-config; do |
| 51 | for cc in "${CROSS_COMPILE}gcc" clang; do |
| 52 | cflags= |
| 53 | pcflags= |
| 54 | scflags=--libs |
| 55 | |
| 56 | case "$mode" in |
| 57 | (static) |
| 58 | cflags=-static |
| 59 | pcflags=--static |
| 60 | scflags=--static-libs |
| 61 | ;; |
| 62 | esac |
| 63 | |
| 64 | case "$cc" in |
| 65 | (clang) |
| 66 | cflags="$cflags ${DEB_HOST_GNU_TYPE:+--target="${DEB_HOST_GNU_TYPE}"}" |
| 67 | ;; |
| 68 | esac |
| 69 | |
| 70 | exe="use-${tool}-${cc}-${mode}" |
| 71 | |
| 72 | case "$tool" in |
| 73 | (pkg-config) |
| 74 | # Deliberately word-splitting cflags, pcflags, pkg-config output |
| 75 | # shellcheck disable=SC2046,SC2086 |
| 76 | "$cc" $cflags -o "${exe}" use-sdl.c $("${CROSS_COMPILE}pkg-config" $pcflags --cflags --libs sdl2) |
| 77 | ;; |
| 78 | (sdl2-config) |
| 79 | # shellcheck disable=SC2046,SC2086 |
| 80 | "$cc" $cflags -o "${exe}" use-sdl.c $(PKG_CONFIG="${CROSS_COMPILE}pkg-config" sdl2-config --cflags $scflags) |
| 81 | ;; |
| 82 | (*) |
| 83 | exit 1 |
| 84 | ;; |
| 85 | esac |
| 86 | |
| 87 | echo "build (with $tool, $cc, $mode): OK" |
| 88 | [ -x "${exe}" ] |
| 89 | ./"${exe}" |
| 90 | echo "run (with $tool, $cc, $mode): OK" |
| 91 | done |
| 92 | done |