Saturday, February 25, 2017

NEW: Building libpng 1.6.28 using Android NDK r13 CMake based build system

I recently updated to NDK revision 13 and also found ndk samples are now cmake + ninja based. Today 3-4 hours were consumed while trying to compile libpng but finally done it after editing CMakeLists.txt of libpng.

I tried to build libpng using Androud Studio's Gradle plugin from IDE but that was more problematic as it too required CMakeLists.txt editing and kept throwing bad link to libpng.so error. I decided to use shell which is my 1st and last choice to work in most cases. Before putting the scripts/code lets setup our work directory and data and also look at how cmake based build system compiles libpng.


Before starting ensure below tools are installed and working correctly on your system.

  • Android NDK revision 12+ is installed. If you have Android SDK installed but NDK is at some other location then you can move NDK inside SDK and rename it to ndk-bundle Or create a sym-link "ndk-bundle" in SDK pointing to actual NDK. After this NDK will start showing in the Android Studio 2.2+ SDK manager.
  • Install cmake from SDK manager. It will get extracted in Android SDK directory.
  • A good command shell. I use Ubuntu-Studio Linux with bash shell(s). Windows users can use cmd.exe or bash shell through UnixUtils.


Build process:

  1. Dowload libpng 1.6.28 from here http://ftp.osuosl.org/pub/blfs/conglomeration/libpng/libpng-1.6.28.tar.xz and extract to some location with shorter path without spaces. e.g. /home/username/projects/libpng in Linux or c:\work\libpng in windows. This is for convenience and avoid space related issues while compiling.
  2. Copy full path of android.toolchain.cmake present in NDK. Example /media/bindesh/WORK/SDK_IDE/android-ndk-r13b/build/cmake/android.toolchain.cmake. There is same named file present in ANDROID_SDK/cmake/ like this /media/bindesh/WORK/SDK_IDE/android-sdk-linux-windows/cmake/3.6.3155560/android.toolchain.cmake but we must use toolchain file present in NDK. If toolchain present in sdk/cmake is used incompatibility issues like "Invalid Android NDK revision (should be 12" can occur.
  3. Open libpng/CMakeLists.txt file in text editor and add include("/home/bindesh/bin/ndk/build/cmake/android.toolchain.cmake") line after project(libpng C). Change the NDK path to yours.

Copy below bash script to create a file build.sh in libpng folder. Change the cmake, ninja, toolchain, sdk, ndk paths in script and run to build libpng. Replace the toolchain path copied through above steps. I have not tested this on Windows but using UnixUtils's sh.exe it should work.


build script:
#!/bin/sh

# run this script after changing the paths of ndk, sdk, cmake, ninja etc to build libpng or other cmake based library.
# Don't forget to add below line in main CMakeLists.txt after project() line of code.
# include("PATH_TO_NDK/build/cmake/android.toolchain.cmake")

clear
reset

# clean previous files
rm CMakeCache.txt


# Change these paths and run this script to build libpng
ANDROID_NDK_PATH=/home/bindesh/bin/ndk
ANDROID_SDK_PATH=/home/bindesh/bin/android-sdk
ANDROID_NDK=${ANDROID_NDK_PATH}

ANDROID_CMAKE_PATH=${ANDROID_SDK_PATH}/cmake/3.6.3155560/bin
ANDROID_CMAKE_TOOLCHAIN=${ANDROID_NDK_PATH}/build/cmake/android.toolchain.cmake

# Don't use toolchain from cmake
#ANDROID_CMAKE_TOOLCHAIN=/media/bindesh/WORK/SDK_IDE/android-sdk-linux-windows/cmake/3.6.3155560/android.toolchain.cmake


ANDROID_API=9
ANDROID_ARCH=arm
ANDROID_ABI=armeabi-v7a
ANDROID_PLATFORM=android-${ANDROID_API}
ANDROID_ARCH=arch-${ANDROID_ARCH}

