build: Enable additional build errors and warnings

Help catch more errors by enabling additional build errors and warnings.
Address some of the warnings seen with these new flags, including moving
the libusb_transfer structure back out of the usbi_transfer structure to
address 'warning: invalid use of structure with flexible array member'.
Apparently a structure ending with a flexible array member is not okay
with the compiler as the last member within another structure.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
diff --git a/configure.ac b/configure.ac
index 2d6cfad..32f4244 100644
--- a/configure.ac
+++ b/configure.ac
@@ -318,10 +318,23 @@
 AM_CONDITIONAL([THREADS_WINDOWS], [test "x$threads" = xwindows])
 AM_CONDITIONAL([USE_UDEV], [test "x$use_udev" = xyes])
 
-AM_CFLAGS="${AM_CFLAGS} -Wall -Wshadow -Wstrict-prototypes -Wundef -Wunused -Werror=implicit-function-declaration"
+EXTRA_CFLAGS=
+
+dnl The -Wcast-function-type warning causes a flurry of warnings when compiling
+dnl Windows with GCC 8 or later because of dynamically loaded functions
+if test "x$backend" = xwindows; then
+	saved_CFLAGS="${CFLAGS}"
+	CFLAGS="-Werror -Wcast-function-type"
+	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])],
+		[EXTRA_CFLAGS="-Wno-cast-function-type"],
+		[])
+	CFLAGS="${saved_CFLAGS}"
+fi
+
+AM_CFLAGS="${AM_CFLAGS} -Wall -Wextra -Wshadow -Wunused -Wwrite-strings -Werror=format-security -Werror=implicit-function-declaration -Werror=implicit-int -Werror=init-self -Werror=missing-prototypes -Werror=strict-prototypes -Werror=undef -Werror=uninitialized ${EXTRA_CFLAGS}"
 AC_SUBST(AM_CFLAGS)
 
-AM_CXXFLAGS="${AM_CFLAGS}"
+AM_CXXFLAGS="${AM_CFLAGS} -Wmissing-declarations"
 AC_SUBST(AM_CXXFLAGS)
 
 AC_SUBST(LT_LDFLAGS)