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.

395 lines
11 KiB

  1. # Copyright 2019, pEp Foundation
  2. # This file is part of pEpJNIAdapter for Android - x86_64 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 ?= x86_64
  13. ANDROID_API ?= 21
  14. all: build
  15. build: generate-ndk-toolchain showsetup uuid-install sequoia-ffi-install libetpan-build
  16. #------------------------------------------------------------------------------#
  17. # Generate standalone toolchain
  18. generate-ndk-toolchain: ndk-standalone-toolchain/bin/clang
  19. ndk-standalone-toolchain/bin/clang:
  20. bash generate-standalone-ndk-toolchain.sh
  21. #------------------------------------------------------------------------------#
  22. # Manage paths for PREFIX, DESTDIR, LOCAL and PATH
  23. EXTERNAL_ROOT := $(shell pwd)
  24. # install root for built files
  25. DESTDIR = $(EXTERNAL_ROOT)/..
  26. prefix = /output/$(APP_ABI)
  27. LOCAL := $(DESTDIR)$(prefix)
  28. PATH := ${PATH}:$(NDK_TOOLCHAIN)/bin:$(LOCAL)/bin
  29. NDK_SYSROOT=$(ANDROID_NDK_HOME)/sysroot
  30. HOST = x86_64-linux-android
  31. NDK_TOOLCHAIN = $(APP_ABI)-$(NDK_TOOLCHAIN_COMPILER)
  32. # include Android's build flags
  33. TARGET_ARCH_ABI = $(APP_ABI)
  34. include $(ANDROID_NDK)/build/core/toolchains/$(NDK_TOOLCHAIN)/setup.mk
  35. ANDROID_NDK_HOME=$(EXTERNAL_ROOT)/ndk-standalone-toolchain
  36. LD := $(ANDROID_NDK_HOME)/bin/$(HOST)-ld
  37. AR := $(ANDROID_NDK_HOME)/bin/$(HOST)-ar
  38. AS := $(ANDROID_NDK_HOME)/bin/$(HOST)$(ANDROID_API)-clang
  39. CC := $(ANDROID_NDK_HOME)/bin/$(HOST)$(ANDROID_API)-clang
  40. CC := $(ANDROID_NDK_HOME)/bin/$(HOST)$(ANDROID_API)-clang
  41. CXX := $(ANDROID_NDK_HOME)/bin/$(HOST)$(ANDROID_API)-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_x86_64_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. uuid.src.stamp: ../downloads/ossp-uuid_1.6.2.orig.tar.gz
  110. tar xvf $<
  111. mv uuid-1.6.2 uuid
  112. touch $@
  113. uuid-src: uuid.src.stamp
  114. uuid-clean:
  115. rm -rf uuid
  116. rm -rf uuid.src.stamp
  117. uuid/Makefile: uuid.src.stamp
  118. $(SED) -i 's,AC_CHECK_VA_COPY(),,' uuid/uuid.ac
  119. cd uuid && autoconf
  120. -patch -N -p1 --reject-file=- uuid/libtool.m4 ../libtool-Add-Android-Linux-support-iconv.patch
  121. cp ../config.sub uuid
  122. cp ../config.guess uuid
  123. cd uuid && \
  124. CC="$(CC)" AR="$(AR)" RANLIB=$(RANLIB) CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" \
  125. ./configure \
  126. --enable-static \
  127. --host=$(HOST) \
  128. --with-gnu-ld \
  129. --prefix=$(LOCAL)
  130. uuid/.libs/libuuid.so: uuid/Makefile
  131. $(MAKE) -C uuid
  132. $(LOCAL)/lib/libuuid.so: uuid/.libs/libuuid.so
  133. # install fails copying uuid cmdline tool, but libs are copied ...
  134. -$(MAKE) -C uuid DESTDIR=$(DESTDIR) prefix=$(prefix) install
  135. echo "****** THIS ERROR WAS WILLINGLY IGNORED ******"
  136. ls -l $(LOCAL)/lib/libuuid.so
  137. uuid-build: uuid/.libs/libuuid.so
  138. uuid-prebuild: uuid/jni/Android.mk uuid/Makefile
  139. uuid-install: $(LOCAL)/lib/libuuid.so | uuid-prebuild
  140. uuid/jni/Android.mk: uuid.src.stamp
  141. mkdir -p uuid/jni
  142. cp ../libuuid.Android.mk uuid/jni/Android.mk
  143. #------------------------------------------------------------------------------#
  144. # Sequoia
  145. sequoia-deps-build: openssl-install nettle-install
  146. #------------------------------------------------------------------------------#
  147. # OpenSSL
  148. openssl.src.stamp: ../downloads/openssl-$(OPENSSL_VERSION).tar.gz
  149. tar xvf $<
  150. mv openssl-$(OPENSSL_VERSION) openssl
  151. touch $@
  152. openssl-src: openssl.src.stamp
  153. openssl-clean:
  154. rm -rf openssl
  155. rm -rf openssl.src.stamp
  156. OPENSSL_ARCHITECTURE:=android-x86_64
  157. openssl/Makefile: openssl.src.stamp
  158. cd openssl && \
  159. PATH="$(ANDROID_NDK_HOME)/bin:$(PATH)" ../../configure_openssl.sh ${OPENSSL_ARCHITECTURE} $(ANDROID_API) $(LOCAL)
  160. openssl/libssl.so: | openssl/Makefile
  161. PATH="$(ANDROID_NDK_HOME)/bin:$(PATH)" $(MAKE) -C openssl
  162. $(LOCAL)/lib/libssl.so: openssl/libssl.so
  163. cd openssl && \
  164. cp libcrypto.so $(LOCAL)/lib && \
  165. cp libcrypto.a $(LOCAL)/lib && \
  166. cp libssl.so $(LOCAL)/lib && \
  167. cp libssl.a $(LOCAL)/lib
  168. ls -l $(LOCAL)/lib/libssl.so
  169. openssl-build: openssl/libssl.so
  170. openssl-install: $(LOCAL)/lib/libssl.so
  171. #------------------------------------------------------------------------------#
  172. # GMP
  173. gmp.src.stamp: ../downloads/gmp-$(GMP_VERSION).tar.bz2
  174. tar xvf $<
  175. mv gmp-$(GMP_VERSION) gmp
  176. touch $@
  177. gmp-src: gmp.src.stamp
  178. gmp-clean:
  179. rm -rf gmp
  180. rm -rf gmp.src.stamp
  181. gmp/Makefile: gmp.src.stamp
  182. cd gmp && \
  183. CC="$(CC)" LD="$(LD)" AR="$(AR)" AS="$(AS)" RANLIB=$(RANLIB) STRIP="$(STRIP)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" \
  184. ./configure \
  185. --host=$(HOST) \
  186. --prefix=$(LOCAL) \
  187. --disable-static
  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 gmp-install
  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)/x86_64-linux-android/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 x86_64-linux-android -p sequoia-openpgp-ffi --release -Z build-std=core,alloc,std
  244. $(LOCAL)/lib/libsequoia_openpgp_ffi.so: $(CARGO_TARGET_DIR)/x86_64-linux-android/release/libsequoia_openpgp_ffi.so
  245. cp $(CARGO_TARGET_DIR)/x86_64-linux-android/release/libsequoia_openpgp_ffi.* $(LOCAL)/lib/
  246. cp -r sequoia/openpgp-ffi/include/* $(LOCAL)/include
  247. sequoia-ffi-build: $(CARGO_TARGET_DIR)/x86_64-linux-android/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. # clean
  275. clean-assets:
  276. rm -rf $(ASSETS)
  277. clean-install:
  278. rm -rf $(LOCAL)
  279. clean: $(EXTERNAL_SRCS_CLEAN) clean-assets clean-install libetpan-clean
  280. clean-all: clean
  281. rm -rf *.git
  282. rm -rf *.stamp
  283. #------------------------------------------------------------------------------#
  284. .PHONY = clean clean-install clean-assets libetpan-clean \
  285. libiconv-build libiconv-install \
  286. libetpan-build \
  287. uuid-build uuid-prebuild uuid-install \
  288. gmp-build gmp-install \
  289. sequoia-deps-build \
  290. openssl-build openssl-install \
  291. nettle-build nettle-install \
  292. sequoia-ffi-build sequoia-ffi-install\
  293. assets \
  294. $(EXTERNAL_LOCAL_GITS_UPDATE) $(EXTERNAL_SRCS) $(EXTERNAL_SRCS_CLEAN)\
  295. showsetup