| 1 | #!/bin/sh |
| 2 | # autopkgtest check: Build and run a program against glib, to verify that the |
| 3 | # headers and pkg-config file are installed correctly |
| 4 | # (C) 2012,2019 Canonical Ltd. |
| 5 | # (C) 2018 Simon McVittie |
| 6 | # Authors: Martin Pitt <[email protected]>, Simon McVittie |
| 7 | |
| 8 | set -eux |
| 9 | |
| 10 | mode=dynamic |
| 11 | |
| 12 | getopt_temp="$(getopt -o '' --long 'static' -n debian/tests/build -- "$@")" |
| 13 | eval set -- "$getopt_temp" |
| 14 | |
| 15 | while true; do |
| 16 | case "$1" in |
| 17 | (--static) |
| 18 | mode=static |
| 19 | shift |
| 20 | continue |
| 21 | ;; |
| 22 | |
| 23 | (--) |
| 24 | shift |
| 25 | break |
| 26 | ;; |
| 27 | |
| 28 | (*) |
| 29 | echo "getopt: Internal error" >&2 |
| 30 | exit 2 |
| 31 | esac |
| 32 | done |
| 33 | |
| 34 | WORKDIR=$(mktemp -d) |
| 35 | trap 'rm -rf "${WORKDIR}"' 0 INT QUIT ABRT PIPE TERM |
| 36 | cd "${WORKDIR}" |
| 37 | |
| 38 | if [ -n "${DEB_HOST_GNU_TYPE:-}" ]; then |
| 39 | CROSS_COMPILE="${DEB_HOST_GNU_TYPE}-" |
| 40 | else |
| 41 | CROSS_COMPILE= |
| 42 | fi |
| 43 | |
| 44 | cat <<EOF > glib.c |
| 45 | #include <glib.h> |
| 46 | |
| 47 | int main(void) |
| 48 | { |
| 49 | g_assert_cmpint (g_strcmp0 (NULL, "hello"), ==, -1); |
| 50 | g_assert_cmpstr (g_getenv ("foo"), ==, "bar"); |
| 51 | return 0; |
| 52 | } |
| 53 | EOF |
| 54 | cat <<EOF > gobject.c |
| 55 | #include <glib-object.h> |
| 56 | |
| 57 | int main(void) |
| 58 | { |
| 59 | g_assert_cmpuint (G_TYPE_OBJECT, !=, G_TYPE_INVALID); |
| 60 | return 0; |
| 61 | } |
| 62 | EOF |
| 63 | cat <<EOF > gio.c |
| 64 | #include <gio/gio.h> |
| 65 | |
| 66 | int main(void) |
| 67 | { |
| 68 | g_assert_cmpuint (G_TYPE_FILE, !=, G_TYPE_INVALID); |
| 69 | return 0; |
| 70 | } |
| 71 | EOF |
| 72 | cat <<EOF > gio-unix.c |
| 73 | #include <gio/gunixfdlist.h> |
| 74 | |
| 75 | int main(void) |
| 76 | { |
| 77 | g_assert_cmpuint (G_TYPE_UNIX_FD_LIST, !=, G_TYPE_INVALID); |
| 78 | return 0; |
| 79 | } |
| 80 | EOF |
| 81 | cat <<EOF > gmodule.c |
| 82 | #include <gmodule.h> |
| 83 | |
| 84 | int main(void) |
| 85 | { |
| 86 | GModule *module; |
| 87 | |
| 88 | g_assert_true (g_module_supported ()); |
| 89 | module = g_module_open (NULL, 0); |
| 90 | g_assert_nonnull (module); |
| 91 | g_assert_true (g_module_close (module)); |
| 92 | return 0; |
| 93 | } |
| 94 | EOF |
| 95 | cat <<EOF > gthread.c |
| 96 | #include <glib.h> |
| 97 | |
| 98 | static gpointer |
| 99 | other_cb (gpointer nil) |
| 100 | { |
| 101 | return "hello"; |
| 102 | } |
| 103 | |
| 104 | int main(void) |
| 105 | { |
| 106 | GThread *other; |
| 107 | gpointer ret; |
| 108 | |
| 109 | other = g_thread_new ("other", other_cb, NULL); |
| 110 | g_assert_nonnull (other); |
| 111 | ret = g_thread_join (other); |
| 112 | g_assert_cmpstr (ret, ==, "hello"); |
| 113 | return 0; |
| 114 | } |
| 115 | EOF |
| 116 | |
| 117 | for lib in glib gobject gio gio-unix gmodule gthread; do |
| 118 | cflags= |
| 119 | pcflags= |
| 120 | packages="${lib}-2.0" |
| 121 | |
| 122 | case "$mode" in |
| 123 | (static) |
| 124 | cflags=-static |
| 125 | pcflags=--static |
| 126 | |
| 127 | case "$lib" in |
| 128 | (gio|gio-unix) |
| 129 | # GIO depends on libmount which no longer supports |
| 130 | # being linked statically |
| 131 | continue |
| 132 | ;; |
| 133 | esac |
| 134 | ;; |
| 135 | esac |
| 136 | |
| 137 | # shellcheck disable=SC2046 |
| 138 | ${CROSS_COMPILE}gcc $cflags -o ${lib}-$mode ${lib}.c $(${CROSS_COMPILE}pkg-config $pcflags --cflags --libs ${packages}) |
| 139 | echo "build ($lib, $mode): OK" |
| 140 | [ -x ${lib}-$mode ] |
| 141 | foo=bar ./${lib}-$mode |
| 142 | echo "run ($lib, $mode): OK" |
| 143 | done |