• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1LOCAL_PATH := $(call my-dir)
2
3# This is the way used to be: For ARM, ndk-build forces "softfp"
4# regardless armeabi (default to use -msoft-float) or armeabi-v7a
5# (default to use -mfpu=vfpv3-d16)
6include $(CLEAR_VARS)
7LOCAL_MODULE := float-softfp-abi
8LOCAL_SRC_FILES := test-float.c
9include $(BUILD_EXECUTABLE)
10
11
12ifeq ($(filter %armeabi-v7a,$(TARGET_ARCH_ABI)),)
13
14#
15# The following two examples are relevant only to armeabi-v7a
16#
17
18$(warning Examples hard-float-softfp-abi and hard-float-hard-abi not relevant to ABI $(TARGET_ARCH_ABI))
19
20else
21
22ifeq (,$(filter clang%,$(NDK_TOOLCHAIN_VERSION)))
23
24# This is to compile all user code in -mhard-float (which implies
25# -mfloat-abi=hard and overrides -mfloat-abi=softfp previously added
26# by ndk-build), but still link system libm.so which use softfp.
27# All functions in Android platform headers taking or returning float/double
28# has __attribute__((pcs("aapcs"))), so even under the implied -mfloat-abi=hard
29# softfp ABI is still observed by compiler for Android native APIs.
30#
31# You also need to ensure that
32# 1. All code and library *must* be recompiled with consistent soft-abi.
33#    If your project use ndk-build and import other project, you may want to do
34#
35#    $NDK/ndk-build -B APP_ABI=armeabi-v7a APP_CFLAGS=-mhard-float APP_LDFLAGS=-Wl,--no-warn-mismatch
36#
37#    If your project use libraries compiled by others, it's likely those were built with
38#    -msoft-abi=softfp or evan -msoft-float (for armeabi).  Recompile them with -mhard-float
39#
40# 2. Correct headers (eg. #include <math.h>) are always included, and there is no
41#    declaration like "extern double sin(double)" w/o proper __attribute__ in
42#    your code instead of including math.h, etc.  See the end of sys/cdefs.h
43#    the conditions upon which __NDK_FPABI__ and __NDK_FPABI_MATH__ are defined
44#
45# 3. All JNI functions should have JNICALL which is defined to __NDK_FPABI__ in jni.h.
46#
47# 4. If you use undocumented APIs which takes/returns float/double, be careful
48#    to add __attribute__((pcs("aapcs"))) for arm
49#
50# Note that "--no-warn-mismatch" is needed for linker (except mclinker which check correctly)
51# to suppress linker error about not all functions use VFP register to pass argument, eg.
52#
53#   .../arm-linux-androideabi/bin/ld: error: ..../test-float.o
54#           uses VFP register arguments, output does not
55#
56include $(CLEAR_VARS)
57LOCAL_MODULE := hard-float-softfp-abi
58LOCAL_CFLAGS += -mhard-float
59LOCAL_SRC_FILES := test-float.c
60LOCAL_LDFLAGS := -Wl,--no-warn-mismatch
61include $(BUILD_EXECUTABLE)
62
63else
64
65# Clang before 3.4 doesn't allow change of calling convenstion for builtin,
66# and produces error message reads:
67#
68#  a.i:564:6: error: function declared 'aapcs' here was previously declared without calling convention
69#  int  sin(double d) __attribute__((pcs("aapcs")));544
70#       ^
71#  a.i:564:6: note: previous declaration is here
72#
73# As a result, "-mhard-float" doesn't work properly for now (3.3 and 3.2), unless
74# libm_hard is also used.  See example below.
75#
76
77$(warning Skip example hard-float-softfp-abi for clang for now)
78
79endif # check clang
80
81# This is to compile all user code in -mhard-float and link a customized
82# libm_hard.a which follows -mfloat-abi=hard. _NDK_MATH_NO_SOFTFP=1
83# is to turn off __attribute__((pcs("aapcs"))) in math.h for all math
84# functions to accept float-abi (implicit "hard" in this case) as specified by user.
85#
86include $(CLEAR_VARS)
87LOCAL_MODULE := hard-float-hard-abi
88LOCAL_CFLAGS += -mhard-float -D_NDK_MATH_NO_SOFTFP=1
89LOCAL_LDLIBS += -lm_hard
90LOCAL_SRC_FILES := test-float.c
91LOCAL_LDFLAGS := -Wl,--no-warn-mismatch
92include $(BUILD_EXECUTABLE)
93
94endif # check armeabi-v7a
95