How to build Boost 1.64.0 libraries (static, shared) for ARM, MIPS, x86, +64-bit variants (using clang)

Authored: 06/28/2017
Updated: 07/31/2017

On a Linux machine (very important, b2 sucks at building anything on platforms that aren't Linux), preferably Ubuntu (16.04.2 LTS), do the following:

NOTE: "~/" assumes the directory "/home/ubuntu(and vice-versa) in this guide.

This guide also assumes necessary tools are installed on your system (python, unzip, etc.).

1. Download appropriate software
$ cd ~

# boost 1.64.0
$ wget
$ tar -xzf boost_1_64_0.tar.gz

# Android NDK r15b
$ wget
$ unzip -q

2. Build standalone toolchains (required for building using clang) NOTE: make sure you have enough disk space!!
$ mkdir ~/standalone_toolchains
$ ~/android-ndk-r15b/build/tools/ --arch arm --install-dir ~/standalone_toolchains/arm
$ ~/android-ndk-r15b/build/tools/ --arch arm64 --install-dir ~/standalone_toolchains/arm64
$ ~/android-ndk-r15b/build/tools/ --arch mips --install-dir ~/standalone_toolchains/mips
$ ~/android-ndk-r15b/build/tools/ --arch mips64 --install-dir ~/standalone_toolchains/mips64
$ ~/android-ndk-r15b/build/tools/ --arch x86 --install-dir ~/standalone_toolchains/x86
$ ~/android-ndk-r15b/build/tools/ --arch x86_64 --install-dir ~/standalone_toolchains/x86_64

3. Edit libtool.m4 in Boost to avoid versioning issue with the library files. This issue still stands as a problem for
   people who want to build Boost for Android. To work around this issue, modify version_type=linux to version_type=none 
   in the linux*) section in boost_1_64_0/tools/build/src/engine/boehm_gc/libtool.m4.

4. Bootstrap Boost
$ cd ~/boost_1_64_0
$ ./

5a. Create user-config.jam file in home (~/) directory
$ touch ~/user-config.jam

5b. Edit the user-config.jam file to reflect the following:
# user-config.jam file
# Defines which standalone toolchains to use for building.

standaloneToolchains = /home/ubuntu/standalone_toolchains ;

# Uncomment to build using preferred toolchain.

using clang : arm : $(standaloneToolchains)/arm/bin/clang++ ;
# using clang : arm : $(standaloneToolchains)/arm/bin/clang++ <compileflags>-march=armv7-a;
# using clang : arm64 : $(standaloneToolchains)/arm64/bin/clang++ ;

# using clang : mips : $(standaloneToolchains)/mips/bin/clang++ ;
# using clang : mips64 : $(standaloneToolchains)/mips64/bin/clang++ ;

# x86, x86_64
# using clang : x86 : $(standaloneToolchains)/x86/bin/clang++ ;
# using clang : x86_64 : $(standaloneToolchains)/x86_64/bin/clang++ ;

6a. Uncomment the appropriate line in user-config.jam for each time you run step 6b

6b. Build boost for android using appropriate references to the correct toolchains (this example builds for arm)
$ mkdir ~/boost-android
$ cd ~/boost_1_64_0
$ ./b2 -d+2 -j 2 --reconfigure target-os=android toolset=clang-arm include=/home/ubuntu/standalone_toolchains/arm/include/c++/4.9.x link=static,shared variant=release threading=multi --without-context --without-coroutine --prefix=/home/ubuntu/boost-android/arm install

6c. (example to build for mips64)
# NOTE: be sure to configure `user-config.jam` properly to reflect the toolchain you want to use

$ ./b2 -d+2 -j 2 --reconfigure target-os=android toolset=clang-mips64 include=/home/ubuntu/standalone_toolchains/mips64/include/c++/4.9.x link=static,shared variant=release threading=multi --without-context --without-coroutine --prefix=/home/ubuntu/boost-android/mips64 install

6d. Repeat process for all architecture variants of the libraries you require

7. Verify static library object files
$ cd ~
$ cp ~/boost-android/arm/lib/libboost_system.a .
$ tar -xf libboost_system.a
$ file error_code.o
error_code.o: ELF 32-bit LSB relocatable, ARM, EABI5 version 1 (SYSV), not stripped

8. Verify shared library object files
$ file ~/boost-android/mips64/lib/
~/boost-android/mips64/lib/ ELF 64-bit LSB shared object, MIPS, MIPS64 rel6 version 1 (SYSV), dynamically linked, not stripped