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