## Instructions for building Intel® Threading Building Blocks (Intel® TBB) on Android*

### Linux*

The android_setup.csh script is sourced to initialize the environment to build the Intel TBB library.

Note: android_setup.csh has been tested on Android* NDKs from r7. Future changes in the NDK directory structure may require changes in the setup script.

Note: android_setup.csh has not been tested with the android-ndk-r8d. In particular the LLVM* compiler has not been tested.

The format of the arguments are:

> source android_setup.csh <-n NDK> <-c cpu-type> <-g version> <-p NDK-path> <-a abi-level> -d device-id <-v> <-h>

> source android_setup.csh <-p NDK-path> -s standalone-toolchain-location -d device-id <-v> <-h>

> source android_setup.csh <-p NDK-path> -t prebuilt-toolchain-location <-a abi-level> -d device-id <-v> <-h>

switch | default | description
--- | --- | ---
-n | 8 | the version of the Android* NDK being built against. For example, if the NDK is android-ndk-r8b, specify "-n 8b"
-c | x86 | an available cpu type. Currently-accepted values are "x86" and "arm".
-g | 4.4.3 | a version of GCC* available in the NDK. For example, NDK r8b has "4.4.3" and "4.6".
-p | /localdisk | the location of the NDKs and the default location of the toolchains if not specified by absolute path. For example, if the NDK "android-ndk-r8" was uncompressed in the /tmp directory, then when using the "-n 8" switch, specify "-p /tmp". If this switch is specified it must appear before any switches affected by it.
-s | none | either an absolute path to the standalone toolchain, or a path relative to the "-p NDK-path" location. If for example the standalone toolchain is in /tmp/my-toolchain, then the path can be specified either by "s /tmp/my-toolchain" or "-p /tmp -s my-toolchain". If the -s switch is specified the cpu-type, GCC-version and abi-level are derived from the toolchain.
-t | none | either an absolute path to the prebuilt toolchain, or a path relative to the "-p NDK-path" location. For example, if the NDK is installed in /localdisk, then to specify the x86 compiler for GCC* 4.4.3, use "-t /localdisk/android-ndk-r8b/toolchains/x86-4.4.3/prebuilt/linux-x86". If the -t switch is specified the cpu-type and GCC-version are derived from the toolchain.
-a | 14 | a supported ABI level in the NDK.
-d | none | the ID returned by "adb devices" on the host machine. Note that some devices do not appear on the list but can be connected to. The device must be connected to the host machine for both library build and test, so target system information is available.
-v |  | verbose output
-h |  | explains the command line syntax, if the NDK directory is correct lists the available NDKs, executes an "adb devices" to list the available devices. To list the NDKs in a different location, specify the location with the "-p" switch prior to the "-h" switch.

Example command lines:

- source android_setup.csh -n 8c -g 4.6 -a 14 -c x86 -d mydevice
  Use android-ndk-r8c in the NDK directory, the GCC* 4.6 compiler, ABI level 14, the x86 cpu and connect to device "mydevice" to build libraries and to build libraries and to execute tests.
- source android_setup.csh -s /tmp/my-toolchain -d mydevice
  Use the standalone toolchain in "/tmp/my-toolchain". The values for GCC* level, ABI level and CPU are derived from the data in the toolchain. Connect to "mydevice" to to build libraries and to execute tests.

The environment variables set by the script are:

- $ANDROID_SERIAL - the device ID of the Android device connected to the host machine which will execute the unit tests. The device ID may have the port number ":5555" appended if needed.
- $CPLUS - the name of the C++ cross-compiler being used.
- $CC - the name of the C cross-compiler being used.
- $SYSROOT - The location of the /usr/include directory for the attached device. The value is passed to the compiler with the --sysroot switch.
- $CPLUS_INCLUDE_PATH - the list of the include paths being used by the compiler.
- $CPLUS_LIB_PATH - the location of dynamic library needed by the attached device (libgnustl_shared.so) and during the build stage. The value is used by android.linux.launcher.sh to find the libraries to copy to the device prior to execution.
- $tbb_tool_prefix - used by the Intel TBB build system.
- The location of the cross-compilers is added to the $PATH.
- For user convenience the environment variable $SETUPARGS is set to the arguments used in the last invocation of android_setup.csh in the current shell.

Once the environment is set up the shared libraries can be built. The format of the build command is

> gmake target=android cpp0x=1 run_cmd=\# <other switches>

Note the "run_cmd=\#" switch. The "run_cmd" is executed after the build stage is complete; when building the library no run step is required. The "#" just makes this run command a no-op.

After the libraries are built the unit tests can be performed. To test:

> gmake target=android cpp0x=1 run_cmd="../android.linux.launcher.sh" test

### The android.linux.launcher.sh script

Running an executable on an attached Android* device requires all the shared libraries and data being used be copied to the device. The android.linux.launcher.sh script does this.

Note: The script is tailored to meet the needs of the unit test system, and may not be suitable for general use.

The script will:

- Create a directory on the device to run the test from. If $ANDROID_TEST_DIRECTORY is not set, the location of the directory is /data/tbb/$(basename $PWD). All components of the path which do not exist are created.
- Transfer the executable file to the directory created on the device.
- Transfer the libgnustl_shared.so in $CPLUS_LIB_PATH to the directory created on the device.
- For each directory in $LD_LIBRARY_PATH, will transfer any files matching the pattern "libtbb*" to the directory created on the device. ($LD_LIBRARY_PATH is set by tbbvars.csh and tbbvars.sh, so one of these scripts must be run before android.linux.launcher.sh will work if not used as part of the gmake test command.)
- Where $exeroot is the base name of the executable, transfer any files from the current directory matching the patterns "$exeroot*.so" and "$exeroot*.so.*" to the device.
- For each additional argument to the script which is a file, will transfer the file to the device, creating a copy of the subdirectory it resides in on the device if necessary.
- Launch an adb shell to execute the program on the device, passing any arguments and fetching back the return code.
- Delete the transferred files and the test directory created by the script.

Copyright © 2005-2013 Intel Corporation. All Rights Reserved.

Intel is a registered trademark or trademark of Intel Corporation or its subsidiaries in the United States and other countries.

* Other names and brands may be claimed as the property of others.