+dnl
+dnl Check for -z,nodelete linker flag: the type system assumes that
+dnl libgobject stays loaded for the lifetime of the process.
+dnl Since ld.bfd does not treat wrong -z options as fatal by default,
+dnl we also try to check for the --fatal-warnings linker flag if
+dnl auto-detecting.
+dnl
+
+AC_ARG_ENABLE([znodelete],
+ [AS_HELP_STRING([--disable-znodelete],
+ [avoid linking with -z,nodelete])],,
+ [SAVED_LDFLAGS="${LDFLAGS}" SAVED_LIBS="${LIBS}"
+ AC_MSG_CHECKING([for --fatal-warnings linker flag])
+ LDFLAGS=-Wl,--fatal-warnings
+ LIBS=
+ AC_TRY_LINK([], [return 0],
+ AC_MSG_RESULT(yes)
+ [ldflags_fatal=-Wl,--fatal-warnings],
+ AC_MSG_RESULT(no)
+ ldflags_fatal=)
+ AC_MSG_CHECKING([for -z,nodelete linker flag])
+ LDFLAGS="$ldflags_fatal -Wl,-z,nodelete"
+ AC_TRY_LINK([], [return 0],
+ AC_MSG_RESULT(yes)
+ enable_znodelete=yes,
+ AC_MSG_RESULT(no)
+ enable_znodelete=no)
+ LDFLAGS="${SAVED_LDFLAGS}" LIBS="${SAVED_LIBS}"])
+
+if test "x${enable_znodelete}" = "xyes"; then
+ GOBJECT_LINK_FLAGS=-Wl,-z,nodelete
+fi
+
+AC_SUBST(GOBJECT_LINK_FLAGS)
+
+dnl
+dnl Check for -fvisibility=hidden to determine if we can do GNU-style
+dnl visibility attributes for symbol export control
+dnl
+GLIB_HIDDEN_VISIBILITY_CFLAGS=""
+case "$host" in
+ *-*-mingw*)
+ dnl on mingw32 we do -fvisibility=hidden and __declspec(dllexport)
+ AC_DEFINE([_GLIB_EXTERN], [__attribute__((visibility("default"))) __declspec(dllexport) extern],
+ [defines how to decorate public symbols while building])
+ CFLAGS="${CFLAGS} -fvisibility=hidden"
+ ;;
+ *)
+ dnl on other compilers, check if we can do -fvisibility=hidden
+ SAVED_CFLAGS="${CFLAGS}"
+ CFLAGS="-fvisibility=hidden"
+ AC_MSG_CHECKING([for -fvisibility=hidden compiler flag])
+ AC_TRY_COMPILE([], [return 0],
+ AC_MSG_RESULT(yes)
+ enable_fvisibility_hidden=yes,
+ AC_MSG_RESULT(no)
+ enable_fvisibility_hidden=no)
+ CFLAGS="${SAVED_CFLAGS}"
+
+ AS_IF([test "${enable_fvisibility_hidden}" = "yes"], [
+ AC_DEFINE([_GLIB_EXTERN], [__attribute__((visibility("default"))) extern],
+ [defines how to decorate public symbols while building])
+ GLIB_HIDDEN_VISIBILITY_CFLAGS="-fvisibility=hidden"
+ ])
+ ;;
+esac
+AC_SUBST(GLIB_HIDDEN_VISIBILITY_CFLAGS)
+
+dnl Compiler flags; macro originates from systemd
+dnl See https://bugzilla.gnome.org/show_bug.cgi?id=608953
+AC_ARG_ENABLE(compile-warnings,
+ [AS_HELP_STRING([--disable-compile-warnings],
+ [Don't use builtin compiler warnings])],,
+ enable_compile_warnings=yes)
+AS_IF([test "x$enable_compile_warnings" = xyes], [
+ CC_CHECK_FLAGS_APPEND([GLIB_WARN_CFLAGS], [CFLAGS], [\
+ -Wall -Wstrict-prototypes -Werror=declaration-after-statement \
+ -Werror=missing-prototypes -Werror=implicit-function-declaration \
+ -Werror=pointer-arith -Werror=init-self -Werror=format-security \
+ -Werror=format=2 -Werror=missing-include-dirs])
+])
+AC_SUBST(GLIB_WARN_CFLAGS)
+