${ANDROID_CMAKE_PATH}/cmake -DCMAKE_TOOLCHAIN_FILE=${ANDROID_CMAKE_TOOLCHAIN} -DANDROID_ABI=${ANDROID_ABI} -DANDROID_TOOLCHAIN=gcc -DANDROID_NATIVE_API_LEVEL=${ANDROID_API} -DANDROID_PLATFORM=${ANDROID_PLATFORM} -DCMAKE_MAKE_PROGRAM=${ANDROID_CMAKE_PATH}/ninja -G"Android Gradle - Ninja" 
#-DCMAKE_BUILD_TYPE=Release

#${ANDROID_CMAKE_PATH}/cmake -DCMAKE_TOOLCHAIN_FILE=${ANDROID_CMAKE_TOOLCHAIN} -DCMAKE_MAKE_PROGRAM=${ANDROID_CMAKE_PATH}/ninja -G"Android Gradle - Ninja" -DANDROID_NDK=${ANDROID_NDK}
${ANDROID_CMAKE_PATH}/ninja
#make 
 

mv ./libpng16.a ./libpng16-${ANDROID_ABI}.a


 


Below is the CMakeOutput.log to check details of build environment.

Preview:
The target system is: Android - 9 - armv7-a
The host system is: Linux - 4.8.0-22-lowlatency - x86_64
Compiling the C compiler identification source file "CMakeCCompilerId.c" succeeded.
Compiler: /home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc 
Build flags: -g;-DANDROID;-ffunction-sections;-funwind-tables;-fstack-protector-strong;-no-canonical-prefixes;-march=armv7-a;-mfloat-abi=softfp;-mfpu=vfpv3-d16;-mthumb;-Wa,--noexecstack;-Wformat;-Werror=format-security;-g;-DANDROID;-ffunction-sections;-funwind-tables;-fstack-protector-strong;-no-canonical-prefixes;-march=armv7-a;-mfloat-abi=softfp;-mfpu=vfpv3-d16;-mthumb;-Wa,--noexecstack;-Wformat;-Werror=format-security;
Id flags: -c

The output was:
0


Compilation of the C compiler identification source "CMakeCCompilerId.c" produced "CMakeCCompilerId.o"

The C compiler identification is GNU, found in "/media/bindesh/WORK/00_write/libpng-1.6.28/CMakeFiles/3.6.0-rc2/CompilerIdC/CMakeCCompilerId.o"

Determining if the C compiler works passed with the following output:
Change Dir: /media/bindesh/WORK/00_write/libpng-1.6.28/CMakeFiles/CMakeTmp

Run Build Command:"/home/bindesh/bin/android-sdk/cmake/3.6.3155560/bin/ninja" "cmTC_76f0a"
[1/2] Building C object CMakeFiles/cmTC_76f0a.dir/testCCompiler.c.o
[2/2] Linking C executable cmTC_76f0a


Detecting C compiler ABI info compiled with the following output:
Change Dir: /media/bindesh/WORK/00_write/libpng-1.6.28/CMakeFiles/CMakeTmp

