File: configure.ac

package info (click to toggle)
libusb-1.0 2%3A1.0.24-3
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 4,076 kB
  • sloc: ansic: 21,739; sh: 4,176; cpp: 1,200; makefile: 167
file content (385 lines) | stat: -rw-r--r-- 14,033 bytes parent folder | download
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
dnl These m4 macros are whitespace sensitive and break if moved around much.
m4_define([LU_VERSION_H], m4_include([libusb/version.h]))
m4_define([LU_DEFINE_VERSION_ATOM],
	[m4_define([$1], m4_bregexp(LU_VERSION_H,
	[^#define\s*$1\s*\([0-9]*\).*], [\1]))])
m4_define([LU_DEFINE_VERSION_RC_ATOM],
	[m4_define([$1], m4_bregexp(LU_VERSION_H,
	[^#define\s*$1\s*"\(-rc[0-9]*\)".*], [\1]))])
dnl The m4_bregexp() returns (only) the numbers following the #define named
dnl in the first macro parameter. m4_define() then defines the name for use
dnl in AC_INIT.

LU_DEFINE_VERSION_ATOM([LIBUSB_MAJOR])
LU_DEFINE_VERSION_ATOM([LIBUSB_MINOR])
LU_DEFINE_VERSION_ATOM([LIBUSB_MICRO])
LU_DEFINE_VERSION_RC_ATOM([LIBUSB_RC])

AC_PREREQ([2.69])
AC_INIT([libusb-1.0], [LIBUSB_MAJOR[.]LIBUSB_MINOR[.]LIBUSB_MICRO[]LIBUSB_RC], [libusb-devel@lists.sourceforge.net], [libusb-1.0], [http://libusb.info])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_SRCDIR([libusb/core.c])
AC_CONFIG_MACRO_DIR([m4])
AC_PROG_CC
AC_PROG_CXX
AC_C_INLINE
AM_INIT_AUTOMAKE
LT_INIT
LT_LANG([Windows Resource])

dnl Library versioning
dnl These numbers should be tweaked on every release. Read carefully:
dnl http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
dnl http://sourceware.org/autobook/autobook/autobook_91.html
lt_current=3
lt_revision=0
lt_age=3
LT_LDFLAGS="-version-info ${lt_current}:${lt_revision}:${lt_age} -no-undefined"

m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])

EXTRA_CPPFLAGS=
EXTRA_CFLAGS=

dnl check for -std=gnu11 compiler support (optional)
dnl note that we don't just check if the compiler accepts '-std=x11'
dnl but also that it supports the _Thread_local keyword because some compilers
dnl (e.g. gcc 4.8) accept the command line option but do not implement TLS
saved_CFLAGS="${CFLAGS}"
CFLAGS="-std=gnu11"
AC_MSG_CHECKING([if $CC supports -std=gnu11])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([_Thread_local int x;], [x = 42;])],
	[AC_MSG_RESULT([yes])
	 c_dialect=gnu],
	[AC_MSG_RESULT([no])
	 c_dialect=])
if test "x$c_dialect" != xgnu; then
	dnl fallback check for -std=c11 compiler support (required)
	CFLAGS="-std=c11"
	AC_MSG_CHECKING([if $CC supports -std=c11])
	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([_Thread_local int x;], [x = 42;])],
		[AC_MSG_RESULT([yes])],
		[AC_MSG_RESULT([no])
		 AC_MSG_ERROR([compiler with C11 support is required to build libusb])])
	c_dialect=c
fi
CFLAGS="${saved_CFLAGS}"

AC_DEFINE([_GNU_SOURCE], [1], [Enable GNU extensions.])
AC_DEFINE([DEFAULT_VISIBILITY], [__attribute__ ((visibility ("default")))], [Define to the attribute for default visibility.])
AC_DEFINE([PRINTF_FORMAT(a, b)], [__attribute__ ((__format__ (__printf__, a, b)))], [Define to the attribute for enabling parameter checks on printf-like functions.])

create_import_lib=
is_android_linux=
AC_MSG_CHECKING([operating system])
case $host in
*-darwin*)
	AC_MSG_RESULT([Darwin/Mac OS X])
	backend=darwin
	platform=posix
	;;
*-haiku*)
	AC_MSG_RESULT([Haiku])
	backend=haiku
	platform=posix
	;;
*-linux* | *-uclinux*)
	dnl on Android Linux, some functions are in different places
	case $host in
	*-linux-android*)
		AC_MSG_RESULT([Android Linux])
		is_android_linux=yes
		;;
	*)
		AC_MSG_RESULT([Linux])
		;;
	esac
	backend=linux
	platform=posix
	;;
*-netbsd*)
	AC_MSG_RESULT([NetBSD])
	backend=netbsd
	platform=posix
	;;
