how to rewrite the Makefile into android.mk?

梦想与她 提交于 2019-11-30 04:00:20

You're going about the incorrect way. The Android.mk file is equivalent to the Makefile.ac in the autotools world. So start with the conversion of the Makefile.ac, rather than the Makefile itself.

However, the one issue you'll face is that there isn't any equivalent for the configure script in the NDK. This means that there is no automated method to create the config.h usually found in projects using autotools.

A quick and hacky solution is to run ./configure with appropriate options to generate a config.h that is correct, port the Makefile.am into Android.mk and then build with the NDK.

The options I use are using ndk r7c(I build against API_8 which is 2.2):

./configure \
--host=arm-linux-androideabi \
CC=arm-linux-androideabi-gcc \
LD=arm-linux-androideabi-ld \
CPPFLAGS="-I/home/sdk/ndk/platforms/android-8/arch-arm/usr/include/" \
CFLAGS="-nostdlib" \
LDFLAGS="-Wl,-rpath-link=/home/sdk/ndk/platforms/android-8/arch-arm/usr/lib/ -L/home/sdk/ndk/platforms/android-8/arch-arm/usr/lib/" \
LIBS="-lc"

An example of what I did (file(1) and libmagic) can be downloaded from http://forum.xda-developers.com/showthread.php?t=1612760

FooF

Maybe you do not need to convert the Makefile or Makefile.ac into Android.mk. You can also use Android NDK tool chains independently as detailed in Android NDK documentation (${NDK_INSTALL_DIR}/doc/STANDALONE-TOOLCHAIN.html). You would need to specify -sysroot option for cross compile gcc when running ./configure, something like this perhaps:

./configure --host=xxx CC="xxx-gcc" \
CFLAGS="-sysroot ${NDK_INSTALL_DIR}/platforms/android-<level>/arch-<arch>/" \
CPPFLAGS="-sysroot ..." ...

You could make it even easier by building dedicated tool chain removing the need to provide -sysroot option (this also detailed in the above NDK documentation file).

Related questions:

  • Answer to Tool to generate an Android.mk says you could use cmake to build Android.mk files - I have not tried and have no idea about this approach.
  • Android.mk for LibXtract (includes my answer with some more details than given here about using independent tool chain).
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!