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