forked from libusb/hidapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure.ac
256 lines (228 loc) · 7.62 KB
/
configure.ac
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
AC_PREREQ(2.63)
AC_INIT([hidapi],[m4_normalize(m4_builtin([include], VERSION))],[https://github.com/libusb/hidapi/issues])
echo "This build script for HIDAPI is deprecated."
echo "Consider using CMake instead."
# Library soname version
# Follow the following rules (particularly the ones in the second link):
# http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
# http://sourceware.org/autobook/autobook/autobook_91.html
lt_current="0"
lt_revision="0"
lt_age="0"
LTLDFLAGS="-version-info ${lt_current}:${lt_revision}:${lt_age}"
AC_CONFIG_MACRO_DIR([m4])
AM_INIT_AUTOMAKE([foreign -Wall -Werror])
m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
LT_INIT
AC_PROG_CC
AC_PROG_CXX
AC_PROG_OBJC
PKG_PROG_PKG_CONFIG
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
hidapi_lib_error() {
echo ""
echo " Library $1 was not found on this system."
echo " Please install it and re-run ./configure"
echo ""
exit 1
}
hidapi_prog_error() {
echo ""
echo " Program $1 was not found on this system."
echo " This program is part of $2."
echo " Please install it and re-run ./configure"
echo ""
exit 1
}
AC_MSG_CHECKING([operating system])
AC_MSG_RESULT($host)
case $host in
*-linux*)
AC_MSG_RESULT([ (Linux back-end)])
AC_DEFINE(OS_LINUX, 1, [Linux implementations])
AC_SUBST(OS_LINUX)
backend="linux"
os="linux"
threads="pthreads"
# HIDAPI/hidraw libs
PKG_CHECK_MODULES([libudev], [libudev], true, [hidapi_lib_error libudev])
LIBS_HIDRAW_PR="${LIBS_HIDRAW_PR} $libudev_LIBS"
CFLAGS_HIDRAW="${CFLAGS_HIDRAW} $libudev_CFLAGS"
# HIDAPI/libusb libs
AC_CHECK_LIB([rt], [clock_gettime], [LIBS_LIBUSB_PRIVATE="${LIBS_LIBUSB_PRIVATE} -lrt"], [hidapi_lib_error librt])
PKG_CHECK_MODULES([libusb], [libusb-1.0 >= 1.0.9], true, [hidapi_lib_error libusb-1.0])
LIBS_LIBUSB_PRIVATE="${LIBS_LIBUSB_PRIVATE} $libusb_LIBS"
CFLAGS_LIBUSB="${CFLAGS_LIBUSB} $libusb_CFLAGS"
;;
*-darwin*)
AC_MSG_RESULT([ (Mac OS X back-end)])
AC_DEFINE(OS_DARWIN, 1, [Mac implementation])
AC_SUBST(OS_DARWIN)
backend="mac"
os="darwin"
threads="pthreads"
LIBS="${LIBS} -framework IOKit -framework CoreFoundation -framework AppKit"
;;
*-freebsd*)
AC_MSG_RESULT([ (FreeBSD back-end)])
AC_DEFINE(OS_FREEBSD, 1, [FreeBSD implementation])
AC_SUBST(OS_FREEBSD)
backend="libusb"
os="freebsd"
threads="pthreads"
CFLAGS="$CFLAGS -I/usr/local/include"
LDFLAGS="$LDFLAGS -L/usr/local/lib"
LIBS="${LIBS}"
PKG_CHECK_MODULES([libusb], [libusb-1.0 >= 1.0.9], true, [hidapi_lib_error libusb-1.0])
LIBS_LIBUSB_PRIVATE="${LIBS_LIBUSB_PRIVATE} $libusb_LIBS"
CFLAGS_LIBUSB="${CFLAGS_LIBUSB} $libusb_CFLAGS"
AC_CHECK_LIB([iconv], [iconv_open], [LIBS_LIBUSB_PRIVATE="${LIBS_LIBUSB_PRIVATE} -liconv"], [hidapi_lib_error libiconv])
;;
*-kfreebsd*)
AC_MSG_RESULT([ (kFreeBSD back-end)])
AC_DEFINE(OS_KFREEBSD, 1, [kFreeBSD implementation])
AC_SUBST(OS_KFREEBSD)
backend="libusb"
os="kfreebsd"
threads="pthreads"
PKG_CHECK_MODULES([libusb], [libusb-1.0 >= 1.0.9], true, [hidapi_lib_error libusb-1.0])
LIBS_LIBUSB_PRIVATE="${LIBS_LIBUSB_PRIVATE} $libusb_LIBS"
CFLAGS_LIBUSB="${CFLAGS_LIBUSB} $libusb_CFLAGS"
;;
*-*-haiku)
AC_MSG_RESULT([ (Haiku back-end)])
AC_DEFINE(OS_HAIKU, 1, [Haiku implementation])
AC_SUBST(OS_HAIKU)
backend="libusb"
os="haiku"
threads="pthreads"
PKG_CHECK_MODULES([libusb], [libusb-1.0 >= 1.0.9], true, [hidapi_lib_error libusb-1.0])
LIBS_LIBUSB_PRIVATE="${LIBS_LIBUSB_PRIVATE} $libusb_LIBS"
CFLAGS_LIBUSB="${CFLAGS_LIBUSB} $libusb_CFLAGS"
AC_CHECK_LIB([iconv], [libiconv_open], [LIBS_LIBUSB_PRIVATE="${LIBS_LIBUSB_PRIVATE} -liconv"], [hidapi_lib_error libiconv])
;;
*-mingw*)
AC_MSG_RESULT([ (Windows back-end, using MinGW)])
backend="windows"
os="windows"
threads="windows"
win_implementation="mingw"
LDFLAGS="${LDFLAGS} -static-libgcc"
;;
*-msys*)
AC_MSG_RESULT([ (Windows back-end, using MSYS2)])
backend="windows"
os="windows"
threads="windows"
win_implementation="mingw"
LDFLAGS="${LDFLAGS} -static-libgcc"
;;
*-cygwin*)
AC_MSG_RESULT([ (Windows back-end, using Cygwin)])
backend="windows"
os="windows"
threads="windows"
win_implementation="cygwin"
;;
*)
AC_MSG_ERROR([HIDAPI is not supported on your operating system yet])
esac
LIBS_HIDRAW="${LIBS} ${LIBS_HIDRAW_PR}"
LIBS_LIBUSB="${LIBS} ${LIBS_LIBUSB_PRIVATE}"
AC_SUBST([LIBS_HIDRAW])
AC_SUBST([LIBS_LIBUSB])
AC_SUBST([CFLAGS_LIBUSB])
AC_SUBST([CFLAGS_HIDRAW])
if test "x$os" = xwindows; then
AC_DEFINE(OS_WINDOWS, 1, [Windows implementations])
AC_SUBST(OS_WINDOWS)
LDFLAGS="${LDFLAGS} -no-undefined"
LIBS="${LIBS}"
fi
if test "x$threads" = xpthreads; then
AX_PTHREAD([found_pthreads=yes], [found_pthreads=no])
if test "x$found_pthreads" = xyes; then
if test "x$os" = xlinux; then
# Only use pthreads for libusb implementation on Linux.
LIBS_LIBUSB="$PTHREAD_LIBS $LIBS_LIBUSB"
CFLAGS_LIBUSB="$CFLAGS_LIBUSB $PTHREAD_CFLAGS"
# There's no separate CC on Linux for threading,
# so it's ok that both implementations use $PTHREAD_CC
CC="$PTHREAD_CC"
else
LIBS="$PTHREAD_LIBS $LIBS"
CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
CC="$PTHREAD_CC"
fi
fi
fi
# Test GUI
AC_ARG_ENABLE([testgui],
[AS_HELP_STRING([--enable-testgui],
[enable building of test GUI (default n)])],
[testgui_enabled=$enableval],
[testgui_enabled='no'])
AM_CONDITIONAL([BUILD_TESTGUI], [test "x$testgui_enabled" != "xno"])
# Configure the MacOS TestGUI app bundle
rm -Rf testgui/TestGUI.app
mkdir -p testgui/TestGUI.app
cp -R ${srcdir}/testgui/TestGUI.app.in/* testgui/TestGUI.app
chmod -R u+w testgui/TestGUI.app
mkdir testgui/TestGUI.app/Contents/MacOS/
if test "x$testgui_enabled" != "xno"; then
if test "x$os" = xdarwin; then
# On Mac OS, do not use pkg-config.
AC_CHECK_PROG([foxconfig], [fox-config], [fox-config], false)
if test "x$foxconfig" = "xfalse"; then
hidapi_prog_error fox-config "FOX Toolkit"
fi
LIBS_TESTGUI="${LIBS_TESTGUI} `$foxconfig --libs`"
LIBS_TESTGUI="${LIBS_TESTGUI} -framework Cocoa -L/usr/X11R6/lib"
CFLAGS_TESTGUI="${CFLAGS_TESTGUI} `$foxconfig --cflags`"
OBJCFLAGS="${OBJCFLAGS} -x objective-c++"
elif test "x$os" = xwindows; then
# On Windows, just set the paths for Fox toolkit
if test "x$win_implementation" = xmingw; then
CFLAGS_TESTGUI="-I\$(srcdir)/../../hidapi-externals/fox/include -g -c"
LIBS_TESTGUI=" -mwindows \$(srcdir)/../../hidapi-externals/fox/lib/libFOX-1.6.a -lgdi32 -Wl,--enable-auto-import -static-libgcc -static-libstdc++ -lkernel32"
else
# Cygwin
CFLAGS_TESTGUI="-DWIN32 -I\$(srcdir)/../../hidapi-externals/fox/include -g -c"
LIBS_TESTGUI="\$(srcdir)/../../hidapi-externals/fox/lib/libFOX-cygwin-1.6.a -lgdi32 -Wl,--enable-auto-import -static-libgcc -static-libstdc++ -lkernel32"
fi
else
# On Linux and FreeBSD platforms, use pkg-config to find fox.
PKG_CHECK_MODULES([fox], [fox17], [], [PKG_CHECK_MODULES([fox], [fox])])
LIBS_TESTGUI="${LIBS_TESTGUI} $fox_LIBS"
if test "x$os" = xfreebsd; then
LIBS_TESTGUI="${LIBS_TESTGUI} -L/usr/local/lib"
fi
CFLAGS_TESTGUI="${CFLAGS_TESTGUI} $fox_CFLAGS"
fi
fi
AC_SUBST([LIBS_TESTGUI])
AC_SUBST([CFLAGS_TESTGUI])
AC_SUBST([backend])
# OS info for Automake
AM_CONDITIONAL(OS_LINUX, test "x$os" = xlinux)
AM_CONDITIONAL(OS_DARWIN, test "x$os" = xdarwin)
AM_CONDITIONAL(OS_FREEBSD, test "x$os" = xfreebsd)
AM_CONDITIONAL(OS_KFREEBSD, test "x$os" = xkfreebsd)
AM_CONDITIONAL(OS_HAIKU, test "x$os" = xhaiku)
AM_CONDITIONAL(OS_WINDOWS, test "x$os" = xwindows)
AC_CONFIG_HEADERS([config.h])
if test "x$os" = "xlinux"; then
AC_CONFIG_FILES([pc/hidapi-hidraw.pc])
AC_CONFIG_FILES([pc/hidapi-libusb.pc])
else
AC_CONFIG_FILES([pc/hidapi.pc])
fi
AC_SUBST(LTLDFLAGS)
AC_CONFIG_FILES([Makefile \
hidtest/Makefile \
libusb/Makefile \
linux/Makefile \
mac/Makefile \
testgui/Makefile \
windows/Makefile])
AC_OUTPUT