]> sigrok.org Git - libserialport.git/blob - configure.ac
Fix a potential segfault in sp_get_port_handle().
[libserialport.git] / configure.ac
1 ##
2 ## This file is part of the libserialport project.
3 ##
4 ## Copyright (C) 2010-2012 Bert Vermeulen <bert@biot.com>
5 ## Copyright (C) 2013 Martin Ling <martin-libserialport@earth.li>
6 ##
7 ## This program is free software: you can redistribute it and/or modify
8 ## it under the terms of the GNU Lesser General Public License as
9 ## published by the Free Software Foundation, either version 3 of the
10 ## License, or (at your option) any later version.
11 ##
12 ## This program is distributed in the hope that it will be useful,
13 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 ## GNU General Public License for more details.
16 ##
17 ## You should have received a copy of the GNU Lesser General Public License
18 ## along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 ##
20
21 # We require at least autoconf 2.63 (AC_INIT format changed there).
22 AC_PREREQ([2.63])
23
24 # libserialport package version number (NOT the same as shared lib version!).
25 m4_define([sp_package_version_major], [0])
26 m4_define([sp_package_version_minor], [1])
27 m4_define([sp_package_version_micro], [1])
28 m4_define([sp_package_version], [sp_package_version_major.sp_package_version_minor.sp_package_version_micro])
29
30 AC_INIT([libserialport], [sp_package_version], [martin-libserialport@earth.li],
31         [libserialport], [http://sigrok.org/wiki/Libserialport])
32 AC_CONFIG_HEADERS([config.h])
33 AC_CONFIG_MACRO_DIR([autostuff])
34 AC_CONFIG_AUX_DIR([autostuff])
35
36 AH_TOP([#ifndef SP_CONFIG_H
37 #define SP_CONFIG_H])
38 AH_BOTTOM([#endif])
39
40 # We require at least automake 1.11 (needed for 'silent rules').
41 AM_INIT_AUTOMAKE([1.11 -Wall -Werror check-news])
42 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
43 m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
44
45 # Checks for programs.
46 AC_PROG_CC
47 AC_PROG_CPP
48 AC_PROG_INSTALL
49 AC_PROG_LN_S
50
51 # Initialize libtool.
52 LT_INIT
53
54 # Initialize pkg-config.
55 # We require at least 0.22, as "Requires.private" behaviour changed there.
56 PKG_PROG_PKG_CONFIG([0.22])
57
58 # Library version for libserialport (NOT the same as the package version).
59 # Carefully read the libtool docs before updating these numbers!
60 # The algorithm for determining which number to change (and how) is nontrivial!
61 # http://www.gnu.org/software/libtool/manual/libtool.html#Updating-version-info
62 SP_LIB_VERSION_CURRENT=0
63 SP_LIB_VERSION_REVISION=0
64 SP_LIB_VERSION_AGE=0
65 SP_LIB_VERSION="$SP_LIB_VERSION_CURRENT:$SP_LIB_VERSION_REVISION:$SP_LIB_VERSION_AGE"
66 SP_LIB_LDFLAGS="-version-info $SP_LIB_VERSION"
67 AC_SUBST(SP_LIB_VERSION_CURRENT)
68 AC_SUBST(SP_LIB_VERSION_REVISION)
69 AC_SUBST(SP_LIB_VERSION_AGE)
70 AC_SUBST(SP_LIB_VERSION)
71 AC_SUBST(SP_LIB_LDFLAGS)
72
73 # Checks for libraries.
74
75 SP_LIBS=""
76
77 case $host_os in
78 *linux*)
79         AM_CONDITIONAL([LINUX], true)
80         AM_CONDITIONAL([WIN32], false)
81         AM_CONDITIONAL([MACOSX], false)
82         AM_CONDITIONAL([FREEBSD], false)
83         ;;
84 *darwin*)
85         AM_CONDITIONAL([LINUX], false)
86         AM_CONDITIONAL([WIN32], false)
87         AM_CONDITIONAL([MACOSX], true)
88         AM_CONDITIONAL([FREEBSD], false)
89         AC_CHECK_HEADER(IOKit/IOKitLib.h, [], [AC_MSG_ERROR([IOKit/IOKitLib.h not found])])
90         ;;
91 mingw* | cygwin*)
92         AM_CONDITIONAL([LINUX], false)
93         AM_CONDITIONAL([WIN32], true)
94         AM_CONDITIONAL([MACOSX], false)
95         AM_CONDITIONAL([FREEBSD], false)
96         SP_LIBS="-lsetupapi"
97         ;;
98 *freebsd*)
99         AM_CONDITIONAL([LINUX], false)
100         AM_CONDITIONAL([WIN32], false)
101         AM_CONDITIONAL([MACOSX], false)
102         AM_CONDITIONAL([FREEBSD], true)
103         ;;
104 *)
105         AM_CONDITIONAL([LINUX], false)
106         AM_CONDITIONAL([WIN32], false)
107         AM_CONDITIONAL([MACOSX], false)
108         AM_CONDITIONAL([FREEBSD], false)
109         AC_DEFINE(NO_ENUMERATION,,[Enumeration is unsupported])
110         AC_DEFINE(NO_PORT_METADATA,,[Port metadata is unavailable])
111 esac
112
113 AC_SUBST(SP_LIBS)
114
115 # Define size_t if not defined as standard.
116 AC_TYPE_SIZE_T
117
118 # Check for specific termios structures.
119 AC_CHECK_TYPE([struct termios2],
120         [AC_DEFINE(HAVE_TERMIOS2, 1,
121                 [struct termios2 is available.])],
122         [], [[#include <linux/termios.h>]])
123 AC_CHECK_TYPE([struct termiox],
124         [AC_DEFINE(HAVE_TERMIOX, 1,
125                 [struct termiox is available.])],
126         [], [[#include <linux/termios.h>]])
127 AC_CHECK_MEMBERS([struct termios.c_ispeed, struct termios.c_ospeed],
128         [AC_DEFINE(HAVE_TERMIOS_SPEED, 1,
129                 [struct termios has c_ispeed/c_ospeed.])],
130         [], [[#include <linux/termios.h>]])
131 AC_CHECK_MEMBERS([struct termios2.c_ispeed, struct termios2.c_ospeed],
132         [AC_DEFINE(HAVE_TERMIOS2_SPEED, 1,
133                 [struct termios2 has c_ispeed/c_ospeed.])],
134         [], [[#include <linux/termios.h>]])
135
136 # Check for the BOTHER definition, needed for setting arbitrary baud rates.
137 # We can't just #ifdef BOTHER in the code, because of the separation between
138 # code using libc headers and code using kernel termios.h headers.
139 AC_MSG_CHECKING(for BOTHER)
140 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
141 #include <linux/termios.h>
142 ]],
143 [[
144 #ifndef BOTHER
145 #error BOTHER is not defined
146 #endif
147 ]])],
148 [AC_DEFINE(HAVE_BOTHER, 1, [BOTHER macro is available])
149 AC_MSG_RESULT([yes])], [AC_MSG_RESULT([no])])
150
151 # Check for serial_struct.
152 AC_CHECK_TYPE([struct serial_struct],
153         [AC_DEFINE(HAVE_SERIAL_STRUCT, 1,
154                 [struct serial is available.])],
155         [], [[#include <linux/serial.h>]])
156
157 saved="$CFLAGS"; CFLAGS="$CFLAGS -Werror"
158 AC_DEFINE(SP_API,,[Macro preceding public API functions])
159 AC_DEFINE(SP_PRIV,,[Macro preceding private functions])
160 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
161                 __attribute__((visibility("hidden"))) void foo(void) { }
162         ]])],
163         [AC_DEFINE(SP_API, __attribute__((visibility("default"))))]
164         [AC_DEFINE(SP_PRIV, __attribute__((visibility("hidden"))))],
165 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
166                 __declspec(dllexport) void foo(void) { }
167         ]])],
168         [AC_DEFINE(SP_API, __declspec(dllexport))]
169         [AC_DEFINE(SP_PRIV,)],
170         [AC_DEFINE(SP_API,)]
171         [AC_DEFINE(SP_PRIV,)]))
172 CFLAGS="$saved"
173
174 AC_SUBST(MAKEFLAGS, '--no-print-directory')
175 AC_SUBST(AM_LIBTOOLFLAGS, '--silent')
176
177 SP_PACKAGE_VERSION_MAJOR=sp_package_version_major
178 SP_PACKAGE_VERSION_MINOR=sp_package_version_minor
179 SP_PACKAGE_VERSION_MICRO=sp_package_version_micro
180 SP_PACKAGE_VERSION=sp_package_version
181
182 AC_SUBST(SP_PACKAGE_VERSION_MAJOR)
183 AC_SUBST(SP_PACKAGE_VERSION_MINOR)
184 AC_SUBST(SP_PACKAGE_VERSION_MICRO)
185 AC_SUBST(SP_PACKAGE_VERSION)
186
187 AC_CONFIG_FILES([Makefile libserialport.h libserialport.pc])
188
189 AC_OUTPUT
190
191 echo
192 echo "libserialport configuration summary:"
193 echo
194 echo "  - Package version (major.minor.micro):    $SP_PACKAGE_VERSION"
195 echo "  - Library version (current:revision:age): $SP_LIB_VERSION"
196 echo "  - Prefix: $prefix"
197 echo "  - Building on: $build"
198 echo "  - Building for: $host"
199 echo