Run Build Command:"/home/bindesh/bin/android-sdk/cmake/3.6.3155560/bin/ninja" "cmTC_7ad81"
[1/2] Building C object CMakeFiles/cmTC_7ad81.dir/CMakeCCompilerABI.c.o
[2/2] Linking C executable cmTC_7ad81
Using built-in specs.
COLLECT_GCC=/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc
COLLECT_LTO_WRAPPER=/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../libexec/gcc/arm-linux-androideabi/4.9.x/lto-wrapper
Target: arm-linux-androideabi
Configured with: /usr/local/google/buildbot/src/android/gcc/toolchain/build/../gcc/gcc-4.9/configure --prefix=/tmp/59719db9ae19ff43aef46bbcb79596b6 --target=arm-linux-androideabi --host=x86_64-linux-gnu --build=x86_64-linux-gnu --with-gnu-as --with-gnu-ld --enable-languages=c,c++ --with-gmp=/buildbot/tmp/build/toolchain/temp-install --with-mpfr=/buildbot/tmp/build/toolchain/temp-install --with-mpc=/buildbot/tmp/build/toolchain/temp-install --with-cloog=/buildbot/tmp/build/toolchain/temp-install --with-isl=/buildbot/tmp/build/toolchain/temp-install --with-ppl=/buildbot/tmp/build/toolchain/temp-install --disable-ppl-version-check --disable-cloog-version-check --disable-isl-version-check --enable-cloog-backend=isl --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' --disable-libssp --enable-threads --disable-nls --disable-libmudflap --disable-libgomp --disable-libstdc__-v3 --disable-sjlj-exceptions --disable-shared --disable-tls --disable-libitm --with-float=soft --with-fpu=vfp --with-arch=armv5te --enable-target-optspace --enable-bionic-libs --enable-libatomic-ifuncs=no --enable-initfini-array --disable-nls --prefix=/tmp/59719db9ae19ff43aef46bbcb79596b6 --with-sysroot=/tmp/59719db9ae19ff43aef46bbcb79596b6/sysroot --with-binutils-version=2.25 --with-mpfr-version=3.1.1 --with-mpc-version=1.0.1 --with-gmp-version=5.0.5 --with-gcc-version=4.9 --with-gdb-version=none --with-gxx-include-dir=/tmp/59719db9ae19ff43aef46bbcb79596b6/include/c++/4.9.x --with-bugurl=http://source.android.com/source/report-bugs.html --enable-languages=c,c++ --disable-bootstrap --enable-plugins --enable-libgomp --enable-gnu-indirect-function --disable-libsanitizer --enable-gold --enable-threads --enable-eh-frame-hdr-for-static --enable-graphite=yes --with-isl-version=0.11.1 --with-cloog-version=0.18.0 --with-arch=armv5te --program-transform-name='s&^&arm-linux-androideabi-&' --enable-gold=default
Thread model: posix
gcc version 4.9.x 20150123 (prerelease) (GCC) 
COMPILER_PATH=/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../libexec/gcc/arm-linux-androideabi/4.9.x/:/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../libexec/gcc/:/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/
LIBRARY_PATH=/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/armv7-a/thumb/:/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/lib/armv7-a/thumb/:/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/:/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/:/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/lib/:/home/bindesh/bin/ndk/platforms/android-9/arch-arm/usr/lib/
COLLECT_GCC_OPTIONS='-g' '-D' 'ANDROID' '-fstack-protector-strong' '-march=armv7-a' '-mfloat-abi=softfp' '-mfpu=vfpv3-d16' '-mthumb' '-Wformat=1' '-Werror=format-security' '-g' '-D' 'ANDROID' '-ffunction-sections' '-funwind-tables' '-fstack-protector-strong' '-march=armv7-a' '-mfloat-abi=softfp' '-mfpu=vfpv3-d16' '-mthumb' '-Wformat=1' '-Werror=format-security' '-v' '-o' 'cmTC_7ad81' '-mtls-dialect=gnu'
 /home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../libexec/gcc/arm-linux-androideabi/4.9.x/collect2 -plugin /home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../libexec/gcc/arm-linux-androideabi/4.9.x/liblto_plugin.so -plugin-opt=/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../libexec/gcc/arm-linux-androideabi/4.9.x/lto-wrapper -plugin-opt=-fresolution=/tmp/ccNet1nu.res -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-ldl -plugin-opt=-pass-through=-lgcc --sysroot=/home/bindesh/bin/ndk/platforms/android-9/arch-arm --eh-frame-hdr -dynamic-linker /system/bin/linker -X -m armelf_linux_eabi -z noexecstack -z relro -z now -o cmTC_7ad81 /home/bindesh/bin/ndk/platforms/android-9/arch-arm/usr/lib/crtbegin_dynamic.o -L/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/armv7-a/thumb -L/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/lib/armv7-a/thumb -L/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x -L/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../lib/gcc -L/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/lib -L/home/bindesh/bin/ndk/platforms/android-9/arch-arm/usr/lib --build-id --warn-shared-textrel --fatal-warnings --fix-cortex-a8 --no-undefined -z noexecstack -z relro -z now --gc-sections -z nocopyreloc CMakeFiles/cmTC_7ad81.dir/CMakeCCompilerABI.c.o -lgcc -lc -ldl -lgcc /home/bindesh/bin/ndk/platforms/android-9/arch-arm/usr/lib/crtend_android.o


