From 9e71266d47c6b8be5ffc0b5412a4f86bd55c7c07 Mon Sep 17 00:00:00 2001 From: Alan Ott Date: Sat, 30 Jun 2012 11:15:21 -0400 Subject: [PATCH 01/47] First pass at Autotools. Tested on Linux only. --- Makefile.am | 24 +++++++++++ configure.ac | 103 ++++++++++++++++++++++++++++++++++++++++++++ libusb/Makefile.am | 8 ++++ linux/Makefile.am | 8 ++++ mac/Makefile.am | 8 ++++ testgui/Makefile.am | 29 +++++++++++++ 6 files changed, 180 insertions(+) create mode 100644 Makefile.am create mode 100644 configure.ac create mode 100644 libusb/Makefile.am create mode 100644 linux/Makefile.am create mode 100644 mac/Makefile.am create mode 100644 testgui/Makefile.am diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 00000000..81e5c855 --- /dev/null +++ b/Makefile.am @@ -0,0 +1,24 @@ + + +pkgconfigdir=$(libdir)/pkgconfig + +if OS_LINUX +pkgconfig_DATA=pc/hidapi-hidraw.pc pc/hidapi-libusb.pc +else +pkgconfig_DATA=pc/hidapi.pc +endif + + +SUBDIRS= + +if OS_LINUX +SUBDIRS += linux libusb +endif + +if OS_DARWIN +SUBDIRS += mac +endif + +if BUILD_TESTGUI +SUBDIRS += testgui +endif diff --git a/configure.ac b/configure.ac new file mode 100644 index 00000000..0b3cf22e --- /dev/null +++ b/configure.ac @@ -0,0 +1,103 @@ +AC_PREREQ([2.65]) +AC_INIT([hidapi], [0.8], [alan@signal11.us]) +AC_CONFIG_MACRO_DIR([m4]) +AM_INIT_AUTOMAKE([foreign -Wall -Werror]) +LT_INIT + + +AC_PROG_CC +AC_PROG_CXX +AC_PROG_RANLIB + +m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) + + +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" + + # HIDAPI/hidraw libs + PKG_CHECK_MODULES([libudev], [libudev]) + LIBS_HIDRAW_PR+=" $libudev_LIBS" + CFLAGS_HIDRAW+=" $libudev_CFLAGS" + AC_CHECK_LIB([rt], [clock_gettime], [LIBS_HIDRAW_PR+=" -lrt"]) + + # HIDAPI/libusb libs + PKG_CHECK_MODULES([libusb], [libusb-1.0]) + LIBS_LIBUSB_PRIVATE+=" $libusb_LIBS" + CFLAGS_LIBUSB+=" $libusb_CFLAGS" + AC_CHECK_LIB([rt], [clock_gettime], [LIBS_LIBUSB_PRIVATE+=" -lrt"]) + AC_CHECK_LIB([pthread], [pthread_create], [LIBS_LIBUSB_PRIVATE+=" -lpthread"]) + ;; +*-darwin*) + AC_MSG_RESULT([ (Mac OS X back-end)]) + AC_DEFINE(OS_DARWIN, 1, [Mac implementation]) + AC_SUBST(OS_DARWIN) + backend="darwin" + LIBS="${LIBS} -framework IOKit -framework CoreFoundation" + ;; +*-freebsd*) + AC_MSG_RESULT([ (FreeBSD back-end)]) + AC_DEFINE(OS_FREEBSD, 1, [FreeBSD implementation]) + AC_SUBST(OS_FREEBSD) + backend="freebsd" + PKG_CHECK_MODULES([libusb], [libusb]) + LIBS_LIBUSB_PRIVATE+=" $libusb_LIBS" + CFLAGS_LIBUSB+=" $libusb_CFLAGS" + AC_CHECK_LIB([pthread], [pthread_create], [LIBS_LIBUSB_PRIVATE+=" -lpthread"]) + AC_CHECK_LIB([iconv], [iconv_open], [LIBS_LIBUSB_PRIVATE+=" -liconv"]) + + CFLAGS="$CFLAGS -I/usr/local/include" + LDFLAGS="$LDFLAGS -I/usr/local/lib" + LIBS="${LIBS}" + ;; +*) + 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]) + +# 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"]) + +if test "x$testgui_enabled" != "xno"; then + PKG_CHECK_MODULES([fox], [fox]) + LIBS_TESTGUI+=" $fox_LIBS" + CFLAGS_TESTGUI+=" $fox_CFLAGS" +fi +AC_SUBST([LIBS_TESTGUI]) +AC_SUBST([CFLAGS_TESTGUI]) + + + +# OS info for Automake +AM_CONDITIONAL(OS_LINUX, test "x$backend" = xlinux) +AM_CONDITIONAL(OS_DARWIN, test "x$backend" = xdarwin) +AM_CONDITIONAL(OS_FREEBSD, test "x$backend" = xfreebsd) + +AC_CONFIG_HEADERS([config.h]) + +if test "x$backend" = "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_CONFIG_FILES([Makefile linux/Makefile libusb/Makefile mac/Makefile testgui/Makefile]) +AC_OUTPUT diff --git a/libusb/Makefile.am b/libusb/Makefile.am new file mode 100644 index 00000000..ab15a183 --- /dev/null +++ b/libusb/Makefile.am @@ -0,0 +1,8 @@ +lib_LTLIBRARIES = libhidapi-libusb.la +libhidapi_libusb_la_SOURCES = hid.c +libhidapi_libusb_la_LDFLAGS = -version-info 0:0:0 +AM_CPPFLAGS = -I$(srcdir)/../hidapi $(CFLAGS_LIBUSB) +libhidapi_libusb_la_LIBADD = $(LIBS_LIBUSB) + +hdrdir = $(includedir)/hidapi +hdr_HEADERS = $(srcdir)/../hidapi/hidapi.h diff --git a/linux/Makefile.am b/linux/Makefile.am new file mode 100644 index 00000000..8192a401 --- /dev/null +++ b/linux/Makefile.am @@ -0,0 +1,8 @@ +lib_LTLIBRARIES = libhidapi-hidraw.la +libhidapi_hidraw_la_SOURCES = hid.c +libhidapi_hidraw_la_LDFLAGS = -version-info 0:0:0 +AM_CPPFLAGS = -I$(srcdir)/../hidapi/ $(CFLAGS_HIDRAW) +libhidapi_hidraw_la_LIBADD = $(LIBS_HIDRAW) + +hdrdir = $(includedir)/hidapi +hdr_HEADERS = $(srcdir)/../hidapi/hidapi.h diff --git a/mac/Makefile.am b/mac/Makefile.am new file mode 100644 index 00000000..cc04ca9d --- /dev/null +++ b/mac/Makefile.am @@ -0,0 +1,8 @@ +lib_LTLIBRARIES = libhidapi.la +libhidapi_la_SOURCES = hid.c +libhidapi_la_LDFLAGS = -version-info 0:0:0 +AM_CPPFLAGS = -I../hidapi/ +#libhidapi_la_LIBADD = $(LIBS_HIDRAW) + +hdrdir = $(includedir)/hidapi +hdr_HEADERS = ../hidapi/hidapi.h diff --git a/testgui/Makefile.am b/testgui/Makefile.am new file mode 100644 index 00000000..fb096113 --- /dev/null +++ b/testgui/Makefile.am @@ -0,0 +1,29 @@ + +AM_CPPFLAGS = -I$(srcdir)/../hidapi/ $(CFLAGS_TESTGUI) + +## Linux +if OS_LINUX +bin_PROGRAMS = hidapi-hidraw-testgui hidapi-libusb-testgui + +hidapi_hidraw_testgui_SOURCES = test.cpp +hidapi_hidraw_testgui_LDADD = $(srcdir)/../linux/libhidapi-hidraw.la $(LIBS_TESTGUI) + +hidapi_libusb_testgui_SOURCES = test.cpp +hidapi_libusb_testgui_LDADD = $(srcdir)/../libusb/libhidapi-libusb.la $(LIBS_TESTGUI) +endif + +## Mac OS X +if OS_DARWIN +bin_PROGRAMS = hidapi-testgui + +hidapi_testgui_SOURCES = test.cpp +hidapi_testgui_LDADD = $(srcdir)/../mac/libhidapi.la $(LIBS_TESTGUI) +endif + +## FreeBSD +if OS_FREEBSD +bin_PROGRAMS = hidapi-testgui + +hidapi_testgui_SOURCES = test.cpp +hidapi_testgui_LDADD = $(srcdir)/../libusb/libhidapi.la $(LIBS_TESTGUI) +endif From 8f294eb1db29412c0c3f394a4c73a5bd883ec040 Mon Sep 17 00:00:00 2001 From: Alan Ott Date: Sat, 30 Jun 2012 11:34:26 -0400 Subject: [PATCH 02/47] pkg-config files --- pc/hidapi-hidraw.pc.in | 10 ++++++++++ pc/hidapi-libusb.pc.in | 10 ++++++++++ pc/hidapi.pc.in | 10 ++++++++++ 3 files changed, 30 insertions(+) create mode 100644 pc/hidapi-hidraw.pc.in create mode 100644 pc/hidapi-libusb.pc.in create mode 100644 pc/hidapi.pc.in diff --git a/pc/hidapi-hidraw.pc.in b/pc/hidapi-hidraw.pc.in new file mode 100644 index 00000000..b9b86d81 --- /dev/null +++ b/pc/hidapi-hidraw.pc.in @@ -0,0 +1,10 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: hidapi-hidraw +Description: C Library for USB/Bluetooth HID device access from Linux, Mac OS X, FreeBSD, and Windows. This is the hidraw implementation. +Version: @VERSION@ +Libs: -L${libdir} -lhidapi-hidraw +Cflags: -I{includedir}/hidapi diff --git a/pc/hidapi-libusb.pc.in b/pc/hidapi-libusb.pc.in new file mode 100644 index 00000000..353d61fc --- /dev/null +++ b/pc/hidapi-libusb.pc.in @@ -0,0 +1,10 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: hidapi-libusb +Description: C Library for USB HID device access from Linux, Mac OS X, FreeBSD, and Windows. This is the libusb implementation. +Version: @VERSION@ +Libs: -L${libdir} -lhidapi-libusb +Cflags: -I{includedir}/hidapi diff --git a/pc/hidapi.pc.in b/pc/hidapi.pc.in new file mode 100644 index 00000000..c25ea504 --- /dev/null +++ b/pc/hidapi.pc.in @@ -0,0 +1,10 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: hidapi +Description: C Library for USB/Bluetooth HID device access from Linux, Mac OS X, FreeBSD, and Windows. +Version: @VERSION@ +Libs: -L${libdir} -lhidapi +Cflags: -I{includedir}/hidapi From d3b9f157185ee53b045c4f60fc75e18d6b722b40 Mon Sep 17 00:00:00 2001 From: Alan Ott Date: Sat, 30 Jun 2012 16:11:23 -0400 Subject: [PATCH 03/47] Autotools support for mac platform. --- configure.ac | 17 +++++++++++++---- testgui/Makefile.am | 9 ++++++++- testgui/Makefile.mac | 12 ++++++------ testgui/copy_to_bundle.sh | 24 ++++++++++++++++++++---- 4 files changed, 47 insertions(+), 15 deletions(-) diff --git a/configure.ac b/configure.ac index 0b3cf22e..1907da75 100644 --- a/configure.ac +++ b/configure.ac @@ -7,7 +7,7 @@ LT_INIT AC_PROG_CC AC_PROG_CXX -AC_PROG_RANLIB +AC_PROG_OBJC m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) @@ -76,9 +76,18 @@ AC_ARG_ENABLE([testgui], AM_CONDITIONAL([BUILD_TESTGUI], [test "x$testgui_enabled" != "xno"]) if test "x$testgui_enabled" != "xno"; then - PKG_CHECK_MODULES([fox], [fox]) - LIBS_TESTGUI+=" $fox_LIBS" - CFLAGS_TESTGUI+=" $fox_CFLAGS" + if test "x$backend" = xdarwin; then + # On Mac OS, don't use pkg-config. + LIBS_TESTGUI+=`/opt/local/bin/fox-config --libs` + LIBS_TESTGUI+=" -framework Cocoa" + CFLAGS_TESTGUI+=`/opt/local/bin/fox-config --cflags` + OBJCFLAGS+=" -x objective-c++" + else + # On non-Mac platforms, use pkg-config to find fox. + PKG_CHECK_MODULES([fox], [fox]) + LIBS_TESTGUI+=" $fox_LIBS" + CFLAGS_TESTGUI+=" $fox_CFLAGS" + fi fi AC_SUBST([LIBS_TESTGUI]) AC_SUBST([CFLAGS_TESTGUI]) diff --git a/testgui/Makefile.am b/testgui/Makefile.am index fb096113..e4d7fc99 100644 --- a/testgui/Makefile.am +++ b/testgui/Makefile.am @@ -16,8 +16,15 @@ endif if OS_DARWIN bin_PROGRAMS = hidapi-testgui -hidapi_testgui_SOURCES = test.cpp +hidapi_testgui_SOURCES = test.cpp mac_support_cocoa.m hidapi_testgui_LDADD = $(srcdir)/../mac/libhidapi.la $(LIBS_TESTGUI) + +# Rules for copying the binary and its dependencies into the app bundle. +TestGUI.app/Contents/MacOS/hidapi-testgui$(EXEEXT): hidapi-testgui$(EXEEXT) + ./copy_to_bundle.sh + +all: all-am TestGUI.app/Contents/MacOS/hidapi-testgui$(EXEEXT) + endif ## FreeBSD diff --git a/testgui/Makefile.mac b/testgui/Makefile.mac index 8acd1e1c..218858d5 100644 --- a/testgui/Makefile.mac +++ b/testgui/Makefile.mac @@ -6,7 +6,7 @@ # 2010-07-03 ########################################### -all: testgui +all: hidapi-testgui CC=gcc CXX=g++ @@ -18,11 +18,11 @@ CFLAGS=-I../hidapi -Wall -g -c `fox-config --cflags` LIBS=`fox-config --libs` -framework IOKit -framework CoreFoundation -framework Cocoa -testgui: $(OBJS) - g++ -Wall -g $^ $(LIBS) -o testgui +hidapi-testgui: $(OBJS) + g++ -Wall -g $^ $(LIBS) -o hidapi-testgui ./copy_to_bundle.sh - #cp TestGUI.app/Contents/MacOS/testgui TestGUI.app/Contents/MacOS/tg - #cp start.sh TestGUI.app/Contents/MacOS/testgui + #cp TestGUI.app/Contents/MacOS/hidapi-testgui TestGUI.app/Contents/MacOS/tg + #cp start.sh TestGUI.app/Contents/MacOS/hidapi-testgui $(COBJS): %.o: %.c $(CC) $(CFLAGS) $< -o $@ @@ -35,6 +35,6 @@ $(OBJCOBJS): %.o: %.m clean: - rm $(OBJS) testgui + rm $(OBJS) hidapi-testgui .PHONY: clean diff --git a/testgui/copy_to_bundle.sh b/testgui/copy_to_bundle.sh index 3527af29..5e316d3f 100755 --- a/testgui/copy_to_bundle.sh +++ b/testgui/copy_to_bundle.sh @@ -3,9 +3,10 @@ #### Configuration: # The name of the executable. It is assumed # that it is in the current working directory. -EXE_NAME=testgui +EXE_NAME=hidapi-testgui # Path to the executable directory inside the bundle. -EXEPATH=./TestGUI.app/Contents/MacOS +# This must be an absolute path, so use $PWD. +EXEPATH=$PWD/TestGUI.app/Contents/MacOS # Libraries to explicitly bundle, even though they # may not be in /opt/local. One per line. These # are used with grep, so only a portion of the name @@ -75,6 +76,21 @@ function copydeps { } rm $EXEPATH/* -cp $EXE_NAME $EXEPATH -copydeps $EXEPATH/$EXE_NAME +# Copy the binary into the bundle. Use ../libtool to do this if it's +# available beacuse if $EXE_NAME was built with autotools, it will be +# necessary. If ../libtool not available, just use cp to do the copy, but +# only if $EXE_NAME is a binary. +if [ -x ../libtool ]; then + ../libtool --mode=install cp $EXE_NAME $EXEPATH +else + file -bI $EXE_NAME |grep binary + if [ $? -ne 0 ]; then + echo "There is no ../libtool and $EXE_NAME is not a binary." + echo "I'm not sure what to do." + exit 1 + else + cp $EXE_NAME $EXEPATH + fi +fi +copydeps $EXEPATH/$EXE_NAME From f2cbcbcb610746d886b4999ad2248a89d4c43af3 Mon Sep 17 00:00:00 2001 From: Alan Ott Date: Wed, 2 May 2012 23:08:09 -0400 Subject: [PATCH 04/47] Add missing $ to includedir path. --- pc/hidapi-hidraw.pc.in | 2 +- pc/hidapi-libusb.pc.in | 2 +- pc/hidapi.pc.in | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pc/hidapi-hidraw.pc.in b/pc/hidapi-hidraw.pc.in index b9b86d81..e20558d5 100644 --- a/pc/hidapi-hidraw.pc.in +++ b/pc/hidapi-hidraw.pc.in @@ -7,4 +7,4 @@ Name: hidapi-hidraw Description: C Library for USB/Bluetooth HID device access from Linux, Mac OS X, FreeBSD, and Windows. This is the hidraw implementation. Version: @VERSION@ Libs: -L${libdir} -lhidapi-hidraw -Cflags: -I{includedir}/hidapi +Cflags: -I${includedir}/hidapi diff --git a/pc/hidapi-libusb.pc.in b/pc/hidapi-libusb.pc.in index 353d61fc..2e495065 100644 --- a/pc/hidapi-libusb.pc.in +++ b/pc/hidapi-libusb.pc.in @@ -7,4 +7,4 @@ Name: hidapi-libusb Description: C Library for USB HID device access from Linux, Mac OS X, FreeBSD, and Windows. This is the libusb implementation. Version: @VERSION@ Libs: -L${libdir} -lhidapi-libusb -Cflags: -I{includedir}/hidapi +Cflags: -I${includedir}/hidapi diff --git a/pc/hidapi.pc.in b/pc/hidapi.pc.in index c25ea504..5835c99b 100644 --- a/pc/hidapi.pc.in +++ b/pc/hidapi.pc.in @@ -7,4 +7,4 @@ Name: hidapi Description: C Library for USB/Bluetooth HID device access from Linux, Mac OS X, FreeBSD, and Windows. Version: @VERSION@ Libs: -L${libdir} -lhidapi -Cflags: -I{includedir}/hidapi +Cflags: -I${includedir}/hidapi From 0e935a872ce24dca8851afe5df6ac25afbedc77a Mon Sep 17 00:00:00 2001 From: Alan Ott Date: Thu, 3 May 2012 03:07:37 -0400 Subject: [PATCH 05/47] Autotools integration on FreeBSD. --- Makefile.am | 9 +++++++++ configure.ac | 28 ++++++++++++++++++---------- libusb/Makefile.am | 12 +++++++++++- 3 files changed, 38 insertions(+), 11 deletions(-) diff --git a/Makefile.am b/Makefile.am index 81e5c855..4803d51c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,6 +1,11 @@ +if OS_FREEBSD +pkgconfigdir=$(prefix)/libdata/pkgconfig +else pkgconfigdir=$(libdir)/pkgconfig +echo $pkgconfigdir +endif if OS_LINUX pkgconfig_DATA=pc/hidapi-hidraw.pc pc/hidapi-libusb.pc @@ -19,6 +24,10 @@ if OS_DARWIN SUBDIRS += mac endif +if OS_FREEBSD +SUBDIRS += libusb +endif + if BUILD_TESTGUI SUBDIRS += testgui endif diff --git a/configure.ac b/configure.ac index 1907da75..dfa1b677 100644 --- a/configure.ac +++ b/configure.ac @@ -8,9 +8,17 @@ 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 +} AC_MSG_CHECKING([operating system]) AC_MSG_RESULT($host) @@ -46,15 +54,14 @@ case $host in AC_DEFINE(OS_FREEBSD, 1, [FreeBSD implementation]) AC_SUBST(OS_FREEBSD) backend="freebsd" - PKG_CHECK_MODULES([libusb], [libusb]) - LIBS_LIBUSB_PRIVATE+=" $libusb_LIBS" - CFLAGS_LIBUSB+=" $libusb_CFLAGS" - AC_CHECK_LIB([pthread], [pthread_create], [LIBS_LIBUSB_PRIVATE+=" -lpthread"]) - AC_CHECK_LIB([iconv], [iconv_open], [LIBS_LIBUSB_PRIVATE+=" -liconv"]) CFLAGS="$CFLAGS -I/usr/local/include" - LDFLAGS="$LDFLAGS -I/usr/local/lib" + LDFLAGS="$LDFLAGS -L/usr/local/lib" LIBS="${LIBS}" + AC_CHECK_LIB([usb], [libusb_init], [LIBS_LIBUSB_PRIVATE="${LIBS_LIBUSB_PRIVATE} -lusb"], [hidapi_lib_error libusb]) + AC_CHECK_LIB([pthread], [pthread_create], [LIBS_LIBUSB_PRIVATE="${LIBS_LIBUSB_PRIVATE} -lpthread"], [hidapi_lib_error libpthread]) + AC_CHECK_LIB([iconv], [iconv_open], [LIBS_LIBUSB_PRIVATE="${LIBS_LIBUSB_PRIVATE} -liconv"], [hidapi_lib_error libiconv]) + echo libs_priv: $LIBS_LIBUSB_PRIVATE ;; *) AC_MSG_ERROR([HIDAPI is not supported on your operating system yet]) @@ -85,15 +92,16 @@ if test "x$testgui_enabled" != "xno"; then else # On non-Mac platforms, use pkg-config to find fox. PKG_CHECK_MODULES([fox], [fox]) - LIBS_TESTGUI+=" $fox_LIBS" - CFLAGS_TESTGUI+=" $fox_CFLAGS" + LIBS_TESTGUI="${LIBS_TESTGUI} $fox_LIBS" + if test "x$backend" = 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]) - - # OS info for Automake AM_CONDITIONAL(OS_LINUX, test "x$backend" = xlinux) AM_CONDITIONAL(OS_DARWIN, test "x$backend" = xdarwin) diff --git a/libusb/Makefile.am b/libusb/Makefile.am index ab15a183..18451955 100644 --- a/libusb/Makefile.am +++ b/libusb/Makefile.am @@ -1,8 +1,18 @@ +AM_CPPFLAGS = -I$(srcdir)/../hidapi $(CFLAGS_LIBUSB) + +if OS_LINUX lib_LTLIBRARIES = libhidapi-libusb.la libhidapi_libusb_la_SOURCES = hid.c libhidapi_libusb_la_LDFLAGS = -version-info 0:0:0 -AM_CPPFLAGS = -I$(srcdir)/../hidapi $(CFLAGS_LIBUSB) libhidapi_libusb_la_LIBADD = $(LIBS_LIBUSB) +endif + +if OS_FREEBSD +lib_LTLIBRARIES = libhidapi.la +libhidapi_la_SOURCES = hid.c +libhidapi_la_LDFLAGS = -version-info 0:0:0 +libhidapi_la_LIBADD = $(LIBS_LIBUSB) +endif hdrdir = $(includedir)/hidapi hdr_HEADERS = $(srcdir)/../hidapi/hidapi.h From df05c6f2cc317e046764af398ff32a038e3d5f6c Mon Sep 17 00:00:00 2001 From: Alan Ott Date: Thu, 3 May 2012 03:08:07 -0400 Subject: [PATCH 06/47] Added .gitignore for autoconf-generated files. --- .gitignore | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..bbac37c9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,18 @@ + +# Autotools-added generated files +Makefile.in +aclocal.m4 +autom4te.cache/ +config.guess +config.h.in +config.sub +configure +depcomp +install-sh +libusb/Makefile.in +linux/Makefile.in +ltmain.sh +m4/ +mac/Makefile.in +missing +testgui/Makefile.in From 5436e70cded70d671195a25ffabb2388c633e660 Mon Sep 17 00:00:00 2001 From: Alan Ott Date: Sun, 1 Jul 2012 17:51:10 -0400 Subject: [PATCH 07/47] Add pkg.m4, because it's not a part of autoconf :( --- .gitignore | 1 - m4/.gitignore | 4 ++ m4/pkg.m4 | 157 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 161 insertions(+), 1 deletion(-) create mode 100644 m4/.gitignore create mode 100644 m4/pkg.m4 diff --git a/.gitignore b/.gitignore index bbac37c9..587a6532 100644 --- a/.gitignore +++ b/.gitignore @@ -12,7 +12,6 @@ install-sh libusb/Makefile.in linux/Makefile.in ltmain.sh -m4/ mac/Makefile.in missing testgui/Makefile.in diff --git a/m4/.gitignore b/m4/.gitignore new file mode 100644 index 00000000..d1cc719b --- /dev/null +++ b/m4/.gitignore @@ -0,0 +1,4 @@ +# Ignore All, except pkg.m4, and of course this file. +* +!.gitignore +!pkg.m4 diff --git a/m4/pkg.m4 b/m4/pkg.m4 new file mode 100644 index 00000000..0048a3fa --- /dev/null +++ b/m4/pkg.m4 @@ -0,0 +1,157 @@ +# pkg.m4 - Macros to locate and utilise pkg-config. -*- Autoconf -*- +# +# Copyright © 2004 Scott James Remnant . +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + +# PKG_PROG_PKG_CONFIG([MIN-VERSION]) +# ---------------------------------- +AC_DEFUN([PKG_PROG_PKG_CONFIG], +[m4_pattern_forbid([^_?PKG_[A-Z_]+$]) +m4_pattern_allow([^PKG_CONFIG(_PATH)?$]) +AC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility])dnl +if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then + AC_PATH_TOOL([PKG_CONFIG], [pkg-config]) +fi +if test -n "$PKG_CONFIG"; then + _pkg_min_version=m4_default([$1], [0.9.0]) + AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version]) + if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then + AC_MSG_RESULT([yes]) + else + AC_MSG_RESULT([no]) + PKG_CONFIG="" + fi + +fi[]dnl +])# PKG_PROG_PKG_CONFIG + +# PKG_CHECK_EXISTS(MODULES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) +# +# Check to see whether a particular set of modules exists. Similar +# to PKG_CHECK_MODULES(), but does not set variables or print errors. +# +# +# Similar to PKG_CHECK_MODULES, make sure that the first instance of +# this or PKG_CHECK_MODULES is called, or make sure to call +# PKG_CHECK_EXISTS manually +# -------------------------------------------------------------- +AC_DEFUN([PKG_CHECK_EXISTS], +[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl +if test -n "$PKG_CONFIG" && \ + AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$1"]); then + m4_ifval([$2], [$2], [:]) +m4_ifvaln([$3], [else + $3])dnl +fi]) + + +# _PKG_CONFIG([VARIABLE], [COMMAND], [MODULES]) +# --------------------------------------------- +m4_define([_PKG_CONFIG], +[if test -n "$PKG_CONFIG"; then + if test -n "$$1"; then + pkg_cv_[]$1="$$1" + else + PKG_CHECK_EXISTS([$3], + [pkg_cv_[]$1=`$PKG_CONFIG --[]$2 "$3" 2>/dev/null`], + [pkg_failed=yes]) + fi +else + pkg_failed=untried +fi[]dnl +])# _PKG_CONFIG + +# _PKG_SHORT_ERRORS_SUPPORTED +# ----------------------------- +AC_DEFUN([_PKG_SHORT_ERRORS_SUPPORTED], +[AC_REQUIRE([PKG_PROG_PKG_CONFIG]) +if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then + _pkg_short_errors_supported=yes +else + _pkg_short_errors_supported=no +fi[]dnl +])# _PKG_SHORT_ERRORS_SUPPORTED + + +# PKG_CHECK_MODULES(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND], +# [ACTION-IF-NOT-FOUND]) +# +# +# Note that if there is a possibility the first call to +# PKG_CHECK_MODULES might not happen, you should be sure to include an +# explicit call to PKG_PROG_PKG_CONFIG in your configure.ac +# +# +# -------------------------------------------------------------- +AC_DEFUN([PKG_CHECK_MODULES], +[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl +AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl +AC_ARG_VAR([$1][_LIBS], [linker flags for $1, overriding pkg-config])dnl + +pkg_failed=no +AC_MSG_CHECKING([for $1]) + +_PKG_CONFIG([$1][_CFLAGS], [cflags], [$2]) +_PKG_CONFIG([$1][_LIBS], [libs], [$2]) + +m4_define([_PKG_TEXT], [Alternatively, you may set the environment variables $1[]_CFLAGS +and $1[]_LIBS to avoid the need to call pkg-config. +See the pkg-config man page for more details.]) + +if test $pkg_failed = yes; then + _PKG_SHORT_ERRORS_SUPPORTED + if test $_pkg_short_errors_supported = yes; then + $1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --errors-to-stdout --print-errors "$2"` + else + $1[]_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors "$2"` + fi + # Put the nasty error message in config.log where it belongs + echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD + + ifelse([$4], , [AC_MSG_ERROR(dnl +[Package requirements ($2) were not met: + +$$1_PKG_ERRORS + +Consider adjusting the PKG_CONFIG_PATH environment variable if you +installed software in a non-standard prefix. + +_PKG_TEXT +])], + [AC_MSG_RESULT([no]) + $4]) +elif test $pkg_failed = untried; then + ifelse([$4], , [AC_MSG_FAILURE(dnl +[The pkg-config script could not be found or is too old. Make sure it +is in your PATH or set the PKG_CONFIG environment variable to the full +path to pkg-config. + +_PKG_TEXT + +To get pkg-config, see .])], + [$4]) +else + $1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS + $1[]_LIBS=$pkg_cv_[]$1[]_LIBS + AC_MSG_RESULT([yes]) + ifelse([$3], , :, [$3]) +fi[]dnl +])# PKG_CHECK_MODULES From 2a38afa0f0d2e0ecff4178a6ddedfb70a84d7fd2 Mon Sep 17 00:00:00 2001 From: Alan Ott Date: Sun, 1 Jul 2012 22:00:51 -0400 Subject: [PATCH 08/47] Remove errant echo in makefile --- Makefile.am | 1 - 1 file changed, 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index 4803d51c..433bd504 100644 --- a/Makefile.am +++ b/Makefile.am @@ -4,7 +4,6 @@ if OS_FREEBSD pkgconfigdir=$(prefix)/libdata/pkgconfig else pkgconfigdir=$(libdir)/pkgconfig -echo $pkgconfigdir endif if OS_LINUX From 1c2dde6e3ba29d67f013d1dfc702ea5d2d3a2d72 Mon Sep 17 00:00:00 2001 From: Alan Ott Date: Tue, 3 Jul 2012 02:18:14 +0800 Subject: [PATCH 09/47] Updated Makefile for MinGW. --- testgui/Makefile.mingw | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/testgui/Makefile.mingw b/testgui/Makefile.mingw index f01c13e1..d3bfac30 100644 --- a/testgui/Makefile.mingw +++ b/testgui/Makefile.mingw @@ -10,11 +10,11 @@ all: testgui CC=gcc CXX=g++ -COBJS= -CPPOBJS=../windows/hid.o test.o +COBJS=../windows/hid.o +CPPOBJS=test.o OBJS=$(COBJS) $(CPPOBJS) CFLAGS=-I../hidapi -I../../hidapi-externals/fox/include -g -c -LIBS= -lsetupapi -L../../hidapi-externals/fox/lib -lFOX-1.6 -lgdi32 -Wl,--enable-auto-import -lkernel32 +LIBS= -lsetupapi -L../../hidapi-externals/fox/lib -lFOX-1.6 -lgdi32 -Wl,--enable-auto-import -static-libgcc -static-libstdc++ -lkernel32 testgui: $(OBJS) From 96ce1aad70760efe345582c760ba638e360d7c80 Mon Sep 17 00:00:00 2001 From: Alan Ott Date: Tue, 3 Jul 2012 04:54:02 +0800 Subject: [PATCH 10/47] Change Makefile.mingw to create hidapi-testgui.exe --- testgui/Makefile.mingw | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/testgui/Makefile.mingw b/testgui/Makefile.mingw index d3bfac30..df0f69d1 100644 --- a/testgui/Makefile.mingw +++ b/testgui/Makefile.mingw @@ -6,7 +6,7 @@ # 2010-06-01 ########################################### -all: testgui +all: hidapi-testgui CC=gcc CXX=g++ @@ -14,11 +14,11 @@ COBJS=../windows/hid.o CPPOBJS=test.o OBJS=$(COBJS) $(CPPOBJS) CFLAGS=-I../hidapi -I../../hidapi-externals/fox/include -g -c -LIBS= -lsetupapi -L../../hidapi-externals/fox/lib -lFOX-1.6 -lgdi32 -Wl,--enable-auto-import -static-libgcc -static-libstdc++ -lkernel32 +LIBS= -mwindows -lsetupapi -L../../hidapi-externals/fox/lib -Wl,-Bstatic -lFOX-1.6 -Wl,-Bdynamic -lgdi32 -Wl,--enable-auto-import -static-libgcc -static-libstdc++ -lkernel32 -testgui: $(OBJS) - g++ -g $^ $(LIBS) -o testgui +hidapi-testgui: $(OBJS) + g++ -g $^ $(LIBS) -o hidapi-testgui $(COBJS): %.o: %.c $(CC) $(CFLAGS) $< -o $@ @@ -27,6 +27,6 @@ $(CPPOBJS): %.o: %.cpp $(CXX) $(CFLAGS) $< -o $@ clean: - rm *.o testgui.exe + rm -f *.o hidapi-testgui.exe .PHONY: clean From daebe52cd32651786d846ce0d20caa3fce98ae38 Mon Sep 17 00:00:00 2001 From: Alan Ott Date: Tue, 3 Jul 2012 12:18:11 +0800 Subject: [PATCH 11/47] Autotools on Windows --- Makefile.am | 6 +++++- configure.ac | 35 ++++++++++++++++++++++++++++++++--- testgui/Makefile.am | 8 ++++++++ windows/Makefile.am | 15 +++++++++++++++ windows/Makefile.mingw | 7 +++++-- 5 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 windows/Makefile.am diff --git a/Makefile.am b/Makefile.am index 4803d51c..4a5c6fc7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,10 +1,10 @@ +ACLOCAL_AMFLAGS = -I m4 if OS_FREEBSD pkgconfigdir=$(prefix)/libdata/pkgconfig else pkgconfigdir=$(libdir)/pkgconfig -echo $pkgconfigdir endif if OS_LINUX @@ -28,6 +28,10 @@ if OS_FREEBSD SUBDIRS += libusb endif +if OS_WINDOWS +SUBDIRS += windows +endif + if BUILD_TESTGUI SUBDIRS += testgui endif diff --git a/configure.ac b/configure.ac index dfa1b677..3123a3ba 100644 --- a/configure.ac +++ b/configure.ac @@ -2,9 +2,9 @@ AC_PREREQ([2.65]) AC_INIT([hidapi], [0.8], [alan@signal11.us]) AC_CONFIG_MACRO_DIR([m4]) AM_INIT_AUTOMAKE([foreign -Wall -Werror]) +AC_CONFIG_MACRO_DIR([m4]) LT_INIT - AC_PROG_CC AC_PROG_CXX AC_PROG_OBJC @@ -63,6 +63,16 @@ case $host in AC_CHECK_LIB([iconv], [iconv_open], [LIBS_LIBUSB_PRIVATE="${LIBS_LIBUSB_PRIVATE} -liconv"], [hidapi_lib_error libiconv]) echo libs_priv: $LIBS_LIBUSB_PRIVATE ;; +*-mingw*) + AC_MSG_RESULT([ (Windows back-end, using MinGW)]) + backend="windows" + win_implementation="mingw" + ;; +*-cygwin*) + AC_MSG_RESULT([ (Windows back-end, using Cygwin)]) + backend="windows" + win_implementation="cygwin" + ;; *) AC_MSG_ERROR([HIDAPI is not supported on your operating system yet]) esac @@ -74,6 +84,14 @@ AC_SUBST([LIBS_LIBUSB]) AC_SUBST([CFLAGS_LIBUSB]) AC_SUBST([CFLAGS_HIDRAW]) +if test "x$backend" = xwindows; then + AC_DEFINE(OS_WINDOWS, 1, [Windows implementations]) + AC_SUBST(OS_WINDOWS) + LDFLAGS="${LDFLAGS} -no-undefined" + LIBS="${LIBS} -lsetupapi" +fi + + # Test GUI AC_ARG_ENABLE([testgui], [AS_HELP_STRING([--enable-testgui], @@ -89,8 +107,18 @@ if test "x$testgui_enabled" != "xno"; then LIBS_TESTGUI+=" -framework Cocoa" CFLAGS_TESTGUI+=`/opt/local/bin/fox-config --cflags` OBJCFLAGS+=" -x objective-c++" + elif test "x$backend" = 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 non-Mac platforms, use pkg-config to find fox. + # On Linux and FreeBSD platforms, use pkg-config to find fox. PKG_CHECK_MODULES([fox], [fox]) LIBS_TESTGUI="${LIBS_TESTGUI} $fox_LIBS" if test "x$backend" = xfreebsd; then @@ -106,6 +134,7 @@ AC_SUBST([CFLAGS_TESTGUI]) AM_CONDITIONAL(OS_LINUX, test "x$backend" = xlinux) AM_CONDITIONAL(OS_DARWIN, test "x$backend" = xdarwin) AM_CONDITIONAL(OS_FREEBSD, test "x$backend" = xfreebsd) +AM_CONDITIONAL(OS_WINDOWS, test "x$backend" = xwindows) AC_CONFIG_HEADERS([config.h]) @@ -116,5 +145,5 @@ else AC_CONFIG_FILES([pc/hidapi.pc]) fi -AC_CONFIG_FILES([Makefile linux/Makefile libusb/Makefile mac/Makefile testgui/Makefile]) +AC_CONFIG_FILES([Makefile linux/Makefile libusb/Makefile mac/Makefile windows/Makefile testgui/Makefile]) AC_OUTPUT diff --git a/testgui/Makefile.am b/testgui/Makefile.am index e4d7fc99..21594908 100644 --- a/testgui/Makefile.am +++ b/testgui/Makefile.am @@ -34,3 +34,11 @@ bin_PROGRAMS = hidapi-testgui hidapi_testgui_SOURCES = test.cpp hidapi_testgui_LDADD = $(srcdir)/../libusb/libhidapi.la $(LIBS_TESTGUI) endif + +## Windows +if OS_WINDOWS +bin_PROGRAMS = hidapi-testgui + +hidapi_testgui_SOURCES = test.cpp +hidapi_testgui_LDADD = $(srcdir)/../windows/libhidapi.la $(LIBS_TESTGUI) +endif diff --git a/windows/Makefile.am b/windows/Makefile.am new file mode 100644 index 00000000..861e7433 --- /dev/null +++ b/windows/Makefile.am @@ -0,0 +1,15 @@ +lib_LTLIBRARIES = libhidapi.la +libhidapi_la_SOURCES = hid.c +libhidapi_la_LDFLAGS = -version-info 0:0:0 +AM_CPPFLAGS = -I$(srcdir)/../hidapi/ +libhidapi_la_LIBADD = $(LIBS) + +hdrdir = $(includedir)/hidapi +hdr_HEADERS = $(srcdir)/../hidapi/hidapi.h + +EXTRA_DIST = \ + ddk_build \ + hidapi.vcproj \ + hidtest.vcproj \ + Makefile.mingw \ + hidapi.sln diff --git a/windows/Makefile.mingw b/windows/Makefile.mingw index 3f133860..b8000041 100644 --- a/windows/Makefile.mingw +++ b/windows/Makefile.mingw @@ -6,7 +6,7 @@ # 2010-06-01 ########################################### -all: hidtest +all: hidtest libhidapi.dll CC=gcc CXX=g++ @@ -15,11 +15,14 @@ CPPOBJS=../hidtest/hidtest.o OBJS=$(COBJS) $(CPPOBJS) CFLAGS=-I../hidapi -g -c LIBS= -lsetupapi - +DLL_LDFLAGS = -mwindows -lsetupapi hidtest: $(OBJS) g++ -g $^ $(LIBS) -o hidtest +libhidapi.dll: $(OBJS) + $(CC) -g $^ $(DLL_LDFLAGS) -o libhidapi.dll + $(COBJS): %.o: %.c $(CC) $(CFLAGS) $< -o $@ From c97df4f756eb71743ba0a6ff39d67c43f83ee59f Mon Sep 17 00:00:00 2001 From: Alan Ott Date: Tue, 3 Jul 2012 00:31:05 -0400 Subject: [PATCH 12/47] extra_dist --- Makefile.am | 4 ++++ testgui/Makefile.am | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/Makefile.am b/Makefile.am index 4a5c6fc7..93631ef1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -35,3 +35,7 @@ endif if BUILD_TESTGUI SUBDIRS += testgui endif + +EXTRA_DIST = + +dist_doc_DATA = README.txt AUTHORS.txt diff --git a/testgui/Makefile.am b/testgui/Makefile.am index 21594908..0a3c9773 100644 --- a/testgui/Makefile.am +++ b/testgui/Makefile.am @@ -42,3 +42,13 @@ bin_PROGRAMS = hidapi-testgui hidapi_testgui_SOURCES = test.cpp hidapi_testgui_LDADD = $(srcdir)/../windows/libhidapi.la $(LIBS_TESTGUI) endif + +EXTRA_DIST = \ + copy_to_bundle.sh \ + Makefile.freebsd \ + Makefile.linux \ + Makefile.mac \ + Makefile.mingw \ + TestGUI.app/ \ + testgui.sln \ + testgui.vcproj From 15de3b5f403bbebfa9865ab0c128799aaeaa12ab Mon Sep 17 00:00:00 2001 From: Alan Ott Date: Tue, 3 Jul 2012 00:47:18 -0400 Subject: [PATCH 13/47] Update of .gitignore files --- libusb/.gitignore | 6 +++++- linux/.gitignore | 5 ++++- mac/.gitignore | 6 +++++- pc/.gitignore | 1 + testgui/.gitignore | 8 +++++++- 5 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 pc/.gitignore diff --git a/libusb/.gitignore b/libusb/.gitignore index ad92ec18..67460db9 100644 --- a/libusb/.gitignore +++ b/libusb/.gitignore @@ -1,4 +1,8 @@ *.o *.so -hidtest +*.la +*.lo +*.a +.libs +.deps hidtest-libusb diff --git a/linux/.gitignore b/linux/.gitignore index 5ce2baa3..127bf37d 100644 --- a/linux/.gitignore +++ b/linux/.gitignore @@ -12,4 +12,7 @@ Release *.o *.so hidtest-hidraw -hidtest-libusb +.deps +.libs +*.lo +*.la diff --git a/mac/.gitignore b/mac/.gitignore index 38276a52..7cc3f0d0 100644 --- a/mac/.gitignore +++ b/mac/.gitignore @@ -10,4 +10,8 @@ Release *.dll *.pdb *.o -hidtest \ No newline at end of file +hidapi-hidtest +.deps +.libs +*.la +*.lo diff --git a/pc/.gitignore b/pc/.gitignore new file mode 100644 index 00000000..6fd0ef02 --- /dev/null +++ b/pc/.gitignore @@ -0,0 +1 @@ +*.pc diff --git a/testgui/.gitignore b/testgui/.gitignore index 714527ff..11ef5e4a 100644 --- a/testgui/.gitignore +++ b/testgui/.gitignore @@ -10,4 +10,10 @@ Release *.dll *.pdb *.o -testgui \ No newline at end of file +hidapi-testgui +hidapi-hidraw-testgui +hidapi-libusb-testgui +.deps +.libs +*.la +*.lo From 0a20c9ba1f03204cb26c9291a6079a5c0fb28554 Mon Sep 17 00:00:00 2001 From: Alan Ott Date: Tue, 3 Jul 2012 00:47:50 -0400 Subject: [PATCH 14/47] update of .gitignore --- .gitignore | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.gitignore b/.gitignore index 587a6532..b033097e 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,13 @@ ltmain.sh mac/Makefile.in missing testgui/Makefile.in +windows/Makefile.in + +Makefile +autoscan.log +config.h +config.log +config.status +configure.scan +stamp-h1 +libtool From d2cc00ccaf27b2add2217d13b7ee56d0b6328b4a Mon Sep 17 00:00:00 2001 From: Alan Ott Date: Tue, 3 Jul 2012 00:56:01 -0400 Subject: [PATCH 15/47] Added EXTRA_DIST --- Makefile.am | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile.am b/Makefile.am index 93631ef1..baf07729 100644 --- a/Makefile.am +++ b/Makefile.am @@ -36,6 +36,6 @@ if BUILD_TESTGUI SUBDIRS += testgui endif -EXTRA_DIST = +EXTRA_DIST = udev doxygen -dist_doc_DATA = README.txt AUTHORS.txt +dist_doc_DATA = README.txt AUTHORS.txt LICENSE-bsd.txt LICENSE-gpl3.txt LICENSE-orig.txt LICENSE.txt From 15d4448d17da14941e909149850a31b773f36cef Mon Sep 17 00:00:00 2001 From: Alan Ott Date: Tue, 3 Jul 2012 00:57:13 -0400 Subject: [PATCH 16/47] Windows .gitignore --- windows/.gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/windows/.gitignore b/windows/.gitignore index 15ffee76..a3f6d875 100644 --- a/windows/.gitignore +++ b/windows/.gitignore @@ -9,3 +9,7 @@ Release *.suo *.dll *.pdb +.deps +.libs +*.lo +*.la From 631dedd3cb5aec057d334a98223ecf6f04ddca1f Mon Sep 17 00:00:00 2001 From: Alan Ott Date: Tue, 3 Jul 2012 11:06:57 -0400 Subject: [PATCH 17/47] added scm-clean target --- Makefile.am | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Makefile.am b/Makefile.am index baf07729..f8dc1d0b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -39,3 +39,32 @@ endif EXTRA_DIST = udev doxygen dist_doc_DATA = README.txt AUTHORS.txt LICENSE-bsd.txt LICENSE-gpl3.txt LICENSE-orig.txt LICENSE.txt + +SCMCLEAN_TARGETS= \ + aclocal.m4 \ + config.guess \ + config.sub \ + configure \ + config.h.in \ + depcomp \ + install-sh \ + ltmain.sh \ + missing \ + mac/Makefile.in \ + testgui/Makefile.in \ + libusb/Makefile.in \ + Makefile.in \ + linux/Makefile.in \ + windows/Makefile.in \ + m4/libtool.m4 \ + m4/lt~obsolete.m4 \ + m4/ltoptions.m4 \ + m4/ltsugar.m4 \ + m4/ltversion.m4 + +SCMCLEAN_DIR_TARGETS = \ + autom4te.cache + +scm-clean: distclean + rm -f $(SCMCLEAN_TARGETS) + rm -Rf $(SCMCLEAN_DIR_TARGETS) From 2d42a340594f0c86f4dc40e3bd60646e0b32ecbb Mon Sep 17 00:00:00 2001 From: Alan Ott Date: Tue, 3 Jul 2012 11:07:10 -0400 Subject: [PATCH 18/47] Added more generated files to .gitignore. --- .gitignore | 2 -- 1 file changed, 2 deletions(-) diff --git a/.gitignore b/.gitignore index b033097e..bc0410f0 100644 --- a/.gitignore +++ b/.gitignore @@ -18,10 +18,8 @@ testgui/Makefile.in windows/Makefile.in Makefile -autoscan.log config.h config.log config.status -configure.scan stamp-h1 libtool From bdcde3632cd47be78626ce5cbc75e170d924db40 Mon Sep 17 00:00:00 2001 From: Alan Ott Date: Tue, 3 Jul 2012 21:19:37 -0400 Subject: [PATCH 19/47] Autotools build files for hidtest example. --- Makefile.am | 3 ++- configure.ac | 2 +- hidtest/Makefile.am | 21 +++++++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 hidtest/Makefile.am diff --git a/Makefile.am b/Makefile.am index f8dc1d0b..360bd68f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -13,7 +13,6 @@ else pkgconfig_DATA=pc/hidapi.pc endif - SUBDIRS= if OS_LINUX @@ -32,6 +31,8 @@ if OS_WINDOWS SUBDIRS += windows endif +SUBDIRS += hidtest + if BUILD_TESTGUI SUBDIRS += testgui endif diff --git a/configure.ac b/configure.ac index 3123a3ba..5b54d038 100644 --- a/configure.ac +++ b/configure.ac @@ -145,5 +145,5 @@ else AC_CONFIG_FILES([pc/hidapi.pc]) fi -AC_CONFIG_FILES([Makefile linux/Makefile libusb/Makefile mac/Makefile windows/Makefile testgui/Makefile]) +AC_CONFIG_FILES([Makefile linux/Makefile libusb/Makefile mac/Makefile windows/Makefile hidtest/Makefile testgui/Makefile]) AC_OUTPUT diff --git a/hidtest/Makefile.am b/hidtest/Makefile.am new file mode 100644 index 00000000..c8e96649 --- /dev/null +++ b/hidtest/Makefile.am @@ -0,0 +1,21 @@ + +AM_CPPFLAGS = -I$(srcdir)/../hidapi/ + +## Linux +if OS_LINUX +noinst_PROGRAMS = hidtest-libusb hidtest-hidraw + +hidtest_hidraw_SOURCES = hidtest.cpp +hidtest_hidraw_LDADD = $(srcdir)/../linux/libhidapi-hidraw.la + +hidtest_libusb_SOURCES = hidtest.cpp +hidtest_libusb_LDADD = $(srcdir)/../libusb/libhidapi-libusb.la +else + +# Other OS's +noinst_PROGRAMS = hidtest + +hidtest_SOURCES = test.cpp +hidtest_LDADD = $(srcdir)/../windows/libhidapi.la + +endif From c0f28b1f4c877975e879732f489da5ea9bcd5173 Mon Sep 17 00:00:00 2001 From: Alan Ott Date: Tue, 3 Jul 2012 21:22:53 -0400 Subject: [PATCH 20/47] Updated README for new build system. --- README.txt | 227 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 177 insertions(+), 50 deletions(-) diff --git a/README.txt b/README.txt index 4dc0e1af..b971d78c 100644 --- a/README.txt +++ b/README.txt @@ -1,13 +1,14 @@ -HID API for Windows, Linux, FreeBSD and Mac OS X + HIDAPI library for Windows, Linux, FreeBSD and Mac OS X + ========================================================= About ------- +====== HIDAPI is a multi-platform library which allows an application to interface with USB and Bluetooth HID-Class devices on Windows, Linux, FreeBSD, and Mac -OS X. On Windows, a DLL is built. On other platforms (and optionally on -Windows), the single source file can simply be dropped into a target -application. +OS X. HIDAPI can be either built as a shared library (.so or .dll) or +can be embedded directly into a target application by adding a single source +file (per platform) and a single header. HIDAPI has four back-ends: * Windows (using hid.dll) @@ -32,15 +33,18 @@ Linux/FreeBSD/libusb (libusb/hid-libusb.c): This back-end uses libusb-1.0 to communicate directly to a USB device. This back-end will of course not work with Bluetooth devices. +HIDAPI also comes with a Test GUI. The Test GUI is cross-platform and uses +Fox Toolkit (http://www.fox-toolkit.org). It will build on every platform +which HIDAPI supports. Since it relies on a 3rd party library, building it +is optional but recommended because it is so useful when debugging hardware. + What Does the API Look Like? ------------------------------ +============================= The API provides the the most commonly used HID functions including sending and receiving of input, output, and feature reports. The sample program, -which communicates with a heavily modified version the USB Generic HID -sample which is part of the Microchip Application Library (in folder -"Microchip Solutions\USB Device - HID - Custom Demos\Generic HID - Firmware" -when the Microchip Application Framework is installed), looks like this -(with error checking removed for simplicity): +which communicates with a heavily hacked up version of the Microchip USB +Generic HID sample looks like this (with error checking removed for +simplicity): #include #include @@ -97,51 +101,174 @@ int main(int argc, char* argv[]) return 0; } +If you have your own simple test programs which communicate with standard +hardware development boards (such as those from Microchip, TI, Atmel, +FreeScale and others), please consider sending me something like the above +for inclusion into the HIDAPI source. This will help others who have the +same hardware as you do. + License --------- +======== HIDAPI may be used by one of three licenses as outlined in LICENSE.txt. Download ---------- -It can be downloaded from github +========= +HIDAPI can be downloaded from github git clone git://github.com/signal11/hidapi.git Build Instructions -------------------- -To build the console test program: - Windows: - Build the .sln file in the windows/ directory. - Linux: - For the hidraw implementation, cd to the linux/ directory and run make. - For the libusb implementation, cd to the libusb/ directory and run make. - FreeBSD: - cd to the libusb/ directory and run gmake. - Mac OS X: - cd to the mac/ directory and run make. - -To build the Test GUI: - The test GUI uses Fox toolkit, available from www.fox-toolkit.org. - On Debian-based systems such as Ubuntu, install Fox using the following: - sudo apt-get install libfox-1.6-dev - On FreeBSD, install iconv and Fox as root: - pkg_add -r gmake libiconv fox16 - On Mac OSX, install Fox from ports: - sudo port install fox - On Windows, download the hidapi-externals.zip file from the main download - site and extract it just outside of hidapi, so that hidapi-externals and - hidapi are on the same level, as shown: - - Parent_Folder - | - +hidapi - +hidapi-externals - - Then to build: - On Windows, build the .sln file in the testgui/ directory. - On Linux and Mac, run make from the testgui/ directory. - On FreeBSD, run gmake from the testgui/ directory. - -To build using the DDK (old method): +=================== + +This section is long. Don't be put off by this. It's not long because it's +complicated to build HIDAPI; it's quite the opposite. This section is long +because of the flexibility of HIDAPI and the large number of ways in which +it can be built and used. You will likely pick a single build method. + +HIDAPI can be built in several different ways. If you elect to build a +shared library, you will need to build it from the HIDAPI source +distribution. If you choose instead to embed HIDAPI directly into your +application, you can skip the building and look at the provided platform +Makefiles for guidance. These platform Makefiles are located in linux/ +libusb/ mac/ and windows/ and are called Makefile.PLATFORM where PLATFORM is +the name of the platform (eg: Makefile.linux or Makefile.mac). +In addition, Visual Studio projects are provided. Even if you're going to +embed HIDAPI into your project, it is still beneficial to build the example +programs. + + +Prerequisites: +--------------- + + Linux: + ------- + On Linux, you will need to install development packages for libudev, + libusb and optionally Fox-toolkit (for the test GUI). On + Debian/Ubuntu systems these can be installed by running: + sudo apt-get install libudev-dev libusb-1.0-0-dev libfox-1.6-dev + + If you downloaded the source directly from the git repository (using + git clone), you'll need Autotools: + sudo apt-get install autotools-dev + + FreeBSD: + --------- + On FreeBSD you will need to install GNU make, libiconv, and + optionally Fox-Toolkit (for the test GUI). This is done by running + the following: + pkg_add -r gmake libiconv fox16 + + If you downloaded the source directly from the git repository (using + git clone), you'll need Autotools: + pkg_add -r autotools + + Mac: + ----- + On Mac, you will need to install Fox-Toolkit if you wish to build + the Test GUI. There are two ways to do this, and each has a slight + complication. Which method you use depends on your use case. + + If you wish to build the Test GUI just for your own testing on your + own computer, then the easiest method is to install Fox-Toolkit + using ports: + sudo port install fox + + If you wish to build the TestGUI app bundle to redistribute to + others, you will need to install Fox-toolkit from source. This is + because the version of fox that gets installed using ports uses the + ports X11 libraries which are not compatible with the Apple X11 + libraries. If you install Fox with ports and then try to distribute + your built app bundle, it will simply fail to run on other systems. + To install Fox-Toolkit manually, download the source package from + http://www.fox-toolkit.org, extract it, and run the following from + within the extracted source: + ./configure && make && make install + + Windows: + --------- + On Windows, if you want to build the test GUI, you will need to get + the hidapi-externals.zip package from the download site. This + contains pre-built binaries for Fox-toolkit. Extract + hidapi-externals.zip just outside of hidapi, so that + hidapi-externals and hidapi are on the same level, as shown: + + Parent_Folder + | + +hidapi + +hidapi-externals + + Again, this step is not required if you do not wish to build the + test GUI. + + +Building HIDAPI into a shared library on Unix Platforms: +--------------------------------------------------------- + +On Unix-like systems such as Linux, FreeBSD, Mac, and even Windows, using +Mingw or Cygwin, the easiest way to build a standard system-installed shared +library is to use the GNU Autotools build system. If you checked out the +source from the git repository, run the following: + + ./bootstrap + ./configure + make + make install <----- as root, or using sudo + +If you downloaded a source package (ie: if you did not run git clone), you +can skip the ./bootstrap step. + +./configure can take several arguments which control the build. The two most +likely to be used are: + --enable-testgui + Enable build of the Test GUI. This requires Fox toolkit to + be installed. Instructions for installing Fox-Toolkit on + each platform are in the Prerequisites section above. + + --prefix=/usr + Specify where you want the output headers and libraries to + be installed. The example above will put the headers in + /usr/include and the binaries in /usr/lib. The default is to + install into /usr/local which is fine on most systems. + +Building the manual way on Unix platforms: +------------------------------------------- + +Manual Makefiles are provided mostly to give the user and idea what it takes +to build a program which embeds HIDAPI directly inside of it. These should +really be used as examples only. If you want to build a system-wide shared +library, use the Autotools method described above. + + To build HIDAPI using the manual makefiles, change to the directory + of your platform and run make: + cd linux/ make -F Makefile-manual + + To build the Test GUI using the manual makefiles: + cd testgui/ + make -F Makefile-manual + + +Building on Windows: +--------------------- + +To build the HIDAPI DLL on Windows using Visual Studio, build the .sln file +in the windows/ directory. + +To build the Test GUI on windows using Visual Studio, build the .sln file in +the testgui/ directory. + +To build HIDAPI using MinGW or Cygwin using Autotools, use the instructions +in the section titled "Building HIDAPI into a shared library on Unix +Platforms" above. Note that building the Test GUI with MinGW or Cygwin will +require the Windows procedure in the Prerequisites section above (ie: +hidapi-externals.zip). + +To build HIDAPI using MinGW using the Manual Makefiles, see the section +"Building the manual way on Unix platforms" above. + +HIDAPI can also be built using the Windows DDK (now also called the Windows +Driver Kit or WDK). This method was originally required for the HIDAPI build +but not anymore. However, some users still prefer this method. It is not as +well supported anymore but should still work. Patches are welcome if it does +not. To build using the DDK: 1. Install the Windows Driver Kit (WDK) from Microsoft. 2. From the Start menu, in the Windows Driver Kits folder, select Build @@ -154,9 +281,9 @@ To build using the DDK (old method): by the build system which is appropriate for your environment. On Windows XP, this directory is objfre_wxp_x86/i386. --------------------------------- Signal 11 Software - 2010-04-11 2010-07-28 2011-09-10 2012-05-01 + 2012-07-03 From f955396c0c1ee045a2a4c6b5b6bb678f7fe62db2 Mon Sep 17 00:00:00 2001 From: Alan Ott Date: Tue, 3 Jul 2012 21:28:22 -0400 Subject: [PATCH 21/47] Renamed manual makefiles so they're out of the way of autotools. --- libusb/{Makefile => Makefile-manual} | 0 linux/{Makefile => Makefile-manual} | 0 mac/{Makefile => Makefile-manual} | 0 testgui/{Makefile => Makefile-manual} | 0 windows/{Makefile => Makefile-manual} | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename libusb/{Makefile => Makefile-manual} (100%) rename linux/{Makefile => Makefile-manual} (100%) rename mac/{Makefile => Makefile-manual} (100%) rename testgui/{Makefile => Makefile-manual} (100%) rename windows/{Makefile => Makefile-manual} (100%) diff --git a/libusb/Makefile b/libusb/Makefile-manual similarity index 100% rename from libusb/Makefile rename to libusb/Makefile-manual diff --git a/linux/Makefile b/linux/Makefile-manual similarity index 100% rename from linux/Makefile rename to linux/Makefile-manual diff --git a/mac/Makefile b/mac/Makefile-manual similarity index 100% rename from mac/Makefile rename to mac/Makefile-manual diff --git a/testgui/Makefile b/testgui/Makefile-manual similarity index 100% rename from testgui/Makefile rename to testgui/Makefile-manual diff --git a/windows/Makefile b/windows/Makefile-manual similarity index 100% rename from windows/Makefile rename to windows/Makefile-manual From c42f65efca0fadcbc32d61cd96d40c55bdcacca5 Mon Sep 17 00:00:00 2001 From: Alan Ott Date: Tue, 3 Jul 2012 21:31:49 -0400 Subject: [PATCH 22/47] Fixed to refect Makefile-manual naming. --- README.txt | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/README.txt b/README.txt index b971d78c..ff8481eb 100644 --- a/README.txt +++ b/README.txt @@ -129,11 +129,9 @@ shared library, you will need to build it from the HIDAPI source distribution. If you choose instead to embed HIDAPI directly into your application, you can skip the building and look at the provided platform Makefiles for guidance. These platform Makefiles are located in linux/ -libusb/ mac/ and windows/ and are called Makefile.PLATFORM where PLATFORM is -the name of the platform (eg: Makefile.linux or Makefile.mac). -In addition, Visual Studio projects are provided. Even if you're going to -embed HIDAPI into your project, it is still beneficial to build the example -programs. +libusb/ mac/ and windows/ and are called Makefile-manual. In addition, +Visual Studio projects are provided. Even if you're going to embed HIDAPI +into your project, it is still beneficial to build the example programs. Prerequisites: @@ -238,13 +236,13 @@ really be used as examples only. If you want to build a system-wide shared library, use the Autotools method described above. To build HIDAPI using the manual makefiles, change to the directory - of your platform and run make: - cd linux/ make -F Makefile-manual + of your platform and run make. For example, on Linux run: + cd linux/ + make -f Makefile-manual To build the Test GUI using the manual makefiles: cd testgui/ - make -F Makefile-manual - + make -f Makefile-manual Building on Windows: --------------------- From 1c56f52223a8f3c078f0782d1fa2fbca5bf0bf15 Mon Sep 17 00:00:00 2001 From: Alan Ott Date: Tue, 3 Jul 2012 22:35:51 -0400 Subject: [PATCH 23/47] Added library versioning. --- configure.ac | 22 +++++++++++++++++++++- libusb/Makefile.am | 4 ++-- linux/Makefile.am | 2 +- mac/Makefile.am | 2 +- windows/Makefile.am | 2 +- 5 files changed, 26 insertions(+), 6 deletions(-) diff --git a/configure.ac b/configure.ac index 5b54d038..c1df3e49 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,23 @@ AC_PREREQ([2.65]) -AC_INIT([hidapi], [0.8], [alan@signal11.us]) + +# Version number. This is currently the only place. +m4_define([HIDAPI_MAJOR], 0) +m4_define([HIDAPI_MINOR], 7) +m4_define([HIDAPI_RELEASE], 0) +m4_define([HIDAPI_RC], +) +m4_define([VERSION_STRING], HIDAPI_MAJOR[.]HIDAPI_MINOR[.]HIDAPI_RELEASE[]HIDAPI_RC) + +AC_INIT([hidapi], VERSION_STRING, [alan@signal11.us]) + +# 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]) AC_CONFIG_MACRO_DIR([m4]) @@ -145,5 +163,7 @@ else AC_CONFIG_FILES([pc/hidapi.pc]) fi +AC_SUBST(LTLDFLAGS) + AC_CONFIG_FILES([Makefile linux/Makefile libusb/Makefile mac/Makefile windows/Makefile hidtest/Makefile testgui/Makefile]) AC_OUTPUT diff --git a/libusb/Makefile.am b/libusb/Makefile.am index 18451955..c821e382 100644 --- a/libusb/Makefile.am +++ b/libusb/Makefile.am @@ -3,14 +3,14 @@ AM_CPPFLAGS = -I$(srcdir)/../hidapi $(CFLAGS_LIBUSB) if OS_LINUX lib_LTLIBRARIES = libhidapi-libusb.la libhidapi_libusb_la_SOURCES = hid.c -libhidapi_libusb_la_LDFLAGS = -version-info 0:0:0 +libhidapi_libusb_la_LDFLAGS = $(LTLDFLAGS) libhidapi_libusb_la_LIBADD = $(LIBS_LIBUSB) endif if OS_FREEBSD lib_LTLIBRARIES = libhidapi.la libhidapi_la_SOURCES = hid.c -libhidapi_la_LDFLAGS = -version-info 0:0:0 +libhidapi_la_LDFLAGS = $(LTLDFLAGS) libhidapi_la_LIBADD = $(LIBS_LIBUSB) endif diff --git a/linux/Makefile.am b/linux/Makefile.am index 8192a401..44947107 100644 --- a/linux/Makefile.am +++ b/linux/Makefile.am @@ -1,6 +1,6 @@ lib_LTLIBRARIES = libhidapi-hidraw.la libhidapi_hidraw_la_SOURCES = hid.c -libhidapi_hidraw_la_LDFLAGS = -version-info 0:0:0 +libhidapi_hidraw_la_LDFLAGS = $(LTLDFLAGS) AM_CPPFLAGS = -I$(srcdir)/../hidapi/ $(CFLAGS_HIDRAW) libhidapi_hidraw_la_LIBADD = $(LIBS_HIDRAW) diff --git a/mac/Makefile.am b/mac/Makefile.am index cc04ca9d..d80c4609 100644 --- a/mac/Makefile.am +++ b/mac/Makefile.am @@ -1,6 +1,6 @@ lib_LTLIBRARIES = libhidapi.la libhidapi_la_SOURCES = hid.c -libhidapi_la_LDFLAGS = -version-info 0:0:0 +libhidapi_la_LDFLAGS = $(LTLDFLAGS) AM_CPPFLAGS = -I../hidapi/ #libhidapi_la_LIBADD = $(LIBS_HIDRAW) diff --git a/windows/Makefile.am b/windows/Makefile.am index 861e7433..025d5959 100644 --- a/windows/Makefile.am +++ b/windows/Makefile.am @@ -1,6 +1,6 @@ lib_LTLIBRARIES = libhidapi.la libhidapi_la_SOURCES = hid.c -libhidapi_la_LDFLAGS = -version-info 0:0:0 +libhidapi_la_LDFLAGS = $(LTLDFLAGS) AM_CPPFLAGS = -I$(srcdir)/../hidapi/ libhidapi_la_LIBADD = $(LIBS) From d9d077bf18d2134d367244a044096387173420da Mon Sep 17 00:00:00 2001 From: Alan Ott Date: Thu, 3 May 2012 03:20:09 -0400 Subject: [PATCH 24/47] Fix typos on non-Linux OS's --- hidtest/Makefile.am | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hidtest/Makefile.am b/hidtest/Makefile.am index c8e96649..7b1cf213 100644 --- a/hidtest/Makefile.am +++ b/hidtest/Makefile.am @@ -15,7 +15,7 @@ else # Other OS's noinst_PROGRAMS = hidtest -hidtest_SOURCES = test.cpp -hidtest_LDADD = $(srcdir)/../windows/libhidapi.la +hidtest_SOURCES = hidtest.cpp +hidtest_LDADD = $(srcdir)/../libusb/libhidapi.la endif From 1859e00935ec708cd179e0169f8b83a474c934d1 Mon Sep 17 00:00:00 2001 From: Alan Ott Date: Wed, 4 Jul 2012 00:00:06 -0400 Subject: [PATCH 25/47] Fixes for mac --- configure.ac | 28 +++++++++++++++++----------- hidtest/Makefile.am | 2 +- hidtest/hidtest.cpp | 2 +- testgui/Makefile.am | 29 +++++++---------------------- 4 files changed, 26 insertions(+), 35 deletions(-) diff --git a/configure.ac b/configure.ac index c1df3e49..7de1161c 100644 --- a/configure.ac +++ b/configure.ac @@ -46,6 +46,7 @@ case $host in AC_DEFINE(OS_LINUX, 1, [Linux implementations]) AC_SUBST(OS_LINUX) backend="linux" + os="linux" # HIDAPI/hidraw libs PKG_CHECK_MODULES([libudev], [libudev]) @@ -64,14 +65,16 @@ case $host in AC_MSG_RESULT([ (Mac OS X back-end)]) AC_DEFINE(OS_DARWIN, 1, [Mac implementation]) AC_SUBST(OS_DARWIN) - backend="darwin" + backend="mac" + os="darwin" LIBS="${LIBS} -framework IOKit -framework CoreFoundation" ;; *-freebsd*) AC_MSG_RESULT([ (FreeBSD back-end)]) AC_DEFINE(OS_FREEBSD, 1, [FreeBSD implementation]) AC_SUBST(OS_FREEBSD) - backend="freebsd" + backend="libusb" + os="freebsd" CFLAGS="$CFLAGS -I/usr/local/include" LDFLAGS="$LDFLAGS -L/usr/local/lib" @@ -84,11 +87,13 @@ case $host in *-mingw*) AC_MSG_RESULT([ (Windows back-end, using MinGW)]) backend="windows" + os="windows" win_implementation="mingw" ;; *-cygwin*) AC_MSG_RESULT([ (Windows back-end, using Cygwin)]) backend="windows" + os="windows" win_implementation="cygwin" ;; *) @@ -102,7 +107,7 @@ AC_SUBST([LIBS_LIBUSB]) AC_SUBST([CFLAGS_LIBUSB]) AC_SUBST([CFLAGS_HIDRAW]) -if test "x$backend" = xwindows; then +if test "x$os" = xwindows; then AC_DEFINE(OS_WINDOWS, 1, [Windows implementations]) AC_SUBST(OS_WINDOWS) LDFLAGS="${LDFLAGS} -no-undefined" @@ -119,13 +124,13 @@ AC_ARG_ENABLE([testgui], AM_CONDITIONAL([BUILD_TESTGUI], [test "x$testgui_enabled" != "xno"]) if test "x$testgui_enabled" != "xno"; then - if test "x$backend" = xdarwin; then + if test "x$os" = xdarwin; then # On Mac OS, don't use pkg-config. LIBS_TESTGUI+=`/opt/local/bin/fox-config --libs` LIBS_TESTGUI+=" -framework Cocoa" CFLAGS_TESTGUI+=`/opt/local/bin/fox-config --cflags` OBJCFLAGS+=" -x objective-c++" - elif test "x$backend" = xwindows; then + 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" @@ -139,7 +144,7 @@ if test "x$testgui_enabled" != "xno"; then # On Linux and FreeBSD platforms, use pkg-config to find fox. PKG_CHECK_MODULES([fox], [fox]) LIBS_TESTGUI="${LIBS_TESTGUI} $fox_LIBS" - if test "x$backend" = xfreebsd; then + if test "x$os" = xfreebsd; then LIBS_TESTGUI="${LIBS_TESTGUI} -L/usr/local/lib" fi CFLAGS_TESTGUI="${CFLAGS_TESTGUI} $fox_CFLAGS" @@ -147,16 +152,17 @@ if test "x$testgui_enabled" != "xno"; then fi AC_SUBST([LIBS_TESTGUI]) AC_SUBST([CFLAGS_TESTGUI]) +AC_SUBST([backend]) # OS info for Automake -AM_CONDITIONAL(OS_LINUX, test "x$backend" = xlinux) -AM_CONDITIONAL(OS_DARWIN, test "x$backend" = xdarwin) -AM_CONDITIONAL(OS_FREEBSD, test "x$backend" = xfreebsd) -AM_CONDITIONAL(OS_WINDOWS, test "x$backend" = xwindows) +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_WINDOWS, test "x$os" = xwindows) AC_CONFIG_HEADERS([config.h]) -if test "x$backend" = "xlinux"; then +if test "x$os" = "xlinux"; then AC_CONFIG_FILES([pc/hidapi-hidraw.pc]) AC_CONFIG_FILES([pc/hidapi-libusb.pc]) else diff --git a/hidtest/Makefile.am b/hidtest/Makefile.am index 7b1cf213..a4c1f769 100644 --- a/hidtest/Makefile.am +++ b/hidtest/Makefile.am @@ -16,6 +16,6 @@ else noinst_PROGRAMS = hidtest hidtest_SOURCES = hidtest.cpp -hidtest_LDADD = $(srcdir)/../libusb/libhidapi.la +hidtest_LDADD = $(srcdir)/../$(backend)/libhidapi.la endif diff --git a/hidtest/hidtest.cpp b/hidtest/hidtest.cpp index cb4fa559..71245c89 100644 --- a/hidtest/hidtest.cpp +++ b/hidtest/hidtest.cpp @@ -66,7 +66,7 @@ int main(int argc, char* argv[]) // Open the device using the VID, PID, // and optionally the Serial number. ////handle = hid_open(0x4d8, 0x3f, L"12345"); - handle = hid_open(0x4d8, 0x3f, NULL); + handle = hid_open(0x46d, 0xc216, NULL); if (!handle) { printf("unable to open device\n"); return 1; diff --git a/testgui/Makefile.am b/testgui/Makefile.am index 0a3c9773..f59847d1 100644 --- a/testgui/Makefile.am +++ b/testgui/Makefile.am @@ -1,8 +1,8 @@ AM_CPPFLAGS = -I$(srcdir)/../hidapi/ $(CFLAGS_TESTGUI) -## Linux if OS_LINUX +## Linux bin_PROGRAMS = hidapi-hidraw-testgui hidapi-libusb-testgui hidapi_hidraw_testgui_SOURCES = test.cpp @@ -10,15 +10,16 @@ hidapi_hidraw_testgui_LDADD = $(srcdir)/../linux/libhidapi-hidraw.la $(LIBS_TEST hidapi_libusb_testgui_SOURCES = test.cpp hidapi_libusb_testgui_LDADD = $(srcdir)/../libusb/libhidapi-libusb.la $(LIBS_TESTGUI) +else +## Other OS's +bin_PROGRAMS = hidapi-testgui + +hidapi_testgui_SOURCES = test.cpp +hidapi_testgui_LDADD = $(srcdir)/../$(backend)/libhidapi.la $(LIBS_TESTGUI) endif -## Mac OS X if OS_DARWIN -bin_PROGRAMS = hidapi-testgui - hidapi_testgui_SOURCES = test.cpp mac_support_cocoa.m -hidapi_testgui_LDADD = $(srcdir)/../mac/libhidapi.la $(LIBS_TESTGUI) - # Rules for copying the binary and its dependencies into the app bundle. TestGUI.app/Contents/MacOS/hidapi-testgui$(EXEEXT): hidapi-testgui$(EXEEXT) ./copy_to_bundle.sh @@ -27,22 +28,6 @@ all: all-am TestGUI.app/Contents/MacOS/hidapi-testgui$(EXEEXT) endif -## FreeBSD -if OS_FREEBSD -bin_PROGRAMS = hidapi-testgui - -hidapi_testgui_SOURCES = test.cpp -hidapi_testgui_LDADD = $(srcdir)/../libusb/libhidapi.la $(LIBS_TESTGUI) -endif - -## Windows -if OS_WINDOWS -bin_PROGRAMS = hidapi-testgui - -hidapi_testgui_SOURCES = test.cpp -hidapi_testgui_LDADD = $(srcdir)/../windows/libhidapi.la $(LIBS_TESTGUI) -endif - EXTRA_DIST = \ copy_to_bundle.sh \ Makefile.freebsd \ From d6a9953a57fa84ad23fb290caa07aac076aa05cf Mon Sep 17 00:00:00 2001 From: Alan Ott Date: Wed, 4 Jul 2012 00:25:46 -0400 Subject: [PATCH 26/47] bootstrap script --- bootstrap | 1 + 1 file changed, 1 insertion(+) create mode 100755 bootstrap diff --git a/bootstrap b/bootstrap new file mode 100755 index 00000000..1e99d714 --- /dev/null +++ b/bootstrap @@ -0,0 +1 @@ +autoreconf -ivf From de09917de2e074e61ec01d777f7f73bb7a2d9338 Mon Sep 17 00:00:00 2001 From: Ludovic Rousseau Date: Wed, 4 Jul 2012 09:40:38 +0200 Subject: [PATCH 27/47] Add missing Fixed by autoupdate --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 7de1161c..b76d98ea 100644 --- a/configure.ac +++ b/configure.ac @@ -7,7 +7,7 @@ m4_define([HIDAPI_RELEASE], 0) m4_define([HIDAPI_RC], +) m4_define([VERSION_STRING], HIDAPI_MAJOR[.]HIDAPI_MINOR[.]HIDAPI_RELEASE[]HIDAPI_RC) -AC_INIT([hidapi], VERSION_STRING, [alan@signal11.us]) +AC_INIT([hidapi],[VERSION_STRING],[alan@signal11.us]) # Library soname version # Follow the following rules (particularly the ones in the second link): From 24d70e657cc463491590c400b2b4919d8da49b17 Mon Sep 17 00:00:00 2001 From: Ludovic Rousseau Date: Wed, 4 Jul 2012 09:45:10 +0200 Subject: [PATCH 28/47] Reformat AC_CONFIG_FILES() files Use only 1 file per line --- configure.ac | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index b76d98ea..4cfff6ad 100644 --- a/configure.ac +++ b/configure.ac @@ -171,5 +171,11 @@ fi AC_SUBST(LTLDFLAGS) -AC_CONFIG_FILES([Makefile linux/Makefile libusb/Makefile mac/Makefile windows/Makefile hidtest/Makefile testgui/Makefile]) +AC_CONFIG_FILES([Makefile \ + hidtest/Makefile \ + libusb/Makefile \ + linux/Makefile \ + mac/Makefile \ + testgui/Makefile \ + windows/Makefile]) AC_OUTPUT From 1a4bbbc01a4dc89452ac5b85984a85c254b4fb1f Mon Sep 17 00:00:00 2001 From: Ludovic Rousseau Date: Wed, 4 Jul 2012 09:51:22 +0200 Subject: [PATCH 29/47] Use $(top_srcdir) to reference a source file The build directory may be different from the source directory. --- mac/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mac/Makefile.am b/mac/Makefile.am index d80c4609..e9dcb6b6 100644 --- a/mac/Makefile.am +++ b/mac/Makefile.am @@ -1,7 +1,7 @@ lib_LTLIBRARIES = libhidapi.la libhidapi_la_SOURCES = hid.c libhidapi_la_LDFLAGS = $(LTLDFLAGS) -AM_CPPFLAGS = -I../hidapi/ +AM_CPPFLAGS = -I$(top_srcdir)/hidapi/ #libhidapi_la_LIBADD = $(LIBS_HIDRAW) hdrdir = $(includedir)/hidapi From 6c9d6ec0fd421be110dad249e4bcff2d4734aabd Mon Sep 17 00:00:00 2001 From: Ludovic Rousseau Date: Wed, 4 Jul 2012 09:52:50 +0200 Subject: [PATCH 30/47] Use $(top_builddir) to reference a built .la The build directory may be different from the source directory. --- hidtest/Makefile.am | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/hidtest/Makefile.am b/hidtest/Makefile.am index a4c1f769..364efe1a 100644 --- a/hidtest/Makefile.am +++ b/hidtest/Makefile.am @@ -1,4 +1,3 @@ - AM_CPPFLAGS = -I$(srcdir)/../hidapi/ ## Linux @@ -6,16 +5,16 @@ if OS_LINUX noinst_PROGRAMS = hidtest-libusb hidtest-hidraw hidtest_hidraw_SOURCES = hidtest.cpp -hidtest_hidraw_LDADD = $(srcdir)/../linux/libhidapi-hidraw.la +hidtest_hidraw_LDADD = $(top_builddir)/linux/libhidapi-hidraw.la hidtest_libusb_SOURCES = hidtest.cpp -hidtest_libusb_LDADD = $(srcdir)/../libusb/libhidapi-libusb.la +hidtest_libusb_LDADD = $(top_builddir)/libusb/libhidapi-libusb.la else # Other OS's noinst_PROGRAMS = hidtest hidtest_SOURCES = hidtest.cpp -hidtest_LDADD = $(srcdir)/../$(backend)/libhidapi.la +hidtest_LDADD = $(top_builddir)/$(backend)/libhidapi.la endif From 7174a28e926a03c4908f435ae959e5aeda857b81 Mon Sep 17 00:00:00 2001 From: Alan Ott Date: Wed, 4 Jul 2012 09:21:00 -0400 Subject: [PATCH 31/47] Fix from autoupdate --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 4cfff6ad..f9688ce3 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_PREREQ([2.65]) +AC_PREREQ(2.65) # Version number. This is currently the only place. m4_define([HIDAPI_MAJOR], 0) From e1becc53b27976a358bf2c30d28be85df09a6f59 Mon Sep 17 00:00:00 2001 From: Alan Ott Date: Wed, 4 Jul 2012 10:01:54 -0400 Subject: [PATCH 32/47] Reference all source files from $(top_srcdir) and built libraries from $(top_builddir) --- hidtest/Makefile.am | 2 +- libusb/Makefile.am | 4 ++-- linux/Makefile.am | 4 ++-- mac/Makefile.am | 3 +-- testgui/Makefile.am | 8 ++++---- windows/Makefile.am | 4 ++-- 6 files changed, 12 insertions(+), 13 deletions(-) diff --git a/hidtest/Makefile.am b/hidtest/Makefile.am index 364efe1a..d2786445 100644 --- a/hidtest/Makefile.am +++ b/hidtest/Makefile.am @@ -1,4 +1,4 @@ -AM_CPPFLAGS = -I$(srcdir)/../hidapi/ +AM_CPPFLAGS = -I$(top_srcdir)/hidapi/ ## Linux if OS_LINUX diff --git a/libusb/Makefile.am b/libusb/Makefile.am index c821e382..f7c53a4c 100644 --- a/libusb/Makefile.am +++ b/libusb/Makefile.am @@ -1,4 +1,4 @@ -AM_CPPFLAGS = -I$(srcdir)/../hidapi $(CFLAGS_LIBUSB) +AM_CPPFLAGS = -I$(top_srcdir)/hidapi $(CFLAGS_LIBUSB) if OS_LINUX lib_LTLIBRARIES = libhidapi-libusb.la @@ -15,4 +15,4 @@ libhidapi_la_LIBADD = $(LIBS_LIBUSB) endif hdrdir = $(includedir)/hidapi -hdr_HEADERS = $(srcdir)/../hidapi/hidapi.h +hdr_HEADERS = $(top_srcdir)/hidapi/hidapi.h diff --git a/linux/Makefile.am b/linux/Makefile.am index 44947107..640adc18 100644 --- a/linux/Makefile.am +++ b/linux/Makefile.am @@ -1,8 +1,8 @@ lib_LTLIBRARIES = libhidapi-hidraw.la libhidapi_hidraw_la_SOURCES = hid.c libhidapi_hidraw_la_LDFLAGS = $(LTLDFLAGS) -AM_CPPFLAGS = -I$(srcdir)/../hidapi/ $(CFLAGS_HIDRAW) +AM_CPPFLAGS = -I$(top_srcdir)/hidapi/ $(CFLAGS_HIDRAW) libhidapi_hidraw_la_LIBADD = $(LIBS_HIDRAW) hdrdir = $(includedir)/hidapi -hdr_HEADERS = $(srcdir)/../hidapi/hidapi.h +hdr_HEADERS = $(top_srcdir)/hidapi/hidapi.h diff --git a/mac/Makefile.am b/mac/Makefile.am index e9dcb6b6..bf1f6897 100644 --- a/mac/Makefile.am +++ b/mac/Makefile.am @@ -2,7 +2,6 @@ lib_LTLIBRARIES = libhidapi.la libhidapi_la_SOURCES = hid.c libhidapi_la_LDFLAGS = $(LTLDFLAGS) AM_CPPFLAGS = -I$(top_srcdir)/hidapi/ -#libhidapi_la_LIBADD = $(LIBS_HIDRAW) hdrdir = $(includedir)/hidapi -hdr_HEADERS = ../hidapi/hidapi.h +hdr_HEADERS = $(top_srcdir)/hidapi/hidapi.h diff --git a/testgui/Makefile.am b/testgui/Makefile.am index f59847d1..6d2d0067 100644 --- a/testgui/Makefile.am +++ b/testgui/Makefile.am @@ -1,21 +1,21 @@ -AM_CPPFLAGS = -I$(srcdir)/../hidapi/ $(CFLAGS_TESTGUI) +AM_CPPFLAGS = -I$(top_srcdir)/hidapi/ $(CFLAGS_TESTGUI) if OS_LINUX ## Linux bin_PROGRAMS = hidapi-hidraw-testgui hidapi-libusb-testgui hidapi_hidraw_testgui_SOURCES = test.cpp -hidapi_hidraw_testgui_LDADD = $(srcdir)/../linux/libhidapi-hidraw.la $(LIBS_TESTGUI) +hidapi_hidraw_testgui_LDADD = $(top_builddir)/linux/libhidapi-hidraw.la $(LIBS_TESTGUI) hidapi_libusb_testgui_SOURCES = test.cpp -hidapi_libusb_testgui_LDADD = $(srcdir)/../libusb/libhidapi-libusb.la $(LIBS_TESTGUI) +hidapi_libusb_testgui_LDADD = $(top_builddir)/libusb/libhidapi-libusb.la $(LIBS_TESTGUI) else ## Other OS's bin_PROGRAMS = hidapi-testgui hidapi_testgui_SOURCES = test.cpp -hidapi_testgui_LDADD = $(srcdir)/../$(backend)/libhidapi.la $(LIBS_TESTGUI) +hidapi_testgui_LDADD = $(top_builddir)/$(backend)/libhidapi.la $(LIBS_TESTGUI) endif if OS_DARWIN diff --git a/windows/Makefile.am b/windows/Makefile.am index 025d5959..947b5295 100644 --- a/windows/Makefile.am +++ b/windows/Makefile.am @@ -1,11 +1,11 @@ lib_LTLIBRARIES = libhidapi.la libhidapi_la_SOURCES = hid.c libhidapi_la_LDFLAGS = $(LTLDFLAGS) -AM_CPPFLAGS = -I$(srcdir)/../hidapi/ +AM_CPPFLAGS = -I$(top_srcdir)/hidapi/ libhidapi_la_LIBADD = $(LIBS) hdrdir = $(includedir)/hidapi -hdr_HEADERS = $(srcdir)/../hidapi/hidapi.h +hdr_HEADERS = $(top_srcdir)/hidapi/hidapi.h EXTRA_DIST = \ ddk_build \ From 20dfbfdc33945309d2745f211b6323ed32f4b9f8 Mon Sep 17 00:00:00 2001 From: Alan Ott Date: Thu, 5 Jul 2012 01:49:30 +0800 Subject: [PATCH 33/47] Change to long parameters in bootstrap --- bootstrap | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bootstrap b/bootstrap index 1e99d714..81e9b74b 100755 --- a/bootstrap +++ b/bootstrap @@ -1 +1,2 @@ -autoreconf -ivf +#!/bin/sh -x +autoreconf --install --verbose --force From 8755c66702acdf0fcba3afb921ac00f9b6f9792b Mon Sep 17 00:00:00 2001 From: Alan Ott Date: Thu, 5 Jul 2012 02:01:30 +0800 Subject: [PATCH 34/47] added AM_PROG_LD under m4_ifdef. From Ludovic Rousseau --- configure.ac | 3 +++ 1 file changed, 3 insertions(+) diff --git a/configure.ac b/configure.ac index f9688ce3..ba742909 100644 --- a/configure.ac +++ b/configure.ac @@ -21,6 +21,8 @@ LTLDFLAGS="-version-info ${lt_current}:${lt_revision}:${lt_age}" AC_CONFIG_MACRO_DIR([m4]) AM_INIT_AUTOMAKE([foreign -Wall -Werror]) AC_CONFIG_MACRO_DIR([m4]) + +m4_ifdef([AM_PROG_AR], [AM_PROG_AR]) LT_INIT AC_PROG_CC @@ -28,6 +30,7 @@ AC_PROG_CXX AC_PROG_OBJC PKG_PROG_PKG_CONFIG + m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) hidapi_lib_error() { From 45b734bea25eeb38a2aa7fb1c007a3bd908e4067 Mon Sep 17 00:00:00 2001 From: Alan Ott Date: Thu, 5 Jul 2012 02:27:26 +0800 Subject: [PATCH 35/47] .gitattributes for line endings --- .gitattributes | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..275fdda2 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,4 @@ +* text=auto + +bootstrap text eol=lf +configure.ac text eol=lf From ea3d8278ef7b5aba68e341369bad01547bb5cbf0 Mon Sep 17 00:00:00 2001 From: Alan Ott Date: Wed, 4 Jul 2012 14:30:14 -0400 Subject: [PATCH 36/47] added vcproj and sln as crlf to .gitattributes --- .gitattributes | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitattributes b/.gitattributes index 275fdda2..edb79feb 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,4 +1,7 @@ * text=auto +*.sln text eol=crlf +*.vcproj text eol=crlf + bootstrap text eol=lf configure.ac text eol=lf From 2b2411079e387c9e1e8498ab3beeb90b11153d18 Mon Sep 17 00:00:00 2001 From: Alan Ott Date: Wed, 4 Jul 2012 14:54:05 -0400 Subject: [PATCH 37/47] Add built files in hidtest/ to .gitignore --- hidtest/.gitignore | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hidtest/.gitignore b/hidtest/.gitignore index ce4c15d9..a9ce7a23 100644 --- a/hidtest/.gitignore +++ b/hidtest/.gitignore @@ -10,3 +10,8 @@ Release *.dll *.pdb *.o +.deps/ +.libs/ +hidtest-hidraw +hidtest-libusb +hidtest From 4c3db1104547a6b04511c8b84d7a4ac149d89271 Mon Sep 17 00:00:00 2001 From: Alan Ott Date: Thu, 5 Jul 2012 00:26:56 -0400 Subject: [PATCH 38/47] Added Makefile-manual to EXTRA_DIST --- libusb/Makefile.am | 2 ++ linux/Makefile.am | 2 ++ mac/Makefile.am | 2 ++ testgui/Makefile.am | 1 + windows/Makefile.am | 1 + 5 files changed, 8 insertions(+) diff --git a/libusb/Makefile.am b/libusb/Makefile.am index f7c53a4c..7f6c9dc1 100644 --- a/libusb/Makefile.am +++ b/libusb/Makefile.am @@ -16,3 +16,5 @@ endif hdrdir = $(includedir)/hidapi hdr_HEADERS = $(top_srcdir)/hidapi/hidapi.h + +EXTRA_DIST = Makefile-manual diff --git a/linux/Makefile.am b/linux/Makefile.am index 640adc18..230eeb75 100644 --- a/linux/Makefile.am +++ b/linux/Makefile.am @@ -6,3 +6,5 @@ libhidapi_hidraw_la_LIBADD = $(LIBS_HIDRAW) hdrdir = $(includedir)/hidapi hdr_HEADERS = $(top_srcdir)/hidapi/hidapi.h + +EXTRA_DIST = Makefile-manual diff --git a/mac/Makefile.am b/mac/Makefile.am index bf1f6897..23d96e08 100644 --- a/mac/Makefile.am +++ b/mac/Makefile.am @@ -5,3 +5,5 @@ AM_CPPFLAGS = -I$(top_srcdir)/hidapi/ hdrdir = $(includedir)/hidapi hdr_HEADERS = $(top_srcdir)/hidapi/hidapi.h + +EXTRA_DIST = Makefile-manual diff --git a/testgui/Makefile.am b/testgui/Makefile.am index 6d2d0067..0604da1c 100644 --- a/testgui/Makefile.am +++ b/testgui/Makefile.am @@ -30,6 +30,7 @@ endif EXTRA_DIST = \ copy_to_bundle.sh \ + Makefile-manual \ Makefile.freebsd \ Makefile.linux \ Makefile.mac \ diff --git a/windows/Makefile.am b/windows/Makefile.am index 947b5295..97e261ac 100644 --- a/windows/Makefile.am +++ b/windows/Makefile.am @@ -11,5 +11,6 @@ EXTRA_DIST = \ ddk_build \ hidapi.vcproj \ hidtest.vcproj \ + Makefile-manual \ Makefile.mingw \ hidapi.sln From dee41ec751f06fd69ef79568d5aadda460156f6f Mon Sep 17 00:00:00 2001 From: Alan Ott Date: Sat, 7 Jul 2012 11:38:11 -0400 Subject: [PATCH 39/47] Fix bugs where it wouldn't build the testgui with non-ports Fox-toolkit. Thanks to Xiaofan chen for pointing this out. --- configure.ac | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index ba742909..74d301ad 100644 --- a/configure.ac +++ b/configure.ac @@ -41,6 +41,15 @@ hidapi_lib_error() { 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 @@ -129,9 +138,13 @@ AM_CONDITIONAL([BUILD_TESTGUI], [test "x$testgui_enabled" != "xno"]) if test "x$testgui_enabled" != "xno"; then if test "x$os" = xdarwin; then # On Mac OS, don't use pkg-config. - LIBS_TESTGUI+=`/opt/local/bin/fox-config --libs` - LIBS_TESTGUI+=" -framework Cocoa" - CFLAGS_TESTGUI+=`/opt/local/bin/fox-config --cflags` + 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+=`$foxconfig --libs` + LIBS_TESTGUI+=" -framework Cocoa -L/usr/X11R6/lib" + CFLAGS_TESTGUI+=`$foxconfig --cflags` OBJCFLAGS+=" -x objective-c++" elif test "x$os" = xwindows; then # On Windows, just set the paths for Fox toolkit From 6f08c09f85798e26ba0560c8784e8d191f72b4f3 Mon Sep 17 00:00:00 2001 From: Alan Ott Date: Sat, 7 Jul 2012 16:41:41 -0400 Subject: [PATCH 40/47] Exit with error if required packages are not found. --- configure.ac | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/configure.ac b/configure.ac index 74d301ad..2354dd89 100644 --- a/configure.ac +++ b/configure.ac @@ -60,18 +60,19 @@ case $host in backend="linux" os="linux" + # libs required for both implementations + AC_CHECK_LIB([rt], [clock_gettime], [LIBS_LIBUSB_PRIVATE+=" -lrt"], [hidapi_lib_error librt]) + # HIDAPI/hidraw libs - PKG_CHECK_MODULES([libudev], [libudev]) + PKG_CHECK_MODULES([libudev], [libudev], true, [hidapi_lib_error libudev]) LIBS_HIDRAW_PR+=" $libudev_LIBS" CFLAGS_HIDRAW+=" $libudev_CFLAGS" - AC_CHECK_LIB([rt], [clock_gettime], [LIBS_HIDRAW_PR+=" -lrt"]) # HIDAPI/libusb libs - PKG_CHECK_MODULES([libusb], [libusb-1.0]) + PKG_CHECK_MODULES([libusb], [libusb-1.0], true, [hidapi_lib_error libusb-1.0]) LIBS_LIBUSB_PRIVATE+=" $libusb_LIBS" CFLAGS_LIBUSB+=" $libusb_CFLAGS" - AC_CHECK_LIB([rt], [clock_gettime], [LIBS_LIBUSB_PRIVATE+=" -lrt"]) - AC_CHECK_LIB([pthread], [pthread_create], [LIBS_LIBUSB_PRIVATE+=" -lpthread"]) + AC_CHECK_LIB([pthread], [pthread_create], [LIBS_LIBUSB_PRIVATE+=" -lpthread"], [hidapi_lib_error libpthread]) ;; *-darwin*) AC_MSG_RESULT([ (Mac OS X back-end)]) From 6f57f2a81dd27faf3a37927d0513cf945bc38cd4 Mon Sep 17 00:00:00 2001 From: Alan Ott Date: Sat, 7 Jul 2012 16:42:13 -0400 Subject: [PATCH 41/47] README.txt: add section on Cross Compiling. --- README.txt | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/README.txt b/README.txt index ff8481eb..144ae26c 100644 --- a/README.txt +++ b/README.txt @@ -279,6 +279,50 @@ not. To build using the DDK: by the build system which is appropriate for your environment. On Windows XP, this directory is objfre_wxp_x86/i386. +Cross Compiling +================ + +This section talks about cross compiling HIDAPI for Linux using autotools. +This is useful for using HIDAPI on embedded Linux targets. These +instructions assume the most raw kind of embedded Linux build, where all +prerequisites will need to be built first. This process will of course vary +based on your embedded Linux build system if you are using one, such as +OpenEmbedded or Buildroot. + +For the purpose of this section, it will be assumed that the following +environment variables are exported. + + $ export STAGING=$HOME/out + $ export HOST=arm-linux + +STAGING and HOST can be modified to suit your setup. + +Prerequisites +-------------- + +Note that the build of libudev is the very basic configuration. + +Build Libusb. From the libusb source directory, run: + ./configure --host=$HOST --prefix=$STAGING + make + make install + +Build libudev. From the libudev source directory, run: + ./configure --disable-gudev --disable-introspection --disable-hwdb \ + --host=arm-linux --prefix=$STAGING + make + make install + +Building HIDAPI +---------------- + +Build HIDAPI: + + PKG_CONFIG_DIR= \ + PKG_CONFIG_LIBDIR=${STAGING}/lib/pkgconfig:${STAGING}/share/pkgconfig \ + PKG_CONFIG_SYSROOT_DIR=${STAGING} \ + ./configure --host=arm-linux --prefix=${STAGING} + Signal 11 Software - 2010-04-11 2010-07-28 From 9d60ed5912553b24bc1ab69fc42d6ee63604ab10 Mon Sep 17 00:00:00 2001 From: Alan Ott Date: Sat, 7 Jul 2012 18:31:35 -0400 Subject: [PATCH 42/47] README.txt: fix a missing $HOST and remove {} from shell vars. --- README.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.txt b/README.txt index 144ae26c..7111b16e 100644 --- a/README.txt +++ b/README.txt @@ -319,9 +319,9 @@ Building HIDAPI Build HIDAPI: PKG_CONFIG_DIR= \ - PKG_CONFIG_LIBDIR=${STAGING}/lib/pkgconfig:${STAGING}/share/pkgconfig \ - PKG_CONFIG_SYSROOT_DIR=${STAGING} \ - ./configure --host=arm-linux --prefix=${STAGING} + PKG_CONFIG_LIBDIR=$STAGING/lib/pkgconfig:$STAGING/share/pkgconfig \ + PKG_CONFIG_SYSROOT_DIR=$STAGING \ + ./configure --host=$HOST --prefix=$STAGING Signal 11 Software - 2010-04-11 From 8067be7a25660167ff709d0e6b4bafe4ce83a56b Mon Sep 17 00:00:00 2001 From: Alan Ott Date: Sun, 8 Jul 2012 13:01:57 -0400 Subject: [PATCH 43/47] Make TestGUI.app work for out of source builds. Move TestGUI.app to TestGUI.app.in (to get copied by build system) Make Makefile.am call ./copy_to_bundle.sh from $(srcdir) Make Makefile.mac handle TestGUI.app.in Thanks to Xiaofan Chen for reporting this bug. --- configure.ac | 2 ++ testgui/Makefile.am | 2 +- testgui/Makefile.mac | 12 +++++++++--- .../Contents/Info.plist | 0 .../Contents/MacOS/libFOX-1.7.0.dylib | Bin .../Contents/MacOS/libpng12.0.dylib | Bin .../Contents/MacOS/libz.1.dylib | Bin .../Contents/MacOS/testgui | Bin .../Contents/PkgInfo | 0 .../Resources/English.lproj/InfoPlist.strings | Bin .../Contents/Resources/Signal11.icns | Bin 11 files changed, 12 insertions(+), 4 deletions(-) rename testgui/{TestGUI.app => TestGUI.app.in}/Contents/Info.plist (100%) rename testgui/{TestGUI.app => TestGUI.app.in}/Contents/MacOS/libFOX-1.7.0.dylib (100%) rename testgui/{TestGUI.app => TestGUI.app.in}/Contents/MacOS/libpng12.0.dylib (100%) rename testgui/{TestGUI.app => TestGUI.app.in}/Contents/MacOS/libz.1.dylib (100%) rename testgui/{TestGUI.app => TestGUI.app.in}/Contents/MacOS/testgui (100%) rename testgui/{TestGUI.app => TestGUI.app.in}/Contents/PkgInfo (100%) rename testgui/{TestGUI.app => TestGUI.app.in}/Contents/Resources/English.lproj/InfoPlist.strings (100%) rename testgui/{TestGUI.app => TestGUI.app.in}/Contents/Resources/Signal11.icns (100%) diff --git a/configure.ac b/configure.ac index 74d301ad..e8e67922 100644 --- a/configure.ac +++ b/configure.ac @@ -146,6 +146,8 @@ if test "x$testgui_enabled" != "xno"; then LIBS_TESTGUI+=" -framework Cocoa -L/usr/X11R6/lib" CFLAGS_TESTGUI+=`$foxconfig --cflags` OBJCFLAGS+=" -x objective-c++" + mkdir -p testgui/TestGUI.app + cp -R ${srcdir}/testgui/TestGUI.app.in/ testgui/TestGUI.app elif test "x$os" = xwindows; then # On Windows, just set the paths for Fox toolkit if test "x$win_implementation" = xmingw; then diff --git a/testgui/Makefile.am b/testgui/Makefile.am index 0604da1c..3aebe4fa 100644 --- a/testgui/Makefile.am +++ b/testgui/Makefile.am @@ -22,7 +22,7 @@ if OS_DARWIN hidapi_testgui_SOURCES = test.cpp mac_support_cocoa.m # Rules for copying the binary and its dependencies into the app bundle. TestGUI.app/Contents/MacOS/hidapi-testgui$(EXEEXT): hidapi-testgui$(EXEEXT) - ./copy_to_bundle.sh + $(srcdir)/copy_to_bundle.sh all: all-am TestGUI.app/Contents/MacOS/hidapi-testgui$(EXEEXT) diff --git a/testgui/Makefile.mac b/testgui/Makefile.mac index 218858d5..35bd5818 100644 --- a/testgui/Makefile.mac +++ b/testgui/Makefile.mac @@ -15,11 +15,12 @@ CPPOBJS=test.o OBJCOBJS=mac_support_cocoa.o OBJS=$(COBJS) $(CPPOBJS) $(OBJCOBJS) CFLAGS=-I../hidapi -Wall -g -c `fox-config --cflags` +LDFLAGS=-L/usr/X11R6/lib LIBS=`fox-config --libs` -framework IOKit -framework CoreFoundation -framework Cocoa -hidapi-testgui: $(OBJS) - g++ -Wall -g $^ $(LIBS) -o hidapi-testgui +hidapi-testgui: $(OBJS) TestGUI.app + g++ -Wall -g $(OBJS) $(LIBS) $(LDFLAGS) -o hidapi-testgui ./copy_to_bundle.sh #cp TestGUI.app/Contents/MacOS/hidapi-testgui TestGUI.app/Contents/MacOS/tg #cp start.sh TestGUI.app/Contents/MacOS/hidapi-testgui @@ -33,8 +34,13 @@ $(CPPOBJS): %.o: %.cpp $(OBJCOBJS): %.o: %.m $(CXX) $(CFLAGS) -x objective-c++ $< -o $@ +TestGUI.app: TestGUI.app.in + rm -Rf TestGUI.app + mkdir -p TestGUI.app + cp -R TestGUI.app.in/ TestGUI.app clean: - rm $(OBJS) hidapi-testgui + rm -f $(OBJS) hidapi-testgui + rm -Rf TestGUI.app .PHONY: clean diff --git a/testgui/TestGUI.app/Contents/Info.plist b/testgui/TestGUI.app.in/Contents/Info.plist similarity index 100% rename from testgui/TestGUI.app/Contents/Info.plist rename to testgui/TestGUI.app.in/Contents/Info.plist diff --git a/testgui/TestGUI.app/Contents/MacOS/libFOX-1.7.0.dylib b/testgui/TestGUI.app.in/Contents/MacOS/libFOX-1.7.0.dylib similarity index 100% rename from testgui/TestGUI.app/Contents/MacOS/libFOX-1.7.0.dylib rename to testgui/TestGUI.app.in/Contents/MacOS/libFOX-1.7.0.dylib diff --git a/testgui/TestGUI.app/Contents/MacOS/libpng12.0.dylib b/testgui/TestGUI.app.in/Contents/MacOS/libpng12.0.dylib similarity index 100% rename from testgui/TestGUI.app/Contents/MacOS/libpng12.0.dylib rename to testgui/TestGUI.app.in/Contents/MacOS/libpng12.0.dylib diff --git a/testgui/TestGUI.app/Contents/MacOS/libz.1.dylib b/testgui/TestGUI.app.in/Contents/MacOS/libz.1.dylib similarity index 100% rename from testgui/TestGUI.app/Contents/MacOS/libz.1.dylib rename to testgui/TestGUI.app.in/Contents/MacOS/libz.1.dylib diff --git a/testgui/TestGUI.app/Contents/MacOS/testgui b/testgui/TestGUI.app.in/Contents/MacOS/testgui similarity index 100% rename from testgui/TestGUI.app/Contents/MacOS/testgui rename to testgui/TestGUI.app.in/Contents/MacOS/testgui diff --git a/testgui/TestGUI.app/Contents/PkgInfo b/testgui/TestGUI.app.in/Contents/PkgInfo similarity index 100% rename from testgui/TestGUI.app/Contents/PkgInfo rename to testgui/TestGUI.app.in/Contents/PkgInfo diff --git a/testgui/TestGUI.app/Contents/Resources/English.lproj/InfoPlist.strings b/testgui/TestGUI.app.in/Contents/Resources/English.lproj/InfoPlist.strings similarity index 100% rename from testgui/TestGUI.app/Contents/Resources/English.lproj/InfoPlist.strings rename to testgui/TestGUI.app.in/Contents/Resources/English.lproj/InfoPlist.strings diff --git a/testgui/TestGUI.app/Contents/Resources/Signal11.icns b/testgui/TestGUI.app.in/Contents/Resources/Signal11.icns similarity index 100% rename from testgui/TestGUI.app/Contents/Resources/Signal11.icns rename to testgui/TestGUI.app.in/Contents/Resources/Signal11.icns From 988175fe400a5a3e3009dad5651fd06350b7af6d Mon Sep 17 00:00:00 2001 From: Alan Ott Date: Sun, 8 Jul 2012 13:09:03 -0400 Subject: [PATCH 44/47] Change executable filename to hidapi-testgui. --- testgui/TestGUI.app.in/Contents/Info.plist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testgui/TestGUI.app.in/Contents/Info.plist b/testgui/TestGUI.app.in/Contents/Info.plist index e199a1b1..ab473d53 100644 --- a/testgui/TestGUI.app.in/Contents/Info.plist +++ b/testgui/TestGUI.app.in/Contents/Info.plist @@ -7,7 +7,7 @@ CFBundleDisplayName CFBundleExecutable - TestGUI + hidapi-testgui CFBundleIconFile Signal11.icns CFBundleIdentifier From 8e1fcc99fc5fa1aad5c15555f5369605d6247950 Mon Sep 17 00:00:00 2001 From: Alan Ott Date: Sun, 8 Jul 2012 13:09:25 -0400 Subject: [PATCH 45/47] Add TestGUI.app to .gitignore. --- testgui/.gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/testgui/.gitignore b/testgui/.gitignore index 11ef5e4a..f989ea8c 100644 --- a/testgui/.gitignore +++ b/testgui/.gitignore @@ -17,3 +17,4 @@ hidapi-libusb-testgui .libs *.la *.lo +TestGUI.app From 23b98e418bd443dcd79e8e77a4ab43b0c9238512 Mon Sep 17 00:00:00 2001 From: Alan Ott Date: Mon, 9 Jul 2012 14:21:37 -0400 Subject: [PATCH 46/47] When bundling, change permission of copied file to allow writes by owner. --- testgui/copy_to_bundle.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/testgui/copy_to_bundle.sh b/testgui/copy_to_bundle.sh index 5e316d3f..aa5de1c9 100755 --- a/testgui/copy_to_bundle.sh +++ b/testgui/copy_to_bundle.sh @@ -53,6 +53,7 @@ function copydeps { z=0 else cp $i $EXEPATH + chmod 755 $EXEPATH/$BASE fi From 296b08a13953a88fe1ab0eff01f04a0b9d8ddeb6 Mon Sep 17 00:00:00 2001 From: Alan Ott Date: Fri, 13 Jul 2012 01:13:59 -0400 Subject: [PATCH 47/47] Convert to useing ax_pthread.m4 to detect proper pthread flags autmatically. --- configure.ac | 29 ++++- m4/.gitignore | 1 + m4/ax_pthread.m4 | 309 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 334 insertions(+), 5 deletions(-) create mode 100644 m4/ax_pthread.m4 diff --git a/configure.ac b/configure.ac index 2354dd89..f518150a 100644 --- a/configure.ac +++ b/configure.ac @@ -59,9 +59,7 @@ case $host in AC_SUBST(OS_LINUX) backend="linux" os="linux" - - # libs required for both implementations - AC_CHECK_LIB([rt], [clock_gettime], [LIBS_LIBUSB_PRIVATE+=" -lrt"], [hidapi_lib_error librt]) + threads="pthreads" # HIDAPI/hidraw libs PKG_CHECK_MODULES([libudev], [libudev], true, [hidapi_lib_error libudev]) @@ -69,10 +67,10 @@ case $host in CFLAGS_HIDRAW+=" $libudev_CFLAGS" # HIDAPI/libusb libs + AC_CHECK_LIB([rt], [clock_gettime], [LIBS_LIBUSB_PRIVATE+=" -lrt"], [hidapi_lib_error librt]) PKG_CHECK_MODULES([libusb], [libusb-1.0], true, [hidapi_lib_error libusb-1.0]) LIBS_LIBUSB_PRIVATE+=" $libusb_LIBS" CFLAGS_LIBUSB+=" $libusb_CFLAGS" - AC_CHECK_LIB([pthread], [pthread_create], [LIBS_LIBUSB_PRIVATE+=" -lpthread"], [hidapi_lib_error libpthread]) ;; *-darwin*) AC_MSG_RESULT([ (Mac OS X back-end)]) @@ -80,6 +78,7 @@ case $host in AC_SUBST(OS_DARWIN) backend="mac" os="darwin" + threads="pthreads" LIBS="${LIBS} -framework IOKit -framework CoreFoundation" ;; *-freebsd*) @@ -88,12 +87,12 @@ case $host in AC_SUBST(OS_FREEBSD) backend="libusb" os="freebsd" + threads="pthreads" CFLAGS="$CFLAGS -I/usr/local/include" LDFLAGS="$LDFLAGS -L/usr/local/lib" LIBS="${LIBS}" AC_CHECK_LIB([usb], [libusb_init], [LIBS_LIBUSB_PRIVATE="${LIBS_LIBUSB_PRIVATE} -lusb"], [hidapi_lib_error libusb]) - AC_CHECK_LIB([pthread], [pthread_create], [LIBS_LIBUSB_PRIVATE="${LIBS_LIBUSB_PRIVATE} -lpthread"], [hidapi_lib_error libpthread]) AC_CHECK_LIB([iconv], [iconv_open], [LIBS_LIBUSB_PRIVATE="${LIBS_LIBUSB_PRIVATE} -liconv"], [hidapi_lib_error libiconv]) echo libs_priv: $LIBS_LIBUSB_PRIVATE ;; @@ -101,12 +100,14 @@ case $host in AC_MSG_RESULT([ (Windows back-end, using MinGW)]) backend="windows" os="windows" + threads="windows" win_implementation="mingw" ;; *-cygwin*) AC_MSG_RESULT([ (Windows back-end, using Cygwin)]) backend="windows" os="windows" + threads="windows" win_implementation="cygwin" ;; *) @@ -127,6 +128,24 @@ if test "x$os" = xwindows; then LIBS="${LIBS} -lsetupapi" 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], diff --git a/m4/.gitignore b/m4/.gitignore index d1cc719b..8f79b020 100644 --- a/m4/.gitignore +++ b/m4/.gitignore @@ -2,3 +2,4 @@ * !.gitignore !pkg.m4 +!ax_pthread.m4 diff --git a/m4/ax_pthread.m4 b/m4/ax_pthread.m4 new file mode 100644 index 00000000..d90de34d --- /dev/null +++ b/m4/ax_pthread.m4 @@ -0,0 +1,309 @@ +# =========================================================================== +# http://www.gnu.org/software/autoconf-archive/ax_pthread.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) +# +# DESCRIPTION +# +# This macro figures out how to build C programs using POSIX threads. It +# sets the PTHREAD_LIBS output variable to the threads library and linker +# flags, and the PTHREAD_CFLAGS output variable to any special C compiler +# flags that are needed. (The user can also force certain compiler +# flags/libs to be tested by setting these environment variables.) +# +# Also sets PTHREAD_CC to any special C compiler that is needed for +# multi-threaded programs (defaults to the value of CC otherwise). (This +# is necessary on AIX to use the special cc_r compiler alias.) +# +# NOTE: You are assumed to not only compile your program with these flags, +# but also link it with them as well. e.g. you should link with +# $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS $LIBS +# +# If you are only building threads programs, you may wish to use these +# variables in your default LIBS, CFLAGS, and CC: +# +# LIBS="$PTHREAD_LIBS $LIBS" +# CFLAGS="$CFLAGS $PTHREAD_CFLAGS" +# CC="$PTHREAD_CC" +# +# In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute constant +# has a nonstandard name, defines PTHREAD_CREATE_JOINABLE to that name +# (e.g. PTHREAD_CREATE_UNDETACHED on AIX). +# +# Also HAVE_PTHREAD_PRIO_INHERIT is defined if pthread is found and the +# PTHREAD_PRIO_INHERIT symbol is defined when compiling with +# PTHREAD_CFLAGS. +# +# ACTION-IF-FOUND is a list of shell commands to run if a threads library +# is found, and ACTION-IF-NOT-FOUND is a list of commands to run it if it +# is not found. If ACTION-IF-FOUND is not specified, the default action +# will define HAVE_PTHREAD. +# +# Please let the authors know if this macro fails on any platform, or if +# you have any other suggestions or comments. This macro was based on work +# by SGJ on autoconf scripts for FFTW (http://www.fftw.org/) (with help +# from M. Frigo), as well as ac_pthread and hb_pthread macros posted by +# Alejandro Forero Cuervo to the autoconf macro repository. We are also +# grateful for the helpful feedback of numerous users. +# +# Updated for Autoconf 2.68 by Daniel Richard G. +# +# LICENSE +# +# Copyright (c) 2008 Steven G. Johnson +# Copyright (c) 2011 Daniel Richard G. +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation, either version 3 of the License, or (at your +# option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +# Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . +# +# As a special exception, the respective Autoconf Macro's copyright owner +# gives unlimited permission to copy, distribute and modify the configure +# scripts that are the output of Autoconf when processing the Macro. You +# need not follow the terms of the GNU General Public License when using +# or distributing such scripts, even though portions of the text of the +# Macro appear in them. The GNU General Public License (GPL) does govern +# all other use of the material that constitutes the Autoconf Macro. +# +# This special exception to the GPL applies to versions of the Autoconf +# Macro released by the Autoconf Archive. When you make and distribute a +# modified version of the Autoconf Macro, you may extend this special +# exception to the GPL to apply to your modified version as well. + +#serial 18 + +AU_ALIAS([ACX_PTHREAD], [AX_PTHREAD]) +AC_DEFUN([AX_PTHREAD], [ +AC_REQUIRE([AC_CANONICAL_HOST]) +AC_LANG_PUSH([C]) +ax_pthread_ok=no + +# We used to check for pthread.h first, but this fails if pthread.h +# requires special compiler flags (e.g. on True64 or Sequent). +# It gets checked for in the link test anyway. + +# First of all, check if the user has set any of the PTHREAD_LIBS, +# etcetera environment variables, and if threads linking works using +# them: +if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then + save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $PTHREAD_CFLAGS" + save_LIBS="$LIBS" + LIBS="$PTHREAD_LIBS $LIBS" + AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS]) + AC_TRY_LINK_FUNC(pthread_join, ax_pthread_ok=yes) + AC_MSG_RESULT($ax_pthread_ok) + if test x"$ax_pthread_ok" = xno; then + PTHREAD_LIBS="" + PTHREAD_CFLAGS="" + fi + LIBS="$save_LIBS" + CFLAGS="$save_CFLAGS" +fi + +# We must check for the threads library under a number of different +# names; the ordering is very important because some systems +# (e.g. DEC) have both -lpthread and -lpthreads, where one of the +# libraries is broken (non-POSIX). + +# Create a list of thread flags to try. Items starting with a "-" are +# C compiler flags, and other items are library names, except for "none" +# which indicates that we try without any flags at all, and "pthread-config" +# which is a program returning the flags for the Pth emulation library. + +ax_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config" + +# The ordering *is* (sometimes) important. Some notes on the +# individual items follow: + +# pthreads: AIX (must check this before -lpthread) +# none: in case threads are in libc; should be tried before -Kthread and +# other compiler flags to prevent continual compiler warnings +# -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h) +# -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able) +# lthread: LinuxThreads port on FreeBSD (also preferred to -pthread) +# -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads) +# -pthreads: Solaris/gcc +# -mthreads: Mingw32/gcc, Lynx/gcc +# -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it +# doesn't hurt to check since this sometimes defines pthreads too; +# also defines -D_REENTRANT) +# ... -mt is also the pthreads flag for HP/aCC +# pthread: Linux, etcetera +# --thread-safe: KAI C++ +# pthread-config: use pthread-config program (for GNU Pth library) + +case ${host_os} in + solaris*) + + # On Solaris (at least, for some versions), libc contains stubbed + # (non-functional) versions of the pthreads routines, so link-based + # tests will erroneously succeed. (We need to link with -pthreads/-mt/ + # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather + # a function called by this macro, so we could check for that, but + # who knows whether they'll stub that too in a future libc.) So, + # we'll just look for -pthreads and -lpthread first: + + ax_pthread_flags="-pthreads pthread -mt -pthread $ax_pthread_flags" + ;; + + darwin*) + ax_pthread_flags="-pthread $ax_pthread_flags" + ;; +esac + +if test x"$ax_pthread_ok" = xno; then +for flag in $ax_pthread_flags; do + + case $flag in + none) + AC_MSG_CHECKING([whether pthreads work without any flags]) + ;; + + -*) + AC_MSG_CHECKING([whether pthreads work with $flag]) + PTHREAD_CFLAGS="$flag" + ;; + + pthread-config) + AC_CHECK_PROG(ax_pthread_config, pthread-config, yes, no) + if test x"$ax_pthread_config" = xno; then continue; fi + PTHREAD_CFLAGS="`pthread-config --cflags`" + PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`" + ;; + + *) + AC_MSG_CHECKING([for the pthreads library -l$flag]) + PTHREAD_LIBS="-l$flag" + ;; + esac + + save_LIBS="$LIBS" + save_CFLAGS="$CFLAGS" + LIBS="$PTHREAD_LIBS $LIBS" + CFLAGS="$CFLAGS $PTHREAD_CFLAGS" + + # Check for various functions. We must include pthread.h, + # since some functions may be macros. (On the Sequent, we + # need a special flag -Kthread to make this header compile.) + # We check for pthread_join because it is in -lpthread on IRIX + # while pthread_create is in libc. We check for pthread_attr_init + # due to DEC craziness with -lpthreads. We check for + # pthread_cleanup_push because it is one of the few pthread + # functions on Solaris that doesn't have a non-functional libc stub. + # We try pthread_create on general principles. + AC_LINK_IFELSE([AC_LANG_PROGRAM([#include + static void routine(void *a) { a = 0; } + static void *start_routine(void *a) { return a; }], + [pthread_t th; pthread_attr_t attr; + pthread_create(&th, 0, start_routine, 0); + pthread_join(th, 0); + pthread_attr_init(&attr); + pthread_cleanup_push(routine, 0); + pthread_cleanup_pop(0) /* ; */])], + [ax_pthread_ok=yes], + []) + + LIBS="$save_LIBS" + CFLAGS="$save_CFLAGS" + + AC_MSG_RESULT($ax_pthread_ok) + if test "x$ax_pthread_ok" = xyes; then + break; + fi + + PTHREAD_LIBS="" + PTHREAD_CFLAGS="" +done +fi + +# Various other checks: +if test "x$ax_pthread_ok" = xyes; then + save_LIBS="$LIBS" + LIBS="$PTHREAD_LIBS $LIBS" + save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $PTHREAD_CFLAGS" + + # Detect AIX lossage: JOINABLE attribute is called UNDETACHED. + AC_MSG_CHECKING([for joinable pthread attribute]) + attr_name=unknown + for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do + AC_LINK_IFELSE([AC_LANG_PROGRAM([#include ], + [int attr = $attr; return attr /* ; */])], + [attr_name=$attr; break], + []) + done + AC_MSG_RESULT($attr_name) + if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then + AC_DEFINE_UNQUOTED(PTHREAD_CREATE_JOINABLE, $attr_name, + [Define to necessary symbol if this constant + uses a non-standard name on your system.]) + fi + + AC_MSG_CHECKING([if more special flags are required for pthreads]) + flag=no + case ${host_os} in + aix* | freebsd* | darwin*) flag="-D_THREAD_SAFE";; + osf* | hpux*) flag="-D_REENTRANT";; + solaris*) + if test "$GCC" = "yes"; then + flag="-D_REENTRANT" + else + flag="-mt -D_REENTRANT" + fi + ;; + esac + AC_MSG_RESULT(${flag}) + if test "x$flag" != xno; then + PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS" + fi + + AC_CACHE_CHECK([for PTHREAD_PRIO_INHERIT], + ax_cv_PTHREAD_PRIO_INHERIT, [ + AC_LINK_IFELSE([ + AC_LANG_PROGRAM([[#include ]], [[int i = PTHREAD_PRIO_INHERIT;]])], + [ax_cv_PTHREAD_PRIO_INHERIT=yes], + [ax_cv_PTHREAD_PRIO_INHERIT=no]) + ]) + AS_IF([test "x$ax_cv_PTHREAD_PRIO_INHERIT" = "xyes"], + AC_DEFINE([HAVE_PTHREAD_PRIO_INHERIT], 1, [Have PTHREAD_PRIO_INHERIT.])) + + LIBS="$save_LIBS" + CFLAGS="$save_CFLAGS" + + # More AIX lossage: must compile with xlc_r or cc_r + if test x"$GCC" != xyes; then + AC_CHECK_PROGS(PTHREAD_CC, xlc_r cc_r, ${CC}) + else + PTHREAD_CC=$CC + fi +else + PTHREAD_CC="$CC" +fi + +AC_SUBST(PTHREAD_LIBS) +AC_SUBST(PTHREAD_CFLAGS) +AC_SUBST(PTHREAD_CC) + +# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND: +if test x"$ax_pthread_ok" = xyes; then + ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1]) + : +else + ax_pthread_ok=no + $2 +fi +AC_LANG_POP +])dnl AX_PTHREAD