src/hidapi/configure.ac
author Sam Lantinga <slouken@libsdl.org>
Thu, 09 Aug 2018 16:05:48 -0700
changeset 12098 8eb14aba4e87
permissions -rw-r--r--
Added missing files from previous commits
slouken@12098
     1
AC_PREREQ(2.63)
slouken@12098
     2
slouken@12098
     3
# Version number. This is currently the only place.
slouken@12098
     4
m4_define([HIDAPI_MAJOR],   0)
slouken@12098
     5
m4_define([HIDAPI_MINOR],   8)
slouken@12098
     6
m4_define([HIDAPI_RELEASE], 0)
slouken@12098
     7
m4_define([HIDAPI_RC],      -rc1)
slouken@12098
     8
m4_define([VERSION_STRING], HIDAPI_MAJOR[.]HIDAPI_MINOR[.]HIDAPI_RELEASE[]HIDAPI_RC)
slouken@12098
     9
slouken@12098
    10
AC_INIT([hidapi],[VERSION_STRING],[alan@signal11.us])
slouken@12098
    11
slouken@12098
    12
# Library soname version
slouken@12098
    13
# Follow the following rules (particularly the ones in the second link):
slouken@12098
    14
#  http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
slouken@12098
    15
#  http://sourceware.org/autobook/autobook/autobook_91.html
slouken@12098
    16
lt_current="0"
slouken@12098
    17
lt_revision="0"
slouken@12098
    18
lt_age="0"
slouken@12098
    19
LTLDFLAGS="-version-info ${lt_current}:${lt_revision}:${lt_age}"
slouken@12098
    20
slouken@12098
    21
AC_CONFIG_MACRO_DIR([m4])
slouken@12098
    22
AM_INIT_AUTOMAKE([foreign -Wall -Werror])
slouken@12098
    23
AC_CONFIG_MACRO_DIR([m4])
slouken@12098
    24
slouken@12098
    25
m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
slouken@12098
    26
LT_INIT
slouken@12098
    27
slouken@12098
    28
AC_PROG_CC
slouken@12098
    29
AC_PROG_CXX
slouken@12098
    30
AC_PROG_OBJC
slouken@12098
    31
PKG_PROG_PKG_CONFIG
slouken@12098
    32
slouken@12098
    33
slouken@12098
    34
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
slouken@12098
    35
slouken@12098
    36
hidapi_lib_error() {
slouken@12098
    37
	echo ""
slouken@12098
    38
	echo "  Library $1 was not found on this system."
slouken@12098
    39
	echo "  Please install it and re-run ./configure"
slouken@12098
    40
	echo ""
slouken@12098
    41
	exit 1
slouken@12098
    42
}
slouken@12098
    43
slouken@12098
    44
hidapi_prog_error() {
slouken@12098
    45
	echo ""
slouken@12098
    46
	echo "  Program $1 was not found on this system."
slouken@12098
    47
	echo "  This program is part of $2."
slouken@12098
    48
	echo "  Please install it and re-run ./configure"
slouken@12098
    49
	echo ""
slouken@12098
    50
	exit 1
slouken@12098
    51
}
slouken@12098
    52
slouken@12098
    53
AC_MSG_CHECKING([operating system])
slouken@12098
    54
AC_MSG_RESULT($host)
slouken@12098
    55
case $host in
slouken@12098
    56
*-linux*)
slouken@12098
    57
	AC_MSG_RESULT([ (Linux back-end)])
slouken@12098
    58
	AC_DEFINE(OS_LINUX, 1, [Linux implementations])
slouken@12098
    59
	AC_SUBST(OS_LINUX)
slouken@12098
    60
	backend="linux"
slouken@12098
    61
	os="linux"
slouken@12098
    62
	threads="pthreads"
slouken@12098
    63
slouken@12098
    64
	# HIDAPI/hidraw libs
slouken@12098
    65
	PKG_CHECK_MODULES([libudev], [libudev], true, [hidapi_lib_error libudev])
slouken@12098
    66
	LIBS_HIDRAW_PR+=" $libudev_LIBS"
slouken@12098
    67
	CFLAGS_HIDRAW+=" $libudev_CFLAGS"
slouken@12098
    68
slouken@12098
    69
	# HIDAPI/libusb libs