Parsed C implicit link information from above output:
  link line regex: [^( *|.*[/\])(arm-linux-androideabi-ld|([^/\]+-)?ld|collect2)[^/\]*( |$)]
  ignore line: [Change Dir: /media/bindesh/WORK/00_write/libpng-1.6.28/CMakeFiles/CMakeTmp]
  ignore line: []
  ignore line: [Run Build Command:"/home/bindesh/bin/android-sdk/cmake/3.6.3155560/bin/ninja" "cmTC_7ad81"]
  ignore line: [[1/2] Building C object CMakeFiles/cmTC_7ad81.dir/CMakeCCompilerABI.c.o]
  ignore line: [[2/2] Linking C executable cmTC_7ad81]
  ignore line: [Using built-in specs.]
  ignore line: [COLLECT_GCC=/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc]
  ignore line: [COLLECT_LTO_WRAPPER=/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../libexec/gcc/arm-linux-androideabi/4.9.x/lto-wrapper]
  ignore line: [Target: arm-linux-androideabi]
  ignore line: [Configured with: /usr/local/google/buildbot/src/android/gcc/toolchain/build/../gcc/gcc-4.9/configure --prefix=/tmp/59719db9ae19ff43aef46bbcb79596b6 --target=arm-linux-androideabi --host=x86_64-linux-gnu --build=x86_64-linux-gnu --with-gnu-as --with-gnu-ld --enable-languages=c,c++ --with-gmp=/buildbot/tmp/build/toolchain/temp-install --with-mpfr=/buildbot/tmp/build/toolchain/temp-install --with-mpc=/buildbot/tmp/build/toolchain/temp-install --with-cloog=/buildbot/tmp/build/toolchain/temp-install --with-isl=/buildbot/tmp/build/toolchain/temp-install --with-ppl=/buildbot/tmp/build/toolchain/temp-install --disable-ppl-version-check --disable-cloog-version-check --disable-isl-version-check --enable-cloog-backend=isl --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' --disable-libssp --enable-threads --disable-nls --disable-libmudflap --disable-libgomp --disable-libstdc__-v3 --disable-sjlj-exceptions --disable-shared --disable-tls --disable-libitm --with-float=soft --with-fpu=vfp --with-arch=armv5te --enable-target-optspace --enable-bionic-libs --enable-libatomic-ifuncs=no --enable-initfini-array --disable-nls --prefix=/tmp/59719db9ae19ff43aef46bbcb79596b6 --with-sysroot=/tmp/59719db9ae19ff43aef46bbcb79596b6/sysroot --with-binutils-version=2.25 --with-mpfr-version=3.1.1 --with-mpc-version=1.0.1 --with-gmp-version=5.0.5 --with-gcc-version=4.9 --with-gdb-version=none --with-gxx-include-dir=/tmp/59719db9ae19ff43aef46bbcb79596b6/include/c++/4.9.x --with-bugurl=http://source.android.com/source/report-bugs.html --enable-languages=c,c++ --disable-bootstrap --enable-plugins --enable-libgomp --enable-gnu-indirect-function --disable-libsanitizer --enable-gold --enable-threads --enable-eh-frame-hdr-for-static --enable-graphite=yes --with-isl-version=0.11.1 --with-cloog-version=0.18.0 --with-arch=armv5te --program-transform-name='s&^&arm-linux-androideabi-&' --enable-gold=default]
  ignore line: [Thread model: posix]
  ignore line: [gcc version 4.9.x 20150123 (prerelease) (GCC) ]
  ignore line: [COMPILER_PATH=/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../libexec/gcc/arm-linux-androideabi/4.9.x/:/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../libexec/gcc/:/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/]
  ignore line: [LIBRARY_PATH=/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/armv7-a/thumb/:/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/lib/armv7-a/thumb/:/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/:/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/:/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/lib/:/home/bindesh/bin/ndk/platforms/android-9/arch-arm/usr/lib/]
  ignore line: [COLLECT_GCC_OPTIONS='-g' '-D' 'ANDROID' '-fstack-protector-strong' '-march=armv7-a' '-mfloat-abi=softfp' '-mfpu=vfpv3-d16' '-mthumb' '-Wformat=1' '-Werror=format-security' '-g' '-D' 'ANDROID' '-ffunction-sections' '-funwind-tables' '-fstack-protector-strong' '-march=armv7-a' '-mfloat-abi=softfp' '-mfpu=vfpv3-d16' '-mthumb' '-Wformat=1' '-Werror=format-security' '-v' '-o' 'cmTC_7ad81' '-mtls-dialect=gnu']
  link line: [ /home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../libexec/gcc/arm-linux-androideabi/4.9.x/collect2 -plugin /home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../libexec/gcc/arm-linux-androideabi/4.9.x/liblto_plugin.so -plugin-opt=/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../libexec/gcc/arm-linux-androideabi/4.9.x/lto-wrapper -plugin-opt=-fresolution=/tmp/ccNet1nu.res -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-ldl -plugin-opt=-pass-through=-lgcc --sysroot=/home/bindesh/bin/ndk/platforms/android-9/arch-arm --eh-frame-hdr -dynamic-linker /system/bin/linker -X -m armelf_linux_eabi -z noexecstack -z relro -z now -o cmTC_7ad81 /home/bindesh/bin/ndk/platforms/android-9/arch-arm/usr/lib/crtbegin_dynamic.o -L/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/armv7-a/thumb -L/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/lib/armv7-a/thumb -L/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x -L/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../lib/gcc -L/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/lib -L/home/bindesh/bin/ndk/platforms/android-9/arch-arm/usr/lib --build-id --warn-shared-textrel --fatal-warnings --fix-cortex-a8 --no-undefined -z noexecstack -z relro -z now --gc-sections -z nocopyreloc CMakeFiles/cmTC_7ad81.dir/CMakeCCompilerABI.c.o -lgcc -lc -ldl -lgcc /home/bindesh/bin/ndk/platforms/android-9/arch-arm/usr/lib/crtend_android.o]
    arg [/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../libexec/gcc/arm-linux-androideabi/4.9.x/collect2] ==> ignore
    arg [-plugin] ==> ignore
    arg [/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../libexec/gcc/arm-linux-androideabi/4.9.x/liblto_plugin.so] ==> ignore
    arg [-plugin-opt=/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../libexec/gcc/arm-linux-androideabi/4.9.x/lto-wrapper] ==> ignore
    arg [-plugin-opt=-fresolution=/tmp/ccNet1nu.res] ==> ignore
    arg [-plugin-opt=-pass-through=-lgcc] ==> ignore
    arg [-plugin-opt=-pass-through=-lc] ==> ignore
    arg [-plugin-opt=-pass-through=-ldl] ==> ignore
    arg [-plugin-opt=-pass-through=-lgcc] ==> ignore
    arg [--sysroot=/home/bindesh/bin/ndk/platforms/android-9/arch-arm] ==> ignore
    arg [--eh-frame-hdr] ==> ignore
    arg [-dynamic-linker] ==> ignore
    arg [/system/bin/linker] ==> ignore
    arg [-X] ==> ignore
    arg [-m] ==> ignore
    arg [armelf_linux_eabi] ==> ignore
    arg [-znoexecstack] ==> ignore
    arg [-zrelro] ==> ignore
    arg [-znow] ==> ignore
    arg [-o] ==> ignore
    arg [cmTC_7ad81] ==> ignore
    arg [/home/bindesh/bin/ndk/platforms/android-9/arch-arm/usr/lib/crtbegin_dynamic.o] ==> ignore
    arg [-L/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/armv7-a/thumb] ==> dir [/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/armv7-a/thumb]
    arg [-L/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/lib/armv7-a/thumb] ==> dir [/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/lib/armv7-a/thumb]
    arg [-L/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x] ==> dir [/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x]
    arg [-L/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../lib/gcc] ==> dir [/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../lib/gcc]
    arg [-L/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/lib] ==> dir [/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/lib]
    arg [-L/home/bindesh/bin/ndk/platforms/android-9/arch-arm/usr/lib] ==> dir [/home/bindesh/bin/ndk/platforms/android-9/arch-arm/usr/lib]
    arg [--build-id] ==> ignore
    arg [--warn-shared-textrel] ==> ignore
    arg [--fatal-warnings] ==> ignore
    arg [--fix-cortex-a8] ==> ignore
    arg [--no-undefined] ==> ignore
    arg [-znoexecstack] ==> ignore
    arg [-zrelro] ==> ignore
    arg [-znow] ==> ignore
    arg [--gc-sections] ==> ignore
    arg [-znocopyreloc] ==> ignore
    arg [CMakeFiles/cmTC_7ad81.dir/CMakeCCompilerABI.c.o] ==> ignore
    arg [-lgcc] ==> lib [gcc]
    arg [-lc] ==> lib [c]
    arg [-ldl] ==> lib [dl]
    arg [-lgcc] ==> lib [gcc]
    arg [/home/bindesh/bin/ndk/platforms/android-9/arch-arm/usr/lib/crtend_android.o] ==> ignore
  remove lib [gcc]
  remove lib [gcc]
  collapse library dir [/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/armv7-a/thumb] ==> [/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/armv7-a/thumb]
  collapse library dir [/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/lib/armv7-a/thumb] ==> [/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/arm-linux-androideabi/lib/armv7-a/thumb]
  collapse library dir [/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x] ==> [/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x]
  collapse library dir [/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../lib/gcc] ==> [/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/lib/gcc]
  collapse library dir [/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/lib] ==> [/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/arm-linux-androideabi/lib]
  collapse library dir [/home/bindesh/bin/ndk/platforms/android-9/arch-arm/usr/lib] ==> [/home/bindesh/bin/ndk/platforms/android-9/arch-arm/usr/lib]
  implicit libs: [c;dl]
  implicit dirs: [/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/armv7-a/thumb;/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/arm-linux-androideabi/lib/armv7-a/thumb;/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x;/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/lib/gcc;/home/bindesh/bin/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/arm-linux-androideabi/lib;/home/bindesh/bin/ndk/platforms/android-9/arch-arm/usr/lib]
  implicit fwks: []




Detecting C [-std=c11] compiler features compiled with the following output:
Change Dir: /media/bindesh/WORK/00_write/libpng-1.6.28/CMakeFiles/CMakeTmp

Run Build Command:"/home/bindesh/bin/android-sdk/cmake/3.6.3155560/bin/ninja" "cmTC_5d10b"
[1/2] Building C object CMakeFiles/cmTC_5d10b.dir/feature_tests.c.o
[2/2] Linking C executable cmTC_5d10b


    Feature record: C_FEATURE:1c_function_prototypes
    Feature record: C_FEATURE:1c_restrict
    Feature record: C_FEATURE:1c_static_assert
    Feature record: C_FEATURE:1c_variadic_macros


Detecting C [-std=c99] compiler features compiled with the following output:
Change Dir: /media/bindesh/WORK/00_write/libpng-1.6.28/CMakeFiles/CMakeTmp

Run Build Command:"/home/bindesh/bin/android-sdk/cmake/3.6.3155560/bin/ninja" "cmTC_bb98c"
[1/2] Building C object CMakeFiles/cmTC_bb98c.dir/feature_tests.c.o
[2/2] Linking C executable cmTC_bb98c


    Feature record: C_FEATURE:1c_function_prototypes
    Feature record: C_FEATURE:1c_restrict
    Feature record: C_FEATURE:0c_static_assert
    Feature record: C_FEATURE:1c_variadic_macros


Detecting C [-std=c90] compiler features compiled with the following output:
Change Dir: /media/bindesh/WORK/00_write/libpng-1.6.28/CMakeFiles/CMakeTmp

Run Build Command:"/home/bindesh/bin/android-sdk/cmake/3.6.3155560/bin/ninja" "cmTC_f387f"
[1/2] Building C object CMakeFiles/cmTC_f387f.dir/feature_tests.c.o
[2/2] Linking C executable cmTC_f387f


    Feature record: C_FEATURE:1c_function_prototypes
    Feature record: C_FEATURE:0c_restrict
    Feature record: C_FEATURE:0c_static_assert
    Feature record: C_FEATURE:0c_variadic_macros
Performing C SOURCE FILE Test HAVE_LD_VERSION_SCRIPT succeeded with the following output:
Change Dir: /media/bindesh/WORK/00_write/libpng-1.6.28/CMakeFiles/CMakeTmp

Run Build Command:"/home/bindesh/bin/android-sdk/cmake/3.6.3155560/bin/ninja" "cmTC_d0d1b"
[1/2] Building C object CMakeFiles/cmTC_d0d1b.dir/src.c.o
[2/2] Linking C executable cmTC_d0d1b

Source file was:
void sym(void) {}
void sym2(void) {}
int main(void) {return 0;}



Head of CMakeLists.txt file for reference

# CMakeLists.txt

# Copyright (C) 2007,2009-2016 Glenn Randers-Pehrson
# Written by Christian Ehrlicher, 2007
# Revised by Roger Lowman, 2009-2010
# Revised by Clifford Yapp, 2011-2012
# Revised by Roger Leigh, 2016
# Revised by Andreas Franek, 2016

# This code is released under the libpng license.
# For conditions of distribution and use, see the disclaimer
# and license in png.h

cmake_minimum_required(VERSION 2.8.3)
cmake_policy(VERSION 2.8.3)

# Set MacOSX @rpath usage globally.
if (POLICY CMP0020)
  cmake_policy(SET CMP0020 NEW)
endif(POLICY CMP0020)
if (POLICY CMP0042)
  cmake_policy(SET CMP0042 NEW)
endif(POLICY CMP0042)
# Use new variable expansion policy.
if (POLICY CMP0053)
  cmake_policy(SET CMP0053 NEW)
endif(POLICY CMP0053)
if (POLICY CMP0054)
  cmake_policy(SET CMP0054 NEW)
endif(POLICY CMP0054)

set(CMAKE_CONFIGURATION_TYPES "Release;Debug;MinSizeRel;RelWithDebInfo")

project(libpng C)
enable_testing()

set(PNGLIB_MAJOR 1)
set(PNGLIB_MINOR 6)
set(PNGLIB_RELEASE 28)
set(PNGLIB_NAME libpng${PNGLIB_MAJOR}${PNGLIB_MINOR})
set(PNGLIB_VERSION ${PNGLIB_MAJOR}.${PNGLIB_MINOR}.${PNGLIB_RELEASE})


include("/home/bindesh/bin/ndk/build/cmake/android.toolchain.cmake")


# needed packages

#Allow users to specify location of Zlib, 
# Useful if zlib is being built alongside this as a sub-project
option(PNG_BUILD_ZLIB "Custom zlib Location, else find_package is used" OFF) 




This script will build libpng for specified ABI. Change the ABI to build x86, MIPS etc binaries. Sample output binary for above script can be downloaded from here:

 
https://github.com/bindeshkumarsingh/android-native-libs/blob/master/armeabi-v7a_libpng-1.6.28.7z

2 comments:

DanielFDaza said...

It's so amazing to find these kind of things on the Internet. As a former blogger, I sometimes felt frustrated about writing on very specific topics that hardly anyone read about. But in the future a single person might read the post and then it might have a great impact in the life of that person, which in my opinion makes worth the effort of documenting everything and making it public. Thank you for sharing your knowledge!

bindesh singh said...

Thank you Daniel. Same is the situation here. Very few people read such posts no matter my page comes on the top page while searching for the topic. However i am also switching to other topics to write/share. Done with programming, software...