1# Building HIDAPI using Autotools (deprecated) 2 3--- 4**NOTE**: for all intentions and purposes the Autotools build scripts for HIDAPI are _deprecated_ and going to be obsolete in the future. 5HIDAPI Team recommends using CMake build for HIDAPI. 6If you are already using Autotools build scripts provided by HIDAPI, 7consider switching to CMake build scripts as soon as possible. 8 9--- 10 11To be able to use Autotools to build HIDAPI, it has to be [installed](#installing-autotools)/available in the system. 12 13Make sure you've checked [prerequisites](BUILD.md#prerequisites) and installed all required dependencies. 14 15## Installing Autotools 16 17HIDAPI uses few specific tools/packages from Autotools: `autoconf`, `automake`, `libtool`. 18 19On different platforms or package managers, those could be named a bit differently or packaged together. 20You'll have to check the documentation/package list for your specific package manager. 21 22### Linux 23 24On Ubuntu the tools are available via APT: 25 26```sh 27sudo apt install autoconf automake libtool 28``` 29 30### FreeBSD 31 32FreeBSD Autotools can be installed as: 33 34```sh 35pkg_add -r autotools 36``` 37 38Additionally, on FreeBSD you will need to install GNU make: 39```sh 40pkg_add -r gmake 41``` 42 43## Building HIDAPI with Autotools 44 45A simple command list, to build HIDAPI with Autotools as a _shared library_ and install in into your system: 46 47```sh 48./bootstrap # this prepares the configure script 49./configure 50make # build the library 51make install # as root, or using sudo, this will install hidapi into your system 52``` 53 54`./configure` can take several arguments which control the build. A few commonly used options: 55```sh 56 --enable-testgui 57 # Enable the build of Foxit-based Test GUI. This requires Fox toolkit to 58 # be installed/available. See README.md#test-gui for remarks. 59 60 --prefix=/usr 61 # Specify where you want the output headers and libraries to 62 # be installed. The example above will put the headers in 63 # /usr/include and the binaries in /usr/lib. The default is to 64 # install into /usr/local which is fine on most systems. 65 66 --disable-shared 67 # By default, both shared and static libraries are going to be built/installed. 68 # This option disables shared library build, if only static library is required. 69``` 70 71 72## Cross Compiling 73 74This section talks about cross compiling HIDAPI for Linux using Autotools. 75This is useful for using HIDAPI on embedded Linux targets. These 76instructions assume the most raw kind of embedded Linux build, where all 77prerequisites will need to be built first. This process will of course vary 78based on your embedded Linux build system if you are using one, such as 79OpenEmbedded or Buildroot. 80 81For the purpose of this section, it will be assumed that the following 82environment variables are exported. 83```sh 84$ export STAGING=$HOME/out 85$ export HOST=arm-linux 86``` 87 88`STAGING` and `HOST` can be modified to suit your setup. 89 90### Prerequisites 91 92Depending on what backend you want to cross-compile, you also need to prepare the dependencies: 93`libusb` for libusb HIDAPI backend, or `libudev` for hidraw HIDAPI backend. 94 95An example of cross-compiling `libusb`. From `libusb` source directory, run: 96```sh 97./configure --host=$HOST --prefix=$STAGING 98make 99make install 100``` 101 102An example of cross-comping `libudev` is not covered by this section. 103Check `libudev`'s documentation for details. 104 105### Building HIDAPI 106 107Build HIDAPI: 108```sh 109PKG_CONFIG_DIR= \ 110PKG_CONFIG_LIBDIR=$STAGING/lib/pkgconfig:$STAGING/share/pkgconfig \ 111PKG_CONFIG_SYSROOT_DIR=$STAGING \ 112./configure --host=$HOST --prefix=$STAGING 113# make / make install - same as for a regular build 114``` 115