src/hidapi/configure.ac
author Ryan C. Gordon <icculus@icculus.org>
Sun, 21 Oct 2018 22:40:17 -0400
changeset 12345 50e1cca28b39
parent 12098 8eb14aba4e87
permissions -rw-r--r--
wasapi/win32: Sort initial device lists by device GUID.

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