-AC_CHECK_TYPE([struct termios2], [AC_DEFINE(HAVE_TERMIOS2, 1)], [], [[#include <linux/termios.h>]])
-AC_CHECK_TYPE([struct termiox], [AC_DEFINE(HAVE_TERMIOX, 1)], [], [[#include <linux/termios.h>]])
-AC_CHECK_MEMBERS([struct termios.c_ispeed, struct termios.c_ospeed],
- [AC_DEFINE(HAVE_TERMIOS_SPEED, 1)], [], [[#include <linux/termios.h>]])
-AC_CHECK_MEMBERS([struct termios2.c_ispeed, struct termios2.c_ospeed],
- [AC_DEFINE(HAVE_TERMIOS2_SPEED, 1)], [], [[#include <linux/termios.h>]])
-
-AC_SUBST(MAKEFLAGS, '--no-print-directory')
-AC_SUBST(AM_LIBTOOLFLAGS, '--silent')
+AC_CHECK_TYPES([struct termios2, struct termiox],,,
+ [[#include <linux/termios.h>]])
+AC_CHECK_MEMBERS([struct termios.c_ispeed, struct termios.c_ospeed,
+ struct termios2.c_ispeed, struct termios2.c_ospeed],,,
+ [[#include <linux/termios.h>]])
+
+# Check for the BOTHER definition, needed for setting arbitrary baud rates.
+# We can't just #ifdef BOTHER in the code, because of the separation between
+# code using libc headers and code using kernel termios.h headers.
+AC_CHECK_DECLS([BOTHER],,, [[#include <linux/termios.h>]])
+
+# Check for serial_struct.
+AC_CHECK_TYPES([struct serial_struct],,, [[#include <linux/serial.h>]])
+
+AC_CACHE_CHECK([for visibility control], [sp_cv_visibility_control], [
+ sp_saved_CFLAGS=$CFLAGS
+ CFLAGS="$CFLAGS -Werror"
+ AC_COMPILE_IFELSE([AC_LANG_SOURCE(
+ [[__attribute__((visibility("hidden"))) void foo(void) {}]])],
+ [sp_cv_visibility_control=attribute],
+ [AC_COMPILE_IFELSE([AC_LANG_SOURCE(
+ [[__declspec(dllexport) void foo(void) {}]])],
+ [sp_cv_visibility_control=declspec],
+ [sp_cv_visibility_control=none])])
+ CFLAGS=$sp_saved_CFLAGS
+])
+AS_CASE([$sp_cv_visibility_control],
+ [attribute], [SP_API='__attribute__((visibility("default")))'
+ SP_PRIV='__attribute__((visibility("hidden")))'],
+ [declspec], [SP_API='__declspec(dllexport)' SP_PRIV=],
+ [SP_API= SP_PRIV=])
+AC_DEFINE_UNQUOTED([SP_API], [$SP_API], [Macro preceding public API functions])
+AC_DEFINE_UNQUOTED([SP_PRIV], [$SP_PRIV], [Macro preceding private functions])
+
+AC_CONFIG_FILES([Makefile libserialport.pc])