Guest User

compilerflags

a guest
Mar 18th, 2013
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.74 KB | None | 0 0
  1. #
  2. # Copyright (C) 2006 The Android Open Source Project
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16.  
  17. # Configuration for Linux on ARM.
  18. # Included by combo/select.mk
  19.  
  20. # You can set TARGET_ARCH_VARIANT to use an arch version other
  21. # than ARMv5TE. Each value should correspond to a file named
  22. # $(BUILD_COMBOS)/arch/<name>.mk which must contain
  23. # makefile variable definitions similar to the preprocessor
  24. # defines in build/core/combo/include/arch/<combo>/AndroidConfig.h. Their
  25. # purpose is to allow module Android.mk files to selectively compile
  26. # different versions of code based upon the funtionality and
  27. # instructions available in a given architecture version.
  28. #
  29. # The blocks also define specific arch_variant_cflags, which
  30. # include defines, and compiler settings for the given architecture
  31. # version.
  32. #
  33. ifeq ($(strip $(TARGET_ARCH_VARIANT)),)
  34. TARGET_ARCH_VARIANT := armv5te
  35. endif
  36.  
  37. TARGET_ARCH_SPECIFIC_MAKEFILE := $(BUILD_COMBOS)/arch/$(TARGET_ARCH)/$(TARGET_ARCH_VARIANT).mk
  38. ifeq ($(strip $(wildcard $(TARGET_ARCH_SPECIFIC_MAKEFILE))),)
  39. $(error Unknown ARM architecture version: $(TARGET_ARCH_VARIANT))
  40. endif
  41.  
  42. include $(TARGET_ARCH_SPECIFIC_MAKEFILE)
  43.  
  44. # You can set TARGET_TOOLS_PREFIX to get gcc from somewhere else
  45. ifeq ($(strip $(TARGET_TOOLS_PREFIX)),)
  46. TARGET_TOOLCHAIN_ROOT := prebuilts/gcc/$(HOST_PREBUILT_TAG)/arm/android-toolchain-eabi
  47. TARGET_TOOLS_PREFIX := $(TARGET_TOOLCHAIN_ROOT)/bin/arm-linux-androideabi-
  48. endif
  49.  
  50. # Only define these if there's actually a gcc in there.
  51. # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
  52. ifneq ($(wildcard $(TARGET_TOOLS_PREFIX)gcc$(HOST_EXECUTABLE_SUFFIX)),)
  53. TARGET_CC := $(TARGET_TOOLS_PREFIX)gcc$(HOST_EXECUTABLE_SUFFIX)
  54. TARGET_CXX := $(TARGET_TOOLS_PREFIX)g++$(HOST_EXECUTABLE_SUFFIX)
  55. TARGET_AR := $(TARGET_TOOLS_PREFIX)ar$(HOST_EXECUTABLE_SUFFIX)
  56. TARGET_OBJCOPY := $(TARGET_TOOLS_PREFIX)objcopy$(HOST_EXECUTABLE_SUFFIX)
  57. TARGET_LD := $(TARGET_TOOLS_PREFIX)ld$(HOST_EXECUTABLE_SUFFIX)
  58. TARGET_STRIP := $(TARGET_TOOLS_PREFIX)strip$(HOST_EXECUTABLE_SUFFIX)
  59. ifeq ($(TARGET_BUILD_VARIANT),user)
  60. TARGET_STRIP_COMMAND = $(TARGET_STRIP) --strip-all $< -o $@
  61. else
  62. TARGET_STRIP_COMMAND = $(TARGET_STRIP) --strip-all $< -o $@ && \
  63. $(TARGET_OBJCOPY) --add-gnu-debuglink=$< $@
  64. endif
  65. endif
  66.  
  67. TARGET_NO_UNDEFINED_LDFLAGS := -Wl,--no-undefined
  68.  
  69. TARGET_arm_CFLAGS := -O3 \
  70. -fomit-frame-pointer \
  71. -fstrict-aliasing \
  72. -funswitch-loops \
  73. -pipe
  74.  
  75. # Modules can choose to compile some source as thumb. As
  76. # non-thumb enabled targets are supported, this is treated
  77. # as a 'hint'. If thumb is not enabled, these files are just
  78. # compiled as ARM.
  79. ifeq ($(ARCH_ARM_HAVE_THUMB_SUPPORT),true)
  80. TARGET_thumb_CFLAGS := -mthumb \
  81. -O3 \
  82. -fomit-frame-pointer \
  83. -fstrict-aliasing \
  84. -Wstrict-aliasing=2 \
  85. -Werror=strict-aliasing \
  86. -pipe
  87. else
  88. TARGET_thumb_CFLAGS := $(TARGET_arm_CFLAGS)
  89. endif
  90.  
  91. # Turn off strict-aliasing if we're building an AOSP variant without the
  92. # patchset...
  93. ifeq ($(DEBUG_NO_STRICT_ALIASING),yes)
  94. TARGET_arm_CFLAGS += -fno-strict-aliasing -Wno-error=strict-aliasing
  95. TARGET_thumb_CFLAGS += -fno-strict-aliasing -Wno-error=strict-aliasing
  96. endif
  97.  
  98. # Set FORCE_ARM_DEBUGGING to "true" in your buildspec.mk
  99. # or in your environment to force a full arm build, even for
  100. # files that are normally built as thumb; this can make
  101. # gdb debugging easier. Don't forget to do a clean build.
  102. #
  103. # NOTE: if you try to build a -O0 build with thumb, several
  104. # of the libraries (libpv, libwebcore, libkjs) need to be built
  105. # with -mlong-calls. When built at -O0, those libraries are
  106. # too big for a thumb "BL <label>" to go from one end to the other.
  107. ifeq ($(FORCE_ARM_DEBUGGING),true)
  108. TARGET_arm_CFLAGS += -fno-omit-frame-pointer -fno-strict-aliasing
  109. TARGET_thumb_CFLAGS += -marm -fno-omit-frame-pointer
  110. endif
  111.  
  112. ifeq ($(TARGET_DISABLE_ARM_PIE),true)
  113. PIE_GLOBAL_CFLAGS :=
  114. PIE_EXECUTABLE_TRANSFORM := -Wl,-T,$(BUILD_SYSTEM)/armelf.x
  115. else
  116. PIE_GLOBAL_CFLAGS := -fPIE
  117. PIE_EXECUTABLE_TRANSFORM := -fPIE -pie
  118. endif
  119.  
  120. TARGET_GLOBAL_CFLAGS += \
  121. -msoft-float -fpic $(PIE_GLOBAL_CFLAGS) \
  122. -ffunction-sections \
  123. -fdata-sections \
  124. -funwind-tables \
  125. -fstack-protector \
  126. -Wa,--noexecstack \
  127. -Werror=format-security \
  128. -D_FORTIFY_SOURCE=1 \
  129. -fno-short-enums \
  130. -pipe \
  131. $(arch_variant_cflags)
  132.  
  133. android_config_h := $(call select-android-config-h,linux-arm)
  134. TARGET_ANDROID_CONFIG_CFLAGS := -include $(android_config_h) -I $(dir $(android_config_h))
  135. TARGET_GLOBAL_CFLAGS += $(TARGET_ANDROID_CONFIG_CFLAGS)
  136.  
  137. # This warning causes dalvik not to build with gcc 4.6.x and -Werror.
  138. # We cannot turn it off blindly since the option is not available
  139. # in gcc-4.4.x. We also want to disable sincos optimization globally
  140. # by turning off the builtin sin function.
  141. ifneq ($(filter 4.6 4.6.%, $(shell $(TARGET_CC) --version)),)
  142. TARGET_GLOBAL_CFLAGS += -Wno-unused-but-set-variable -fno-builtin-sin \
  143. -fno-strict-volatile-bitfields
  144. endif
  145.  
  146. # This is to avoid the dreaded warning compiler message:
  147. # note: the mangling of 'va_list' has changed in GCC 4.4
  148. #
  149. # The fact that the mangling changed does not affect the NDK ABI
  150. # very fortunately (since none of the exposed APIs used va_list
  151. # in their exported C++ functions). Also, GCC 4.5 has already
  152. # removed the warning from the compiler.
  153. #
  154. TARGET_GLOBAL_CFLAGS += -Wno-psabi
  155.  
  156. TARGET_GLOBAL_LDFLAGS += \
  157. -Wl,-z,noexecstack \
  158. -Wl,-z,relro \
  159. -Wl,-z,now \
  160. -Wl,--warn-shared-textrel \
  161. $(arch_variant_ldflags)
  162.  
  163. # We only need thumb interworking in cases where thumb support
  164. # is available in the architecture, and just to be sure, (and
  165. # since sometimes thumb-interwork appears to be default), we
  166. # specifically disable when thumb support is unavailable.
  167. ifeq ($(ARCH_ARM_HAVE_THUMB_SUPPORT),true)
  168. TARGET_GLOBAL_CFLAGS += -mthumb-interwork
  169. else
  170. TARGET_GLOBAL_CFLAGS += -mno-thumb-interwork
  171. endif
  172.  
  173. TARGET_GLOBAL_CPPFLAGS += -fvisibility-inlines-hidden
  174. ifneq ($(DEBUG_NO_STDCXX11),yes)
  175. TARGET_GLOBAL_CPPFLAGS += $(call cc-option,-std=gnu++11)
  176. endif
  177.  
  178. # More flags/options can be added here
  179. TARGET_RELEASE_CFLAGS += \
  180. -DNDEBUG \
  181. -g \
  182. -Wstrict-aliasing=2 \
  183. -Werror=strict-aliasing \
  184. -fgcse-after-reload \
  185. -frerun-cse-after-loop \
  186. -frename-registers
  187.  
  188. libc_root := bionic/libc
  189. libm_root := bionic/libm
  190. libstdc++_root := bionic/libstdc++
  191. libthread_db_root := bionic/libthread_db
  192.  
  193.  
  194. ## on some hosts, the target cross-compiler is not available so do not run this command
  195. ifneq ($(wildcard $(TARGET_CC)),)
  196. # We compile with the global cflags to ensure that
  197. # any flags which affect libgcc are correctly taken
  198. # into account.
  199. TARGET_LIBGCC := $(shell $(TARGET_CC) $(TARGET_GLOBAL_CFLAGS) -print-libgcc-file-name)
  200. endif
  201.  
  202. # Define FDO (Feedback Directed Optimization) options.
  203.  
  204. TARGET_FDO_CFLAGS:=
  205. TARGET_FDO_LIB:=
  206.  
  207. target_libgcov := $(shell $(TARGET_CC) $(TARGET_GLOBAL_CFLAGS) \
  208. -print-file-name=libgcov.a)
  209. ifneq ($(strip $(BUILD_FDO_INSTRUMENT)),)
  210. # Set BUILD_FDO_INSTRUMENT=true to turn on FDO instrumentation.
  211. # The profile will be generated on /data/local/tmp/profile on the device.
  212. TARGET_FDO_CFLAGS := -fprofile-generate=/data/local/tmp/profile -DANDROID_FDO
  213. TARGET_FDO_LIB := $(target_libgcov)
  214. else
  215. # If BUILD_FDO_INSTRUMENT is turned off, then consider doing the FDO optimizations.
  216. # Set TARGET_FDO_PROFILE_PATH to set a custom profile directory for your build.
  217. ifeq ($(strip $(TARGET_FDO_PROFILE_PATH)),)
  218. TARGET_FDO_PROFILE_PATH := fdo/profiles/$(TARGET_ARCH)/$(TARGET_ARCH_VARIANT)
  219. else
  220. ifeq ($(strip $(wildcard $(TARGET_FDO_PROFILE_PATH))),)
  221. $(warning Custom TARGET_FDO_PROFILE_PATH supplied, but directory does not exist. Turn off FDO.)
  222. endif
  223. endif
  224.  
  225. # If the FDO profile directory can't be found, then FDO is off.
  226. ifneq ($(strip $(wildcard $(TARGET_FDO_PROFILE_PATH))),)
  227. TARGET_FDO_CFLAGS := -fprofile-use=$(TARGET_FDO_PROFILE_PATH) -DANDROID_FDO
  228. TARGET_FDO_LIB := $(target_libgcov)
  229. endif
  230. endif
  231.  
  232.  
  233. # unless CUSTOM_KERNEL_HEADERS is defined, we're going to use
  234. # symlinks located in out/ to point to the appropriate kernel
  235. # headers. see 'config/kernel_headers.make' for more details
  236. #
  237. ifneq ($(CUSTOM_KERNEL_HEADERS),)
  238. KERNEL_HEADERS_COMMON := $(CUSTOM_KERNEL_HEADERS)
  239. KERNEL_HEADERS_ARCH := $(CUSTOM_KERNEL_HEADERS)
  240. else
  241. KERNEL_HEADERS_COMMON := $(libc_root)/kernel/common
  242. KERNEL_HEADERS_ARCH := $(libc_root)/kernel/arch-$(TARGET_ARCH)
  243. endif
  244. KERNEL_HEADERS := $(KERNEL_HEADERS_COMMON) $(KERNEL_HEADERS_ARCH)
  245.  
  246. TARGET_C_INCLUDES := \
  247. $(libc_root)/arch-arm/include \
  248. $(libc_root)/include \
  249. $(libstdc++_root)/include \
  250. $(KERNEL_HEADERS) \
  251. $(libm_root)/include \
  252. $(libm_root)/include/arm \
  253. $(libthread_db_root)/include
  254.  
  255. TARGET_CRTBEGIN_STATIC_O := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_static.o
  256. TARGET_CRTBEGIN_DYNAMIC_O := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_dynamic.o
  257. TARGET_CRTEND_O := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtend_android.o
  258.  
  259. TARGET_CRTBEGIN_SO_O := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_so.o
  260. TARGET_CRTEND_SO_O := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtend_so.o
  261.  
  262. TARGET_STRIP_MODULE:=true
  263.  
  264. TARGET_DEFAULT_SYSTEM_SHARED_LIBRARIES := libc libstdc++ libm
  265.  
  266. TARGET_CUSTOM_LD_COMMAND := true
  267.  
  268. # Enable the Dalvik JIT compiler if not already specified.
  269. ifeq ($(strip $(WITH_JIT)),)
  270. WITH_JIT := true
  271. endif
  272.  
  273. define transform-o-to-shared-lib-inner
  274. $(hide) $(PRIVATE_CXX) \
  275. -nostdlib -Wl,-soname,$(notdir $@) \
  276. -Wl,--gc-sections \
  277. -Wl,-shared,-Bsymbolic \
  278. $(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
  279. $(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTBEGIN_SO_O)) \
  280. $(PRIVATE_ALL_OBJECTS) \
  281. -Wl,--whole-archive \
  282. $(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
  283. -Wl,--no-whole-archive \
  284. $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
  285. $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
  286. $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
  287. $(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
  288. -o $@ \
  289. $(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
  290. $(PRIVATE_LDFLAGS) \
  291. $(PRIVATE_TARGET_FDO_LIB) \
  292. $(PRIVATE_TARGET_LIBGCC) \
  293. $(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTEND_SO_O))
  294. endef
  295.  
  296. define transform-o-to-executable-inner
  297. $(hide) $(PRIVATE_CXX) -nostdlib -Bdynamic $(PIE_EXECUTABLE_TRANSFORM) \
  298. -Wl,-dynamic-linker,/system/bin/linker \
  299. -Wl,--gc-sections \
  300. -Wl,-z,nocopyreloc \
  301. -o $@ \
  302. $(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
  303. -Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
  304. $(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
  305. $(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTBEGIN_DYNAMIC_O)) \
  306. $(PRIVATE_ALL_OBJECTS) \
  307. -Wl,--whole-archive \
  308. $(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
  309. -Wl,--no-whole-archive \
  310. $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
  311. $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
  312. $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
  313. $(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
  314. $(PRIVATE_LDFLAGS) \
  315. $(PRIVATE_TARGET_FDO_LIB) \
  316. $(PRIVATE_TARGET_LIBGCC) \
  317. $(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTEND_O))
  318. endef
  319.  
  320. define transform-o-to-static-executable-inner
  321. $(hide) $(PRIVATE_CXX) -nostdlib -Bstatic \
  322. -Wl,--gc-sections \
  323. -o $@ \
  324. $(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
  325. $(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTBEGIN_STATIC_O)) \
  326. $(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
  327. $(PRIVATE_LDFLAGS) \
  328. $(PRIVATE_ALL_OBJECTS) \
  329. -Wl,--whole-archive \
  330. $(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
  331. -Wl,--no-whole-archive \
  332. $(call normalize-target-libraries,$(filter-out %libc_nomalloc.a,$(filter-out %libc.a,$(PRIVATE_ALL_STATIC_LIBRARIES)))) \
  333. -Wl,--start-group \
  334. $(call normalize-target-libraries,$(filter %libc.a,$(PRIVATE_ALL_STATIC_LIBRARIES))) \
  335. $(call normalize-target-libraries,$(filter %libc_nomalloc.a,$(PRIVATE_ALL_STATIC_LIBRARIES))) \
  336. $(PRIVATE_TARGET_FDO_LIB) \
  337. $(PRIVATE_TARGET_LIBGCC) \
  338. -Wl,--end-group \
  339. $(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTEND_O))
  340. endef
Advertisement
Add Comment
Please, Sign In to add comment