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 define my-dir 42 . 43 endef 44 45 # return the directory containing the intermediate files for a given 46 # kind of executable 47 # $1 = type (EXECUTABLES or STATIC_LIBRARIES) 48 # $2 = module name 49 # $3 = ignored 50 # 51 define intermediates-dir-for 52 $(OBJS_DIR)/intermediates/$(2) 53 endef 54 55 # Generate the full path of a given static library 56 define library-path 57 $(OBJS_DIR)/libs/$(1).a 58 endef 59 60 define executable-path 61 $(OBJS_DIR)/$(1)$(EXE) 62 endef 63 64 # Compile a C source file 65 # 66 define compile-c-source 67 SRC:=$(1) 68 OBJ:=$$(LOCAL_OBJS_DIR)/$$(SRC:%.c=%.o) 69 LOCAL_OBJECTS += $$(OBJ) 70 DEPENDENCY_DIRS += $$(dir $$(OBJ)) 71 $$(OBJ): PRIVATE_CFLAGS := $$(CFLAGS) $$(LOCAL_CFLAGS) -I$$(LOCAL_PATH) -I$$(LOCAL_OBJS_DIR) 72 $$(OBJ): PRIVATE_CC := $$(LOCAL_CC) 73 $$(OBJ): PRIVATE_OBJ := $$(OBJ) 74 $$(OBJ): PRIVATE_MODULE := $$(LOCAL_MODULE) 75 $$(OBJ): PRIVATE_SRC := $$(SRC_PATH)/$$(SRC) 76 $$(OBJ): PRIVATE_SRC0 := $$(SRC) 77 $$(OBJ): $$(SRC_PATH)/$$(SRC) 78 @mkdir -p $$(dir $$(PRIVATE_OBJ)) 79 @echo "Compile: $$(PRIVATE_MODULE) <= $$(PRIVATE_SRC0)" 80 $(hide) $$(PRIVATE_CC) $$(PRIVATE_CFLAGS) -c -o $$(PRIVATE_OBJ) -MMD -MP -MF $$(PRIVATE_OBJ).d.tmp $$(PRIVATE_SRC) 81 $(hide) $$(BUILD_SYSTEM)/mkdeps.sh $$(PRIVATE_OBJ) $$(PRIVATE_OBJ).d.tmp $$(PRIVATE_OBJ).d 82 endef 83 84 # Compile a C++ source file 85 # 86 define compile-cxx-source 87 SRC:=$(1) 88 OBJ:=$$(LOCAL_OBJS_DIR)/$$(SRC:%$(LOCAL_CPP_EXTENSION)=%.o) 89 LOCAL_OBJECTS += $$(OBJ) 90 DEPENDENCY_DIRS += $$(dir $$(OBJ)) 91 $$(OBJ): PRIVATE_CFLAGS := $$(CFLAGS) $$(LOCAL_CFLAGS) -I$$(LOCAL_PATH) -I$$(LOCAL_OBJS_DIR) 92 $$(OBJ): PRIVATE_CXX := $$(LOCAL_CC) 93 $$(OBJ): PRIVATE_OBJ := $$(OBJ) 94 $$(OBJ): PRIVATE_MODULE := $$(LOCAL_MODULE) 95 $$(OBJ): PRIVATE_SRC := $$(SRC_PATH)/$$(SRC) 96 $$(OBJ): PRIVATE_SRC0 := $$(SRC) 97 $$(OBJ): $$(SRC_PATH)/$$(SRC) 98 @mkdir -p $$(dir $$(PRIVATE_OBJ)) 99 @echo "Compile: $$(PRIVATE_MODULE) <= $$(PRIVATE_SRC0)" 100 $(hide) $$(PRIVATE_CXX) $$(PRIVATE_CFLAGS) -c -o $$(PRIVATE_OBJ) -MMD -MP -MF $$(PRIVATE_OBJ).d.tmp $$(PRIVATE_SRC) 101 $(hide) $$(BUILD_SYSTEM)/mkdeps.sh $$(PRIVATE_OBJ) $$(PRIVATE_OBJ).d.tmp $$(PRIVATE_OBJ).d 102 endef 103 104 # Compile an Objective-C source file 105 # 106 define compile-objc-source 107 SRC:=$(1) 108 OBJ:=$$(LOCAL_OBJS_DIR)/$$(notdir $$(SRC:%.m=%.o)) 109 LOCAL_OBJECTS += $$(OBJ) 110 DEPENDENCY_DIRS += $$(dir $$(OBJ)) 111 $$(OBJ): PRIVATE_CFLAGS := $$(CFLAGS) $$(LOCAL_CFLAGS) -I$$(LOCAL_PATH) -I$$(LOCAL_OBJS_DIR) 112 $$(OBJ): PRIVATE_CC := $$(LOCAL_CC) 113 $$(OBJ): PRIVATE_OBJ := $$(OBJ) 114 $$(OBJ): PRIVATE_MODULE := $$(LOCAL_MODULE) 115 $$(OBJ): PRIVATE_SRC := $$(SRC_PATH)/$$(SRC) 116 $$(OBJ): PRIVATE_SRC0 := $$(SRC) 117 $$(OBJ): $$(SRC_PATH)/$$(SRC) 118 @mkdir -p $$(dir $$(PRIVATE_OBJ)) 119 @echo "Compile: $$(PRIVATE_MODULE) <= $$(PRIVATE_SRC0)" 120 $(hide) $$(PRIVATE_CC) $$(PRIVATE_CFLAGS) -c -o $$(PRIVATE_OBJ) -MMD -MP -MF $$(PRIVATE_OBJ).d.tmp $$(PRIVATE_SRC) 121 $(hide) $$(BUILD_SYSTEM)/mkdeps.sh $$(PRIVATE_OBJ) $$(PRIVATE_OBJ).d.tmp $$(PRIVATE_OBJ).d 122 endef 123 124 # Compile a generated C source files# 125 # 126 define compile-generated-c-source 127 SRC:=$(1) 128 OBJ:=$$(LOCAL_OBJS_DIR)/$$(notdir $$(SRC:%.c=%.o)) 129 LOCAL_OBJECTS += $$(OBJ) 130 DEPENDENCY_DIRS += $$(dir $$(OBJ)) 131 $$(OBJ): PRIVATE_CFLAGS := $$(CFLAGS) $$(LOCAL_CFLAGS) -I$$(LOCAL_PATH) -I$$(LOCAL_OBJS_DIR) 132 $$(OBJ): PRIVATE_CC := $$(LOCAL_CC) 133 $$(OBJ): PRIVATE_OBJ := $$(OBJ) 134 $$(OBJ): PRIVATE_MODULE := $$(LOCAL_MODULE) 135 $$(OBJ): PRIVATE_SRC := $$(SRC) 136 $$(OBJ): PRIVATE_SRC0 := $$(SRC) 137 $$(OBJ): $$(SRC) 138 @mkdir -p $$(dir $$(PRIVATE_OBJ)) 139 @echo "Compile: $$(PRIVATE_MODULE) <= $$(PRIVATE_SRC0)" 140 $(hide) $$(PRIVATE_CC) $$(PRIVATE_CFLAGS) -c -o $$(PRIVATE_OBJ) -MMD -MP -MF $$(PRIVATE_OBJ).d.tmp $$(PRIVATE_SRC) 141 $(hide) $$(BUILD_SYSTEM)/mkdeps.sh $$(PRIVATE_OBJ) $$(PRIVATE_OBJ).d.tmp $$(PRIVATE_OBJ).d 142 endef 143 144 # Install a file 145 # 146 define install-target 147 SRC:=$(1) 148 DST:=$(2) 149 $$(DST): PRIVATE_SRC := $$(SRC) 150 $$(DST): PRIVATE_DST := $$(DST) 151 $$(DST): PRIVATE_DST_NAME := $$(notdir $$(DST)) 152 $$(DST): PRIVATE_SRC_NAME := $$(SRC) 153 $$(DST): $$(SRC) 154 @mkdir -p $$(dir $$(PRIVATE_DST)) 155 @echo "Install: $$(PRIVATE_DST_NAME) <= $$(PRIVATE_SRC_NAME)" 156 $(hide) cp -f $$(PRIVATE_SRC) $$(PRIVATE_DST) 157 install: $$(DST) 158 endef 159 160 # for now, we only use prebuilt SDL libraries, so copy them 161 define copy-prebuilt-lib 162 _SRC := $(1) 163 _SRC1 := $$(notdir $$(_SRC)) 164 _DST := $$(LIBS_DIR)/$$(_SRC1) 165 LIBRARIES += $$(_DST) 166 $$(_DST): PRIVATE_DST := $$(_DST) 167 $$(_DST): PRIVATE_SRC := $$(_SRC) 168 $$(_DST): $$(_SRC) 169 @mkdir -p $$(dir $$(PRIVATE_DST)) 170 @echo "Prebuilt: $$(PRIVATE_DST)" 171 $(hide) cp -f $$(PRIVATE_SRC) $$(PRIVATE_DST) 172 endef 173 174 define create-dir 175 $(1): 176 mkdir -p $(1) 177 endef 178 179 define transform-generated-source 180 @echo "Generated: $(PRIVATE_MODULE) <= $<" 181 @mkdir -p $(dir $@) 182 $(hide) $(PRIVATE_CUSTOM_TOOL) 183 endef 184 185