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 30 ifeq ($(strip $(SHOW)),) 31 define pretty 32 @echo $1 33 endef 34 hide := @ 35 else 36 define pretty 37 endef 38 hide := 39 endif 40 41 # Return the parent directory of a given path. 42 # $1: path 43 parent-dir = $(dir $1) 44 45 # Return the directory of the current Makefile / Android.mk. 46 my-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 # 54 intermediates-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 # 61 local-host-tool = $(if $(strip $(LOCAL_HOST_BUILD)),$(BUILD_$1),$(MY_$1)) 62 local-host-exe = $(call local-host-tool,EXEEXT) 63 local-host-dll = $(call local-host-tool,DLLEXT) 64 65 local-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. 69 local-intermediates-dir = $(OBJS_DIR)/intermediates/$(LOCAL_MODULE) 70 71 local-library-path = $(OBJS_DIR)/libs/$(1).a 72 local-executable-path = $(OBJS_DIR)/$(1)$(call local-host-tool,EXEEXT) 73 local-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 # 82 define compile-c-source 83 SRC:=$(1) 84 OBJ:=$$(LOCAL_OBJS_DIR)/$$(SRC:%.c=%.o) 85 LOCAL_OBJECTS += $$(OBJ) 86 DEPENDENCY_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 98 endef 99 100 # Compile a C++ source file 101 # 102 define compile-cxx-source 103 SRC:=$(1) 104 OBJ:=$$(LOCAL_OBJS_DIR)/$$(SRC:%$(LOCAL_CPP_EXTENSION)=%.o) 105 LOCAL_OBJECTS += $$(OBJ) 106 DEPENDENCY_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 118 endef 119 120 # Compile an Objective-C source file 121 # 122 define compile-objc-source 123 SRC:=$(1) 124 OBJ:=$$(LOCAL_OBJS_DIR)/$$(notdir $$(SRC:%.m=%.o)) 125 LOCAL_OBJECTS += $$(OBJ) 126 DEPENDENCY_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 138 endef 139 140 # Compile a generated C source files# 141 # 142 define compile-generated-c-source 143 SRC:=$(1) 144 OBJ:=$$(LOCAL_OBJS_DIR)/$$(notdir $$(SRC:%.c=%.o)) 145 LOCAL_OBJECTS += $$(OBJ) 146 DEPENDENCY_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 158 endef 159 160 define compile-generated-cxx-source 161 SRC:=$(1) 162 OBJ:=$$(LOCAL_OBJS_DIR)/$$(notdir $$(SRC:%$(LOCAL_CPP_EXTENSION)=%.o)) 163 LOCAL_OBJECTS += $$(OBJ) 164 DEPENDENCY_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 176 endef 177 178 # Install a file 179 # 180 define install-target 181 SRC:=$(1) 182 DST:=$(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) 191 install: $$(DST) 192 endef 193 194 # for now, we only use prebuilt SDL libraries, so copy them 195 define copy-prebuilt-lib 196 _SRC := $(1) 197 _SRC1 := $$(notdir $$(_SRC)) 198 _DST := $$(LIBS_DIR)/$$(_SRC1) 199 LIBRARIES += $$(_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) 206 endef 207 208 define create-dir 209 $(1): 210 mkdir -p $(1) 211 endef 212 213 define transform-generated-source 214 @echo "Generated: $(PRIVATE_MODULE) <= $<" 215 @mkdir -p $(dir $@) 216 $(hide) $(PRIVATE_CUSTOM_TOOL) 217 endef 218