| 1 | #!/bin/sh |
| 2 | # This test exercises various ways to use SDL2 that are considered |
| 3 | # incorrect, but used to work. |
| 4 | # |
| 5 | # Loosely based on glib2.0's debian/tests/build |
| 6 | # (C) 2012 Canonical Ltd. |
| 7 | # (C) 2018-2020 Simon McVittie |
| 8 | # Authors: Martin Pitt, Simon McVittie |
| 9 | |
| 10 | set -eux |
| 11 | |
| 12 | WORKDIR=$(mktemp -d) |
| 13 | trap 'rm -rf "$WORKDIR"' 0 INT QUIT ABRT PIPE TERM |
| 14 | |
| 15 | if [ -n "${DEB_HOST_GNU_TYPE:-}" ]; then |
| 16 | CROSS_COMPILE="$DEB_HOST_GNU_TYPE-" |
| 17 | else |
| 18 | CROSS_COMPILE= |
| 19 | fi |
| 20 | |
| 21 | export SDL2COMPAT_DEBUG_LOGGING=1 |
| 22 | |
| 23 | cd "$WORKDIR" |
| 24 | cat <<EOF > use-sdl.c |
| 25 | #undef NDEBUG |
| 26 | #include <assert.h> |
| 27 | |
| 28 | #ifdef WRONG_INCLUDE_PATH |
| 29 | # if INDIRECT |
| 30 | # include <SDL2/SDL_ttf.h> |
| 31 | # else |
| 32 | # include <SDL2/SDL.h> |
| 33 | # endif |
| 34 | #else |
| 35 | # if INDIRECT |
| 36 | # include <SDL_ttf.h> |
| 37 | # else |
| 38 | # include <SDL.h> |
| 39 | # endif |
| 40 | #endif |
| 41 | |
| 42 | int main(void) |
| 43 | { |
| 44 | SDL_version compiled; |
| 45 | SDL_version linked; |
| 46 | |
| 47 | SDL_VERSION(&compiled); |
| 48 | SDL_GetVersion(&linked); |
| 49 | |
| 50 | assert(compiled.major == 2); |
| 51 | assert(linked.major == 2); |
| 52 | |
| 53 | return 0; |
| 54 | } |
| 55 | EOF |
| 56 | |
| 57 | cd "$WORKDIR" |
| 58 | cat <<EOF > use-ttf.c |
| 59 | #undef NDEBUG |
| 60 | #include <assert.h> |
| 61 | |
| 62 | #ifdef WRONG_INCLUDE_PATH |
| 63 | # include <SDL2/SDL_ttf.h> |
| 64 | #else |
| 65 | # include <SDL_ttf.h> |
| 66 | #endif |
| 67 | |
| 68 | int main(void) |
| 69 | { |
| 70 | const SDL_version *version = TTF_Linked_Version(); |
| 71 | assert (version != NULL); |
| 72 | |
| 73 | return 0; |
| 74 | } |
| 75 | EOF |
| 76 | |
| 77 | # Emulate the assumption made by neverball_1.6.0+git20180603-2, |
| 78 | # which assumes that the CFLAGS from sdl2-config are enough to |
| 79 | # find related libraries like SDL2_ttf. |
| 80 | |
| 81 | for tool in pkg-config sdl2-config; do |
| 82 | case "$tool" in |
| 83 | (pkg-config) |
| 84 | # shellcheck disable=SC2046 |
| 85 | "${CROSS_COMPILE}gcc" -o "use-${tool}" use-ttf.c $("${CROSS_COMPILE}pkg-config" --cflags --libs sdl2 SDL2_ttf) |
| 86 | ;; |
| 87 | (sdl2-config) |
| 88 | # shellcheck disable=SC2046 |
| 89 | "${CROSS_COMPILE}gcc" -o "use-${tool}" use-ttf.c $(PKG_CONFIG="${CROSS_COMPILE}pkg-config" sdl2-config --cflags --libs) -lSDL2_ttf |
| 90 | ;; |
| 91 | (*) |
| 92 | exit 1 |
| 93 | ;; |
| 94 | esac |
| 95 | |
| 96 | echo "build (with $tool): OK" |
| 97 | [ -x use-${tool} ] |
| 98 | ./use-${tool} |
| 99 | echo "run (with $tool): OK" |
| 100 | done |
| 101 | |
| 102 | # Emulate the assumption made by planetblupi_1.14.2-1, |
| 103 | # which assumes that the SDL2 headers are in /usr/include/SDL2 without |
| 104 | # consulting pkg-config. |
| 105 | |
| 106 | # shellcheck disable=SC2046 |
| 107 | "${CROSS_COMPILE}gcc" -o use-sdl use-sdl.c -I/usr/include/SDL2 $("${CROSS_COMPILE}pkg-config" --libs sdl2) |
| 108 | # shellcheck disable=SC2046 |
| 109 | "${CROSS_COMPILE}gcc" -o use-ttf use-ttf.c -I/usr/include/SDL2 $("${CROSS_COMPILE}pkg-config" --libs sdl2 SDL2_ttf) |
| 110 | echo "build (assuming headers in /usr/include/SDL2): OK" |
| 111 | [ -x use-sdl ] |
| 112 | ./use-sdl |
| 113 | [ -x use-ttf ] |
| 114 | ./use-ttf |
| 115 | echo "run: OK" |
| 116 | |
| 117 | # Emulate the assumption made by jag_0.3.5-5, mrboom_4.9-1 and |
| 118 | # trigger-rally_0.6.6.1-2, which assume that the SDL2 headers can be |
| 119 | # included via #include <SDL2/foo.h>. |
| 120 | |
| 121 | "${CROSS_COMPILE}gcc" -o use-sdl use-sdl.c -DWRONG_INCLUDE_PATH -lSDL2 |
| 122 | "${CROSS_COMPILE}gcc" -o use-ttf use-ttf.c -DWRONG_INCLUDE_PATH -lSDL2 -lSDL2_ttf |
| 123 | echo "build (assuming <SDL2/*.h> and -lSDL2* in default search paths): OK" |
| 124 | [ -x use-sdl ] |
| 125 | ./use-sdl |
| 126 | [ -x use-ttf ] |
| 127 | ./use-ttf |
| 128 | echo "run: OK" |
| 129 | |
| 130 | # clang has different symlink behaviour, so building jag_0.3.5-5 etc. |
| 131 | # with clang would have a different failure mode. Test that too. |
| 132 | |
| 133 | clang ${DEB_HOST_GNU_TYPE:+--target="${DEB_HOST_GNU_TYPE}"} -o use-sdl use-sdl.c -DWRONG_INCLUDE_PATH -lSDL2 |
| 134 | clang ${DEB_HOST_GNU_TYPE:+--target="${DEB_HOST_GNU_TYPE}"} -o use-ttf use-ttf.c -DWRONG_INCLUDE_PATH -lSDL2 -lSDL2_ttf |
| 135 | echo "build (clang, assuming <SDL2/*.h> and -lSDL2* in default search paths): OK" |
| 136 | [ -x use-sdl ] |
| 137 | ./use-sdl |
| 138 | [ -x use-ttf ] |
| 139 | ./use-ttf |
| 140 | echo "run: OK" |