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# this turns off the suffix rules built into make 17.SUFFIXES: 18 19# this turns off the RCS / SCCS implicit rules of GNU Make 20% : RCS/%,v 21% : RCS/% 22% : %,v 23% : s.% 24% : SCCS/s.% 25 26# If a rule fails, delete $@. 27.DELETE_ON_ERROR: 28 29# shared definitions 30ifeq ($(strip $(SHOW)),) 31define pretty 32@echo $1 33endef 34hide := @ 35else 36define pretty 37endef 38hide := 39endif 40 41# Return the parent directory of a given path. 42# $1: path 43parent-dir = $(dir $1) 44 45# Return the directory of the current Makefile / Android.mk. 46my-dir = $(call parent-dir,$(lastword $(MAKEFILE_LIST))) 47 48# Return the directory containing the intermediate files for a given 49# kind of executable 50# $1 = type (EXECUTABLES, STATIC_LIBRARIES or SHARED_LIBRARIES). 51# $2 = module name 52# $3 = ignored 53# 54intermediates-dir-for = $(OBJS_DIR)/intermediates/$(2) 55 56# Return the name of a given host tool, based on the value of 57# LOCAL_HOST_BUILD. If the variable is defined, return $(BUILD_$1), 58# otherwise return $(HOST_$1). 59# $1: Tool name (e.g. CC, LD, etc...) 60# 61local-host-tool = $(if $(strip $(LOCAL_HOST_BUILD)),$(BUILD_$1),$(MY_$1)) 62local-host-exe = $(call local-host-tool,EXEEXT) 63local-host-dll = $(call local-host-tool,DLLEXT) 64 65local-host-define = $(if $(strip $(LOCAL_$1)),,$(eval LOCAL_$1 := $$(call local-host-tool,$1))) 66 67# Return the directory containing the intermediate files for the current 68# module. LOCAL_MODULE must be defined before calling this. 69local-intermediates-dir = $(OBJS_DIR)/intermediates/$(LOCAL_MODULE) 70 71local-library-path = $(OBJS_DIR)/libs/$(1).a 72local-executable-path = $(OBJS_DIR)/$(1)$(call local-host-tool,EXEEXT) 73local-shared-library-path = $(OBJS_DIR)/lib/$(1)$(call local-host-tool,DLLEXT) 74 75 76# Toolchain control support. 77# It's possible to switch between the regular toolchain and the host one 78# in certain cases. 79 80# Compile a C source file 81# 82define compile-c-source 83SRC:=$(1) 84OBJ:=$$(LOCAL_OBJS_DIR)/$$(SRC:%.c=%.o) 85LOCAL_OBJECTS += $$(OBJ) 86DEPENDENCY_DIRS += $$(dir $$(OBJ)) 87$$(OBJ): PRIVATE_CFLAGS := $$(LOCAL_CFLAGS) -I$$(LOCAL_PATH) -I$$(LOCAL_OBJS_DIR) 88$$(OBJ): PRIVATE_CC := $$(LOCAL_CC) 89$$(OBJ): PRIVATE_OBJ := $$(OBJ) 90$$(OBJ): PRIVATE_MODULE := $$(LOCAL_MODULE) 91$$(OBJ): PRIVATE_SRC := $$(LOCAL_PATH)/$$(SRC) 92$$(OBJ): PRIVATE_SRC0 := $$(SRC) 93$$(OBJ): $$(LOCAL_PATH)/$$(SRC) 94 @mkdir -p $$(dir $$(PRIVATE_OBJ)) 95 @echo "Compile: $$(PRIVATE_MODULE) <= $$(PRIVATE_SRC0)" 96 $(hide) $$(PRIVATE_CC) $$(PRIVATE_CFLAGS) -c -o $$(PRIVATE_OBJ) -MMD -MP -MF $$(PRIVATE_OBJ).d.tmp $$(PRIVATE_SRC) 97 $(hide) $$(BUILD_SYSTEM)/mkdeps.sh $$(PRIVATE_OBJ) $$(PRIVATE_OBJ).d.tmp $$(PRIVATE_OBJ).d 98endef 99 100# Compile a C++ source file 101# 102define compile-cxx-source 103SRC:=$(1) 104OBJ:=$$(LOCAL_OBJS_DIR)/$$(SRC:%$(LOCAL_CPP_EXTENSION)=%.o) 105LOCAL_OBJECTS += $$(OBJ) 106DEPENDENCY_DIRS += $$(dir $$(OBJ)) 107$$(OBJ): PRIVATE_CFLAGS := $$(LOCAL_CFLAGS) -I$$(LOCAL_PATH) -I$$(LOCAL_OBJS_DIR) 108$$(OBJ): PRIVATE_CXX := $$(LOCAL_CC) 109$$(OBJ): PRIVATE_OBJ := $$(OBJ) 110$$(OBJ): PRIVATE_MODULE := $$(LOCAL_MODULE) 111$$(OBJ): PRIVATE_SRC := $$(LOCAL_PATH)/$$(SRC) 112$$(OBJ): PRIVATE_SRC0 := $$(SRC) 113$$(OBJ): $$(LOCAL_PATH)/$$(SRC) 114 @mkdir -p $$(dir $$(PRIVATE_OBJ)) 115 @echo "Compile: $$(PRIVATE_MODULE) <= $$(PRIVATE_SRC0)" 116 $(hide) $$(PRIVATE_CXX) $$(PRIVATE_CFLAGS) -c -o $$(PRIVATE_OBJ) -MMD -MP -MF $$(PRIVATE_OBJ).d.tmp $$(PRIVATE_SRC) 117 $(hide) $$(BUILD_SYSTEM)/mkdeps.sh $$(PRIVATE_OBJ) $$(PRIVATE_OBJ).d.tmp $$(PRIVATE_OBJ).d 118endef 119 120# Compile an Objective-C source file 121# 122define compile-objc-source 123SRC:=$(1) 124OBJ:=$$(LOCAL_OBJS_DIR)/$$(notdir $$(SRC:%.m=%.o)) 125LOCAL_OBJECTS += $$(OBJ) 126DEPENDENCY_DIRS += $$(dir $$(OBJ)) 127$$(OBJ): PRIVATE_CFLAGS := $$(LOCAL_CFLAGS) -I$$(LOCAL_PATH) -I$$(LOCAL_OBJS_DIR) 128$$(OBJ): PRIVATE_CC := $$(LOCAL_CC) 129$$(OBJ): PRIVATE_OBJ := $$(OBJ) 130$$(OBJ): PRIVATE_MODULE := $$(LOCAL_MODULE) 131$$(OBJ): PRIVATE_SRC := $$(LOCAL_PATH)/$$(SRC) 132$$(OBJ): PRIVATE_SRC0 := $$(SRC) 133$$(OBJ): $$(LOCAL_PATH)/$$(SRC) 134 @mkdir -p $$(dir $$(PRIVATE_OBJ)) 135 @echo "Compile: $$(PRIVATE_MODULE) <= $$(PRIVATE_SRC0)" 136 $(hide) $$(PRIVATE_CC) $$(PRIVATE_CFLAGS) -c -o $$(PRIVATE_OBJ) -MMD -MP -MF $$(PRIVATE_OBJ).d.tmp $$(PRIVATE_SRC) 137 $(hide) $$(BUILD_SYSTEM)/mkdeps.sh $$(PRIVATE_OBJ) $$(PRIVATE_OBJ).d.tmp $$(PRIVATE_OBJ).d 138endef 139 140# Compile a generated C source files# 141# 142define compile-generated-c-source 143SRC:=$(1) 144OBJ:=$$(LOCAL_OBJS_DIR)/$$(notdir $$(SRC:%.c=%.o)) 145LOCAL_OBJECTS += $$(OBJ) 146DEPENDENCY_DIRS += $$(dir $$(OBJ)) 147$$(OBJ): PRIVATE_CFLAGS := $$(LOCAL_CFLAGS) -I$$(LOCAL_PATH) -I$$(LOCAL_OBJS_DIR) 148$$(OBJ): PRIVATE_CC := $$(LOCAL_CC) 149$$(OBJ): PRIVATE_OBJ := $$(OBJ) 150$$(OBJ): PRIVATE_MODULE := $$(LOCAL_MODULE) 151$$(OBJ): PRIVATE_SRC := $$(SRC) 152$$(OBJ): PRIVATE_SRC0 := $$(SRC) 153$$(OBJ): $$(SRC) 154 @mkdir -p $$(dir $$(PRIVATE_OBJ)) 155 @echo "Compile: $$(PRIVATE_MODULE) <= $$(PRIVATE_SRC0)" 156 $(hide) $$(PRIVATE_CC) $$(PRIVATE_CFLAGS) -c -o $$(PRIVATE_OBJ) -MMD -MP -MF $$(PRIVATE_OBJ).d.tmp $$(PRIVATE_SRC) 157 $(hide) $$(BUILD_SYSTEM)/mkdeps.sh $$(PRIVATE_OBJ) $$(PRIVATE_OBJ).d.tmp $$(PRIVATE_OBJ).d 158endef 159 160define compile-generated-cxx-source 161SRC:=$(1) 162OBJ:=$$(LOCAL_OBJS_DIR)/$$(notdir $$(SRC:%$(LOCAL_CPP_EXTENSION)=%.o)) 163LOCAL_OBJECTS += $$(OBJ) 164DEPENDENCY_DIRS += $$(dir $$(OBJ)) 165$$(OBJ): PRIVATE_CFLAGS := $$(LOCAL_CFLAGS) -I$$(LOCAL_PATH) -I$$(LOCAL_OBJS_DIR) 166$$(OBJ): PRIVATE_CXX := $$(LOCAL_CC) 167$$(OBJ): PRIVATE_OBJ := $$(OBJ) 168$$(OBJ): PRIVATE_MODULE := $$(LOCAL_MODULE) 169$$(OBJ): PRIVATE_SRC := $$(SRC) 170$$(OBJ): PRIVATE_SRC0 := $$(SRC) 171$$(OBJ): $$(SRC) 172 @mkdir -p $$(dir $$(PRIVATE_OBJ)) 173 @echo "Compile: $$(PRIVATE_MODULE) <= $$(PRIVATE_SRC0)" 174 $(hide) $$(PRIVATE_CXX) $$(PRIVATE_CFLAGS) -c -o $$(PRIVATE_OBJ) -MMD -MP -MF $$(PRIVATE_OBJ).d.tmp $$(PRIVATE_SRC) 175 $(hide) $$(BUILD_SYSTEM)/mkdeps.sh $$(PRIVATE_OBJ) $$(PRIVATE_OBJ).d.tmp $$(PRIVATE_OBJ).d 176endef 177 178# Install a file 179# 180define install-target 181SRC:=$(1) 182DST:=$(2) 183$$(DST): PRIVATE_SRC := $$(SRC) 184$$(DST): PRIVATE_DST := $$(DST) 185$$(DST): PRIVATE_DST_NAME := $$(notdir $$(DST)) 186$$(DST): PRIVATE_SRC_NAME := $$(SRC) 187$$(DST): $$(SRC) 188 @mkdir -p $$(dir $$(PRIVATE_DST)) 189 @echo "Install: $$(PRIVATE_DST_NAME) <= $$(PRIVATE_SRC_NAME)" 190 $(hide) cp -f $$(PRIVATE_SRC) $$(PRIVATE_DST) 191install: $$(DST) 192endef 193 194# for now, we only use prebuilt SDL libraries, so copy them 195define copy-prebuilt-lib 196_SRC := $(1) 197_SRC1 := $$(notdir $$(_SRC)) 198_DST := $$(LIBS_DIR)/$$(_SRC1) 199LIBRARIES += $$(_DST) 200$$(_DST): PRIVATE_DST := $$(_DST) 201$$(_DST): PRIVATE_SRC := $$(_SRC) 202$$(_DST): $$(_SRC) 203 @mkdir -p $$(dir $$(PRIVATE_DST)) 204 @echo "Prebuilt: $$(PRIVATE_DST)" 205 $(hide) cp -f $$(PRIVATE_SRC) $$(PRIVATE_DST) 206endef 207 208define create-dir 209$(1): 210 mkdir -p $(1) 211endef 212 213define transform-generated-source 214@echo "Generated: $(PRIVATE_MODULE) <= $<" 215@mkdir -p $(dir $@) 216$(hide) $(PRIVATE_CUSTOM_TOOL) 217endef 218