1
0
mirror of git://sigrok.org/libserialport synced 2023-08-10 21:13:24 +03:00

Build: Clean up configure.ac and Makefile.am

Among other things, rename some config defines so we can take
advantage of standard Autoconf macros.
This commit is contained in:
Daniel Elstner 2015-08-26 21:42:32 +02:00
parent ef08a6d52b
commit f1c916ede1
7 changed files with 104 additions and 156 deletions

View File

@ -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

View File

@ -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)
AC_SUBST([SP_LIB_VERSION],
["$SP_LIB_VERSION_CURRENT:$SP_LIB_VERSION_REVISION:$SP_LIB_VERSION_AGE"])
# Checks for libraries.
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"], [.])
SP_LIBS=""
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*}"])
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
AM_COND_IF([WIN32], [SP_LIBS='-lsetupapi'], [SP_LIBS=])
AC_SUBST([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 <linux/termios.h>]])
AC_CHECK_TYPE([struct termiox],
[AC_DEFINE(HAVE_TERMIOX, 1,
[struct termiox is available.])],
[], [[#include <linux/termios.h>]])
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 <linux/termios.h>]])
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 <linux/termios.h>]])
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_MSG_CHECKING(for BOTHER)
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <linux/termios.h>
]],
[[
#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 <linux/termios.h>]])
# Check for serial_struct.
AC_CHECK_TYPE([struct serial_struct],
[AC_DEFINE(HAVE_SERIAL_STRUCT, 1,
[struct serial is available.])],
[], [[#include <linux/serial.h>]])
AC_CHECK_TYPES([struct serial_struct],,, [[#include <linux/serial.h>]])
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_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_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_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

View File

@ -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.

View File

@ -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}

View File

@ -21,7 +21,7 @@
#ifndef LIBSERIALPORT_LIBSERIALPORT_INTERNAL_H
#define LIBSERIALPORT_LIBSERIALPORT_INTERNAL_H
#include "config.h"
#include <config.h>
#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

View File

@ -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;

View File

@ -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);