src/hidapi/configure.ac
changeset 12098 8eb14aba4e87
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/hidapi/configure.ac	Thu Aug 09 16:05:48 2018 -0700
     1.3 @@ -0,0 +1,236 @@
     1.4 +AC_PREREQ(2.63)
     1.5 +
     1.6 +# Version number. This is currently the only place.
     1.7 +m4_define([HIDAPI_MAJOR],   0)
     1.8 +m4_define([HIDAPI_MINOR],   8)
     1.9 +m4_define([HIDAPI_RELEASE], 0)
    1.10 +m4_define([HIDAPI_RC],      -rc1)
    1.11 +m4_define([VERSION_STRING], HIDAPI_MAJOR[.]HIDAPI_MINOR[.]HIDAPI_RELEASE[]HIDAPI_RC)
    1.12 +
    1.13 +AC_INIT([hidapi],[VERSION_STRING],[alan@signal11.us])
    1.14 +
    1.15 +# Library soname version
    1.16 +# Follow the following rules (particularly the ones in the second link):
    1.17 +#  http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
    1.18 +#  http://sourceware.org/autobook/autobook/autobook_91.html
    1.19 +lt_current="0"
    1.20 +lt_revision="0"
    1.21 +lt_age="0"
    1.22 +LTLDFLAGS="-version-info ${lt_current}:${lt_revision}:${lt_age}"
    1.23 +
    1.24 +AC_CONFIG_MACRO_DIR([m4])
    1.25 +AM_INIT_AUTOMAKE([foreign -Wall -Werror])
    1.26 +AC_CONFIG_MACRO_DIR([m4])
    1.27 +
    1.28 +m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
    1.29 +LT_INIT
    1.30 +
    1.31 +AC_PROG_CC
    1.32 +AC_PROG_CXX
    1.33 +AC_PROG_OBJC
    1.34 +PKG_PROG_PKG_CONFIG
    1.35 +
    1.36 +
    1.37 +m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
    1.38 +
    1.39 +hidapi_lib_error() {
    1.40 +	echo ""
    1.41 +	echo "  Library $1 was not found on this system."
    1.42 +	echo "  Please install it and re-run ./configure"
    1.43 +	echo ""
    1.44 +	exit 1
    1.45 +}
    1.46 +
    1.47 +hidapi_prog_error() {
    1.48 +	echo ""
    1.49 +	echo "  Program $1 was not found on this system."
    1.50 +	echo "  This program is part of $2."
    1.51 +	echo "  Please install it and re-run ./configure"
    1.52 +	echo ""
    1.53 +	exit 1
    1.54 +}
    1.55 +
    1.56 +AC_MSG_CHECKING([operating system])
    1.57 +AC_MSG_RESULT($host)
    1.58 +case $host in
    1.59 +*-linux*)
    1.60 +	AC_MSG_RESULT([ (Linux back-end)])
    1.61 +	AC_DEFINE(OS_LINUX, 1, [Linux implementations])
    1.62 +	AC_SUBST(OS_LINUX)
    1.63 +	backend="linux"
    1.64 +	os="linux"
    1.65 +	threads="pthreads"
    1.66 +
    1.67 +	# HIDAPI/hidraw libs
    1.68 +	PKG_CHECK_MODULES([libudev], [libudev], true, [hidapi_lib_error libudev])
    1.69 +	LIBS_HIDRAW_PR+=" $libudev_LIBS"
    1.70 +	CFLAGS_HIDRAW+=" $libudev_CFLAGS"
    1.71 +
    1.72 +	# HIDAPI/libusb libs
    1.73 +	AC_CHECK_LIB([rt], [clock_gettime], [LIBS_LIBUSB_PRIVATE+=" -lrt"], [hidapi_lib_error librt])
    1.74 +	PKG_CHECK_MODULES([libusb], [libusb-1.0 >= 1.0.9], true, [hidapi_lib_error libusb-1.0])
    1.75 +	LIBS_LIBUSB_PRIVATE+=" $libusb_LIBS"
    1.76 +	CFLAGS_LIBUSB+=" $libusb_CFLAGS"
    1.77 +	;;
    1.78 +*-darwin*)
    1.79 +	AC_MSG_RESULT([ (Mac OS X back-end)])
    1.80 +	AC_DEFINE(OS_DARWIN, 1, [Mac implementation])
    1.81 +	AC_SUBST(OS_DARWIN)
    1.82 +	backend="mac"
    1.83 +	os="darwin"
    1.84 +	threads="pthreads"
    1.85 +	LIBS="${LIBS} -framework IOKit -framework CoreFoundation"
    1.86 +	;;
    1.87 +*-freebsd*)
    1.88 +	AC_MSG_RESULT([ (FreeBSD back-end)])
    1.89 +	AC_DEFINE(OS_FREEBSD, 1, [FreeBSD implementation])
    1.90 +	AC_SUBST(OS_FREEBSD)
    1.91 +	backend="libusb"
    1.92 +	os="freebsd"
    1.93 +	threads="pthreads"
    1.94 +
    1.95 +	CFLAGS="$CFLAGS -I/usr/local/include"
    1.96 +	LDFLAGS="$LDFLAGS -L/usr/local/lib"
    1.97 +	LIBS="${LIBS}"
    1.98 +	AC_CHECK_LIB([usb], [libusb_init], [LIBS_LIBUSB_PRIVATE="${LIBS_LIBUSB_PRIVATE} -lusb"], [hidapi_lib_error libusb])
    1.99 +	AC_CHECK_LIB([iconv], [iconv_open], [LIBS_LIBUSB_PRIVATE="${LIBS_LIBUSB_PRIVATE} -liconv"], [hidapi_lib_error libiconv])
   1.100 +	echo libs_priv: $LIBS_LIBUSB_PRIVATE
   1.101 +	;;
   1.102 +*-kfreebsd*)
   1.103 +	AC_MSG_RESULT([ (kFreeBSD back-end)])
   1.104 +	AC_DEFINE(OS_KFREEBSD, 1, [kFreeBSD implementation])
   1.105 +	AC_SUBST(OS_KFREEBSD)
   1.106 +	backend="libusb"
   1.107 +	os="kfreebsd"
   1.108 +	threads="pthreads"
   1.109 +
   1.110 +	AC_CHECK_LIB([usb], [libusb_init], [LIBS_LIBUSB_PRIVATE="${LIBS_LIBUSB_PRIVATE} -lusb"], [hidapi_lib_error libusb])
   1.111 +	echo libs_priv: $LIBS_LIBUSB_PRIVATE
   1.112 +	;;
   1.113 +*-mingw*)
   1.114 +	AC_MSG_RESULT([ (Windows back-end, using MinGW)])
   1.115 +	backend="windows"
   1.116 +	os="windows"
   1.117 +	threads="windows"
   1.118 +	win_implementation="mingw"
   1.119 +	;;
   1.120 +*-cygwin*)
   1.121 +	AC_MSG_RESULT([ (Windows back-end, using Cygwin)])
   1.122 +	backend="windows"
   1.123 +	os="windows"
   1.124 +	threads="windows"
   1.125 +	win_implementation="cygwin"
   1.126 +	;;
   1.127 +*)
   1.128 +	AC_MSG_ERROR([HIDAPI is not supported on your operating system yet])
   1.129 +esac
   1.130 +
   1.131 +LIBS_HIDRAW="${LIBS} ${LIBS_HIDRAW_PR}"
   1.132 +LIBS_LIBUSB="${LIBS} ${LIBS_LIBUSB_PRIVATE}"
   1.133 +AC_SUBST([LIBS_HIDRAW])
   1.134 +AC_SUBST([LIBS_LIBUSB])
   1.135 +AC_SUBST([CFLAGS_LIBUSB])
   1.136 +AC_SUBST([CFLAGS_HIDRAW])
   1.137 +
   1.138 +if test "x$os" = xwindows; then
   1.139 +	AC_DEFINE(OS_WINDOWS, 1, [Windows implementations])
   1.140 +	AC_SUBST(OS_WINDOWS)
   1.141 +	LDFLAGS="${LDFLAGS} -no-undefined"
   1.142 +	LIBS="${LIBS} -lsetupapi"
   1.143 +fi
   1.144 +
   1.145 +if test "x$threads" = xpthreads; then
   1.146 +	AX_PTHREAD([found_pthreads=yes], [found_pthreads=no])
   1.147 +
   1.148 +	if test "x$found_pthreads" = xyes; then
   1.149 +		if test "x$os" = xlinux; then
   1.150 +			# Only use pthreads for libusb implementation on Linux.
   1.151 +			LIBS_LIBUSB="$PTHREAD_LIBS $LIBS_LIBUSB"
   1.152 +			CFLAGS_LIBUSB="$CFLAGS_LIBUSB $PTHREAD_CFLAGS"
   1.153 +			# There's no separate CC on Linux for threading,
   1.154 +			# so it's ok that both implementations use $PTHREAD_CC
   1.155 +			CC="$PTHREAD_CC"
   1.156 +		else
   1.157 +			LIBS="$PTHREAD_LIBS $LIBS"
   1.158 +			CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
   1.159 +			CC="$PTHREAD_CC"
   1.160 +		fi
   1.161 +	fi
   1.162 +fi
   1.163 +
   1.164 +# Test GUI
   1.165 +AC_ARG_ENABLE([testgui],
   1.166 +	[AS_HELP_STRING([--enable-testgui],
   1.167 +		[enable building of test GUI (default n)])],
   1.168 +	[testgui_enabled=$enableval],
   1.169 +	[testgui_enabled='no'])
   1.170 +AM_CONDITIONAL([BUILD_TESTGUI], [test "x$testgui_enabled" != "xno"])
   1.171 +
   1.172 +# Configure the MacOS TestGUI app bundle
   1.173 +rm -Rf testgui/TestGUI.app
   1.174 +mkdir -p testgui/TestGUI.app
   1.175 +cp -R ${srcdir}/testgui/TestGUI.app.in/* testgui/TestGUI.app
   1.176 +chmod -R u+w testgui/TestGUI.app
   1.177 +mkdir testgui/TestGUI.app/Contents/MacOS/
   1.178 +
   1.179 +if test "x$testgui_enabled" != "xno"; then
   1.180 +	if test "x$os" = xdarwin; then
   1.181 +		# On Mac OS, don't use pkg-config.
   1.182 +		AC_CHECK_PROG([foxconfig], [fox-config], [fox-config], false)
   1.183 +		if test "x$foxconfig" = "xfalse"; then
   1.184 +			hidapi_prog_error fox-config "FOX Toolkit"
   1.185 +		fi
   1.186 +		LIBS_TESTGUI+=`$foxconfig --libs`
   1.187 +		LIBS_TESTGUI+=" -framework Cocoa -L/usr/X11R6/lib"
   1.188 +		CFLAGS_TESTGUI+=`$foxconfig --cflags`
   1.189 +		OBJCFLAGS+=" -x objective-c++"
   1.190 +	elif test "x$os" = xwindows; then
   1.191 +		# On Windows, just set the paths for Fox toolkit
   1.192 +		if test "x$win_implementation" = xmingw; then
   1.193 +			CFLAGS_TESTGUI="-I\$(srcdir)/../../hidapi-externals/fox/include -g -c"
   1.194 +			LIBS_TESTGUI=" -mwindows \$(srcdir)/../../hidapi-externals/fox/lib/libFOX-1.6.a -lgdi32 -Wl,--enable-auto-import -static-libgcc -static-libstdc++ -lkernel32"
   1.195 +		else
   1.196 +			# Cygwin
   1.197 +			CFLAGS_TESTGUI="-DWIN32 -I\$(srcdir)/../../hidapi-externals/fox/include -g -c"
   1.198 +			LIBS_TESTGUI="\$(srcdir)/../../hidapi-externals/fox/lib/libFOX-cygwin-1.6.a -lgdi32 -Wl,--enable-auto-import -static-libgcc -static-libstdc++ -lkernel32"
   1.199 +		fi
   1.200 +	else
   1.201 +		# On Linux and FreeBSD platforms, use pkg-config to find fox.
   1.202 +		PKG_CHECK_MODULES([fox], [fox17], [], [PKG_CHECK_MODULES([fox], [fox])])
   1.203 +		LIBS_TESTGUI="${LIBS_TESTGUI} $fox_LIBS"
   1.204 +		if test "x$os" = xfreebsd; then
   1.205 +			LIBS_TESTGUI="${LIBS_TESTGUI} -L/usr/local/lib"
   1.206 +		fi
   1.207 +		CFLAGS_TESTGUI="${CFLAGS_TESTGUI} $fox_CFLAGS"
   1.208 +	fi
   1.209 +fi
   1.210 +AC_SUBST([LIBS_TESTGUI])
   1.211 +AC_SUBST([CFLAGS_TESTGUI])
   1.212 +AC_SUBST([backend])
   1.213 +
   1.214 +# OS info for Automake
   1.215 +AM_CONDITIONAL(OS_LINUX, test "x$os" = xlinux)
   1.216 +AM_CONDITIONAL(OS_DARWIN, test "x$os" = xdarwin)
   1.217 +AM_CONDITIONAL(OS_FREEBSD, test "x$os" = xfreebsd)
   1.218 +AM_CONDITIONAL(OS_KFREEBSD, test "x$os" = xkfreebsd)
   1.219 +AM_CONDITIONAL(OS_WINDOWS, test "x$os" = xwindows)
   1.220 +
   1.221 +AC_CONFIG_HEADERS([config.h])
   1.222 +
   1.223 +if test "x$os" = "xlinux"; then
   1.224 +	AC_CONFIG_FILES([pc/hidapi-hidraw.pc])
   1.225 +	AC_CONFIG_FILES([pc/hidapi-libusb.pc])
   1.226 +else
   1.227 +	AC_CONFIG_FILES([pc/hidapi.pc])
   1.228 +fi
   1.229 +
   1.230 +AC_SUBST(LTLDFLAGS)
   1.231 +
   1.232 +AC_CONFIG_FILES([Makefile \
   1.233 +	hidtest/Makefile \
   1.234 +	libusb/Makefile \
   1.235 +	linux/Makefile \
   1.236 +	mac/Makefile \
   1.237 +	testgui/Makefile \
   1.238 +	windows/Makefile])
   1.239 +AC_OUTPUT