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