1 LOCAL_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) 6 include $(CLEAR_VARS) 7 LOCAL_MODULE := float-softfp-abi 8 LOCAL_SRC_FILES := test-float.c 9 include $(BUILD_EXECUTABLE) 10 11 12 ifeq ($(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 20 else 21 22 ifeq (,$(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 # 56 include $(CLEAR_VARS) 57 LOCAL_MODULE := hard-float-softfp-abi 58 LOCAL_CFLAGS += -mhard-float 59 ifeq (,$(filter -fuse-ld=mcld,$(APP_LDFLAGS) $(LOCAL_LDFLAGS))) 60 LOCAL_LDFLAGS += -Wl,--no-warn-mismatch 61 endif 62 LOCAL_SRC_FILES := test-float.c 63 include $(BUILD_EXECUTABLE) 64 65 else 66 67 # Clang before 3.4 doesn't allow change of calling convenstion for builtin, 68 # and produces error message reads: 69 # 70 # a.i:564:6: error: function declared 'aapcs' here was previously declared without calling convention 71 # int sin(double d) __attribute__((pcs("aapcs")));544 72 # ^ 73 # a.i:564:6: note: previous declaration is here 74 # 75 # As a result, "-mhard-float" doesn't work properly for now (3.3 and 3.2), unless 76 # libm_hard is also used. See example below. 77 # 78 79 $(warning Skip example hard-float-softfp-abi for clang for now) 80 81 endif # check clang 82 83 # This is to compile all user code in -mhard-float and link a customized 84 # libm_hard.a which follows -mfloat-abi=hard. _NDK_MATH_NO_SOFTFP=1 85 # is to turn off __attribute__((pcs("aapcs"))) in math.h for all math 86 # functions to accept float-abi (implicit "hard" in this case) as specified by user. 87 # 88 include $(CLEAR_VARS) 89 LOCAL_MODULE := hard-float-hard-abi 90 LOCAL_CFLAGS += -mhard-float -D_NDK_MATH_NO_SOFTFP=1 91 LOCAL_LDLIBS += -lm_hard 92 ifeq (,$(filter -fuse-ld=mcld,$(APP_LDFLAGS) $(LOCAL_LDFLAGS))) 93 LOCAL_LDFLAGS += -Wl,--no-warn-mismatch 94 endif 95 LOCAL_SRC_FILES := test-float.c 96 include $(BUILD_EXECUTABLE) 97 98 endif # check armeabi-v7a 99