From: Daniel Elstner Date: Wed, 26 Aug 2015 19:42:32 +0000 (+0200) Subject: Build: Clean up configure.ac and Makefile.am X-Git-Tag: libserialport-0.1.1~16 X-Git-Url: https://sigrok.org/gitweb/?p=libserialport.git;a=commitdiff_plain;h=f1c916ede191ec398cbe53d7f978078311c25785 Build: Clean up configure.ac and Makefile.am Among other things, rename some config defines so we can take advantage of standard Autoconf macros. --- diff --git a/Makefile.am b/Makefile.am index 8c0276c..661960e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -19,8 +19,8 @@ ## ACLOCAL_AMFLAGS = -I autostuff - -AM_CPPFLAGS = -I$(top_srcdir) +AM_LIBTOOLFLAGS = --silent +MAKEFLAGS = --no-print-directory # Enable more compiler warnings. AM_CFLAGS = -std=c99 -Wall -Wextra -pedantic -Wmissing-prototypes -Wshadow @@ -41,18 +41,14 @@ if FREEBSD libserialport_la_SOURCES += freebsd.c endif -libserialport_la_LIBADD = $(LIBOBJS) -if WIN32 -libserialport_la_LIBADD += $(SP_LIBS) -endif +libserialport_la_LIBADD = $(SP_LIBS) -libserialport_la_LDFLAGS = $(SP_LIB_LDFLAGS) -no-undefined +libserialport_la_LDFLAGS = -version-info $(SP_LIB_VERSION) -no-undefined if MACOSX libserialport_la_LDFLAGS += -framework IOKit -framework CoreFoundation endif -library_includedir = $(includedir) -library_include_HEADERS = libserialport.h +nodist_include_HEADERS = libserialport.h pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = libserialport.pc @@ -61,11 +57,12 @@ EXTRA_DIST = Doxyfile MAINTAINERCLEANFILES = ChangeLog -.PHONY: ChangeLog +.PHONY: ChangeLog doc + ChangeLog: git --git-dir $(top_srcdir)/.git log > ChangeLog || touch ChangeLog dist-hook: ChangeLog -doc: $(library_include_HEADERS) $(top_srcdir)/Doxyfile +doc: $(nodist_include_HEADERS) $(top_srcdir)/Doxyfile doxygen $(top_srcdir)/Doxyfile diff --git a/configure.ac b/configure.ac index e569ee0..a325513 100644 --- a/configure.ac +++ b/configure.ac @@ -29,31 +29,40 @@ m4_define([sp_package_version], [sp_package_version_major.sp_package_version_min AC_INIT([libserialport], [sp_package_version], [martin-libserialport@earth.li], [libserialport], [http://sigrok.org/wiki/Libserialport]) -AC_CONFIG_HEADERS([config.h]) +AC_CONFIG_HEADERS([config.h libserialport.h]) AC_CONFIG_MACRO_DIR([autostuff]) AC_CONFIG_AUX_DIR([autostuff]) AH_TOP([#ifndef SP_CONFIG_H #define SP_CONFIG_H]) -AH_BOTTOM([#endif]) + +AH_BOTTOM([#if HAVE_STRUCT_TERMIOS_C_ISPEED && HAVE_STRUCT_TERMIOS_C_OSPEED +# define HAVE_TERMIOS_SPEED 1 +#endif +#if HAVE_STRUCT_TERMIOS2_C_ISPEED && HAVE_STRUCT_TERMIOS2_C_OSPEED +# define HAVE_TERMIOS2_SPEED 1 +#endif + +#endif]) # We require at least automake 1.11 (needed for 'silent rules'). -AM_INIT_AUTOMAKE([1.11 -Wall -Werror check-news]) -m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) +AM_INIT_AUTOMAKE([1.11 -Wall -Werror no-define check-news]) +AM_SILENT_RULES([yes]) m4_ifdef([AM_PROG_AR], [AM_PROG_AR]) # Checks for programs. AC_PROG_CC -AC_PROG_CPP AC_PROG_INSTALL AC_PROG_LN_S # Initialize libtool. LT_INIT -# Initialize pkg-config. -# We require at least 0.22, as "Requires.private" behaviour changed there. -PKG_PROG_PKG_CONFIG([0.22]) +AC_DEFINE([SP_PACKAGE_VERSION_MAJOR], [sp_package_version_major], [.]) +AC_DEFINE([SP_PACKAGE_VERSION_MINOR], [sp_package_version_minor], [.]) +AC_DEFINE([SP_PACKAGE_VERSION_MICRO], [sp_package_version_micro], [.]) +AC_DEFINE([SP_PACKAGE_VERSION_STRING], ["sp_package_version"], [.]) +AC_SUBST([SP_PACKAGE_VERSION], [sp_package_version]) # Library version for libserialport (NOT the same as the package version). # Carefully read the libtool docs before updating these numbers! @@ -62,138 +71,80 @@ PKG_PROG_PKG_CONFIG([0.22]) SP_LIB_VERSION_CURRENT=0 SP_LIB_VERSION_REVISION=0 SP_LIB_VERSION_AGE=0 -SP_LIB_VERSION="$SP_LIB_VERSION_CURRENT:$SP_LIB_VERSION_REVISION:$SP_LIB_VERSION_AGE" -SP_LIB_LDFLAGS="-version-info $SP_LIB_VERSION" -AC_SUBST(SP_LIB_VERSION_CURRENT) -AC_SUBST(SP_LIB_VERSION_REVISION) -AC_SUBST(SP_LIB_VERSION_AGE) -AC_SUBST(SP_LIB_VERSION) -AC_SUBST(SP_LIB_LDFLAGS) - -# Checks for libraries. - -SP_LIBS="" - -case $host_os in -*linux*) - AM_CONDITIONAL([LINUX], true) - AM_CONDITIONAL([WIN32], false) - AM_CONDITIONAL([MACOSX], false) - AM_CONDITIONAL([FREEBSD], false) - ;; -*darwin*) - AM_CONDITIONAL([LINUX], false) - AM_CONDITIONAL([WIN32], false) - AM_CONDITIONAL([MACOSX], true) - AM_CONDITIONAL([FREEBSD], false) - AC_CHECK_HEADER(IOKit/IOKitLib.h, [], [AC_MSG_ERROR([IOKit/IOKitLib.h not found])]) - ;; -mingw* | cygwin*) - AM_CONDITIONAL([LINUX], false) - AM_CONDITIONAL([WIN32], true) - AM_CONDITIONAL([MACOSX], false) - AM_CONDITIONAL([FREEBSD], false) - SP_LIBS="-lsetupapi" - ;; -*freebsd*) - AM_CONDITIONAL([LINUX], false) - AM_CONDITIONAL([WIN32], false) - AM_CONDITIONAL([MACOSX], false) - AM_CONDITIONAL([FREEBSD], true) - ;; -*) - AM_CONDITIONAL([LINUX], false) - AM_CONDITIONAL([WIN32], false) - AM_CONDITIONAL([MACOSX], false) - AM_CONDITIONAL([FREEBSD], false) - AC_DEFINE(NO_ENUMERATION,,[Enumeration is unsupported]) - AC_DEFINE(NO_PORT_METADATA,,[Port metadata is unavailable]) -esac - -AC_SUBST(SP_LIBS) +AC_SUBST([SP_LIB_VERSION], + ["$SP_LIB_VERSION_CURRENT:$SP_LIB_VERSION_REVISION:$SP_LIB_VERSION_AGE"]) + +AC_DEFINE_UNQUOTED([SP_LIB_VERSION_CURRENT], [$SP_LIB_VERSION_CURRENT], [.]) +AC_DEFINE_UNQUOTED([SP_LIB_VERSION_REVISION], [$SP_LIB_VERSION_REVISION], [.]) +AC_DEFINE_UNQUOTED([SP_LIB_VERSION_AGE], [$SP_LIB_VERSION_AGE], [.]) +AC_DEFINE_UNQUOTED([SP_LIB_VERSION_STRING], ["$SP_LIB_VERSION"], [.]) + +AM_CONDITIONAL([LINUX], [test -z "${host_os##linux*}"]) +AM_CONDITIONAL([WIN32], [test -z "${host_os##mingw*}" || test -z "${host_os##cygwin*}"]) +AM_CONDITIONAL([MACOSX], [test -z "${host_os##darwin*}"]) +AM_CONDITIONAL([FREEBSD], [test -z "${host_os##freebsd*}"]) + +AM_COND_IF([WIN32], [SP_LIBS='-lsetupapi'], [SP_LIBS=]) +AC_SUBST([SP_LIBS]) + +AM_COND_IF([MACOSX], [AC_CHECK_HEADER([IOKit/IOKitLib.h], [], + [AC_MSG_ERROR([IOKit/IOKitLib.h not found])])]) + +AS_CASE([$host_os], [linux*|darwin*|mingw*|cygwin*|freebsd*],, [ + AC_DEFINE([NO_ENUMERATION], [1], [Enumeration is unsupported.]) + AC_DEFINE([NO_PORT_METADATA], [1], [Port metadata is unavailable.]) +]) # Define size_t if not defined as standard. AC_TYPE_SIZE_T # Check for specific termios structures. -AC_CHECK_TYPE([struct termios2], - [AC_DEFINE(HAVE_TERMIOS2, 1, - [struct termios2 is available.])], - [], [[#include ]]) -AC_CHECK_TYPE([struct termiox], - [AC_DEFINE(HAVE_TERMIOX, 1, - [struct termiox is available.])], - [], [[#include ]]) -AC_CHECK_MEMBERS([struct termios.c_ispeed, struct termios.c_ospeed], - [AC_DEFINE(HAVE_TERMIOS_SPEED, 1, - [struct termios has c_ispeed/c_ospeed.])], - [], [[#include ]]) -AC_CHECK_MEMBERS([struct termios2.c_ispeed, struct termios2.c_ospeed], - [AC_DEFINE(HAVE_TERMIOS2_SPEED, 1, - [struct termios2 has c_ispeed/c_ospeed.])], - [], [[#include ]]) +AC_CHECK_TYPES([struct termios2, struct termiox],,, + [[#include ]]) +AC_CHECK_MEMBERS([struct termios.c_ispeed, struct termios.c_ospeed, + struct termios2.c_ispeed, struct termios2.c_ospeed],,, + [[#include ]]) # 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_MSG_CHECKING(for BOTHER) -AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ -#include -]], -[[ -#ifndef BOTHER -#error BOTHER is not defined -#endif -]])], -[AC_DEFINE(HAVE_BOTHER, 1, [BOTHER macro is available]) -AC_MSG_RESULT([yes])], [AC_MSG_RESULT([no])]) +AC_CHECK_DECLS([BOTHER],,, [[#include ]]) # Check for serial_struct. -AC_CHECK_TYPE([struct serial_struct], - [AC_DEFINE(HAVE_SERIAL_STRUCT, 1, - [struct serial is available.])], - [], [[#include ]]) - -saved="$CFLAGS"; CFLAGS="$CFLAGS -Werror" -AC_DEFINE(SP_API,,[Macro preceding public API functions]) -AC_DEFINE(SP_PRIV,,[Macro preceding private functions]) -AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ - __attribute__((visibility("hidden"))) void foo(void) { } - ]])], - [AC_DEFINE(SP_API, __attribute__((visibility("default"))))] - [AC_DEFINE(SP_PRIV, __attribute__((visibility("hidden"))))], -AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ - __declspec(dllexport) void foo(void) { } - ]])], - [AC_DEFINE(SP_API, __declspec(dllexport))] - [AC_DEFINE(SP_PRIV,)], - [AC_DEFINE(SP_API,)] - [AC_DEFINE(SP_PRIV,)])) -CFLAGS="$saved" - -AC_SUBST(MAKEFLAGS, '--no-print-directory') -AC_SUBST(AM_LIBTOOLFLAGS, '--silent') - -SP_PACKAGE_VERSION_MAJOR=sp_package_version_major -SP_PACKAGE_VERSION_MINOR=sp_package_version_minor -SP_PACKAGE_VERSION_MICRO=sp_package_version_micro -SP_PACKAGE_VERSION=sp_package_version - -AC_SUBST(SP_PACKAGE_VERSION_MAJOR) -AC_SUBST(SP_PACKAGE_VERSION_MINOR) -AC_SUBST(SP_PACKAGE_VERSION_MICRO) -AC_SUBST(SP_PACKAGE_VERSION) - -AC_CONFIG_FILES([Makefile libserialport.h libserialport.pc]) +AC_CHECK_TYPES([struct serial_struct],,, [[#include ]]) + +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]) AC_OUTPUT -echo -echo "libserialport configuration summary:" -echo -echo " - Package version (major.minor.micro): $SP_PACKAGE_VERSION" -echo " - Library version (current:revision:age): $SP_LIB_VERSION" -echo " - Prefix: $prefix" -echo " - Building on: $build" -echo " - Building for: $host" -echo +cat >&AS_MESSAGE_FD <<_EOF + +libserialport configuration summary: + + - Package version (major.minor.micro): $SP_PACKAGE_VERSION + - Library version (current:revision:age): $SP_LIB_VERSION + - Prefix: $prefix + - Building on: $build + - Building for: $host + +_EOF diff --git a/libserialport.h.in b/libserialport.h.in index b41bf99..8962ef8 100644 --- a/libserialport.h.in +++ b/libserialport.h.in @@ -1603,32 +1603,32 @@ void sp_default_debug_handler(const char *format, ...); */ /** The libserialport package 'major' version number. */ -#define SP_PACKAGE_VERSION_MAJOR @SP_PACKAGE_VERSION_MAJOR@ +#undef SP_PACKAGE_VERSION_MAJOR /** The libserialport package 'minor' version number. */ -#define SP_PACKAGE_VERSION_MINOR @SP_PACKAGE_VERSION_MINOR@ +#undef SP_PACKAGE_VERSION_MINOR /** The libserialport package 'micro' version number. */ -#define SP_PACKAGE_VERSION_MICRO @SP_PACKAGE_VERSION_MICRO@ +#undef SP_PACKAGE_VERSION_MICRO /** The libserialport package version ("major.minor.micro") as string. */ -#define SP_PACKAGE_VERSION_STRING "@SP_PACKAGE_VERSION@" +#undef SP_PACKAGE_VERSION_STRING /* * Library/libtool version macros (can be used for conditional compilation). */ /** The libserialport libtool 'current' version number. */ -#define SP_LIB_VERSION_CURRENT @SP_LIB_VERSION_CURRENT@ +#undef SP_LIB_VERSION_CURRENT /** The libserialport libtool 'revision' version number. */ -#define SP_LIB_VERSION_REVISION @SP_LIB_VERSION_REVISION@ +#undef SP_LIB_VERSION_REVISION /** The libserialport libtool 'age' version number. */ -#define SP_LIB_VERSION_AGE @SP_LIB_VERSION_AGE@ +#undef SP_LIB_VERSION_AGE /** The libserialport libtool version ("current:revision:age") as string. */ -#define SP_LIB_VERSION_STRING "@SP_LIB_VERSION@" +#undef SP_LIB_VERSION_STRING /** * Get the major libserialport package version number. diff --git a/libserialport.pc.in b/libserialport.pc.in index 73089ae..1db208b 100644 --- a/libserialport.pc.in +++ b/libserialport.pc.in @@ -7,7 +7,7 @@ Name: libserialport Description: Cross-platform serial port access library. URL: http://sigrok.org/wiki/Libserialport Requires.private: -Version: @VERSION@ +Version: @SP_PACKAGE_VERSION@ Libs: -L${libdir} -lserialport Libs.private: @SP_LIBS@ Cflags: -I${includedir} diff --git a/libserialport_internal.h b/libserialport_internal.h index 6a682cb..5db81e5 100644 --- a/libserialport_internal.h +++ b/libserialport_internal.h @@ -21,7 +21,7 @@ #ifndef LIBSERIALPORT_LIBSERIALPORT_INTERNAL_H #define LIBSERIALPORT_LIBSERIALPORT_INTERNAL_H -#include "config.h" +#include #ifdef __linux__ #define _BSD_SOURCE /* For timeradd, timersub, timercmp. */ @@ -69,7 +69,7 @@ #include "linux_termios.h" /* TCGETX/TCSETX is not available everywhere. */ -#if defined(TCGETX) && defined(TCSETX) && defined(HAVE_TERMIOX) +#if defined(TCGETX) && defined(TCSETX) && defined(HAVE_STRUCT_TERMIOX) #define USE_TERMIOX #endif #endif @@ -83,7 +83,7 @@ #endif /* Non-standard baudrates are not available everywhere. */ -#if (defined(HAVE_TERMIOS_SPEED) || defined(HAVE_TERMIOS2_SPEED)) && defined(HAVE_BOTHER) +#if (defined(HAVE_TERMIOS_SPEED) || defined(HAVE_TERMIOS2_SPEED)) && defined(HAVE_DECL_BOTHER) #define USE_TERMIOS_SPEED #endif diff --git a/linux.c b/linux.c index fd746dc..1531f92 100644 --- a/linux.c +++ b/linux.c @@ -178,7 +178,7 @@ SP_PRIV enum sp_return list_ports(struct sp_port ***list) { char name[PATH_MAX], target[PATH_MAX]; struct dirent entry, *result; -#ifdef HAVE_SERIAL_STRUCT +#ifdef HAVE_STRUCT_SERIAL_STRUCT struct serial_struct serial_info; int ioctl_result; #endif @@ -218,11 +218,11 @@ SP_PRIV enum sp_return list_ports(struct sp_port ***list) DEBUG("Open failed, skipping"); continue; } -#ifdef HAVE_SERIAL_STRUCT +#ifdef HAVE_STRUCT_SERIAL_STRUCT ioctl_result = ioctl(fd, TIOCGSERIAL, &serial_info); #endif close(fd); -#ifdef HAVE_SERIAL_STRUCT +#ifdef HAVE_STRUCT_SERIAL_STRUCT if (ioctl_result != 0) { DEBUG("ioctl failed, skipping"); continue; diff --git a/linux_termios.c b/linux_termios.c index 92793df..e23d187 100644 --- a/linux_termios.c +++ b/linux_termios.c @@ -39,7 +39,7 @@ SP_PRIV unsigned long get_termios_get_ioctl(void) { -#ifdef HAVE_TERMIOS2 +#ifdef HAVE_STRUCT_TERMIOS2 return TCGETS2; #else return TCGETS; @@ -48,7 +48,7 @@ SP_PRIV unsigned long get_termios_get_ioctl(void) SP_PRIV unsigned long get_termios_set_ioctl(void) { -#ifdef HAVE_TERMIOS2 +#ifdef HAVE_STRUCT_TERMIOS2 return TCSETS2; #else return TCSETS; @@ -57,17 +57,17 @@ SP_PRIV unsigned long get_termios_set_ioctl(void) SP_PRIV size_t get_termios_size(void) { -#ifdef HAVE_TERMIOS2 +#ifdef HAVE_STRUCT_TERMIOS2 return sizeof(struct termios2); #else return sizeof(struct termios); #endif } -#if (defined(HAVE_TERMIOS_SPEED) || defined(HAVE_TERMIOS2_SPEED)) && defined(HAVE_BOTHER) +#if (defined(HAVE_TERMIOS_SPEED) || defined(HAVE_TERMIOS2_SPEED)) && defined(HAVE_DECL_BOTHER) SP_PRIV int get_termios_speed(void *data) { -#ifdef HAVE_TERMIOS2 +#ifdef HAVE_STRUCT_TERMIOS2 struct termios2 *term = (struct termios2 *) data; #else struct termios *term = (struct termios *) data; @@ -80,7 +80,7 @@ SP_PRIV int get_termios_speed(void *data) SP_PRIV void set_termios_speed(void *data, int speed) { -#ifdef HAVE_TERMIOS2 +#ifdef HAVE_STRUCT_TERMIOS2 struct termios2 *term = (struct termios2 *) data; #else struct termios *term = (struct termios *) data; @@ -91,7 +91,7 @@ SP_PRIV void set_termios_speed(void *data, int speed) } #endif -#ifdef HAVE_TERMIOX +#ifdef HAVE_STRUCT_TERMIOX SP_PRIV size_t get_termiox_size(void) { return sizeof(struct termiox);