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