OSDN Git Service

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