*-openbsd*)
	AC_MSG_RESULT([OpenBSD])
	backend=openbsd
	platform=posix
	;;
*-solaris*)
	AC_MSG_RESULT([SunOS])
	backend=sunos
	platform=posix
	;;
*-cygwin*)
	AC_MSG_RESULT([Windows (using Cygwin)])
	backend=windows
	platform=windows
	EXTRA_CFLAGS="-mwin32"
	;;
*-mingw* | *msys*)
	AC_MSG_RESULT([Windows])
	backend=windows
	platform=windows
	test "x$enable_shared" = xyes && create_import_lib=yes
	EXTRA_CFLAGS="-mwin32 -fno-omit-frame-pointer"
	;;
*)
	AC_MSG_RESULT([Null])
	AC_MSG_WARN([The host being compiled for is not supported.])
	AC_MSG_WARN([The library may compile but will not function in any useful manner.])
	backend=null
	platform=posix
	;;
esac

if test "x$platform" = xposix; then
	AC_DEFINE([PLATFORM_POSIX], [1], [Define to 1 if compiling for a POSIX platform.])
	AC_CHECK_TYPES([nfds_t], [], [], [[#include <poll.h>]])
	AC_CHECK_FUNCS([pipe2])
	dnl Some compilers do not support the '-pthread' option so check for it here
	saved_CFLAGS="${CFLAGS}"
	CFLAGS="-Wall -Werror -pthread"
	AC_MSG_CHECKING([if $CC recognizes -pthread])
	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])],
		[AC_MSG_RESULT([yes])
		 AC_SUBST(THREAD_CFLAGS, [-pthread])],
		[AC_MSG_RESULT([no])])
	CFLAGS="${saved_CFLAGS}"
	dnl Android Linux and Darwin provide pthread functions directly in libc
	dnl glibc also provides some pthread functions directly, so search for a thread-specific function
	AC_SEARCH_LIBS([pthread_create], [pthread],
		[test "x$ac_cv_search_pthread_create" != "xnone required" && AC_SUBST(THREAD_LIBS, [-lpthread])],
		[], [])
elif test "x$platform" = xwindows; then
	AC_DEFINE([PLATFORM_WINDOWS], [1], [Define to 1 if compiling for a Windows platform.])
else
	AC_MSG_ERROR([Unknown platform])
fi

case $backend in
darwin)
	AC_CHECK_FUNCS([pthread_threadid_np])
	LIBS="${LIBS} -lobjc -Wl,-framework,IOKit -Wl,-framework,CoreFoundation"
	;;
haiku)
	LIBS="${LIBS} -lbe"
	;;
