From: Martin Ling Date: Sat, 2 Nov 2013 19:14:36 +0000 (+0000) Subject: Fix building on OSX and Linux. X-Git-Tag: libserialport-0.1.0~155 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=1ebf4347e087d10ea7f9bd916c8bdc426ffd4b5e;p=libserialport.git Fix building on OSX and Linux. --- diff --git a/configure.ac b/configure.ac index a12de6d..31e54bb 100644 --- a/configure.ac +++ b/configure.ac @@ -31,6 +31,8 @@ AC_INIT([libserialport], [sp_package_version], [martin-libserialport@earth.li], AC_CONFIG_MACRO_DIR([autostuff]) AC_CONFIG_AUX_DIR([autostuff]) +AC_CANONICAL_TARGET + # We require at least automake 1.11 (needed for 'silent rules'). AM_INIT_AUTOMAKE([1.11 -Wall -Werror]) m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) @@ -77,6 +79,18 @@ AC_SUBST(SP_LIB_LDFLAGS) # These are already checked: inttypes.h stdint.h stdlib.h string.h unistd.h. AC_CHECK_HEADERS([sys/types.h sys/stat.h fcntl.h termios.h sys/ioctl.h errno.h]) +case $target_os in +*linux*) + PKG_CHECK_MODULES([libudev], [libudev >= 0], + [CFLAGS="$CFLAGS $libudev_CFLAGS"; LIBS="$LIBS $libudev_LIBS"], + [AC_MSG_ERROR([libudev.h not found])]) + ;; +*darwin*) + LDFLAGS="$LDFLAGS -Wl,-framework -Wl,IOKit -Wl,-framework -Wl,CoreFoundation" + AC_CHECK_HEADER(IOKit/IOKitLib.h, [], [AC_MSG_ERROR([IOKit/IOKitLib.h not found])]) + ;; +esac + # Checks for typedefs, structures, and compiler characteristics. AC_C_INLINE AC_TYPE_SIZE_T diff --git a/serialport.c b/serialport.c index 20a4afb..e8de069 100644 --- a/serialport.c +++ b/serialport.c @@ -34,8 +34,9 @@ #include #endif #ifdef __APPLE__ -#include -#include +#include +#include +#include #endif #ifdef __linux__ #include "libudev.h" @@ -148,7 +149,7 @@ out_close: if (!(list = sp_list_new())) goto out; - while (port = IOIteratorNext(iter)) { + while ((port = IOIteratorNext(iter))) { cf_path = IORegistryEntryCreateCFProperty(port, CFSTR(kIOCalloutDeviceKey), kCFAllocatorDefault, 0); if (cf_path) {