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