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 31# 32# Ensure that 'make <module>' and 'make clean-<module>' work 33# 34.PHONY: $(LOCAL_MODULE) 35$(LOCAL_MODULE): $(LOCAL_BUILT_MODULE) 36 37cleantarget := clean-$(LOCAL_MODULE)-$(TARGET_ARCH_ABI) 38.PHONY: $(cleantarget) 39clean: $(cleantarget) 40 41$(cleantarget): PRIVATE_MODULE := $(LOCAL_MODULE) 42$(cleantarget): PRIVATE_TEXT := [$(TARGET_ARCH_ABI)] 43$(cleantarget): PRIVATE_CLEAN_FILES := $(LOCAL_BUILT_MODULE) \ 44 $($(my)OBJS) 45 46$(cleantarget):: 47 @echo "Clean: $(PRIVATE_MODULE) $(PRIVATE_TEXT)" 48 $(hide) rm -rf $(PRIVATE_CLEAN_FILES) 49 50# list of generated object files 51LOCAL_OBJECTS := 52 53# 54# always define ANDROID when building binaries 55# 56LOCAL_CFLAGS := -D__ANDROID__ -DANDROID $(LOCAL_CFLAGS) 57 58# 59# Check LOCAL_CPP_EXTENSION, use '.cpp' by default 60# 61LOCAL_CPP_EXTENSION := $(strip $(LOCAL_CPP_EXTENSION)) 62ifeq ($(LOCAL_CPP_EXTENSION),) 63 LOCAL_CPP_EXTENSION := .cpp 64else 65 ifneq ($(words $(LOCAL_CPP_EXTENSION)),1) 66 $(call __gdk_info, LOCAL_CPP_EXTENSION in $(LOCAL_MAKEFILE) must be one word only, not '$(LOCAL_CPP_EXTENSION)') 67 $(call __gdk_error, Aborting) 68 endif 69endif 70 71# all_source_patterns contains the list of filename patterns that correspond 72# to source files recognized by our build system 73all_source_extensions := .c $(LOCAL_CPP_EXTENSION) 74all_source_patterns := $(foreach _ext,$(all_source_extensions),%$(_ext)) 75 76unknown_sources := $(strip $(filter-out $(all_source_patterns),$(LOCAL_SRC_FILES))) 77ifdef unknown_sources 78 $(call __gdk_info,WARNING: Unsupported source file extensions in $(LOCAL_MAKEFILE) for module $(LOCAL_MODULE)) 79 $(call __gdk_info, $(unknown_sources)) 80endif 81 82# LOCAL_OBJECTS will list all object files corresponding to the sources 83# listed in LOCAL_SRC_FILES, in the *same* order. 84# 85LOCAL_OBJECTS := $(LOCAL_SRC_FILES) 86$(foreach _ext,$(all_source_extensions),\ 87 $(eval LOCAL_OBJECTS := $$(LOCAL_OBJECTS:%$(_ext)=%.bc))\ 88) 89LOCAL_OBJECTS := $(filter %.bc,$(LOCAL_OBJECTS)) 90LOCAL_OBJECTS := $(foreach _obj,$(LOCAL_OBJECTS),$(LOCAL_OBJS_DIR)/$(_obj)) 91 92# 93# Build the sources to object files 94# 95 96$(foreach src,$(filter %.c,$(LOCAL_SRC_FILES)), $(call compile-c-source,$(src))) 97$(foreach src,$(filter %$(LOCAL_CPP_EXTENSION),$(LOCAL_SRC_FILES)),\ 98 $(call compile-cpp-source,$(src))) 99 100# 101# The compile-xxx-source calls updated LOCAL_OBJECTS and LOCAL_DEPENDENCY_DIRS 102# 103CLEAN_OBJS_DIRS += $(LOCAL_OBJS_DIR) 104 105$(LOCAL_BUILT_MODULE): 106 107$(LOCAL_BUILT_MODULE): PRIVATE_OBJECTS := $(LOCAL_OBJECTS) 108$(LOCAL_BUILT_MODULE): PRIVATE_NAME := $(notdir $(LOCAL_BUILT_MODULE)) 109 110ifeq ($(call module-get-class,$(LOCAL_MODULE)),BITCODE) 111$(LOCAL_BUILT_MODULE): $(LOCAL_OBJECTS) 112 @ echo "BitcodeLibrary : $(PRIVATE_NAME)" 113 $(hide) $(cmd-link-bitcodes) 114endif 115 116# 117# If this is an installable module 118# 119ifeq ($(call module-is-installable,$(LOCAL_MODULE)),$(true)) 120$(LOCAL_INSTALLED): PRIVATE_NAME := $(notdir $(LOCAL_BUILT_MODULE)) 121$(LOCAL_INSTALLED): PRIVATE_SRC := $(LOCAL_BUILT_MODULE) 122$(LOCAL_INSTALLED): PRIVATE_DST_DIR := $(GDK_APP_DST_DIR) 123$(LOCAL_INSTALLED): PRIVATE_DST := $(LOCAL_INSTALLED) 124 125$(LOCAL_INSTALLED): $(LOCAL_BUILT_MODULE) clean-installed-binaries 126 @ echo "Install BCLib : $(PRIVATE_NAME) => $(call pretty-dir,$(PRIVATE_DST))" 127 $(hide) mkdir -p $(PRIVATE_DST_DIR) 128 $(hide) install -p $(PRIVATE_SRC) $(PRIVATE_DST) 129endif 130