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