root.mk 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. ######
  2. ## Root configuration file shared by all android projects.
  3. ######
  4. ifeq ($(ANDROID_NDK_ROOT),)
  5. export ANDROID_NDK_ROOT=/cygdrive/c/android-ndk-r7c
  6. endif
  7. ifeq ($(ANDROID_SDK_ROOT),)
  8. export ANDROID_SDK_ROOT=/cygdrive/c/android-sdk
  9. endif
  10. ifeq ($(ANDROID_PLATFORM),)
  11. export ANDROID_PLATFORM=android-3
  12. endif
  13. ifeq ($(ANDROID_HOST),)
  14. export ANDROID_HOST=windows
  15. endif
  16. ifeq ($(NEON), yes)
  17. export MARCH=armv7-a
  18. export ANDROID_EABI=armeabi-v7a
  19. else
  20. export MARCH=armv5te
  21. export ANDROID_EABI=armeabi
  22. endif
  23. export ANDROID_GCC_VERSIONS=4.6 4.4.3 4.4.0 4.2.1 # list of preferred GCC versions seperated by SPACE (most preferred first)
  24. export ANDROID_GCC_PREFIXES=arm-eabi arm-linux-androideabi # list of preferred GCC prefixes seperated by SPACE (most preferred first)
  25. # Output directory
  26. export OUTPUT_DIR=$(shell pwd)/output
  27. $(shell mkdir -p $(OUTPUT_DIR))
  28. # Some toolchains cannot find libs in cygwin paths
  29. export OUTPUT_DIR_CYGWIN=$(shell \
  30. if [[ $(OUTPUT_DIR) = /cygdrive/c/* ]]; then \
  31. echo $(OUTPUT_DIR) | sed -e "s/\/cygdrive\/c/C:/g"; \
  32. fi \
  33. )
  34. # Path where to copy executables -on the device or emulator-
  35. export EXEC_DIR=/data/tmp
  36. # Path where to copy libraries (*.so) -on the device or emulator-
  37. export LIB_DIR=/system/lib
  38. # Test the NDK directory structure
  39. export ANDROID_NDK_BASE=$(shell if [ -r $(ANDROID_NDK_ROOT)/build/platforms ] ; then \
  40. echo $(ANDROID_NDK_ROOT)/build/platforms ; \
  41. elif [ -r $(ANDROID_NDK_ROOT)/platforms ] ; then \
  42. echo $(ANDROID_NDK_ROOT)/platforms ; \
  43. else \
  44. echo "Err_Unable_to_recognize_the_NDK_structure_for_ANDROID_NDK_BASE" ; \
  45. fi)
  46. export ANDROID_NDK_TOOL_BASE=$(shell \
  47. for gcc_prefix in $(ANDROID_GCC_PREFIXES) ; do \
  48. for gcc_version in $(ANDROID_GCC_VERSIONS) ; do \
  49. if [ -r $(ANDROID_NDK_ROOT)/build/prebuilt/$(ANDROID_HOST)/$$gcc_prefix-$$gcc_version ] ; then \
  50. echo "$(ANDROID_NDK_ROOT)/build/prebuilt/$(ANDROID_HOST)/$$gcc_prefix-$$gcc_version"; \
  51. break; \
  52. elif [ -r $(ANDROID_NDK_ROOT)/toolchains/$$gcc_prefix-$$gcc_version/prebuilt/$(ANDROID_HOST) ] ; then \
  53. echo "$(ANDROID_NDK_ROOT)/toolchains/$$gcc_prefix-$$gcc_version/prebuilt/$(ANDROID_HOST)"; \
  54. break; \
  55. fi \
  56. done \
  57. done \
  58. )
  59. export ANDROID_GCC_PREFIX=$(shell \
  60. for gcc_prefix in $(ANDROID_GCC_PREFIXES) ; do \
  61. for gcc_version in $(ANDROID_GCC_VERSIONS) ; do \
  62. if [ -r $(ANDROID_NDK_ROOT)/build/prebuilt/$(ANDROID_HOST)/$$gcc_prefix-$$gcc_version ] ; then \
  63. echo "$$gcc_prefix"; \
  64. break; \
  65. elif [ -r $(ANDROID_NDK_ROOT)/toolchains/$$gcc_prefix-$$gcc_version/prebuilt/$(ANDROID_HOST) ] ; then \
  66. echo "$$gcc_prefix"; \
  67. break; \
  68. fi \
  69. done \
  70. done \
  71. )
  72. ifeq ($(ANDROID_NDK_TOOL_BASE),)
  73. export ANDROID_NDK_TOOL_BASE="Err_Unable_to_recognize_the_NDK_structure_for_ANDROID_NDK_TOOL_BASE"
  74. endif
  75. export ANDROID_GNU_STL_ROOT=$(shell \
  76. if [ -r $(ANDROID_NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/libs/$(ANDROID_EABI) ] ; then \
  77. echo "$(ANDROID_NDK_ROOT)/sources/cxx-stl/gnu-libstdc++"; \
  78. else \
  79. for gcc_version in $(ANDROID_GCC_VERSIONS) ; do \
  80. if [ -r $(ANDROID_NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/$$gcc_version/libs/$(ANDROID_EABI) ] ; then \
  81. echo "$(ANDROID_NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/$$gcc_version"; \
  82. break; \
  83. fi \
  84. done \
  85. fi \
  86. )
  87. ifeq ($(ANDROID_GNU_STL_ROOT),)
  88. export ANDROID_GNU_STL_ROOT="Err_Unable_to_find_gnu_stl_root_dir"
  89. endif
  90. ##################################################################################
  91. export PATH:=$(PATH):$(ANDROID_NDK_TOOL_BASE)/bin
  92. export AR=$(ANDROID_GCC_PREFIX)-ar
  93. export AS=$(ANDROID_GCC_PREFIX)-as
  94. export CC=$(ANDROID_GCC_PREFIX)-gcc
  95. export CPP=$(ANDROID_GCC_PREFIX)-g++
  96. export STRIP=$(ANDROID_GCC_PREFIX)-strip
  97. export TARGET_ARCH=arm
  98. ifeq ($(ANDROID_GCC_PREFIX), arm-linux-androideabi)
  99. export ARMELF_XSC=$(ANDROID_NDK_TOOL_BASE)/$(ANDROID_GCC_PREFIX)/lib/ldscripts/armelf_linux_eabi.xsc
  100. else
  101. export ARMELF_XSC=$(ANDROID_NDK_TOOL_BASE)/$(ANDROID_GCC_PREFIX)/lib/ldscripts/armelf.xsc
  102. endif
  103. ifeq ($(LICENSE),)
  104. export LICENSE=gpl
  105. endif
  106. export CFLAGS_COMMON=$(CFLAGS) $(DEBUG_FLAGS) -I$(ANDROID_NDK_BASE)/$(ANDROID_PLATFORM)/arch-arm/usr/include -L$(ANDROID_GNU_STL_ROOT)/include \
  107. -msoft-float \
  108. -fpic \
  109. -fno-exceptions \
  110. -mthumb-interwork \
  111. -funwind-tables \
  112. -fstack-protector \
  113. -D__arm__\
  114. -D__ARM_ARCH__ \
  115. -D__ARM_ARCH_5__ \
  116. -D__ARM_ARCH_5T__ \
  117. -D__ARM_ARCH_5E__ \
  118. -D__ARM_ARCH_5TE__ \
  119. -MMD \
  120. -MP \
  121. -fno-short-enums \
  122. -DWEBRTC_ANDROID \
  123. -DWEBRTC_ARCH_ARM \
  124. -D__ANDROID__ \
  125. -DANDROID=1 \
  126. # Size reduction: use separate sections ("-ffunction-sections -fdata-sections") then link executable/shared lib using "-Wl,-gc-sections,-u,main"
  127. export CFLAGS_COMMON+=-ffunction-sections -fdata-sections
  128. ifeq ($(NEON), yes)
  129. export MARCH=armv7-a
  130. export ARCH_ARM_HAVE_NEON=true
  131. export ARCH_ARM_HAVE_ARMV7A=true
  132. export CFLAGS_COMMON+=-march=$(MARCH) -mno-thumb-interwork -mtune=cortex-a8 -mfpu=neon -flax-vector-conversions -DHAVE_NEON=1 -DWEBRTC_DETECT_ARM_NEON -DARCH_ARM_HAVE_NEON -DARCH_ARM_HAVE_ARMV7A \
  133. -D__ARM_ARCH_7__ -D__ARM_ARCH_7A__ -DWEBRTC_ARM_INLINE_CALLS -DWEBRTC_ANDROID_ARMV7A_NEON -DWEBRTC_ARCH_ARM_NEON -Wno-psabi -mfloat-abi=softfp
  134. else
  135. export MARCH=armv5te
  136. export CFLAGS_COMMON+=-march=$(MARCH) -mtune=xscale
  137. endif
  138. export CFLAGS_LIB= $(CFLAGS_COMMON) \
  139. -fomit-frame-pointer \
  140. -fno-strict-aliasing \
  141. -finline-limit=64
  142. ifeq ($(DEBUG), yes)
  143. export CFLAGS_LIB+=-O0 -g -DDEBUG_LEVEL=DEBUG_LEVEL_INFO
  144. else
  145. export CFLAGS_LIB+=-Os -s
  146. DEBUG:=no
  147. endif
  148. export LDFLAGS_COMMON=$(LDFLAGS) -Wl,--gc-sections,-rpath=/system/lib,-rpath-link=$(ANDROID_NDK_BASE)/$(ANDROID_PLATFORM)/arch-arm/usr/lib,-rpath-link=$(OUTPUT_DIR),-dynamic-linker=/system/bin/linker,-T,$(ARMELF_XSC) -L$(ANDROID_NDK_BASE)/$(ANDROID_PLATFORM)/arch-arm/usr/lib -L$(ANDROID_GNU_STL_ROOT)/libs/$(ANDROID_EABI)
  149. export LDFLAGS_COMMON+=-nostdlib -lc -L$(OUTPUT_DIR) -L$(OUTPUT_DIR_CYGWIN)
  150. ifeq ($(BT), static)
  151. export EXT=a
  152. export LDFLAGS_LIB=
  153. export CFLAGS_LIB+=-static
  154. else
  155. export EXT=so
  156. export LDFLAGS_LIB=$(LDFLAGS_COMMON)
  157. export LDFLAGS_LIB+=-Wl,--no-undefined
  158. export LDFLAGS_LIB+=-Wl,--no-whole-archive
  159. export LDFLAGS_LIB+=-Wl,-soname,lib$(PROJECT).$(EXT),-Bsymbolic,-shared,--whole-archive
  160. endif