slouken@12098
    70
	AC_CHECK_LIB([rt], [clock_gettime], [LIBS_LIBUSB_PRIVATE+=" -lrt"], [hidapi_lib_error librt])
slouken@12098
    71
	PKG_CHECK_MODULES([libusb], [libusb-1.0 >= 1.0.9], true, [hidapi_lib_error libusb-1.0])
slouken@12098
    72
	LIBS_LIBUSB_PRIVATE+=" $libusb_LIBS"
slouken@12098
    73
	CFLAGS_LIBUSB+=" $libusb_CFLAGS"
slouken@12098
    74
	;;
slouken@12098
    75
*-darwin*)
slouken@12098
    76
	AC_MSG_RESULT([ (Mac OS X back-end)])
slouken@12098
    77
	AC_DEFINE(OS_DARWIN, 1, [Mac implementation])
slouken@12098
    78
	AC_SUBST(OS_DARWIN)
slouken@12098
    79
	backend="mac"
slouken@12098
    80
	os="darwin"
slouken@12098
    81
	threads="pthreads"
slouken@12098
    82
	LIBS="${LIBS} -framework IOKit -framework CoreFoundation"
slouken@12098
    83
	;;
slouken@12098
    84
*-freebsd*)
slouken@12098
    85
	AC_MSG_RESULT([ (FreeBSD back-end)])
slouken@12098
    86
	AC_DEFINE(OS_FREEBSD, 1, [FreeBSD implementation])
slouken@12098
    87
	AC_SUBST(OS_FREEBSD)
slouken@12098
    88
	backend="libusb"
slouken@12098
    89
	os="freebsd"
slouken@12098
    90
	threads="pthreads"
slouken@12098
    91
slouken@12098
    92
	CFLAGS="$CFLAGS -I/usr/local/include"
slouken@12098
    93
	LDFLAGS="$LDFLAGS -L/usr/local/lib"
slouken@12098
    94
	LIBS="${LIBS}"
slouken@12098
    95
	AC_CHECK_LIB([usb], [libusb_init], [LIBS_LIBUSB_PRIVATE="${LIBS_LIBUSB_PRIVATE} -lusb"], [hidapi_lib_error libusb])
slouken@12098
    96
	AC_CHECK_LIB([iconv], [iconv_open], [LIBS_LIBUSB_PRIVATE="${LIBS_LIBUSB_PRIVATE} -liconv"], [hidapi_lib_error libiconv])
slouken@12098
    97
	echo libs_priv: $LIBS_LIBUSB_PRIVATE
slouken@12098
    98
	;;
slouken@12098
    99
*-kfreebsd*)
slouken@12098
   100
	AC_MSG_RESULT([ (kFreeBSD back-end)])
slouken@12098
   101
	AC_DEFINE(OS_KFREEBSD, 1, [kFreeBSD implementation])
slouken@12098
   102
	AC_SUBST(OS_KFREEBSD)
slouken@12098
   103
	backend="libusb"
slouken@12098
   104
	os="kfreebsd"
slouken@12098
   105
	threads="pthreads"
slouken@12098
   106
slouken@12098
   107
	AC_CHECK_LIB([usb], [libusb_init], [LIBS_LIBUSB_PRIVATE="${LIBS_LIBUSB_PRIVATE} -lusb"], [hidapi_lib_error libusb])
slouken@12098
   108
	echo libs_priv: $LIBS_LIBUSB_PRIVATE
slouken@12098
   109
	;;
slouken@12098
   110
*-mingw*)
slouken@12098
   111
	AC_MSG_RESULT([ (Windows back-end, using MinGW)])
slouken@12098
   112
	backend="windows"
slouken@12098
   113
	os="windows"
slouken@12098
   114
	threads="windows"
slouken@12098
   115
	win_implementation="mingw"
slouken@12098
   116
	;;
slouken@12098
   117
*-cygwin*)
slouken@12098
   118
	AC_MSG_RESULT([ (Windows back-end, using Cygwin)])
slouken@12098
   119
	backend="windows"
slouken@12098
   120
	os="windows"
slouken@12098
   121
	threads="windows"
slouken@12098
   122
	win_implementation="cygwin"
slouken@12098
   123
	;;
slouken@12098
   124
