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