blob: 79917126f217d8aa8354e95a40ba6b0f881875c9 [file] [log] [blame]
keunyoungb85b2752013-03-08 12:28:03 -08001# 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)) \
keunyoungb85b2752013-03-08 12:28:03 -080038 $(eval _EMUGL_INCLUDE_TYPE := $(BUILD_$2)) \
39 $(call _emugl-init-module,$1,$2,$3)
40
bohu73cb0222017-05-30 10:31:46 -070041ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 26 && echo TREBLE),TREBLE)
42 emugl-begin-module += $(eval LOCAL_VENDOR_MODULE := true)
43endif
44
Yahan Zhoud9069282016-06-17 17:40:14 -070045ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 23 && echo PreMarshmallow),PreMarshmallow)
46 emugl-begin-module += $(eval include external/stlport/libstlport.mk)
47endif
Yahan Zhouda1c76d2016-06-23 13:58:09 -070048ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 21 && echo PreLollipop),PreLollipop)
49 emugl-begin-module += $(eval LOCAL_PRELINK_MODULE := false)
50endif
Yahan Zhou10c76822016-06-20 12:28:34 -070051ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 19 && echo PreKitkat),PreKitkat)
52 emugl-begin-module += $(eval LOCAL_MODULE_TAGS := debug)
53 emugl-begin-module += $(eval LOCAL_SHARED_LIBRARIES += libstlport)
54endif
Yahan Zhoud9069282016-06-17 17:40:14 -070055
keunyoungb85b2752013-03-08 12:28:03 -080056# Used to end a module definition, see function definitions above
57emugl-end-module = \
58 $(eval include $(_EMUGL_INCLUDE_TYPE))\
59 $(eval _EMUGL_INCLUDE_TYPE :=) \
60 $(eval _emugl_$(_emugl_HOST)modules += $(_emugl_MODULE))\
Erwin Jansenf96db3c2018-10-25 23:28:54 -070061 $(if $(EMUGL_DEBUG),$(call emugl-dump-module)) \
62 $(if $(CMAKE_GENERATE), $(call dump-json-module))
keunyoungb85b2752013-03-08 12:28:03 -080063
64# Managing module exports and imports.
65#
66# A module can 'import' another module, by calling emugl-import. This will
67# make the current LOCAL_MODULE inherit various definitions exported from
68# the imported module.
69#
70# Module exports are defined by calling emugl-export. Here is an example:
71#
72# $(call emugl-begin-static-library,foo)
73# LOCAL_SRC_FILES := foo.c
74# $(call emugl-export,C_INCLUDES,$(LOCAL_PATH))
75# $(call emugl-export,SHARED_LIBRARIES,libcutils)
76# $(call emugl-end-module)
77#
78# $(call emugl-begin-shared-library,bar)
79# LOCAL_SRC_FILES := bar.cpp
80# $(call emugl-import,foo)
81# $(call emugl-end-module)
82#
83# Here, we define a static library named 'foo' which exports an include
84# path and a shared library requirement, and a shared library 'bar' which
85# imports it.
86#
87# What this means is that:
88#
89# - 'bar' will automatically inherit foo's LOCAL_PATH in its LOCAL_C_INCLUDES
90# - 'bar' will automatically inherit libcutils in its own LOCAL_SHARED_LIBRARIES
91#
92# Note that order of declaration matters. If 'foo' is defined after 'bar' in
93# the example above, nothing will work correctly because dependencies are
94# computed at import time.
95#
96#
97# IMPORTANT: Imports are transitive, i.e. when module A imports B,
98# it automatically imports anything imported by B too.
99
100# This is the list of recognized export types we support for now.
101EMUGL_EXPORT_TYPES := \
102 CFLAGS \
103 LDLIBS \
104 LDFLAGS \
105 C_INCLUDES \
106 SHARED_LIBRARIES \
107 STATIC_LIBRARIES \
108 ADDITIONAL_DEPENDENCIES
109
Yifan Hong22dd0fe2017-06-08 17:17:17 -0700110ifdef IS_AT_LEAST_OPD1
111EMUGL_EXPORT_TYPES += HEADER_LIBRARIES
bohu8b0bfc72017-05-11 02:11:51 -0700112endif
113
keunyoungb85b2752013-03-08 12:28:03 -0800114# Initialize a module in our database
115# $1: Module name
116# $2: Module type
117# $3: "HOST" for a host module, empty for a target one.
118_emugl-init-module = \
119 $(eval _emugl_HOST := $(if $3,HOST_,))\
120 $(eval _emugl_MODULE := $(_emugl_HOST)$1)\
121 $(if $(filter $(_emugl_$(_emugl_HOST)modules),$(_emugl_MODULE)),\
122 $(error There is already a $(if $3,host,) module named $1!)\
123 )\
124 $(eval _mod = $(_emugl_MODULE)) \
125 $(eval _emugl.$(_mod).type := $(patsubst HOST_%,%,$2))\
126 $(eval _emugl.$(_mod).imports :=) \
127 $(eval _emugl,$(_mod).moved :=) \
128 $(foreach _type,$(EMUGL_EXPORT_TYPES),\
129 $(eval _emugl.$(_mod).export.$(_type) :=)\
130 )
131
132# Called to indicate that a module exports a given local variable for its
133# users. This also adds this to LOCAL_$1
134# $1: Local variable type (e.g. CFLAGS, LDLIBS, etc...)
135# $2: Value(s) to append to the export
136emugl-export = \
137 $(eval _emugl.$(_emugl_MODULE).export.$1 += $2)\
138 $(eval LOCAL_$1 := $2 $(LOCAL_$1))
139
140emugl-export-outer = \
141 $(eval _emugl.$(_emugl_MODULE).export.$1 += $2)
142
143# Called to indicate that a module imports the exports of another module
144# $1: list of modules to import
145#
146emugl-import = \
147 $(foreach _imod,$1,\
148 $(call _emugl-module-import,$(_emugl_HOST)$(_imod))\
149 )
150
151_emugl-module-import = \
152 $(eval _mod := $(_emugl_MODULE))\
153 $(if $(filter-out $(_emugl_$(_emugl_HOST)modules),$1),\
154 $(info Unknown imported emugles module: $1)\
155 $(if $(_emugl_HOST),\
156 $(eval _names := $(patsubst HOST_%,%,$(_emugl_HOST_modules))),\
157 $(eval _names := $(_emugl_modules))\
158 )\
159 $(info Please one of the following names: $(_names))\
160 $(error Aborting)\
161 )\
162 $(if $(filter-out $(_emugl.$(_mod).imports),$1),\
163 $(eval _emugl.$(_mod).imports += $1)\
164 $(foreach _sub,$(_emugl.$1.imports),\
165 $(call _emugl-module-import,$(_sub))\
166 )\
167 $(foreach _type,$(EMUGL_EXPORT_TYPES),\
168 $(eval LOCAL_$(_type) := $(_emugl.$1.export.$(_type)) $(LOCAL_$(_type)))\
169 )\
170 $(if $(filter EXECUTABLE SHARED_LIBRARY,$(_emugl.$(_emugl_MODULE).type)),\
171 $(if $(filter STATIC_LIBRARY,$(_emugl.$1.type)),\
172 $(eval LOCAL_STATIC_LIBRARIES := $(1:HOST_%=%) $(LOCAL_STATIC_LIBRARIES))\
173 )\
174 $(if $(filter SHARED_LIBRARY,$(_emugl.$1.type)),\
175 $(if $(_emugl.$1.moved),,\
176 $(eval LOCAL_SHARED_LIBRARIES := $(1:HOST_%=%) $(LOCAL_SHARED_LIBRARIES))\
177 )\
178 )\
179 )\
180 )
181
182_emugl-dump-list = \
183 $(foreach _list_item,$(strip $1),$(info . $(_list_item)))
184
185emugl-dump-module = \
186 $(info MODULE=$(_emugl_MODULE))\
187 $(info . HOST=$(_emugl_HOST))\
188 $(info . TYPE=$(_emugl.$(_emugl_MODULE).type))\
189 $(info . IMPORTS=$(_emugl.$(_emugl_MODULE).imports))\
190 $(foreach _type,$(EMUGL_EXPORT_TYPES),\
191 $(if $(filter C_INCLUDES ADDITIONAL_DEPENDENCIES,$(_type)),\
192 $(info . EXPORT.$(_type) :=)\
193 $(call _emugl-dump-list,$(_emugl.$(_emugl_MODULE).export.$(_type)))\
194 $(info . LOCAL_$(_type) :=)\
195 $(call _emugl-dump-list,$(LOCAL_$(_type)))\
196 ,\
197 $(info . EXPORT.$(_type) := $(strip $(_emugl.$(_emugl_MODULE).export.$(_type))))\
198 $(info . LOCAL_$(_type) := $(strip $(LOCAL_$(_type))))\
199 )\
200 )\
201 $(info . LOCAL_SRC_FILES := $(LOCAL_SRC_FILES))\
202
203# This function can be called to generate the wrapper source files.
204# LOCAL_MODULE and LOCAL_MODULE_CLASS must be defined or the build will abort.
205# Source files will be stored in the local intermediates directory that will
206# be automatically added to your LOCAL_C_INCLUDES.
207# Usage:
208# $(call emugl-gen-wrapper,<input-dir>,<basename>)
209#
210emugl-gen-wrapper = \
211 $(eval _emugl_out := $(call local-intermediates-dir)) \
212 $(call emugl-gen-wrapper-generic,$(_emugl_out),$1,$2) \
213 $(call emugl-export,C_INCLUDES,$(_emugl_out))
214
215# DO NOT CALL DIRECTLY, USE emugl-gen-wrapper instead.
216#
217# The following function can be called to generate GL library wrapper
218# Usage is:
219#
220# $(call emugl-gen-wrapper-generic,<dst-dir>,<src-dir>,<basename>)
221#
222# <dst-dir> is the destination directory where the generated sources are stored
223# <src-dir> is the source directory where to find <basename>.attrib, etc..
224# <basename> is the emugen basename (see host/tools/emugen/README)
225#
226emugl-gen-wrapper-generic = $(eval $(emugl-gen-wrapper-generic-ev))
227
228define emugl-gen-wrapper-generic-ev
229_emugl_wrap := $$1/$$3
230_emugl_src := $$2/$$3
231GEN := $$(_emugl_wrap)_wrapper_entry.cpp \
232 $$(_emugl_wrap)_wrapper_context.cpp \
233 $$(_emugl_wrap)_wrapper_context.h \
234 $$(_emugl_wrap)_wrapper_proc.h
235
236$$(GEN): PRIVATE_PATH := $$(LOCAL_PATH)
237$$(GEN): PRIVATE_CUSTOM_TOOL := $$(EMUGL_EMUGEN) -W $$1 -i $$2 $$3
238$$(GEN): $$(EMUGL_EMUGEN) $$(_emugl_src).attrib $$(_emugl_src).in $$(_emugl_src).types
239 $$(transform-generated-source)
240
241$$(call emugl-export,ADDITIONAL_DEPENDENCIES,$$(GEN))
242LOCAL_GENERATED_SOURCES += $$(GEN)
243LOCAL_C_INCLUDES += $$1
244
245#ifneq ($$(HOST_OS),windows)
246$$(call emugl-export,LDFLAGS,-ldl)
247#endif
248
249endef
250
251# Call this function when your shared library must be placed in a non-standard
252# library path (i.e. not under /system/lib
253# $1: library sub-path,relative to /system/lib
254# For example: $(call emugl-set-shared-library-subpath,egl)
Yahan Zhoub67ae0d2016-06-22 15:26:08 -0700255
256ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 21 && echo PreLollipop),PreLollipop)
257 emugl-set-shared-library-subpath = \
258 $(eval LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/$1)\
259 $(eval LOCAL_UNSTRIPPED_PATH := $(TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)/$1)\
260 $(eval _emugl.$(LOCAL_MODULE).moved := true)\
261 $(call emugl-export-outer,ADDITIONAL_DEPENDENCIES,$(LOCAL_MODULE_PATH)/$(LOCAL_MODULE)$(TARGET_SHLIB_SUFFIX))
262else
263 emugl-set-shared-library-subpath = \
264 $(eval LOCAL_MODULE_RELATIVE_PATH := $1)\
265 $(eval _emugl.$(LOCAL_MODULE).moved := true)
266endif
267