1 # This top-level build file is included by all modules that implement 2 # the hardware OpenGL ES emulation for Android. 3 # 4 # We use it to ensure that all sub-Makefiles are included in the right 5 # order for various variable definitions and usage to happen in the correct 6 # order. 7 # 8 9 # The following macros are used to start a new GLES emulation module. 10 # 11 # This will define LOCAL_MODULE as $1, plus a few other variables 12 # needed by the build system (e.g. LOCAL_MODULE_TAGS, LOCAL_MODULE_CLASS...) 13 # 14 # NOTE: You still need to define LOCAL_PATH before this 15 # 16 # Usage example: 17 # 18 # $(call emugl-begin-static-library,<name>) 19 # LOCAL_SRC_FILES := .... 20 # LOCAL_C_INCLUDES += .... 21 # $(call emugl-end-module) 22 # 23 emugl-begin-static-library = $(call emugl-begin-module,$1,STATIC_LIBRARY) 24 emugl-begin-shared-library = $(call emugl-begin-module,$1,SHARED_LIBRARY) 25 26 # Internal list of all declared modules (used for sanity checking) 27 _emugl_modules := 28 _emugl_HOST_modules := 29 30 # do not use directly, see functions above instead 31 emugl-begin-module = \ 32 $(eval include $(CLEAR_VARS)) \ 33 $(eval LOCAL_MODULE := $1) \ 34 $(eval LOCAL_MODULE_TAGS := debug) \ 35 $(eval LOCAL_MODULE_CLASS := $(patsubst HOST_%,%,$(patsubst %EXECUTABLE,%EXECUTABLES,$(patsubst %LIBRARY,%LIBRARIES,$2)))) \ 36 $(eval LOCAL_IS_HOST_MODULE := $(if $3,true,))\ 37 $(eval LOCAL_C_INCLUDES := $(EMUGL_COMMON_INCLUDES)) \ 38 $(eval LOCAL_CFLAGS := $(EMUGL_COMMON_CFLAGS)) \ 39 $(eval LOCAL_PRELINK_MODULE := false)\ 40 $(eval _EMUGL_INCLUDE_TYPE := $(BUILD_$2)) \ 41 $(call _emugl-init-module,$1,$2,$3) 42 43 # Used to end a module definition, see function definitions above 44 emugl-end-module = \ 45 $(eval include $(_EMUGL_INCLUDE_TYPE))\ 46 $(eval _EMUGL_INCLUDE_TYPE :=) \ 47 $(eval _emugl_$(_emugl_HOST)modules += $(_emugl_MODULE))\ 48 $(if $(EMUGL_DEBUG),$(call emugl-dump-module)) 49 50 # Managing module exports and imports. 51 # 52 # A module can 'import' another module, by calling emugl-import. This will 53 # make the current LOCAL_MODULE inherit various definitions exported from 54 # the imported module. 55 # 56 # Module exports are defined by calling emugl-export. Here is an example: 57 # 58 # $(call emugl-begin-static-library,foo) 59 # LOCAL_SRC_FILES := foo.c 60 # $(call emugl-export,C_INCLUDES,$(LOCAL_PATH)) 61 # $(call emugl-export,SHARED_LIBRARIES,libcutils) 62 # $(call emugl-end-module) 63 # 64 # $(call emugl-begin-shared-library,bar) 65 # LOCAL_SRC_FILES := bar.cpp 66 # $(call emugl-import,foo) 67 # $(call emugl-end-module) 68 # 69 # Here, we define a static library named 'foo' which exports an include 70 # path and a shared library requirement, and a shared library 'bar' which 71 # imports it. 72 # 73 # What this means is that: 74 # 75 # - 'bar' will automatically inherit foo's LOCAL_PATH in its LOCAL_C_INCLUDES 76 # - 'bar' will automatically inherit libcutils in its own LOCAL_SHARED_LIBRARIES 77 # 78 # Note that order of declaration matters. If 'foo' is defined after 'bar' in 79 # the example above, nothing will work correctly because dependencies are 80 # computed at import time. 81 # 82 # 83 # IMPORTANT: Imports are transitive, i.e. when module A imports B, 84 # it automatically imports anything imported by B too. 85 86 # This is the list of recognized export types we support for now. 87 EMUGL_EXPORT_TYPES := \ 88 CFLAGS \ 89 LDLIBS \ 90 LDFLAGS \ 91 C_INCLUDES \ 92 SHARED_LIBRARIES \ 93 STATIC_LIBRARIES \ 94 ADDITIONAL_DEPENDENCIES 95 96 # Initialize a module in our database 97 # $1: Module name 98 # $2: Module type 99 # $3: "HOST" for a host module, empty for a target one. 100 _emugl-init-module = \ 101 $(eval _emugl_HOST := $(if $3,HOST_,))\ 102 $(eval _emugl_MODULE := $(_emugl_HOST)$1)\ 103 $(if $(filter $(_emugl_$(_emugl_HOST)modules),$(_emugl_MODULE)),\ 104 $(error There is already a $(if $3,host,) module named $1!)\ 105 )\ 106 $(eval _mod = $(_emugl_MODULE)) \ 107 $(eval _emugl.$(_mod).type := $(patsubst HOST_%,%,$2))\ 108 $(eval _emugl.$(_mod).imports :=) \ 109 $(eval _emugl,$(_mod).moved :=) \ 110 $(foreach _type,$(EMUGL_EXPORT_TYPES),\ 111 $(eval _emugl.$(_mod).export.$(_type) :=)\ 112 ) 113 114 # Called to indicate that a module exports a given local variable for its 115 # users. This also adds this to LOCAL_$1 116 # $1: Local variable type (e.g. CFLAGS, LDLIBS, etc...) 117 # $2: Value(s) to append to the export 118 emugl-export = \ 119 $(eval _emugl.$(_emugl_MODULE).export.$1 += $2)\ 120 $(eval LOCAL_$1 := $2 $(LOCAL_$1)) 121 122 emugl-export-outer = \ 123 $(eval _emugl.$(_emugl_MODULE).export.$1 += $2) 124 125 # Called to indicate that a module imports the exports of another module 126 # $1: list of modules to import 127 # 128 emugl-import = \ 129 $(foreach _imod,$1,\ 130 $(call _emugl-module-import,$(_emugl_HOST)$(_imod))\ 131 ) 132 133 _emugl-module-import = \ 134 $(eval _mod := $(_emugl_MODULE))\ 135 $(if $(filter-out $(_emugl_$(_emugl_HOST)modules),$1),\ 136 $(info Unknown imported emugles module: $1)\ 137 $(if $(_emugl_HOST),\ 138 $(eval _names := $(patsubst HOST_%,%,$(_emugl_HOST_modules))),\ 139 $(eval _names := $(_emugl_modules))\ 140 )\ 141 $(info Please one of the following names: $(_names))\ 142 $(error Aborting)\ 143 )\ 144 $(if $(filter-out $(_emugl.$(_mod).imports),$1),\ 145 $(eval _emugl.$(_mod).imports += $1)\ 146 $(foreach _sub,$(_emugl.$1.imports),\ 147 $(call _emugl-module-import,$(_sub))\ 148 )\ 149 $(foreach _type,$(EMUGL_EXPORT_TYPES),\ 150 $(eval LOCAL_$(_type) := $(_emugl.$1.export.$(_type)) $(LOCAL_$(_type)))\ 151 )\ 152 $(if $(filter EXECUTABLE SHARED_LIBRARY,$(_emugl.$(_emugl_MODULE).type)),\ 153 $(if $(filter STATIC_LIBRARY,$(_emugl.$1.type)),\ 154 $(eval LOCAL_STATIC_LIBRARIES := $(1:HOST_%=%) $(LOCAL_STATIC_LIBRARIES))\ 155 )\ 156 $(if $(filter SHARED_LIBRARY,$(_emugl.$1.type)),\ 157 $(if $(_emugl.$1.moved),,\ 158 $(eval LOCAL_SHARED_LIBRARIES := $(1:HOST_%=%) $(LOCAL_SHARED_LIBRARIES))\ 159 )\ 160 )\ 161 )\ 162 ) 163 164 _emugl-dump-list = \ 165 $(foreach _list_item,$(strip $1),$(info . $(_list_item))) 166 167 emugl-dump-module = \ 168 $(info MODULE=$(_emugl_MODULE))\ 169 $(info . HOST=$(_emugl_HOST))\ 170 $(info . TYPE=$(_emugl.$(_emugl_MODULE).type))\ 171 $(info . IMPORTS=$(_emugl.$(_emugl_MODULE).imports))\ 172 $(foreach _type,$(EMUGL_EXPORT_TYPES),\ 173 $(if $(filter C_INCLUDES ADDITIONAL_DEPENDENCIES,$(_type)),\ 174 $(info . EXPORT.$(_type) :=)\ 175 $(call _emugl-dump-list,$(_emugl.$(_emugl_MODULE).export.$(_type)))\ 176 $(info . LOCAL_$(_type) :=)\ 177 $(call _emugl-dump-list,$(LOCAL_$(_type)))\ 178 ,\ 179 $(info . EXPORT.$(_type) := $(strip $(_emugl.$(_emugl_MODULE).export.$(_type))))\ 180 $(info . LOCAL_$(_type) := $(strip $(LOCAL_$(_type))))\ 181 )\ 182 )\ 183 $(info . LOCAL_SRC_FILES := $(LOCAL_SRC_FILES))\ 184 185 # This function can be called to generate the wrapper source files. 186 # LOCAL_MODULE and LOCAL_MODULE_CLASS must be defined or the build will abort. 187 # Source files will be stored in the local intermediates directory that will 188 # be automatically added to your LOCAL_C_INCLUDES. 189 # Usage: 190 # $(call emugl-gen-wrapper,<input-dir>,<basename>) 191 # 192 emugl-gen-wrapper = \ 193 $(eval _emugl_out := $(call local-intermediates-dir)) \ 194 $(call emugl-gen-wrapper-generic,$(_emugl_out),$1,$2) \ 195 $(call emugl-export,C_INCLUDES,$(_emugl_out)) 196 197 # DO NOT CALL DIRECTLY, USE emugl-gen-wrapper instead. 198 # 199 # The following function can be called to generate GL library wrapper 200 # Usage is: 201 # 202 # $(call emugl-gen-wrapper-generic,<dst-dir>,<src-dir>,<basename>) 203 # 204 # <dst-dir> is the destination directory where the generated sources are stored 205 # <src-dir> is the source directory where to find <basename>.attrib, etc.. 206 # <basename> is the emugen basename (see host/tools/emugen/README) 207 # 208 emugl-gen-wrapper-generic = $(eval $(emugl-gen-wrapper-generic-ev)) 209 210 define emugl-gen-wrapper-generic-ev 211 _emugl_wrap := $$1/$$3 212 _emugl_src := $$2/$$3 213 GEN := $$(_emugl_wrap)_wrapper_entry.cpp \ 214 $$(_emugl_wrap)_wrapper_context.cpp \ 215 $$(_emugl_wrap)_wrapper_context.h \ 216 $$(_emugl_wrap)_wrapper_proc.h 217 218 $$(GEN): PRIVATE_PATH := $$(LOCAL_PATH) 219 $$(GEN): PRIVATE_CUSTOM_TOOL := $$(EMUGL_EMUGEN) -W $$1 -i $$2 $$3 220 $$(GEN): $$(EMUGL_EMUGEN) $$(_emugl_src).attrib $$(_emugl_src).in $$(_emugl_src).types 221 $$(transform-generated-source) 222 223 $$(call emugl-export,ADDITIONAL_DEPENDENCIES,$$(GEN)) 224 LOCAL_GENERATED_SOURCES += $$(GEN) 225 LOCAL_C_INCLUDES += $$1 226 227 #ifneq ($$(HOST_OS),windows) 228 $$(call emugl-export,LDFLAGS,-ldl) 229 #endif 230 231 endef 232 233 # Call this function when your shared library must be placed in a non-standard 234 # library path (i.e. not under /system/lib 235 # $1: library sub-path,relative to /system/lib 236 # For example: $(call emugl-set-shared-library-subpath,egl) 237 emugl-set-shared-library-subpath = \ 238 $(eval LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/$1)\ 239 $(eval LOCAL_UNSTRIPPED_PATH := $(TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)/$1)\ 240 $(eval _emugl.$(LOCAL_MODULE).moved := true)\ 241 $(call emugl-export-outer,ADDITIONAL_DEPENDENCIES,$(LOCAL_MODULE_PATH)/$(LOCAL_MODULE)$(TARGET_SHLIB_SUFFIX)) 242 243