*)
slouken@12098
   125
	AC_MSG_ERROR([HIDAPI is not supported on your operating system yet])
slouken@12098
   126
esac
slouken@12098
   127
slouken@12098
   128
LIBS_HIDRAW="${LIBS} ${LIBS_HIDRAW_PR}"
slouken@12098
   129
LIBS_LIBUSB="${LIBS} ${LIBS_LIBUSB_PRIVATE}"
slouken@12098
   130
AC_SUBST([LIBS_HIDRAW])
slouken@12098
   131
AC_SUBST([LIBS_LIBUSB])
slouken@12098
   132
AC_SUBST([CFLAGS_LIBUSB])
slouken@12098
   133
AC_SUBST([CFLAGS_HIDRAW])
slouken@12098
   134
slouken@12098
   135
if test "x$os" = xwindows; then
slouken@12098
   136
	AC_DEFINE(OS_WINDOWS, 1, [Windows implementations])
slouken@12098
   137
	AC_SUBST(OS_WINDOWS)
slouken@12098
   138
	LDFLAGS="${LDFLAGS} -no-undefined"
slouken@12098
   139
	LIBS="${LIBS} -lsetupapi"
slouken@12098
   140
fi
slouken@12098
   141
slouken@12098
   142
if test "x$threads" = xpthreads; then
slouken@12098
   143
	AX_PTHREAD([found_pthreads=yes], [found_pthreads=no])
slouken@12098
   144
slouken@12098
   145
	if test "x$found_pthreads" = xyes; then
slouken@12098
   146
		if test "x$os" = xlinux; then
slouken@12098
   147
			# Only use pthreads for libusb implementation on Linux.
slouken@12098
   148
			LIBS_LIBUSB="$PTHREAD_LIBS $LIBS_LIBUSB"
slouken@12098
   149
			CFLAGS_LIBUSB="$CFLAGS_LIBUSB $PTHREAD_CFLAGS"
slouken@12098
   150
			# There's no separate CC on Linux for threading,
slouken@12098
   151
			# so it's ok that both implementations use $PTHREAD_CC
slouken@12098
   152
			CC="$PTHREAD_CC"
slouken@12098
   153
		else
slouken@12098
   154
			LIBS="$PTHREAD_LIBS $LIBS"
slouken@12098
   155
			CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
slouken@12098
   156
			CC="$PTHREAD_CC"
slouken@12098
   157
		fi
slouken@12098
   158
	fi
slouken@12098
   159
fi
slouken@12098
   160
slouken@12098
   161
# Test GUI
slouken@12098
   162
AC_ARG_ENABLE([testgui],
slouken@12098
   163
	[AS_HELP_STRING([--enable-testgui],
slouken@12098
   164
		[enable building of test GUI (default n)])],
slouken@12098
   165
	[testgui_enabled=$enableval],
slouken@12098
   166
	[testgui_enabled='no'])
slouken@12098
   167
AM_CONDITIONAL([BUILD_TESTGUI], [test "x$testgui_enabled" != "xno"])
slouken@12098
   168
slouken@12098
   169
# Configure the MacOS TestGUI app bundle
slouken@12098
   170
rm -Rf testgui/TestGUI.app
slouken@12098
   171
mkdir -p testgui/TestGUI.app
slouken@12098
   172