linux)
	AC_SEARCH_LIBS([clock_gettime], [rt], [], [], [])
	AC_CHECK_FUNCS([pthread_setname_np])
	AC_ARG_ENABLE([udev],
		[AC_HELP_STRING([--enable-udev], [use udev for device enumeration and hotplug support (recommended) [default=yes]])],
		[use_udev=$enableval], [use_udev=yes])
	if test "x$use_udev" = xyes; then
		dnl system has udev. use it or fail!
		AC_CHECK_HEADER([libudev.h], [], [AC_MSG_ERROR([udev support requested but libudev header not installed])])
		AC_CHECK_LIB([udev], [udev_new], [], [AC_MSG_ERROR([udev support requested but libudev not installed])])
	else
		AC_CHECK_HEADERS([asm/types.h])
		AC_CHECK_HEADER([linux/netlink.h], [], [AC_MSG_ERROR([Linux netlink header not found])])
		AC_CHECK_HEADER([sys/socket.h], [], [AC_MSG_ERROR([Linux socket header not found])])
	fi
	;;
sunos)
	LIBS="${LIBS} -ldevinfo"
	;;
windows)
	AC_CHECK_TYPES([struct timespec], [], [], [[#include <time.h>]])
	AC_DEFINE([_WIN32_WINNT], [_WIN32_WINNT_VISTA], [Define to the oldest supported Windows version.])
	LT_LDFLAGS="${LT_LDFLAGS} -avoid-version -Wl,--add-stdcall-alias"
	;;
*)
	dnl no special handling required
	;;
esac

dnl headers not available on all platforms but required on others
AC_CHECK_HEADERS([sys/time.h])

if test "x$platform" = xposix; then
	dnl the clock_gettime() function needs certain clock IDs defined
	AC_CHECK_FUNCS([clock_gettime], [have_clock_gettime=yes], [have_clock_gettime=])
	if test "x$have_clock_gettime" = xyes; then
		AC_CHECK_DECL([CLOCK_MONOTONIC], [], [AC_MSG_ERROR([C library headers missing definition for CLOCK_MONOTONIC])], [[#include <time.h>]])
		dnl use the monotonic clock for condition variable timed waits if possible
		AC_CHECK_FUNCS([pthread_condattr_setclock], [need_clock_realtime=], [need_clock_realtime=yes])
		if test "x$need_clock_realtime" = xyes; then
			AC_CHECK_DECL([CLOCK_REALTIME], [], [AC_MSG_ERROR([C library headers missing definition for CLOCK_REALTIME])], [[#include <time.h>]])
		fi
	elif test "x$backend" != xdarwin; then
		AC_MSG_ERROR([clock_gettime() is required on this platform])
	fi
fi

dnl eventfd support
if test "x$backend" = xlinux || test "x$backend" = xsunos; then
	AC_ARG_ENABLE([eventfd],
		[AS_HELP_STRING([--enable-eventfd], [use eventfd for signalling [default=auto]])],
		[use_eventfd=$enableval],
		[use_eventfd=auto])
	if test "x$use_eventfd" != xno; then
		AC_CHECK_HEADER([sys/eventfd.h], [eventfd_h=yes], [eventfd_h=])
		if test "x$eventfd_h" = xyes; then
			AC_CHECK_DECLS([EFD_NONBLOCK, EFD_CLOEXEC], [eventfd_h_ok=yes], [eventfd_h_ok=], [[#include <sys/eventfd.h>]])
			if test "x$eventfd_h_ok" = xyes; then
				AC_CHECK_FUNC([eventfd], [eventfd_ok=yes], [eventfd_ok=])
				if test "x$eventfd_ok" = xyes; then
					AC_DEFINE([HAVE_EVENTFD], [1], [Define to 1 if the system has eventfd functionality.])
				elif test "x$use_eventfd" = xyes; then
					AC_MSG_ERROR([eventfd() function not found; glibc 2.9+ required])
				fi
			elif test "x$use_eventfd" = xyes; then
				AC_MSG_ERROR([eventfd header not usable; glibc 2.9+ required])
			fi
		elif test "x$use_eventfd" = xyes; then
			AC_MSG_ERROR([eventfd header not available; glibc 2.9+ required])
		fi
	fi
	AC_MSG_CHECKING([whether to use eventfd for signalling])
	if test "x$use_eventfd" = xno; then
		AC_MSG_RESULT([no (disabled by user)])
	elif test "x$eventfd_h" != xyes; then
		AC_MSG_RESULT([no (header not available)])
	elif test "x$eventfd_h_ok" != xyes; then
		AC_MSG_RESULT([no (header not usable)])
	elif test "x$eventfd_ok" != xyes; then
		AC_MSG_RESULT([no (functions not available)])
	else
		AC_MSG_RESULT([yes])
	fi
fi

dnl timerfd support
if test "x$backend" = xlinux || test "x$backend" = xsunos; then
	AC_ARG_ENABLE([timerfd],
		[AS_HELP_STRING([--enable-timerfd], [use timerfd for timing [default=auto]])],
		[use_timerfd=$enableval],
		[use_timerfd=auto])
	if test "x$use_timerfd" != xno; then
		AC_CHECK_HEADER([sys/timerfd.h], [timerfd_h=yes], [timerfd_h=])
		if test "x$timerfd_h" = xyes; then
			AC_CHECK_DECLS([TFD_NONBLOCK, TFD_CLOEXEC], [timerfd_h_ok=yes], [timerfd_h_ok=], [[#include <sys/timerfd.h>]])
			if test "x$timerfd_h_ok" = xyes; then
				AC_CHECK_FUNC([timerfd_create], [timerfd_ok=yes], [timerfd_ok=])
				if test "x$timerfd_ok" = xyes; then
					AC_DEFINE([HAVE_TIMERFD], [1], [Define to 1 if the system has timerfd functionality.])
				elif test "x$use_timerfd" = xyes; then
					AC_MSG_ERROR([timerfd_create() function not found; glibc 2.9+ required])
				fi
			elif test "x$use_timerfd" = xyes; then
				AC_MSG_ERROR([timerfd header not usable; glibc 2.9+ required])
			fi
		elif test "x$use_timerfd" = xyes; then
			AC_MSG_ERROR([timerfd header not available; glibc 2.9+ required])
		fi
	fi
	AC_MSG_CHECKING([whether to use timerfd for timing])
	if test "x$use_timerfd" = xno; then
		AC_MSG_RESULT([no (disabled by user)])
	elif test "x$timerfd_h" != xyes; then
		AC_MSG_RESULT([no (header not available)])
	elif test "x$timerfd_h_ok" != xyes; then
		AC_MSG_RESULT([no (header not usable)])
	elif test "x$timerfd_ok" != xyes; then
		AC_MSG_RESULT([no (functions not available)])
	else
		AC_MSG_RESULT([yes])
	fi
fi

dnl Message logging
AC_ARG_ENABLE([log],
	[AS_HELP_STRING([--disable-log], [disable all logging])],
	[log_enabled=$enableval],
	[log_enabled=yes])
if test "x$log_enabled" != xno; then
	AC_DEFINE([ENABLE_LOGGING], [1], [Define to 1 to enable message logging.])
fi

AC_ARG_ENABLE([debug-log],
	[AS_HELP_STRING([--enable-debug-log], [start with debug message logging enabled [default=no]])],
	[debug_log_enabled=$enableval],
	[debug_log_enabled=no])
if test "x$debug_log_enabled" != xno; then
	AC_DEFINE([ENABLE_DEBUG_LOGGING], [1], [Define to 1 to start with debug message logging enabled.])
fi

AC_ARG_ENABLE([system-log],
	[AS_HELP_STRING([--enable-system-log], [output logging messages to the systemwide log, if supported by the OS [default=no]])],
	[system_log_enabled=$enableval],
	[system_log_enabled=no])
if test "x$system_log_enabled" != xno; then
	AC_DEFINE([USE_SYSTEM_LOGGING_FACILITY], [1], [Define to 1 to output logging messages to the systemwide log.])
	if test "x$backend" != xwindows && test "x$is_android_linux" != xyes; then
		dnl Check if syslog is available in standard C library
		AC_CHECK_HEADER([syslog.h], [syslog_h=yes], [syslog_h=])
		if test "x$syslog_h" = xyes; then
			AC_CHECK_FUNCS([syslog])
		fi
	fi
fi

dnl Examples build
AC_ARG_ENABLE([examples-build],
	[AS_HELP_STRING([--enable-examples-build], [build example applications [default=no]])],
	[build_examples=$enableval],
	[build_examples=no])

dnl Tests build
AC_ARG_ENABLE([tests-build],
	[AS_HELP_STRING([--enable-tests-build], [build test applications [default=no]])],
	[build_tests=$enableval],
	[build_tests=no])

AM_CONDITIONAL([BUILD_EXAMPLES], [test "x$build_examples" != xno])
AM_CONDITIONAL([BUILD_TESTS], [test "x$build_tests" != xno])
AM_CONDITIONAL([CREATE_IMPORT_LIB], [test "x$create_import_lib" = xyes])
AM_CONDITIONAL([OS_DARWIN], [test "x$backend" = xdarwin])
AM_CONDITIONAL([OS_HAIKU], [test "x$backend" = xhaiku])
AM_CONDITIONAL([OS_LINUX], [test "x$backend" = xlinux])
AM_CONDITIONAL([OS_NETBSD], [test "x$backend" = xnetbsd])
AM_CONDITIONAL([OS_NULL], [test "x$backend" = xnull])
AM_CONDITIONAL([OS_OPENBSD], [test "x$backend" = xopenbsd])
AM_CONDITIONAL([OS_SUNOS], [test "x$backend" = xsunos])
AM_CONDITIONAL([OS_WINDOWS], [test "x$backend" = xwindows])
AM_CONDITIONAL([PLATFORM_POSIX], [test "x$platform" = xposix])
AM_CONDITIONAL([PLATFORM_WINDOWS], [test "x$platform" = xwindows])
AM_CONDITIONAL([USE_UDEV], [test "x$use_udev" = xyes])

dnl The -Wcast-function-type warning causes a flurry of warnings when compiling
dnl Windows with GCC 8 or later because of dynamically loaded functions
if test "x$backend" = xwindows; then
	saved_CFLAGS="${CFLAGS}"
	CFLAGS="-Werror -Wcast-function-type"
	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])],
		[EXTRA_CFLAGS="${EXTRA_CFLAGS} -Wno-cast-function-type"],
		[])
	CFLAGS="${saved_CFLAGS}"
fi

SHARED_CFLAGS="-Wall -Wextra -Wshadow -Wunused -Wwrite-strings -Werror=format-security -Werror=implicit-function-declaration -Werror=implicit-int -Werror=init-self -Werror=missing-prototypes -Werror=strict-prototypes -Werror=undef -Werror=uninitialized"

AM_CPPFLAGS="${EXTRA_CPPFLAGS}"
AC_SUBST(AM_CPPFLAGS)

AM_CFLAGS="-std=${c_dialect}11 ${EXTRA_CFLAGS} ${SHARED_CFLAGS}"
AC_SUBST(AM_CFLAGS)

AM_CXXFLAGS="-std=${c_dialect}++11 ${EXTRA_CFLAGS} ${SHARED_CFLAGS} -Wmissing-declarations"
AC_SUBST(AM_CXXFLAGS)

AC_SUBST(LT_LDFLAGS)

dnl set name of html output directory for doxygen
AC_SUBST(DOXYGEN_HTMLDIR, [api-1.0])

AC_CONFIG_FILES([libusb-1.0.pc])
AC_CONFIG_FILES([Makefile])
AC_CONFIG_FILES([libusb/Makefile])
AC_CONFIG_FILES([examples/Makefile])
AC_CONFIG_FILES([tests/Makefile])
AC_CONFIG_FILES([doc/Makefile])
AC_CONFIG_FILES([doc/doxygen.cfg])
AC_OUTPUT