| 1 | #!/bin/sh |
| 2 | # Copyright 2022 Collabora Ltd |
| 3 | # SPDX-License-Identifier: Zlib |
| 4 | |
| 5 | set -eux |
| 6 | |
| 7 | if [ -n "${DEB_HOST_GNU_TYPE:-}" ]; then |
| 8 | CROSS_COMPILE="$DEB_HOST_GNU_TYPE-" |
| 9 | else |
| 10 | CROSS_COMPILE= |
| 11 | fi |
| 12 | |
| 13 | export PKG_CONFIG="${CROSS_COMPILE}pkgconf" |
| 14 | |
| 15 | cd "$AUTOPKGTEST_TMP" |
| 16 | cat <<EOF > use-sdl.c |
| 17 | #undef NDEBUG |
| 18 | #include <assert.h> |
| 19 | |
| 20 | #include <SDL.h> |
| 21 | |
| 22 | int main(void) |
| 23 | { |
| 24 | const SDL_version *linked; |
| 25 | Uint32 flags; |
| 26 | |
| 27 | flags = SDL_WasInit(SDL_INIT_EVERYTHING); |
| 28 | assert(flags == 0); |
| 29 | |
| 30 | linked = SDL_Linked_Version(); |
| 31 | |
| 32 | assert(SDL_COMPILEDVERSION >= SDL_VERSIONNUM(1, 2, 0)); |
| 33 | assert(linked->major == 1); |
| 34 | |
| 35 | return 0; |
| 36 | } |
| 37 | EOF |
| 38 | |
| 39 | for tool in pkg-config pc-compat sdl-config; do |
| 40 | for cc in "${CROSS_COMPILE}gcc" clang; do |
| 41 | cflags= |
| 42 | |
| 43 | case "$cc" in |
| 44 | (clang) |
| 45 | cflags="$cflags ${DEB_HOST_GNU_TYPE:+--target="${DEB_HOST_GNU_TYPE}"}" |
| 46 | ;; |
| 47 | esac |
| 48 | |
| 49 | exe="use-${tool}-${cc}" |
| 50 | |
| 51 | case "$tool" in |
| 52 | (pkg-config) |
| 53 | # Deliberately word-splitting cflags, pcflags, pkg-config output |
| 54 | # shellcheck disable=SC2046,SC2086 |
| 55 | "$cc" $cflags -o "${exe}" use-sdl.c $("$PKG_CONFIG" --cflags --libs sdl) |
| 56 | ;; |
| 57 | (pc-compat) |
| 58 | # Deliberately word-splitting cflags, pcflags, pkg-config output |
| 59 | # shellcheck disable=SC2046,SC2086 |
| 60 | "$cc" $cflags -o "${exe}" use-sdl.c $("$PKG_CONFIG" --cflags --libs sdl12_compat) |
| 61 | ;; |
| 62 | (sdl-config) |
| 63 | # shellcheck disable=SC2046,SC2086 |
| 64 | "$cc" $cflags -o "${exe}" use-sdl.c $(sdl-config --cflags --libs) |
| 65 | ;; |
| 66 | (*) |
| 67 | exit 1 |
| 68 | ;; |
| 69 | esac |
| 70 | |
| 71 | echo "build (with $tool, $cc): OK" |
| 72 | [ -x "${exe}" ] |
| 73 | ./"${exe}" |
| 74 | echo "run (with $tool, $cc): OK" |
| 75 | done |
| 76 | done |