cp -R ${srcdir}/testgui/TestGUI.app.in/* testgui/TestGUI.app
slouken@12098
   173
chmod -R u+w testgui/TestGUI.app
slouken@12098
   174
mkdir testgui/TestGUI.app/Contents/MacOS/
slouken@12098
   175
slouken@12098
   176
if test "x$testgui_enabled" != "xno"; then
slouken@12098
   177
	if test "x$os" = xdarwin; then
slouken@12098
   178
		# On Mac OS, don't use pkg-config.
slouken@12098
   179
		AC_CHECK_PROG([foxconfig], [fox-config], [fox-config], false)
slouken@12098
   180
		if test "x$foxconfig" = "xfalse"; then
slouken@12098
   181
			hidapi_prog_error fox-config "FOX Toolkit"
slouken@12098
   182
		fi
slouken@12098
   183
		LIBS_TESTGUI+=`$foxconfig --libs`
slouken@12098
   184
		LIBS_TESTGUI+=" -framework Cocoa -L/usr/X11R6/lib"
slouken@12098
   185
		CFLAGS_TESTGUI+=`$foxconfig --cflags`
slouken@12098
   186
		OBJCFLAGS+=" -x objective-c++"
slouken@12098
   187
	elif test "x$os" = xwindows; then
slouken@12098
   188
		# On Windows, just set the paths for Fox toolkit
slouken@12098
   189
		if test "x$win_implementation" = xmingw; then
slouken@12098
   190
			CFLAGS_TESTGUI="-I\$(srcdir)/../../hidapi-externals/fox/include -g -c"
slouken@12098
   191
			LIBS_TESTGUI=" -mwindows \$(srcdir)/../../hidapi-externals/fox/lib/libFOX-1.6.a -lgdi32 -Wl,--enable-auto-import -static-libgcc -static-libstdc++ -lkernel32"
slouken@12098
   192
		else
slouken@12098
   193
			# Cygwin
slouken@12098
   194
			CFLAGS_TESTGUI="-DWIN32 -I\$(srcdir)/../../hidapi-externals/fox/include -g -c"
slouken@12098
   195
			LIBS_TESTGUI="\$(srcdir)/../../hidapi-externals/fox/lib/libFOX-cygwin-1.6.a -lgdi32 -Wl,--enable-auto-import -static-libgcc -static-libstdc++ -lkernel32"
slouken@12098
   196
		fi
slouken@12098
   197
	else
slouken@12098
   198
		# On Linux and FreeBSD platforms, use pkg-config to find fox.
slouken@12098
   199
		PKG_CHECK_MODULES([fox], [fox17], [], [PKG_CHECK_MODULES([fox], [fox])])
slouken@12098
   200
		LIBS_TESTGUI="${LIBS_TESTGUI} $fox_LIBS"
slouken@12098
   201
		if test "x$os" = xfreebsd; then
slouken@12098
   202
			LIBS_TESTGUI="${LIBS_TESTGUI} -L/usr/local/lib"
slouken@12098
   203
		fi
slouken@12098
   204
		CFLAGS_TESTGUI="${CFLAGS_TESTGUI} $fox_CFLAGS"
slouken@12098
   205
	fi
slouken@12098
   206
fi
slouken@12098
   207
AC_SUBST([LIBS_TESTGUI])
slouken@12098
   208
AC_SUBST([CFLAGS_TESTGUI])
slouken@12098
   209
AC_SUBST([backend])
slouken@12098
   210
slouken@12098
   211
# OS info for Automake
slouken@12098
   212
AM_CONDITIONAL(OS_LINUX, test "x$os" = xlinux)
slouken@12098
   213
AM_CONDITIONAL(OS_DARWIN, test "x$os" = xdarwin)
slouken@12098
   214
AM_CONDITIONAL(OS_FREEBSD, test "x$os" = xfreebsd)
slouken@12098
   215
AM_CONDITIONAL(OS_KFREEBSD, test "x$os" = xkfreebsd)
slouken@12098
   216
AM_CONDITIONAL(OS_WINDOWS, test "x$os" = xwindows)
slouken@12098
   217
slouken@12098
   218
AC_CONFIG_HEADERS([config.h])
slouken@12098
   219
slouken@12098
   220
if test "x$os" = "xlinux"; then
slouken@12098
   221
	AC_CONFIG_FILES([pc/hidapi-hidraw.pc])
slouken@12098
   222
	AC_CONFIG_FILES([pc/hidapi-libusb.pc])
slouken@12098
   223
else
slouken@12098
   224
	AC_CONFIG_FILES([pc/hidapi.pc])
slouken@12098
   225
fi
slouken@12098
   226
slouken@12098
   227
AC_SUBST(LTLDFLAGS)
slouken@12098
   228
slouken@12098
   229
AC_CONFIG_FILES([Makefile \
slouken@12098
   230
	hidtest/Makefile \
slouken@12098
   231
	libusb/Makefile \
slouken@12098
   232
	linux/Makefile \
slouken@12098
   233
	mac/Makefile \
slouken@12098
   234
	testgui/Makefile \
slouken@12098
   235
	windows/Makefile])
slouken@12098
   236
AC_OUTPUT