1 # Copyright (C) 2008 The Android Open Source Project 2 # 3 # Licensed under the Apache License, Version 2.0 (the "License"); 4 # you may not use this file except in compliance with the License. 5 # You may obtain a copy of the License at 6 # 7 # http://www.apache.org/licenses/LICENSE-2.0 8 # 9 # Unless required by applicable law or agreed to in writing, software 10 # distributed under the License is distributed on an "AS IS" BASIS, 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 # See the License for the specific language governing permissions and 13 # limitations under the License. 14 # 15 16 # we expect the 'my' variable to be defined, either to 17 # 'HOST_' or 'TARGET_', and this allows us to call the 18 # appropriate compiler with $($(my)CC) 19 # 20 $(call assert-defined,my) 21 22 # LOCAL_MAKEFILE must also exist and name the Android.mk that 23 # included the module build script. 24 # 25 $(call assert-defined,LOCAL_MAKEFILE) 26 27 include $(BUILD_SYSTEM)/build-module.mk 28 29 # list of generated object files 30 LOCAL_OBJECTS := 31 32 # always define ANDROID when building binaries 33 # 34 LOCAL_CFLAGS := -DANDROID $(LOCAL_CFLAGS) 35 36 # 37 # Add the default system shared libraries to the build 38 # 39 ifndef LOCAL_IS_HOST_MODULE 40 ifeq ($(LOCAL_SYSTEM_SHARED_LIBRARIES),none) 41 LOCAL_SHARED_LIBRARIES += $(TARGET_DEFAULT_SYSTEM_SHARED_LIBRARIES) 42 else 43 LOCAL_SHARED_LIBRARIES += $(LOCAL_SYSTEM_SHARED_LIBRARIES) 44 endif 45 endif 46 47 48 # 49 # Check LOCAL_CPP_EXTENSION, use '.cpp' by default 50 # 51 LOCAL_CPP_EXTENSION := $(strip $(LOCAL_CPP_EXTENSION)) 52 ifeq ($(LOCAL_CPP_EXTENSION),) 53 LOCAL_CPP_EXTENSION := .cpp 54 else 55 ifneq ($(words $(LOCAL_CPP_EXTENSION)),1) 56 $(call __ndk_info, LOCAL_CPP_EXTENSION in $(LOCAL_MAKEFILE) must be one word only, not '$(LOCAL_CPP_EXTENSION)') 57 $(call __ndk_error, Aborting) 58 endif 59 endif 60 61 # 62 # If LOCAL_ALLOW_UNDEFINED_SYMBOLS is not true, the linker will allow the generation 63 # of a binary that uses undefined symbols. 64 # 65 ifneq ($(LOCAL_ALLOW_UNDEFINED_SYMBOLS),true) 66 LOCAL_LDFLAGS += $(LOCAL_LDFLAGS) $($(my)NO_UNDEFINED_LDFLAGS) 67 endif 68 69 # If LOCAL_DISABLE_NO_EXECUTE is not true, we disable generated code from running from 70 # the heap and stack by default. 71 # 72 ifndef ($(LOCAL_DISABLE_NO_EXECUTE),true) 73 LOCAL_CFLAGS += $($(my)NO_EXECUTE_CFLAGS) 74 LOCAL_LDFLAGS += $($(my)NO_EXECUTE_LDFLAGS) 75 endif 76 77 # 78 # The original Android build system allows you to use the .arm prefix 79 # to a source file name to indicate that it should be defined in either 80 # 'thumb' or 'arm' mode, depending on the value of LOCAL_ARM_MODE 81 # 82 # First, check LOCAL_ARM_MODE, it should be empty, 'thumb' or 'arm' 83 # We make the default 'thumb' 84 # 85 LOCAL_ARM_MODE := $(strip $(LOCAL_ARM_MODE)) 86 ifdef LOCAL_ARM_MODE 87 ifneq ($(words $(LOCAL_ARM_MODE)),1) 88 $(call __ndk_info, LOCAL_ARM_MODE in $(LOCAL_MAKEFILE) must be one word, not '$(LOCAL_ARM_MODE)') 89 $(call __ndk_error, Aborting) 90 endif 91 # check that LOCAL_ARM_MODE is defined to either 'arm' or 'thumb' 92 $(if $(filter-out thumb arm, $(LOCAL_ARM_MODE)),\ 93 $(call __ndk_info, LOCAL_ARM_MODE must be defined to either 'arm' or 'thumb' in $(LOCAL_MAKEFILE) not '$(LOCAL_ARM_MODE)')\ 94 $(call __ndk_error, Aborting)\ 95 ) 96 endif 97 98 # As a special case, the original Android build system 99 # allows one to specify that certain source files can be 100 # forced to build in ARM mode by using a '.arm' suffix 101 # after the extension, e.g. 102 # 103 # LOCAL_SRC_FILES := foo.c.arm 104 # 105 # to build source file $(LOCAL_PATH)/foo.c as ARM 106 # 107 108 # As a special extension, the NDK also supports the .neon extension suffix 109 # to indicate that a single file can be compiled with ARM NEON support 110 # We must support both foo.c.neon and foo.c.arm.neon here 111 # 112 # Also, if LOCAL_ARM_NEON is set to 'true', force Neon mode for all source 113 # files 114 # 115 116 neon_sources := $(filter %.neon,$(LOCAL_SRC_FILES)) 117 neon_sources := $(neon_sources:%.neon=%) 118 119 LOCAL_ARM_NEON := $(strip $(LOCAL_ARM_NEON)) 120 ifdef LOCAL_ARM_NEON 121 $(if $(filter-out true false,$(LOCAL_ARM_NEON)),\ 122 $(call __ndk_info,LOCAL_ARM_NEON must be defined either to 'true' or 'false' in $(LOCAL_MAKEFILE), not '$(LOCAL_ARM_NEON)')\ 123 $(call __ndk_error,Aborting) \ 124 ) 125 endif 126 ifeq ($(LOCAL_ARM_NEON),true) 127 neon_sources += $(LOCAL_SRC_FILES:%.neon=%)) 128 endif 129 130 neon_sources := $(strip $(neon_sources)) 131 ifdef neon_sources 132 ifneq ($(TARGET_ARCH_ABI),armeabi-v7a) 133 $(call __ndk_info,NEON support is only possible for armeabi-v7a ABI) 134 $(call __ndk_info,Please add checks afainst TARGET_ARCH_ABI in $(LOCAL_MAKEFILE)) 135 $(call __ndk_error,Aborting) 136 endif 137 $(call tag-src-files,$(neon_sources:%.arm=%),neon) 138 endif 139 140 LOCAL_SRC_FILES := $(LOCAL_SRC_FILES:%.neon=%) 141 142 # strip the .arm suffix from LOCAL_SRC_FILES 143 # and tag the relevant sources with the 'arm' tag 144 # 145 arm_sources := $(filter %.arm,$(LOCAL_SRC_FILES)) 146 arm_sources := $(arm_sources:%.arm=%) 147 thumb_sources := $(filter-out %.arm,$(LOCAL_SRC_FILES)) 148 LOCAL_SRC_FILES := $(arm_sources) $(thumb_sources) 149 150 ifeq ($(LOCAL_ARM_MODE),arm) 151 arm_sources := $(LOCAL_SRC_FILES) 152 endif 153 ifeq ($(LOCAL_ARM_MODE),thumb) 154 arm_sources := $(empty) 155 endif 156 $(call tag-src-files,$(arm_sources),arm) 157 158 # Process all source file tags to determine toolchain-specific 159 # target compiler flags, and text. 160 # 161 $(call TARGET-process-src-files-tags) 162 163 # only call dump-src-file-tags during debugging 164 #$(dump-src-file-tags) 165 166 # Build the sources to object files 167 # 168 169 $(foreach src,$(filter %.c,$(LOCAL_SRC_FILES)), $(call compile-c-source,$(src))) 170 $(foreach src,$(filter %.S %.s,$(LOCAL_SRC_FILES)), $(call compile-s-source,$(src))) 171 172 $(foreach src,$(filter %$(LOCAL_CPP_EXTENSION),$(LOCAL_SRC_FILES)),\ 173 $(call compile-cpp-source,$(src))) 174 175 unknown_sources := $(strip $(filter-out %.c %.S %.s %$(LOCAL_CPP_EXTENSION),$(LOCAL_SRC_FILES))) 176 ifdef unknown_sources 177 $(call __ndk_info,WARNING: Unsupported source file extensions in $(LOCAL_MAKEFILE) for module $(LOCAL_MODULE)) 178 $(call __ndk_info, $(unknown_sources)) 179 endif 180 181 # 182 # The compile-xxx-source calls updated LOCAL_OBJECTS and LOCAL_DEPENDENCY_DIRS 183 # 184 ALL_DEPENDENCY_DIRS += $(sort $(LOCAL_DEPENDENCY_DIRS)) 185 CLEAN_OBJS_DIRS += $(LOCAL_OBJS_DIR) 186 187 # 188 # Handle the static and shared libraries this module depends on 189 # 190 LOCAL_STATIC_LIBRARIES := $(call strip-lib-prefix,$(LOCAL_STATIC_LIBRARIES)) 191 LOCAL_SHARED_LIBRARIES := $(call strip-lib-prefix,$(LOCAL_SHARED_LIBRARIES)) 192 193 static_libraries := $(call map,static-library-path,$(LOCAL_STATIC_LIBRARIES)) 194 shared_libraries := $(call map,shared-library-path,$(LOCAL_SHARED_LIBRARIES)) \ 195 $(TARGET_PREBUILT_SHARED_LIBRARIES) 196 197 $(call module-add-static-depends,$(LOCAL_MODULE),$(LOCAL_STATIC_LIBRARIES)) 198 $(call module-add-shared-depends,$(LOCAL_MODULE),$(LOCAL_SHARED_LIBRARIES)) 199 200 $(LOCAL_BUILT_MODULE): $(static_libraries) $(shared_libraries) 201 202 # If LOCAL_LDLIBS contains anything like -l<library> then 203 # prepend a -L$(SYSROOT)/usr/lib to it to ensure that the linker 204 # looks in the right location 205 # 206 ifneq ($(filter -l%,$(LOCAL_LDLIBS)),) 207 LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib $(LOCAL_LDLIBS) 208 endif 209 210 $(LOCAL_BUILT_MODULE): PRIVATE_STATIC_LIBRARIES := $(static_libraries) 211 $(LOCAL_BUILT_MODULE): PRIVATE_SHARED_LIBRARIES := $(shared_libraries) 212 $(LOCAL_BUILT_MODULE): PRIVATE_OBJECTS := $(LOCAL_OBJECTS) 213 214 $(LOCAL_BUILT_MODULE): PRIVATE_LDFLAGS := $(TARGET_LDFLAGS) $(LOCAL_LDFLAGS) 215 $(LOCAL_BUILT_MODULE): PRIVATE_LDLIBS := $(LOCAL_LDLIBS) $(TARGET_LDLIBS) 216 217 $(LOCAL_BUILT_MODULE): PRIVATE_NAME := $(notdir $(LOCAL_BUILT_MODULE)) 218