aboutsummaryrefslogtreecommitdiff
path: root/configure.ac
blob: 761cdc623520436329678e796a9b75109b50cd20 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# SPDX-License-Identifier: LGPL-2.1-or-later

#
# This file is part of libgpiod.
#
# Copyright (C) 2017-2018 Bartosz Golaszewski <bartekgola@gmail.com>
#

AC_PREREQ(2.61)

AC_INIT([libgpiod], 1.2)
AC_SUBST(EXTRA_VERSION, [.devel])

AC_DEFINE_UNQUOTED([GPIOD_VERSION_STR],
			["$PACKAGE_VERSION$EXTRA_VERSION"],
			[Full library version string.])
AC_SUBST(VERSION_STR, [$PACKAGE_VERSION$EXTRA_VERSION])

# From the libtool manual:
#
# (...)
# 3. If the library source code has changed at all since the last update, then
#    increment revision ('c:r:a' becomes 'c:r+1:a').
# 4. If any interfaces have been added, removed, or changed since the last
#    update, increment current, and set revision to 0.
# 5. If any interfaces have been added since the last public release, then
#    increment age.
# 6. If any interfaces have been removed or changed since the last public
#    release, then set age to 0.
#
# Define the libtool version as (C.R.A):
# NOTE: this version only applies to the core C library.
AC_SUBST(ABI_VERSION, [2.0.0])
# Have a separate ABI version for C++ bindings:
AC_SUBST(ABI_CXX_VERSION, [1.0.0])

AC_CONFIG_AUX_DIR([autostuff])
AC_CONFIG_MACRO_DIRS([m4])
AM_INIT_AUTOMAKE([foreign subdir-objects])

m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
m4_pattern_forbid([^AX_],
	[Unexpanded AX_ macro found. Please install GNU autoconf-archive.])

AC_ARG_VAR([PYTHON_CPPFLAGS],
	[Compiler flags to find Python headers [default: auto-detect]])
AC_ARG_VAR([PYTHON_LIBS],
	[Libraries to link into Python extensions [default: auto-detect]])

AC_CONFIG_SRCDIR([src])
AC_CONFIG_HEADER([config.h])

AC_DEFINE([_GNU_SOURCE], [], [We want GNU extensions])

# Silence warning: ar: 'u' modifier ignored since 'D' is the default
AC_SUBST(AR_FLAGS, [cr])

AM_PROG_AR
AC_PROG_CC
AC_PROG_CXX
AC_PROG_LIBTOOL
AC_PROG_INSTALL

AC_DEFUN([ERR_NOT_FOUND],
	[AC_MSG_ERROR([$1 not found (needed to build $2)], [1])])

AC_DEFUN([FUNC_NOT_FOUND_LIB],
	[ERR_NOT_FOUND([$1()], [the library])])

AC_DEFUN([HEADER_NOT_FOUND_LIB],
	[ERR_NOT_FOUND([$1 header], [the library])])

# This is always checked (library needs this)
AC_HEADER_STDC
AC_FUNC_MALLOC
AC_CHECK_FUNC([ioctl], [], [FUNC_NOT_FOUND_LIB([ioctl])])
AC_CHECK_FUNC([asprintf], [], [FUNC_NOT_FOUND_LIB([asprintf])])
AC_CHECK_FUNC([scandir], [], [FUNC_NOT_FOUND_LIB([scandir])])
AC_CHECK_FUNC([alphasort], [], [FUNC_NOT_FOUND_LIB([alphasort])])
AC_CHECK_FUNC([ppoll], [], [FUNC_NOT_FOUND_LIB([ppoll])])
AC_CHECK_HEADERS([getopt.h], [], [HEADER_NOT_FOUND_LIB([getopt.h])])
AC_CHECK_HEADERS([dirent.h], [], [HEADER_NOT_FOUND_LIB([dirent.h])])
AC_CHECK_HEADERS([sys/poll.h], [], [HEADER_NOT_FOUND_LIB([sys/poll.h])])
AC_CHECK_HEADERS([sys/sysmacros.h], [], [HEADER_NOT_FOUND_LIB([sys/sysmacros.h])])
AC_CHECK_HEADERS([linux/gpio.h], [], [HEADER_NOT_FOUND_LIB([linux/gpio.h])])

AC_ARG_ENABLE([tools],
	[AC_HELP_STRING([--enable-tools],
		[enable libgpiod command-line tools [default=no]])],
	[
		if test "x$enableval" = xyes
		then
			with_tools=true
		else
			with_tools=false
		fi
	],
	[with_tools=false])
