Skip to content

Instantly share code, notes, and snippets.

@vitorio
Created July 28, 2018 01:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vitorio/11e98a72bb71f51caf10d13b3caa558d to your computer and use it in GitHub Desktop.
Save vitorio/11e98a72bb71f51caf10d13b3caa558d to your computer and use it in GitHub Desktop.
Compiling libnfc (latest) natively on OS X within your home directory

These instructions compile a native OS X version of libnfc (latest, from source control) that lives in your home directory, and which cannot be moved around, but should always be discoverable by applications.

Assumes OS X with Xcode or Xcode command-line tools, not macports or homebrew

To install Xcode command-line tools in recent versions of OS X, open Terminal, type xcode-select --install and click "Install"

Older versions of OS X may need to manually download disk images of older versions of Xcode and/or the Xcode command-line tools, as various certificates may have expired (e.g. 10.7.4 requires a manual install from the Xcode 4.6.2 command-line tools image)

Download latest pkg-config (tested with 0.29.1) from https://pkg-config.freedesktop.org/releases/?C=M;O=D

Download latest autoconf (tested with 2.69) from http://ftp.gnu.org/gnu/autoconf/?C=M;O=D

Download latest automake (tested with 1.15.1) from http://ftp.gnu.org/gnu/automake/?C=M;O=D

Download latest libtool (tested with 2.4.6) from http://ftp.gnu.org/gnu/libtool/?C=M;O=D

Download latest libusb (tested with 1.0.20) from https://sourceforge.net/projects/libusb/files/latest/download?source=files

Download latest libusb-compat (tested with 0.1.15) from https://sourceforge.net/projects/libusb/files/libusb-compat-0.1/

Download latest libnfc from source control (tested with 216145f):

$ cd ~/Downloads/
$ git clone https://github.com/nfc-tools/libnfc.git

Compile pkg-config, autoconf, automake, libtool, libusb, libusb-compat, libnfc

$ cd ~/Downloads/
$ cd pkg-config-0.29.1
$ ./configure --with-internal-glib --prefix=$HOME/
$ make
$ make install
$ cd ..
$ cd autoconf-2.69
$ ./configure --prefix=$HOME/
$ make
$ make install
$ export PATH="$HOME/bin:$PATH"
$ cd ..
$ cd automake-1.15.1
$ ./configure --prefix=$HOME/
$ make
$ make install
$ cd ..
$ cd libtool-2.4.6
$ ./configure --prefix=$HOME/
$ make
$ make install
$ cd ..
$ cd libusb-1.0.20
$ ./configure --prefix=$HOME/
$ make
$ make install
$ cd ..
$ cd libusb-compat-0.1.5
$ PKG_CONFIG=$HOME/bin/pkg-config ./configure --prefix=$HOME/
$ make
$ make install
$ cd ..
$ cd libnfc
$ autoreconf -vis
$ PKG_CONFIG=$HOME/bin/pkg-config ./configure --prefix=$HOME/
$ make
$ make install

(If you're compiling libusb 1.0.22+, or from HEAD, you may need to run ./bootstrap.sh before the configure command.)

Now, your home directory has four new (probably) folders with pkg-config, autoconf, automake, libtool, libusb, libusb-compat, and libnfc in them:

$ ls -al
drwxr-xr-x   25 username  1897370479    850 Aug 27 00:24 bin
drwxr-xr-x    5 username  1897370479    170 Aug 27 00:24 include
drwxr-xr-x   15 username  1897370479    510 Aug 27 00:23 lib
drwxr-xr-x    5 username  1897370479    170 Aug 27 00:20 share

The ~/lib folder is in the default search path for dynamic libraries, so any software that uses libnfc or libusb should be able to automatically find it. These should always work without modification, even on OS X systems with System Integrity Protection (10.11 El Capitan and later), as long as they stay in ~/lib.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment