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 # Check that LOCAL_MODULE is defined, then restore its LOCAL_XXXX values 17 $(call assert-defined,LOCAL_MODULE) 18 $(call module-restore-locals,$(LOCAL_MODULE)) 19 20 # For now, only support target (device-specific modules). 21 # We may want to introduce support for host modules in the future 22 # but that is too experimental for now. 23 # 24 my := TARGET_ 25 26 # LOCAL_MAKEFILE must also exist and name the Android.mk that 27 # included the module build script. 28 # 29 $(call assert-defined,LOCAL_MAKEFILE LOCAL_BUILD_SCRIPT LOCAL_BUILT_MODULE) 30 31 include $(BUILD_SYSTEM)/import-locals.mk 32 33 # 34 # Ensure that 'make <module>' and 'make clean-<module>' work 35 # 36 .PHONY: $(LOCAL_MODULE) 37 $(LOCAL_MODULE): $(LOCAL_BUILT_MODULE) 38 39 cleantarget := clean-$(LOCAL_MODULE)-$(TARGET_ARCH_ABI) 40 .PHONY: $(cleantarget) 41 clean: $(cleantarget) 42 43 $(cleantarget): PRIVATE_MODULE := $(LOCAL_MODULE) 44 $(cleantarget): PRIVATE_TEXT := [$(TARGET_ARCH_ABI)] 45 $(cleantarget): PRIVATE_CLEAN_FILES := $(LOCAL_BUILT_MODULE) \ 46 $($(my)OBJS) 47 48 $(cleantarget):: 49 @echo "Clean: $(PRIVATE_MODULE) $(PRIVATE_TEXT)" 50 $(hide) rm -rf $(PRIVATE_CLEAN_FILES) 51 52 ifeq ($(NDK_APP_DEBUGGABLE),true) 53 $(NDK_APP_GDBSETUP): PRIVATE_SRC_DIRS += $(LOCAL_C_INCLUDES) $(LOCAL_PATH) 54 endif 55 56 # list of generated object files 57 LOCAL_OBJECTS := 58 59 # always define ANDROID when building binaries 60 # 61 LOCAL_CFLAGS := -DANDROID $(LOCAL_CFLAGS) 62 63 # 64 # Add the default system shared libraries to the build 65 # 66 ifeq ($(LOCAL_SYSTEM_SHARED_LIBRARIES),none) 67 LOCAL_SHARED_LIBRARIES += $(TARGET_DEFAULT_SYSTEM_SHARED_LIBRARIES) 68 else 69 LOCAL_SHARED_LIBRARIES += $(LOCAL_SYSTEM_SHARED_LIBRARIES) 70 endif 71 72 73 # 74 # Check LOCAL_CPP_EXTENSION, use '.cpp' by default 75 # 76 LOCAL_CPP_EXTENSION := $(strip $(LOCAL_CPP_EXTENSION)) 77 ifeq ($(LOCAL_CPP_EXTENSION),) 78 LOCAL_CPP_EXTENSION := .cpp 79 else 80 ifneq ($(words $(LOCAL_CPP_EXTENSION)),1) 81 $(call __ndk_info, LOCAL_CPP_EXTENSION in $(LOCAL_MAKEFILE) must be one word only, not '$(LOCAL_CPP_EXTENSION)') 82 $(call __ndk_error, Aborting) 83 endif 84 endif 85 86 # 87 # If LOCAL_ALLOW_UNDEFINED_SYMBOLS is not true, the linker will allow the generation 88 # of a binary that uses undefined symbols. 89 # 90 ifneq ($(LOCAL_ALLOW_UNDEFINED_SYMBOLS),true) 91 LOCAL_LDFLAGS += $($(my)NO_UNDEFINED_LDFLAGS) 92 endif 93 94 # If LOCAL_DISABLE_NO_EXECUTE is not true, we disable generated code from running from 95 # the heap and stack by default. 96 # 97 ifndef ($(LOCAL_DISABLE_NO_EXECUTE),true) 98 LOCAL_CFLAGS += $($(my)NO_EXECUTE_CFLAGS) 99 LOCAL_LDFLAGS += $($(my)NO_EXECUTE_LDFLAGS) 100 endif 101 102 # 103 # The original Android build system allows you to use the .arm prefix 104 # to a source file name to indicate that it should be defined in either 105 # 'thumb' or 'arm' mode, depending on the value of LOCAL_ARM_MODE 106 # 107 # First, check LOCAL_ARM_MODE, it should be empty, 'thumb' or 'arm' 108 # We make the default 'thumb' 109 # 110 LOCAL_ARM_MODE := $(strip $(LOCAL_ARM_MODE)) 111 ifdef LOCAL_ARM_MODE 112 ifneq ($(words $(LOCAL_ARM_MODE)),1) 113 $(call __ndk_info, LOCAL_ARM_MODE in $(LOCAL_MAKEFILE) must be one word, not '$(LOCAL_ARM_MODE)') 114 $(call __ndk_error, Aborting) 115 endif 116 # check that LOCAL_ARM_MODE is defined to either 'arm' or 'thumb' 117 $(if $(filter-out thumb arm, $(LOCAL_ARM_MODE)),\ 118 $(call __ndk_info, LOCAL_ARM_MODE must be defined to either 'arm' or 'thumb' in $(LOCAL_MAKEFILE) not '$(LOCAL_ARM_MODE)')\ 119 $(call __ndk_error, Aborting)\ 120 ) 121 endif 122 123 # As a special case, the original Android build system 124 # allows one to specify that certain source files can be 125 # forced to build in ARM mode by using a '.arm' suffix 126 # after the extension, e.g. 127 # 128 # LOCAL_SRC_FILES := foo.c.arm 129 # 130 # to build source file $(LOCAL_PATH)/foo.c as ARM 131 # 132 133 # As a special extension, the NDK also supports the .neon extension suffix 134 # to indicate that a single file can be compiled with ARM NEON support 135 # We must support both foo.c.neon and foo.c.arm.neon here 136 # 137 # Also, if LOCAL_ARM_NEON is set to 'true', force Neon mode for all source 138 # files 139 # 140 141 neon_sources := $(filter %.neon,$(LOCAL_SRC_FILES)) 142 neon_sources := $(neon_sources:%.neon=%) 143 144 LOCAL_ARM_NEON := $(strip $(LOCAL_ARM_NEON)) 145 ifdef LOCAL_ARM_NEON 146 $(if $(filter-out true false,$(LOCAL_ARM_NEON)),\ 147 $(call __ndk_info,LOCAL_ARM_NEON must be defined either to 'true' or 'false' in $(LOCAL_MAKEFILE), not '$(LOCAL_ARM_NEON)')\ 148 $(call __ndk_error,Aborting) \ 149 ) 150 endif 151 ifeq ($(LOCAL_ARM_NEON),true) 152 neon_sources += $(LOCAL_SRC_FILES:%.neon=%)) 153 endif 154 155 neon_sources := $(strip $(neon_sources)) 156 ifdef neon_sources 157 ifneq ($(TARGET_ARCH_ABI),armeabi-v7a) 158 $(call __ndk_info,NEON support is only possible for armeabi-v7a ABI) 159 $(call __ndk_info,Please add checks against TARGET_ARCH_ABI in $(LOCAL_MAKEFILE)) 160 $(call __ndk_error,Aborting) 161 endif 162 $(call tag-src-files,$(neon_sources:%.arm=%),neon) 163 endif 164 165 LOCAL_SRC_FILES := $(LOCAL_SRC_FILES:%.neon=%) 166 167 # strip the .arm suffix from LOCAL_SRC_FILES 168 # and tag the relevant sources with the 'arm' tag 169 # 170 arm_sources := $(filter %.arm,$(LOCAL_SRC_FILES)) 171 arm_sources := $(arm_sources:%.arm=%) 172 thumb_sources := $(filter-out %.arm,$(LOCAL_SRC_FILES)) 173 LOCAL_SRC_FILES := $(arm_sources) $(thumb_sources) 174 175 ifeq ($(LOCAL_ARM_MODE),arm) 176 arm_sources := $(LOCAL_SRC_FILES) 177 endif 178 ifeq ($(LOCAL_ARM_MODE),thumb) 179 arm_sources := $(empty) 180 endif 181 $(call tag-src-files,$(arm_sources),arm) 182 183 # Process all source file tags to determine toolchain-specific 184 # target compiler flags, and text. 185 # 186 $(call TARGET-process-src-files-tags) 187 188 # only call dump-src-file-tags during debugging 189 #$(dump-src-file-tags) 190 191 LOCAL_DEPENDENCY_DIRS := 192 LOCAL_OBJECTS := 193 194 # Build the sources to object files 195 # 196 197 $(foreach src,$(filter %.c,$(LOCAL_SRC_FILES)), $(call compile-c-source,$(src))) 198 $(foreach src,$(filter %.S %.s,$(LOCAL_SRC_FILES)), $(call compile-s-source,$(src))) 199 200 $(foreach src,$(filter %$(LOCAL_CPP_EXTENSION),$(LOCAL_SRC_FILES)),\ 201 $(call compile-cpp-source,$(src))) 202 203 unknown_sources := $(strip $(filter-out %.c %.S %.s %$(LOCAL_CPP_EXTENSION),$(LOCAL_SRC_FILES))) 204 ifdef unknown_sources 205 $(call __ndk_info,WARNING: Unsupported source file extensions in $(LOCAL_MAKEFILE) for module $(LOCAL_MODULE)) 206 $(call __ndk_info, $(unknown_sources)) 207 endif 208 209 # 210 # The compile-xxx-source calls updated LOCAL_OBJECTS and LOCAL_DEPENDENCY_DIRS 211 # 212 ALL_DEPENDENCY_DIRS += $(sort $(LOCAL_DEPENDENCY_DIRS)) 213 CLEAN_OBJS_DIRS += $(LOCAL_OBJS_DIR) 214 215 # 216 # Handle the static and shared libraries this module depends on 217 # 218 LOCAL_STATIC_LIBRARIES := $(call strip-lib-prefix,$(LOCAL_STATIC_LIBRARIES)) 219 LOCAL_WHOLE_STATIC_LIBRARIES := $(call strip-lib-prefix,$(LOCAL_WHOLE_STATIC_LIBRARIES)) 220 LOCAL_SHARED_LIBRARIES := $(call strip-lib-prefix,$(LOCAL_SHARED_LIBRARIES)) 221 222 static_libraries := $(call map,module-get-built,$(LOCAL_STATIC_LIBRARIES)) 223 whole_static_libraries := $(call map,module-get-built,$(LOCAL_WHOLE_STATIC_LIBRARIES)) 224 225 shared_libraries := $(call map,module-get-built,$(LOCAL_SHARED_LIBRARIES))\ 226 $(TARGET_PREBUILT_SHARED_LIBRARIES) 227 228 $(LOCAL_BUILT_MODULE): $(static_libraries) $(whole_static_libraries) $(shared_libraries) 229 230 # If LOCAL_LDLIBS contains anything like -l<library> then 231 # prepend a -L$(SYSROOT)/usr/lib to it to ensure that the linker 232 # looks in the right location 233 # 234 ifneq ($(filter -l%,$(LOCAL_LDLIBS)),) 235 LOCAL_LDLIBS := -L$(call host-path,$(SYSROOT)/usr/lib) $(LOCAL_LDLIBS) 236 endif 237 238 $(LOCAL_BUILT_MODULE): PRIVATE_STATIC_LIBRARIES := $(static_libraries) 239 $(LOCAL_BUILT_MODULE): PRIVATE_WHOLE_STATIC_LIBRARIES := $(whole_static_libraries) 240 $(LOCAL_BUILT_MODULE): PRIVATE_SHARED_LIBRARIES := $(shared_libraries) 241 $(LOCAL_BUILT_MODULE): PRIVATE_OBJECTS := $(LOCAL_OBJECTS) 242 243 $(LOCAL_BUILT_MODULE): PRIVATE_LDFLAGS := $(TARGET_LDFLAGS) $(LOCAL_LDFLAGS) 244 $(LOCAL_BUILT_MODULE): PRIVATE_LDLIBS := $(LOCAL_LDLIBS) $(TARGET_LDLIBS) 245 246 $(LOCAL_BUILT_MODULE): PRIVATE_NAME := $(notdir $(LOCAL_BUILT_MODULE)) 247 248 # 249 # If this is a static library module 250 # 251 ifeq ($(call module-get-class,$(LOCAL_MODULE)),STATIC_LIBRARY) 252 $(LOCAL_BUILT_MODULE): $(LOCAL_OBJECTS) 253 @ mkdir -p $(dir $@) 254 @ echo "StaticLibrary : $(PRIVATE_NAME)" 255 $(hide) rm -rf $@ 256 $(hide) $(cmd-build-static-library) 257 258 ALL_STATIC_LIBRARIES += $(LOCAL_BUILT_MODULE) 259 endif 260 261 # 262 # If this is a shared library module 263 # 264 ifeq ($(call module-get-class,$(LOCAL_MODULE)),SHARED_LIBRARY) 265 $(LOCAL_BUILT_MODULE): $(LOCAL_OBJECTS) 266 @ mkdir -p $(dir $@) 267 @ echo "SharedLibrary : $(PRIVATE_NAME)" 268 $(hide) $(cmd-build-shared-library) 269 270 ALL_SHARED_LIBRARIES += $(LOCAL_BUILT_MODULE) 271 endif 272 273 # 274 # If this is an executable module 275 # 276 ifeq ($(call module-get-class,$(LOCAL_MODULE)),EXECUTABLE) 277 $(LOCAL_BUILT_MODULE): $(LOCAL_OBJECTS) 278 @ mkdir -p $(dir $@) 279 @ echo "Executable : $(PRIVATE_NAME)" 280 $(hide) $(cmd-build-executable) 281 282 ALL_EXECUTABLES += $(LOCAL_BUILT_MODULE) 283 endif 284 285 # 286 # If this is a prebuilt module 287 # 288 ifeq ($(call module-is-prebuilt,$(LOCAL_MODULE)),$(true)) 289 $(LOCAL_BUILT_MODULE): $(LOCAL_OBJECTS) 290 @ mkdir -p $(dir $@) 291 @ echo "Prebuilt : $(call pretty-dir,$@) <= $(call pretty-dir,$<)" 292 $(hide) cp -f $< $@ 293 endif 294 295 # 296 # If this is an installable module 297 # 298 ifeq ($(call module-is-installable,$(LOCAL_MODULE)),$(true)) 299 $(LOCAL_INSTALLED): PRIVATE_NAME := $(notdir $(LOCAL_BUILT_MODULE)) 300 $(LOCAL_INSTALLED): PRIVATE_SRC := $(LOCAL_BUILT_MODULE) 301 $(LOCAL_INSTALLED): PRIVATE_DST_DIR := $(NDK_APP_DST_DIR) 302 $(LOCAL_INSTALLED): PRIVATE_DST := $(LOCAL_INSTALLED) 303 304 $(LOCAL_INSTALLED): $(LOCAL_BUILT_MODULE) clean-installed-binaries 305 @ echo "Install : $(PRIVATE_NAME) => $(call pretty-dir,$(PRIVATE_DST))" 306 $(hide) mkdir -p $(PRIVATE_DST_DIR) 307 $(hide) install -p $(PRIVATE_SRC) $(PRIVATE_DST) 308 $(hide) $(call cmd-strip, $(PRIVATE_DST)) 309 endif 310