AM_CONDITIONAL([WITH_TOOLS], [test "x$with_tools" = xtrue])

AC_DEFUN([FUNC_NOT_FOUND_TOOLS],
	[ERR_NOT_FOUND([$1()], [tools])])

AC_DEFUN([HEADER_NOT_FOUND_TOOLS],
	[ERR_NOT_FOUND([$1 header], [tools])])

if test "x$with_tools" = xtrue
then
	# These are only needed to build tools
	AC_CHECK_FUNC([basename], [], [FUNC_NOT_FOUND_TOOLS([basename])])
	AC_CHECK_FUNC([daemon], [], [FUNC_NOT_FOUND_TOOLS([daemon])])
	AC_CHECK_FUNC([signalfd], [], [FUNC_NOT_FOUND_TOOLS([signalfd])])
	AC_CHECK_HEADERS([sys/signalfd.h], [], [HEADER_NOT_FOUND_TOOLS([sys/signalfd.h])])
fi

AC_ARG_ENABLE([tests],
	[AC_HELP_STRING([--enable-tests],
		[enable libgpiod tests [default=no]])],
	[
		if test "x$enableval" = xyes
		then
			with_tests=true
		else
			with_tests=false
		fi
	],
	[with_tests=false])
AM_CONDITIONAL([WITH_TESTS], [test "x$with_tests" = xtrue])

AC_DEFUN([FUNC_NOT_FOUND_TESTS],
	[ERR_NOT_FOUND([$1()], [tests])])

if test "x$with_tests" = xtrue
then
	AC_CHECK_FUNC([qsort], [], [FUNC_NOT_FOUND_TESTS([qsort])])
	AC_CHECK_FUNC([regexec], [], [FUNC_NOT_FOUND_TESTS([regexec])])

	PKG_CHECK_MODULES([KMOD], [libkmod >= 18])
	PKG_CHECK_MODULES([UDEV], [libudev >= 215])
fi

AC_ARG_ENABLE([bindings-cxx],
	[AC_HELP_STRING([--enable-bindings-cxx],
		[enable C++ bindings [default=no]])],
	[
		if test "x$enableval" = xyes
		then
			with_bindings_cxx=true
		else
			with_bindings_cxx=false
		fi
	],
	[with_bindings_cxx=false])
AM_CONDITIONAL([WITH_BINDINGS_CXX], [test "x$with_bindings_cxx" = xtrue])

if test "x$with_bindings_cxx" = xtrue
then
	AC_LIBTOOL_CXX
	# This needs autoconf-archive
	AX_CXX_COMPILE_STDCXX_11([ext], [mandatory])
fi

AC_ARG_ENABLE([bindings-python],
	[AC_HELP_STRING([--enable-bindings-python],
		[enable python3 bindings [default=no]])],
	[
		if test "x$enableval" = xyes
		then
			with_bindings_python=true
		else
			with_bindings_python=false
		fi
	],
	[with_bindings_python=false])
AM_CONDITIONAL([WITH_BINDINGS_PYTHON], [test "x$with_bindings_python" = xtrue])

if test "x$with_bindings_python" = xtrue
then
	AM_PATH_PYTHON([3.0], [],
		[AC_MSG_ERROR([python3 not found - needed for python bindings])])
	AS_IF([test -z "$PYTHON_CPPFLAGS"],
		[AC_SUBST(PYTHON_CPPFLAGS, [`$PYTHON-config --includes`])])
	AS_IF([test -z "$PYTHON_LIBS"],
		[AC_SUBST(PYTHON_LIBS, [`$PYTHON-config --libs`])])
fi

AC_CHECK_PROG([has_doxygen], [doxygen], [true], [false])
AM_CONDITIONAL([HAS_DOXYGEN], [test "x$has_doxygen" = xtrue])
if test "x$has_doxygen" = xfalse
then
	AC_MSG_NOTICE([doxygen not found - documentation cannot be generated])
fi

AC_CONFIG_FILES([libgpiod.pc
		 Makefile
		 include/Makefile
		 src/Makefile
		 src/lib/Makefile
		 src/tools/Makefile
		 tests/Makefile
		 bindings/cxx/libgpiodcxx.pc
		 bindings/Makefile
		 bindings/cxx/Makefile
		 bindings/cxx/examples/Makefile
		 bindings/python/Makefile
		 bindings/python/examples/Makefile])

AC_OUTPUT