1 # Mesa 3-D graphics library
3 # Copyright (C) 2021 GlobalLogic Ukraine
4 # Copyright (C) 2021 Roman Stratiienko (r.stratiienko@gmail.com)
6 # Permission is hereby granted, free of charge, to any person obtaining a
7 # copy of this software and associated documentation files (the "Software"),
8 # to deal in the Software without restriction, including without limitation
9 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 # and/or sell copies of the Software, and to permit persons to whom the
11 # Software is furnished to do so, subject to the following conditions:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 # DEALINGS IN THE SOFTWARE.
24 MY_PATH := $(call my-dir)
26 AOSP_ABSOLUTE_PATH := $(realpath .)
27 define relative-to-absolute
28 $(if $(patsubst /%,,$1),$(AOSP_ABSOLUTE_PATH)/$1,$1)
31 LOCAL_MODULE_CLASS := SHARED_LIBRARIES
32 LOCAL_MODULE := meson.dummy.$(LOCAL_MULTILIB)
34 m_dummy := $(local-generated-sources-dir)/dummy.c
39 LOCAL_GENERATED_SOURCES := $(m_dummy)
40 LOCAL_VENDOR_MODULE := true
42 # Prepare intermediate variables by AOSP make/core internals
43 include $(BUILD_SHARED_LIBRARY)
45 LOCAL_PATH := $(MY_PATH)
48 $(built_static_libraries) \
49 $(built_shared_libraries) \
50 $(built_whole_libraries) \
51 $(strip $(all_objects)) \
52 $(my_target_libatomic) \
53 $(my_target_libcrt_builtins) \
54 $(my_target_crtbegin_so_o) \
55 $(my_target_crtend_so_o)
57 # Build mesa3d using intermediate variables provided by AOSP make/core internals
58 M_TARGET_PREFIX := $(my_2nd_arch_prefix)
60 MESA3D_LIB_DIR := lib$(subst 32,,$(LOCAL_MULTILIB))
62 MESON_OUT_DIR := $($(M_TARGET_PREFIX)TARGET_OUT_INTERMEDIATES)/MESON_MESA3D
63 MESON_GEN_DIR := $(MESON_OUT_DIR)_GEN
64 MESON_GEN_FILES_TARGET := $(MESON_GEN_DIR)/.timestamp
66 MESA3D_GALLIUM_DRI_DIR := $(MESON_OUT_DIR)/install/usr/local/lib/dri
67 $(M_TARGET_PREFIX)MESA3D_GALLIUM_DRI_BIN := $(MESON_OUT_DIR)/install/usr/local/lib/libgallium_dri.so
68 $(M_TARGET_PREFIX)MESA3D_LIBEGL_BIN := $(MESON_OUT_DIR)/install/usr/local/lib/libEGL.so.1.0.0
69 $(M_TARGET_PREFIX)MESA3D_LIBGLESV1_BIN := $(MESON_OUT_DIR)/install/usr/local/lib/libGLESv1_CM.so.1.1.0
70 $(M_TARGET_PREFIX)MESA3D_LIBGLESV2_BIN := $(MESON_OUT_DIR)/install/usr/local/lib/libGLESv2.so.2.0.0
71 $(M_TARGET_PREFIX)MESA3D_LIBGLAPI_BIN := $(MESON_OUT_DIR)/install/usr/local/lib/libglapi.so.0.0.0
72 $(M_TARGET_PREFIX)MESA3D_LIBGBM_BIN := $(MESON_OUT_DIR)/install/usr/local/lib/$(MESA_LIBGBM_NAME).so.1.0.0
76 $($(M_TARGET_PREFIX)MESA3D_LIBEGL_BIN) \
77 $($(M_TARGET_PREFIX)MESA3D_LIBGLESV1_BIN) \
78 $($(M_TARGET_PREFIX)MESA3D_LIBGLESV2_BIN) \
79 $($(M_TARGET_PREFIX)MESA3D_LIBGLAPI_BIN) \
82 cd $(MESON_OUT_DIR) && PATH=/usr/bin:/usr/local/bin:$$PATH meson ./build \
83 --cross-file $(call relative-to-absolute,$(MESON_GEN_DIR))/aosp_cross \
85 -Ddri-search-path=/vendor/$(MESA3D_LIB_DIR)/dri \
87 -Dplatform-sdk-version=$(PLATFORM_SDK_VERSION) \
89 -Dgallium-drivers=$(subst $(space),$(comma),$(BOARD_MESA3D_GALLIUM_DRIVERS)) \
90 -Dvulkan-drivers=$(subst $(space),$(comma),$(subst radeon,amd,$(BOARD_MESA3D_VULKAN_DRIVERS))) \
94 -Dlmsensors=disabled \
96 MESON_BUILD := PATH=/usr/bin:/bin:/sbin:$$PATH ninja -C $(MESON_OUT_DIR)/build
98 $(MESON_GEN_FILES_TARGET): MESON_CPU_FAMILY := $(subst arm64,aarch64,$(TARGET_$(M_TARGET_PREFIX)ARCH))
100 define create-pkgconfig
102 "\nDescription: $2" \
103 "\nVersion: $3" > $1/$2.pc
107 # Taken from build/make/core/binary.mk. We need this
108 # to use definitions from build/make/core/definitions.mk
109 $(MESON_GEN_FILES_TARGET): PRIVATE_GLOBAL_C_INCLUDES := $(my_target_global_c_includes)
110 $(MESON_GEN_FILES_TARGET): PRIVATE_GLOBAL_C_SYSTEM_INCLUDES := $(my_target_global_c_system_includes)
112 $(MESON_GEN_FILES_TARGET): PRIVATE_2ND_ARCH_VAR_PREFIX := $(M_TARGET_PREFIX)
113 $(MESON_GEN_FILES_TARGET): PRIVATE_CC := $(my_cc)
114 $(MESON_GEN_FILES_TARGET): PRIVATE_LINKER := $(my_linker)
115 $(MESON_GEN_FILES_TARGET): PRIVATE_CXX := $(my_cxx)
116 $(MESON_GEN_FILES_TARGET): PRIVATE_CXX_LINK := $(my_cxx_link)
117 $(MESON_GEN_FILES_TARGET): PRIVATE_YACCFLAGS := $(LOCAL_YACCFLAGS)
118 $(MESON_GEN_FILES_TARGET): PRIVATE_ASFLAGS := $(my_asflags)
119 $(MESON_GEN_FILES_TARGET): PRIVATE_CONLYFLAGS := $(my_conlyflags)
120 $(MESON_GEN_FILES_TARGET): PRIVATE_CFLAGS := $(my_cflags)
121 $(MESON_GEN_FILES_TARGET): PRIVATE_CPPFLAGS := $(my_cppflags)
122 $(MESON_GEN_FILES_TARGET): PRIVATE_CFLAGS_NO_OVERRIDE := $(my_cflags_no_override)
123 $(MESON_GEN_FILES_TARGET): PRIVATE_CPPFLAGS_NO_OVERRIDE := $(my_cppflags_no_override)
124 $(MESON_GEN_FILES_TARGET): PRIVATE_RTTI_FLAG := $(LOCAL_RTTI_FLAG)
125 $(MESON_GEN_FILES_TARGET): PRIVATE_DEBUG_CFLAGS := $(debug_cflags)
126 $(MESON_GEN_FILES_TARGET): PRIVATE_C_INCLUDES := $(my_c_includes)
127 $(MESON_GEN_FILES_TARGET): PRIVATE_IMPORTED_INCLUDES := $(imported_includes)
128 $(MESON_GEN_FILES_TARGET): PRIVATE_LDFLAGS := $(my_ldflags)
129 $(MESON_GEN_FILES_TARGET): PRIVATE_LDLIBS := $(my_ldlibs)
130 $(MESON_GEN_FILES_TARGET): PRIVATE_TIDY_CHECKS := $(my_tidy_checks)
131 $(MESON_GEN_FILES_TARGET): PRIVATE_TIDY_FLAGS := $(my_tidy_flags)
132 $(MESON_GEN_FILES_TARGET): PRIVATE_ARFLAGS := $(my_arflags)
133 $(MESON_GEN_FILES_TARGET): PRIVATE_ALL_SHARED_LIBRARIES := $(built_shared_libraries)
134 $(MESON_GEN_FILES_TARGET): PRIVATE_ALL_STATIC_LIBRARIES := $(built_static_libraries)
135 $(MESON_GEN_FILES_TARGET): PRIVATE_ALL_WHOLE_STATIC_LIBRARIES := $(built_whole_libraries)
136 $(MESON_GEN_FILES_TARGET): PRIVATE_ALL_OBJECTS := $(strip $(all_objects))
138 $(MESON_GEN_FILES_TARGET): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
140 $(MESON_GEN_FILES_TARGET): PRIVATE_TARGET_GLOBAL_CFLAGS := $(my_target_global_cflags)
141 $(MESON_GEN_FILES_TARGET): PRIVATE_TARGET_GLOBAL_CONLYFLAGS := $(my_target_global_conlyflags)
142 $(MESON_GEN_FILES_TARGET): PRIVATE_TARGET_GLOBAL_CPPFLAGS := $(my_target_global_cppflags)
143 $(MESON_GEN_FILES_TARGET): PRIVATE_TARGET_GLOBAL_LDFLAGS := $(my_target_global_ldflags)
145 $(MESON_GEN_FILES_TARGET): PRIVATE_TARGET_LIBCRT_BUILTINS := $(my_target_libcrt_builtins)
146 $(MESON_GEN_FILES_TARGET): PRIVATE_TARGET_LIBATOMIC := $(my_target_libatomic)
147 $(MESON_GEN_FILES_TARGET): PRIVATE_TARGET_CRTBEGIN_SO_O := $(my_target_crtbegin_so_o)
148 $(MESON_GEN_FILES_TARGET): PRIVATE_TARGET_CRTEND_SO_O := $(my_target_crtend_so_o)
153 -nostdlib -Wl,--gc-sections \
154 $(PRIVATE_TARGET_CRTBEGIN_SO_O) \
155 $(PRIVATE_ALL_OBJECTS) \
156 -Wl,--whole-archive \
157 $(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES) \
158 -Wl,--no-whole-archive \
159 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
160 $(PRIVATE_ALL_STATIC_LIBRARIES) \
161 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
162 $(if $(filter true,$(NATIVE_COVERAGE)),$(PRIVATE_TARGET_COVERAGE_LIB)) \
163 $(PRIVATE_TARGET_LIBCRT_BUILTINS) \
164 $(PRIVATE_TARGET_LIBATOMIC) \
165 $(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
167 $(PRIVATE_ALL_SHARED_LIBRARIES) \
168 $(PRIVATE_TARGET_CRTEND_SO_O) \
172 define m-lld-flags-cleaned
173 $(patsubst -Wl$(comma)--build-id=%,, \
174 $(subst prebuilts/,$(AOSP_ABSOLUTE_PATH)/prebuilts/, \
175 $(subst $(OUT_DIR)/,$(call relative-to-absolute,$(OUT_DIR))/, \
176 $(subst -Wl$(comma)--fatal-warnings,, \
177 $(subst -Wl$(comma)--no-undefined-version,, \
178 $(subst -Wl$(comma)--gc-sections,, \
179 $(patsubst %dummy.o,, \
180 $(m-lld-flags))))))))
184 $(PRIVATE_TARGET_GLOBAL_CFLAGS) \
185 $(PRIVATE_TARGET_GLOBAL_CPPFLAGS) \
186 $(PRIVATE_ARM_CFLAGS) \
187 $(PRIVATE_RTTI_FLAG) \
189 $(PRIVATE_CPPFLAGS) \
190 $(PRIVATE_DEBUG_CFLAGS) \
191 $(PRIVATE_CFLAGS_NO_OVERRIDE) \
192 $(PRIVATE_CPPFLAGS_NO_OVERRIDE)
196 $(PRIVATE_TARGET_GLOBAL_CFLAGS) \
197 $(PRIVATE_TARGET_GLOBAL_CONLYFLAGS) \
198 $(PRIVATE_ARM_CFLAGS) \
200 $(PRIVATE_CONLYFLAGS) \
201 $(PRIVATE_DEBUG_CFLAGS) \
202 $(PRIVATE_CFLAGS_NO_OVERRIDE)
205 define filter-c-flags
206 $(filter-out -std=gnu++17 -std=gnu99 -fno-rtti, \
207 $(patsubst -W%,, $1))
210 define nospace-includes
211 $(subst $(space)-isystem$(space),$(space)-isystem, \
212 $(subst $(space)-I$(space),$(space)-I, \
213 $(strip $(c-includes))))
216 # Ensure include paths are always absolute
217 # When OUT_DIR_COMMON_BASE env variable is set the AOSP/KATI will use absolute paths
218 # for headers in intermediate output directories, but relative for all others.
221 $(if $(patsubst -I%,,$1),\
222 $(if $(patsubst -isystem/%,,$1),\
223 $(subst -isystem,-isystem$(AOSP_ABSOLUTE_PATH)/,$1),\
226 $(if $(patsubst -I/%,,$1),\
227 $(subst -I,-I$(AOSP_ABSOLUTE_PATH)/,$1),\
234 $(MESON_GEN_FILES_TARGET): PREPROCESS_MESON_CONFIGS:=$(PREPROCESS_MESON_CONFIGS)
235 $(MESON_GEN_FILES_TARGET): MESON_GEN_DIR:=$(MESON_GEN_DIR)
236 $(MESON_GEN_FILES_TARGET): $(sort $(shell find -L $(MESA3D_TOP) -not -path '*/\.*'))
238 echo -e "[properties]\n" \
239 "c_args = [$(foreach flag,$(call filter-c-flags,$(m-c-flags)),'$(flag)', ) \
240 $(foreach inc,$(nospace-includes),'$(call abs-include,$(inc))', )'']\n" \
241 "cpp_args = [$(foreach flag,$(call filter-c-flags,$(m-cpp-flags)),'$(flag)', ) \
242 $(foreach inc,$(nospace-includes),'$(call abs-include,$(inc))', )'']\n" \
243 "c_link_args = [$(foreach flag, $(m-lld-flags-cleaned),'$(flag)',)'']\n" \
244 "cpp_link_args = [$(foreach flag, $(m-lld-flags-cleaned),'$(flag)',)'']\n" \
245 "needs_exe_wrapper = true\n" \
247 "ar = '$(AOSP_ABSOLUTE_PATH)/$($($(M_TARGET_PREFIX))TARGET_AR)'\n" \
248 "c = [$(foreach arg,$(PRIVATE_CC),'$(subst prebuilts/,$(AOSP_ABSOLUTE_PATH)/prebuilts/,$(arg))',)'']\n" \
249 "cpp = [$(foreach arg,$(PRIVATE_CXX),'$(subst prebuilts/,$(AOSP_ABSOLUTE_PATH)/prebuilts/,$(arg))',)'']\n" \
251 "cpp_ld = 'lld'\n\n" \
252 "pkgconfig = ['env', 'PKG_CONFIG_LIBDIR=' + '$(call relative-to-absolute,$(MESON_GEN_DIR))', '/usr/bin/pkg-config']\n\n" \
253 "llvm-config = '/dev/null'\n" \
255 "system = 'linux'\n" \
256 "cpu_family = '$(MESON_CPU_FAMILY)'\n" \
257 "cpu = '$(MESON_CPU_FAMILY)'\n" \
258 "endian = 'little'" > $(dir $@)/aosp_cross
261 $(foreach pkg, $(MESON_GEN_PKGCONFIGS), $(call create-pkgconfig,$(dir $@),$(word 1, $(subst :, ,$(pkg))),$(word 2, $(subst :, ,$(pkg)))))
264 $(MESON_OUT_DIR)/.build.timestamp: MESON_GEN_NINJA:=$(MESON_GEN_NINJA)
265 $(MESON_OUT_DIR)/.build.timestamp: MESON_BUILD:=$(MESON_BUILD)
266 $(MESON_OUT_DIR)/.build.timestamp: $(MESON_GEN_FILES_TARGET) $(link_deps)
269 mkdir -p $(dir $@)/build
270 # Meson will update timestamps in sources directory, continuously retriggering the build
271 # even if nothing changed. Copy sources into intermediate dir to avoid this effect.
272 cp -r $(MESA3D_TOP)/* $(dir $@)
273 ifneq ($(MESON_GEN_LLVM_STUB),)
274 mkdir -p $(dir $@)/subprojects/llvm/
275 echo -e "project('llvm', 'cpp', version : '$(MESON_LLVM_VERSION)')\n" \
276 "dep_llvm = declare_dependency()\n" \
277 "has_rtti = false\n" > $(dir $@)/subprojects/llvm/meson.build
283 MESON_COPY_LIBGALLIUM := \
284 cp `ls -1 $(MESA3D_GALLIUM_DRI_DIR)/* | head -1` $($(M_TARGET_PREFIX)MESA3D_GALLIUM_DRI_BIN)
286 $(MESON_OUT_DIR)/install/.install.timestamp: MESON_COPY_LIBGALLIUM:=$(MESON_COPY_LIBGALLIUM)
287 $(MESON_OUT_DIR)/install/.install.timestamp: MESON_BUILD:=$(MESON_BUILD)
288 $(MESON_OUT_DIR)/install/.install.timestamp: $(MESON_OUT_DIR)/.build.timestamp
291 DESTDIR=$(call relative-to-absolute,$(dir $@)) $(MESON_BUILD) install
292 $(MESON_COPY_LIBGALLIUM)
295 $($(M_TARGET_PREFIX)MESA3D_LIBGBM_BIN) $(MESA3D_GLES_BINS): $(MESON_OUT_DIR)/install/.install.timestamp
300 $(M_TARGET_PREFIX)MESA3D_VULKAN_$1_BIN := $(MESON_OUT_DIR)/install/usr/local/lib/libvulkan_$(MESA_VK_LIB_SUFFIX_$1).so
301 $(MESON_OUT_DIR)/install/usr/local/lib/libvulkan_$(MESA_VK_LIB_SUFFIX_$1).so: $(MESON_OUT_DIR)/install/.install.timestamp
302 touch $(MESON_OUT_DIR)/install/usr/local/lib/libvulkan_$(MESA_VK_LIB_SUFFIX_$1).so
306 $(foreach driver,$(BOARD_MESA3D_VULKAN_DRIVERS), $(eval $(call vulkan_target,$(driver))))
308 $($(M_TARGET_PREFIX)TARGET_OUT_VENDOR_SHARED_LIBRARIES)/dri/.symlinks.timestamp: MESA3D_GALLIUM_DRI_DIR:=$(MESA3D_GALLIUM_DRI_DIR)
309 $($(M_TARGET_PREFIX)TARGET_OUT_VENDOR_SHARED_LIBRARIES)/dri/.symlinks.timestamp: $(MESON_OUT_DIR)/install/.install.timestamp
312 ls -1 $(MESA3D_GALLIUM_DRI_DIR)/ | PATH=/usr/bin:$$PATH xargs -I{} ln -s -f libgallium_dri.so $(dir $@)/{}
315 $($(M_TARGET_PREFIX)MESA3D_GALLIUM_DRI_BIN): $(TARGET_OUT_VENDOR)/$(MESA3D_LIB_DIR)/dri/.symlinks.timestamp