build-binary.mk revision c2cb1cc7609843440140c4e8794b76321f64cc40
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# 24my := 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 31include $(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 39cleantarget := clean-$(LOCAL_MODULE)-$(TARGET_ARCH_ABI) 40.PHONY: $(cleantarget) 41clean: $(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 52ifeq ($(NDK_APP_DEBUGGABLE),true) 53$(NDK_APP_GDBSETUP): PRIVATE_SRC_DIRS += $(LOCAL_C_INCLUDES) $(LOCAL_PATH) 54endif 55 56# list of generated object files 57LOCAL_OBJECTS := 58 59# always define ANDROID when building binaries 60# 61LOCAL_CFLAGS := -DANDROID $(LOCAL_CFLAGS) 62 63# 64# Add the default system shared libraries to the build 65# 66ifeq ($(LOCAL_SYSTEM_SHARED_LIBRARIES),none) 67 LOCAL_SHARED_LIBRARIES += $(TARGET_DEFAULT_SYSTEM_SHARED_LIBRARIES) 68else 69 LOCAL_SHARED_LIBRARIES += $(LOCAL_SYSTEM_SHARED_LIBRARIES) 70endif 71 72 73# 74# Check LOCAL_CPP_EXTENSION, use '.cpp' by default 75# 76LOCAL_CPP_EXTENSION := $(strip $(LOCAL_CPP_EXTENSION)) 77ifeq ($(LOCAL_CPP_EXTENSION),) 78 LOCAL_CPP_EXTENSION := .cpp 79else 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 84endif 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# 90ifneq ($(LOCAL_ALLOW_UNDEFINED_SYMBOLS),true) 91 LOCAL_LDFLAGS += $($(my)NO_UNDEFINED_LDFLAGS) 92endif 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# 97ifndef ($(LOCAL_DISABLE_NO_EXECUTE),true) 98 LOCAL_CFLAGS += $($(my)NO_EXECUTE_CFLAGS) 99 LOCAL_LDFLAGS += $($(my)NO_EXECUTE_LDFLAGS) 100endif 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# 110LOCAL_ARM_MODE := $(strip $(LOCAL_ARM_MODE)) 111ifdef 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 ) 121endif 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 141neon_sources := $(filter %.neon,$(LOCAL_SRC_FILES)) 142neon_sources := $(neon_sources:%.neon=%) 143 144LOCAL_ARM_NEON := $(strip $(LOCAL_ARM_NEON)) 145ifdef 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 ) 150endif 151ifeq ($(LOCAL_ARM_NEON),true) 152 neon_sources += $(LOCAL_SRC_FILES:%.neon=%)) 153endif 154 155neon_sources := $(strip $(neon_sources)) 156ifdef 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 afainst TARGET_ARCH_ABI in $(LOCAL_MAKEFILE)) 160 $(call __ndk_error,Aborting) 161 endif 162 $(call tag-src-files,$(neon_sources:%.arm=%),neon) 163endif 164 165LOCAL_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# 170arm_sources := $(filter %.arm,$(LOCAL_SRC_FILES)) 171arm_sources := $(arm_sources:%.arm=%) 172thumb_sources := $(filter-out %.arm,$(LOCAL_SRC_FILES)) 173LOCAL_SRC_FILES := $(arm_sources) $(thumb_sources) 174 175ifeq ($(LOCAL_ARM_MODE),arm) 176 arm_sources := $(LOCAL_SRC_FILES) 177endif 178ifeq ($(LOCAL_ARM_MODE),thumb) 179 arm_sources := $(empty) 180endif 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 191LOCAL_DEPENDENCY_DIRS := 192LOCAL_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 203unknown_sources := $(strip $(filter-out %.c %.S %.s %$(LOCAL_CPP_EXTENSION),$(LOCAL_SRC_FILES))) 204ifdef unknown_sources 205 $(call __ndk_info,WARNING: Unsupported source file extensions in $(LOCAL_MAKEFILE) for module $(LOCAL_MODULE)) 206 $(call __ndk_info, $(unknown_sources)) 207endif 208 209# 210# The compile-xxx-source calls updated LOCAL_OBJECTS and LOCAL_DEPENDENCY_DIRS 211# 212ALL_DEPENDENCY_DIRS += $(sort $(LOCAL_DEPENDENCY_DIRS)) 213CLEAN_OBJS_DIRS += $(LOCAL_OBJS_DIR) 214 215# 216# Handle the static and shared libraries this module depends on 217# 218LOCAL_STATIC_LIBRARIES := $(call strip-lib-prefix,$(LOCAL_STATIC_LIBRARIES)) 219LOCAL_SHARED_LIBRARIES := $(call strip-lib-prefix,$(LOCAL_SHARED_LIBRARIES)) 220 221static_libraries := $(call map,module-get-built,$(LOCAL_STATIC_LIBRARIES)) 222shared_libraries := $(call map,module-get-built,$(LOCAL_SHARED_LIBRARIES))\ 223 $(call map,module-get-built,$(LOCAL_PREBUILTS))\ 224 $(TARGET_PREBUILT_SHARED_LIBRARIES) 225 226$(LOCAL_BUILT_MODULE): $(static_libraries) $(shared_libraries) 227 228# If LOCAL_LDLIBS contains anything like -l<library> then 229# prepend a -L$(SYSROOT)/usr/lib to it to ensure that the linker 230# looks in the right location 231# 232ifneq ($(filter -l%,$(LOCAL_LDLIBS)),) 233 LOCAL_LDLIBS := -L$(call host-path,$(SYSROOT)/usr/lib) $(LOCAL_LDLIBS) 234endif 235 236$(LOCAL_BUILT_MODULE): PRIVATE_STATIC_LIBRARIES := $(static_libraries) 237$(LOCAL_BUILT_MODULE): PRIVATE_SHARED_LIBRARIES := $(shared_libraries) 238$(LOCAL_BUILT_MODULE): PRIVATE_OBJECTS := $(LOCAL_OBJECTS) 239 240$(LOCAL_BUILT_MODULE): PRIVATE_LDFLAGS := $(TARGET_LDFLAGS) $(LOCAL_LDFLAGS) 241$(LOCAL_BUILT_MODULE): PRIVATE_LDLIBS := $(LOCAL_LDLIBS) $(TARGET_LDLIBS) 242 243$(LOCAL_BUILT_MODULE): PRIVATE_NAME := $(notdir $(LOCAL_BUILT_MODULE)) 244 245# 246# If this is a static library module 247# 248ifeq ($(call module-get-class,$(LOCAL_MODULE)),STATIC_LIBRARY) 249$(LOCAL_BUILT_MODULE): $(LOCAL_OBJECTS) 250 @ mkdir -p $(dir $@) 251 @ echo "StaticLibrary : $(PRIVATE_NAME)" 252 $(hide) rm -rf $@ 253 $(hide) $(cmd-build-static-library) 254 255ALL_STATIC_LIBRARIES += $(LOCAL_BUILT_MODULE) 256endif 257 258# 259# If this is a shared library module 260# 261ifeq ($(call module-get-class,$(LOCAL_MODULE)),SHARED_LIBRARY) 262$(LOCAL_BUILT_MODULE): $(LOCAL_OBJECTS) 263 @ mkdir -p $(dir $@) 264 @ echo "SharedLibrary : $(PRIVATE_NAME)" 265 $(hide) $(cmd-build-shared-library) 266 267ALL_SHARED_LIBRARIES += $(LOCAL_BUILT_MODULE) 268endif 269 270# 271# If this is an executable module 272# 273ifeq ($(call module-get-class,$(LOCAL_MODULE)),EXECUTABLE) 274$(LOCAL_BUILT_MODULE): $(LOCAL_OBJECTS) 275 @ mkdir -p $(dir $@) 276 @ echo "Executable : $(PRIVATE_NAME)" 277 $(hide) $(cmd-build-executable) 278 279ALL_EXECUTABLES += $(LOCAL_BUILT_MODULE) 280endif 281 282# 283# If this is a prebuilt module 284# 285ifeq ($(call module-is-prebuilt,$(LOCAL_MODULE)),$(true)) 286$(LOCAL_BUILT_MODULE): $(LOCAL_OBJECTS) 287 @ mkdir -p $(dir $@) 288 @ echo "Prebuilt : $(call pretty-dir,$@) <= $(call pretty-dir,$<)" 289 $(hide) cp -f $< $@ 290endif 291 292# 293# If this is an installable module 294# 295ifeq ($(call module-is-installable,$(LOCAL_MODULE)),$(true)) 296$(LOCAL_INSTALLED): PRIVATE_NAME := $(notdir $(LOCAL_BUILT_MODULE)) 297$(LOCAL_INSTALLED): PRIVATE_SRC := $(LOCAL_BUILT_MODULE) 298$(LOCAL_INSTALLED): PRIVATE_DST_DIR := $(NDK_APP_DST_DIR) 299$(LOCAL_INSTALLED): PRIVATE_DST := $(LOCAL_INSTALLED) 300 301$(LOCAL_INSTALLED): $(LOCAL_BUILT_MODULE) clean-installed-binaries 302 @ echo "Install : $(PRIVATE_NAME) => $(call pretty-dir,$(PRIVATE_DST))" 303 $(hide) mkdir -p $(PRIVATE_DST_DIR) 304 $(hide) install -p $(PRIVATE_SRC) $(PRIVATE_DST) 305 $(hide) $(call cmd-strip, $(PRIVATE_DST)) 306endif 307