p≡p for Java
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

400 lines
12 KiB

  1. # Copyright 2019, pEp Foundation
  2. # This file is part of pEpJNIAdapter for Android - ARMv7 build
  3. # This file may be used under the terms of the GNU General Public License version 3
  4. # see LICENSE.txt
  5. include ../Makefile.conf
  6. #------------------------------------------------------------------------------#
  7. # Makefile to build deps for use with pEpEngine
  8. # based on gnupg-for-android/external/Makefile
  9. #------------------------------------------------------------------------------#
  10. #------------------------------------------------------------------------------#
  11. # Build parameters
  12. APP_ABI ?= armeabi-v7a
  13. ANDROID_API ?= 18
  14. all: build
  15. #assets
  16. build: generate-ndk-toolchain showsetup uuid-install sequoia-ffi-install libetpan-build
  17. #------------------------------------------------------------------------------#
  18. # Generate standalone toolchain
  19. generate-ndk-toolchain: ndk-standalone-toolchain/bin/clang
  20. ndk-standalone-toolchain/bin/clang:
  21. bash generate-standalone-ndk-toolchain.sh
  22. #------------------------------------------------------------------------------#
  23. # Manage paths for PREFIX, DESTDIR, LOCAL and PATH
  24. EXTERNAL_ROOT := $(shell pwd)
  25. # install root for built files
  26. DESTDIR = $(EXTERNAL_ROOT)/..
  27. prefix = /output/$(APP_ABI)
  28. LOCAL := $(DESTDIR)$(prefix)
  29. PATH := ${PATH}:$(NDK_TOOLCHAIN)/bin:$(LOCAL)/bin
  30. NDK_SYSROOT=$(ANDROID_NDK_HOME)/sysroot
  31. HOST = arm-linux-androideabi
  32. NDK_TOOLCHAIN = $(HOST)-$(NDK_TOOLCHAIN_COMPILER)
  33. # include Android's build flags
  34. TARGET_ARCH_ABI = $(APP_ABI)
  35. include $(ANDROID_NDK)/build/core/toolchains/$(NDK_TOOLCHAIN)/setup.mk
  36. ANDROID_NDK_HOME=$(EXTERNAL_ROOT)/ndk-standalone-toolchain
  37. LD := $(ANDROID_NDK_HOME)/bin/$(HOST)-ld
  38. AR := $(ANDROID_NDK_HOME)/bin/$(HOST)-ar
  39. AS := $(ANDROID_NDK_HOME)/bin/$(HOST)-clang
  40. CC := $(ANDROID_NDK_HOME)/bin/$(HOST)-clang
  41. CXX := $(ANDROID_NDK_HOME)/bin/$(HOST)-clang++
  42. RANLIB := $(ANDROID_NDK_HOME)/bin/$(HOST)-ranlib
  43. STRIP := $(ANDROID_NDK_HOME)/bin/$(HOST)-strip
  44. CFLAGS += -DANDROID -I$(LOCAL)/include $(TARGET_CFLAGS) -fPIE -fPIC -std=c99
  45. LDFLAGS += -llog -L$(LOCAL)/lib $(TARGET_LDFLAGS) -pie
  46. # change 'release' to 'debug' for unoptimized debug builds
  47. CFLAGS += $(TARGET_arm_debug_CFLAGS)
  48. #------------------------------------------------------------------------------#
  49. # GNU Tools trickery
  50. # point pkg-config to the .pc files generated from these builds
  51. export PKG_CONFIG_PATH=$(LOCAL)/lib/pkgconfig
  52. # workaround for cross-compiling bug in autoconf
  53. export ac_cv_func_malloc_0_nonnull=yes
  54. #------------------------------------------------------------------------------#
  55. # debugging stuff
  56. showsetup:
  57. @echo "NDK_TOOLCHAIN: $(NDK_TOOLCHAIN)"
  58. @echo "NDK_SYSROOT: $(NDK_SYSROOT)"
  59. @echo "APP_ABI: $(APP_ABI)"
  60. @echo "HOST: $(HOST)"
  61. @echo "CC: $(CC)"
  62. @echo "LD: $(LD)"
  63. @echo "CFLAGS: $(CFLAGS)"
  64. @echo "LDFLAGS: $(LDFLAGS)"
  65. #------------------------------------------------------------------------------#
  66. # libiconv
  67. libiconv.src.stamp: ../downloads/libiconv-1.15.tar.gz
  68. tar xvf $<
  69. mv libiconv-1.15 libiconv
  70. touch $@
  71. libiconv-src: libiconv.src.stamp
  72. libiconv-clean:
  73. rm -rf libiconv
  74. rm -rf libiconv.src.stamp
  75. libiconv/Makefile: libiconv.src.stamp
  76. cd libiconv && \
  77. CC="$(CC)" LD="$(LD)" AR="$(AR)" AS="$(AS)" RANLIB=$(RANLIB) STRIP="$(STRIP)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" \
  78. ./configure \
  79. --with-lib-path=$(LOCAL)/lib \
  80. --with-include-path=$(LOCAL)/include \
  81. --host=$(HOST) \
  82. --enable-static \
  83. --disable-shared \
  84. --prefix=$(LOCAL)
  85. libiconv/lib/.libs/libiconv.a: libiconv/Makefile
  86. $(MAKE) -C libiconv
  87. $(LOCAL)/lib/libiconv.a: libiconv/lib/.libs/libiconv.a
  88. $(MAKE) -C libiconv DESTDIR=$(DESTDIR) prefix=$(prefix) install
  89. ls -l $(LOCAL)/lib/libiconv.a
  90. libiconv-build: libiconv/lib/.libs/libiconv.a
  91. libiconv-install: $(LOCAL)/lib/libiconv.a
  92. #------------------------------------------------------------------------------#
  93. # libetpan
  94. libetpan.src.stamp: ../downloads/libetpan.tar.gz
  95. mkdir -p libetpan
  96. cd libetpan && tar xvf ../$<
  97. touch $@
  98. libetpan/Makefile: libetpan.src.stamp | libiconv-install
  99. cd libetpan/build-android; ICONV_PREFIX=$(LOCAL) bash ./build.sh
  100. cp -r libetpan/build-android/libetpan-android-1/$(APP_ABI)/lib/* $(LOCAL)/lib/
  101. cp -r libetpan/build-android/libetpan-android-1/include/* $(LOCAL)/include/
  102. touch $@
  103. libetpan-build: libetpan/Makefile
  104. libetpan-clean:
  105. rm -rf libetpan
  106. rm -rf libetpan.src.stamp
  107. #------------------------------------------------------------------------------#
  108. # uuid
  109. # using released package from debian. official ftp wasn't available today
  110. uuid.src.stamp: ../downloads/ossp-uuid_1.6.2.orig.tar.gz
  111. tar xvf $<
  112. mv uuid-1.6.2 uuid
  113. touch $@
  114. uuid-src: uuid.src.stamp
  115. uuid-clean:
  116. rm -rf uuid
  117. rm -rf uuid.src.stamp
  118. uuid/Makefile: uuid.src.stamp
  119. $(SED) -i 's,AC_CHECK_VA_COPY(),,' uuid/uuid.ac
  120. cd uuid && autoconf
  121. -patch -N -p1 --reject-file=- uuid/libtool.m4 ../libtool-Add-Android-Linux-support-iconv.patch
  122. cp ../config.sub uuid
  123. cp ../config.guess uuid
  124. cd uuid && \
  125. CC="$(CC)" AR="$(AR)" RANLIB=$(RANLIB) CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" \
  126. ./configure \
  127. --enable-static \
  128. --host=$(HOST) \
  129. --with-gnu-ld \
  130. --prefix=$(LOCAL)
  131. uuid/.libs/libuuid.so: uuid/Makefile
  132. $(MAKE) -C uuid
  133. $(LOCAL)/lib/libuuid.so: uuid/.libs/libuuid.so
  134. # install fails copying uuid cmdline tool, but libs are copied ...
  135. -$(MAKE) -C uuid DESTDIR=$(DESTDIR) prefix=$(prefix) install
  136. echo "****** THIS ERROR WAS WILLINGLY IGNORED ******"
  137. ls -l $(LOCAL)/lib/libuuid.so
  138. uuid-build: uuid/.libs/libuuid.so
  139. uuid-prebuild: uuid/jni/Android.mk uuid/Makefile
  140. uuid-install: $(LOCAL)/lib/libuuid.so | uuid-prebuild
  141. uuid/jni/Android.mk: uuid.src.stamp
  142. mkdir -p uuid/jni
  143. cp ../libuuid.Android.mk uuid/jni/Android.mk
  144. #------------------------------------------------------------------------------#
  145. # Sequoia
  146. sequoia-deps-build: openssl-install nettle-install
  147. #------------------------------------------------------------------------------#
  148. # OpenSSL
  149. openssl.src.stamp: ../downloads/openssl-$(OPENSSL_VERSION).tar.gz
  150. tar xvf $<
  151. mv openssl-$(OPENSSL_VERSION) openssl
  152. touch $@
  153. openssl-src: openssl.src.stamp
  154. openssl-clean:
  155. rm -rf openssl
  156. rm -rf openssl.src.stamp
  157. OPENSSL_ARCHITECTURE:=android-arm
  158. openssl/Makefile: openssl.src.stamp
  159. cd openssl && \
  160. PATH="$(ANDROID_NDK_HOME)/bin:$(PATH)" ../../configure_openssl.sh ${OPENSSL_ARCHITECTURE} $(ANDROID_API) $(LOCAL)
  161. openssl/libssl.so: | openssl/Makefile
  162. PATH="$(ANDROID_NDK_HOME)/bin:$(PATH)" $(MAKE) -C openssl
  163. $(LOCAL)/lib/libssl.so: openssl/libssl.so
  164. cd openssl && \
  165. cp libcrypto.so $(LOCAL)/lib && \
  166. cp libcrypto.a $(LOCAL)/lib && \
  167. cp libssl.so $(LOCAL)/lib && \
  168. cp libssl.a $(LOCAL)/lib
  169. ls -l $(LOCAL)/lib/libssl.so
  170. openssl-build: openssl/libssl.so
  171. openssl-install: $(LOCAL)/lib/libssl.so
  172. #------------------------------------------------------------------------------#
  173. # GMP
  174. gmp.src.stamp: ../downloads/gmp-$(GMP_VERSION).tar.bz2
  175. tar xvf $<
  176. mv gmp-$(GMP_VERSION) gmp
  177. touch $@
  178. gmp-src: gmp.src.stamp
  179. gmp-clean:
  180. rm -rf gmp
  181. rm -rf gmp.src.stamp
  182. gmp/Makefile: gmp.src.stamp
  183. cd gmp && \
  184. CC="$(CC)" LD="$(LD)" AR="$(AR)" AS="$(AS)" RANLIB=$(RANLIB) STRIP="$(STRIP)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" \
  185. ./configure \
  186. --host=$(HOST) \
  187. --prefix=$(LOCAL)
  188. gmp/.libs/libgmp.so: gmp/Makefile
  189. $(MAKE) -C gmp
  190. $(LOCAL)/lib/libgmp.so: gmp/.libs/libgmp.so
  191. $(MAKE) -C gmp DESTDIR=$(DESTDIR) prefix=$(prefix) install
  192. #gmp/libtool --finish $(LOCAL)/lib/
  193. ls -l $(LOCAL)/lib/libgmp.so
  194. touch $@
  195. gmp-build: gmp/.libs/libgmp.so
  196. gmp-install: $(LOCAL)/lib/libgmp.so
  197. #------------------------------------------------------------------------------#
  198. # NETTLE
  199. nettle.src.stamp: ../downloads/nettle-$(NETTLE_VERSION).tar.gz $(LOCAL)/lib/libgmp.so
  200. tar xvf $<
  201. mv nettle-$(NETTLE_VERSION) nettle
  202. touch $@
  203. nettle-src: nettle.src.stamp
  204. nettle-clean:
  205. rm -rf nettle
  206. rm -rf nettle.src.stamp
  207. nettle/Makefile: nettle.src.stamp
  208. -patch -N -p1 --reject-file=- nettle/configure.ac ../nettle-3.4.1-remove-so-versioning.patch
  209. -patch -N -p1 --reject-file=- nettle/Makefile.in ../nettle-3.4.1-remove-so-versioning-link.patch
  210. cd nettle && \
  211. CC="$(CC)" LD="$(LD)" AR="$(AR)" AS="$(AS)" RANLIB=$(RANLIB) STRIP="$(STRIP)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" \
  212. ./configure \
  213. --with-lib-path=$(LOCAL)/lib \
  214. --with-include-path=$(LOCAL)/include \
  215. --disable-static \
  216. --disable-documentation \
  217. --host=$(HOST) \
  218. --prefix=$(LOCAL)
  219. nettle/libnettle.so: nettle/Makefile
  220. $(MAKE) -C nettle
  221. $(LOCAL)/lib/libnettle.so: nettle/libnettle.so
  222. $(MAKE) -C nettle DESTDIR=$(DESTDIR) prefix=$(prefix) install
  223. nettle-build: nettle/libnettle.so
  224. nettle-install: $(LOCAL)/lib/libnettle.so
  225. #------------------------------------------------------------------------------#
  226. # Sequoia-ffi
  227. CARGO_TARGET_DIR=$(EXTERNAL_ROOT)/../build
  228. sequoia.src.stamp: ../downloads/sequoia.tar.gz
  229. mkdir -p sequoia
  230. cd sequoia && tar xvf ../$<
  231. touch $@
  232. sequoia-ffi-clean:
  233. rm -rf sequoia
  234. rm -rf sequoia.src.stamp
  235. $(CARGO_TARGET_DIR)/armv7-linux-androideabi/release/libsequoia_openpgp_ffi.so: sequoia.src.stamp sequoia-deps-build
  236. cd sequoia && PATH="$(ANDROID_NDK_HOME)/bin:$(PATH)" \
  237. LD_LIBRARY_PATH=$(LOCAL)/lib/ \
  238. PKG_CONFIG_PATH=$(LOCAL)/lib/pkgconfig \
  239. PKG_CONFIG_ALLOW_CROSS=1 \
  240. ARMV7_LINUX_ANDROIDEABI_OPENSSL_LIB_DIR="$(LOCAL)/lib" \
  241. ARMV7_LINUX_ANDROIDEABI_OPENSSL_INCLUDE_DIR="$(LOCAL)/include" \
  242. ARMV7_LINUX_ANDROIDEABI_OPENSSL_DIR="$(LOCAL)/bin" \
  243. CARGO_TARGET_DIR=$(CARGO_TARGET_DIR) rustup run nightly cargo build --target armv7-linux-androideabi -p sequoia-openpgp-ffi --release -Z build-std=core,alloc,std
  244. $(LOCAL)/lib/libsequoia_openpgp_ffi.so: $(CARGO_TARGET_DIR)/armv7-linux-androideabi/release/libsequoia_openpgp_ffi.so
  245. cp $(CARGO_TARGET_DIR)/armv7-linux-androideabi/release/libsequoia_openpgp_ffi.* $(LOCAL)/lib/
  246. cp -r sequoia/openpgp-ffi/include/* $(LOCAL)/include
  247. sequoia-ffi-build: $(CARGO_TARGET_DIR)/armv7-linux-androideabi/release/libsequoia_openpgp_ffi.so
  248. sequoia-ffi-install: sequoia-deps-build $(LOCAL)/lib/libsequoia_openpgp_ffi.so
  249. #------------------------------------------------------------------------------#
  250. # assets for Android app
  251. #ASSETS := $(EXTERNAL_ROOT)/assets
  252. #
  253. #assets: clean-assets
  254. # # add the new stuff
  255. # install -d $(ASSETS)
  256. # cp -a $(LOCAL)/* $(ASSETS)
  257. # # remove all the stuff we don't need
  258. # rm -f $(ASSETS)/bin/*-static
  259. # rm -f $(ASSETS)/bin/curl*
  260. # rm -f $(ASSETS)/lib/*.a $(ASSETS)/lib/*.la
  261. # # remove lib symlinks since Android AssetManager copies them as files
  262. # rm -f $(ASSETS)/lib/*.so
  263. # # remove .so.0 symlink and rename the .so.0.12.0 file to it
  264. # for f in $(ASSETS)/lib/*.so.[0-9]*; do \
  265. # echo $$f; \
  266. # test ! -L $$f || \
  267. # (rm $$f && mv $$f.[0-9]* $$f); \
  268. # done
  269. # rm -rf $(ASSETS)/include
  270. # rm -rf $(ASSETS)/share/man $(ASSETS)/share/info $(ASSETS)/share/doc
  271. # rm -rf $(ASSETS)/tests
  272. #
  273. #------------------------------------------------------------------------------#
  274. # Clone update and archive external projects GIT repos
  275. # Local clone is in external/$project.git while
  276. # selected commit is archived in external/$project
  277. #------------------------------------------------------------------------------#
  278. # clean
  279. clean-assets:
  280. rm -rf $(ASSETS)
  281. clean-install:
  282. rm -rf $(LOCAL)
  283. clean: $(EXTERNAL_SRCS_CLEAN) clean-assets clean-install libetpan-clean
  284. clean-all: clean
  285. rm -rf *.git
  286. rm -rf *.stamp
  287. #------------------------------------------------------------------------------#
  288. .PHONY = clean clean-install clean-assets libetpan-clean \
  289. libiconv-build libiconv-install \
  290. libetpan-build \
  291. uuid-build uuid-prebuild uuid-install \
  292. gmp-build gmp-install \
  293. sequoia-deps-build \
  294. openssl-build openssl-install \
  295. nettle-build nettle-install \
  296. sequoia-ffi-build sequoia-ffi-install\
  297. assets \
  298. $(EXTERNAL_LOCAL_GITS_UPDATE) $(EXTERNAL_SRCS) $(EXTERNAL_SRCS_CLEAN)\
  299. showsetup