1bf215546Sopenharmony_ci# Mesa 3-D graphics library
2bf215546Sopenharmony_ci#
3bf215546Sopenharmony_ci# Copyright (C) 2021 GlobalLogic Ukraine
4bf215546Sopenharmony_ci# Copyright (C) 2021 Roman Stratiienko (r.stratiienko@gmail.com)
5bf215546Sopenharmony_ci#
6bf215546Sopenharmony_ci# Permission is hereby granted, free of charge, to any person obtaining a
7bf215546Sopenharmony_ci# copy of this software and associated documentation files (the "Software"),
8bf215546Sopenharmony_ci# to deal in the Software without restriction, including without limitation
9bf215546Sopenharmony_ci# the rights to use, copy, modify, merge, publish, distribute, sublicense,
10bf215546Sopenharmony_ci# and/or sell copies of the Software, and to permit persons to whom the
11bf215546Sopenharmony_ci# Software is furnished to do so, subject to the following conditions:
12bf215546Sopenharmony_ci#
13bf215546Sopenharmony_ci# The above copyright notice and this permission notice shall be included
14bf215546Sopenharmony_ci# in all copies or substantial portions of the Software.
15bf215546Sopenharmony_ci#
16bf215546Sopenharmony_ci# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17bf215546Sopenharmony_ci# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18bf215546Sopenharmony_ci# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19bf215546Sopenharmony_ci# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20bf215546Sopenharmony_ci# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21bf215546Sopenharmony_ci# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22bf215546Sopenharmony_ci# DEALINGS IN THE SOFTWARE.
23bf215546Sopenharmony_ci
24bf215546Sopenharmony_ciifneq ($(filter true, $(BOARD_MESA3D_USES_MESON_BUILD)),)
25bf215546Sopenharmony_ci
26bf215546Sopenharmony_ciLOCAL_PATH := $(call my-dir)
27bf215546Sopenharmony_ciMESA3D_TOP := $(dir $(LOCAL_PATH))
28bf215546Sopenharmony_ci
29bf215546Sopenharmony_ciLIBDRM_VERSION = $(shell cat external/libdrm/meson.build | grep -o "\<version\>\s*:\s*'\w*\.\w*\.\w*'" | grep -o "\w*\.\w*\.\w*" | head -1)
30bf215546Sopenharmony_ci
31bf215546Sopenharmony_ciMESA_VK_LIB_SUFFIX_amd := radeon
32bf215546Sopenharmony_ciMESA_VK_LIB_SUFFIX_intel := intel
33bf215546Sopenharmony_ciMESA_VK_LIB_SUFFIX_freedreno := freedreno
34bf215546Sopenharmony_ciMESA_VK_LIB_SUFFIX_broadcom := broadcom
35bf215546Sopenharmony_ciMESA_VK_LIB_SUFFIX_panfrost := panfrost
36bf215546Sopenharmony_ciMESA_VK_LIB_SUFFIX_virtio-experimental := virtio
37bf215546Sopenharmony_ciMESA_VK_LIB_SUFFIX_swrast := lvp
38bf215546Sopenharmony_ci
39bf215546Sopenharmony_ciinclude $(CLEAR_VARS)
40bf215546Sopenharmony_ci
41bf215546Sopenharmony_ciLOCAL_SHARED_LIBRARIES := libc libdl libdrm libm liblog libcutils libz libc++ libnativewindow libsync libhardware
42bf215546Sopenharmony_ciLOCAL_STATIC_LIBRARIES := libexpat libarect libelf
43bf215546Sopenharmony_ciLOCAL_HEADER_LIBRARIES := libnativebase_headers hwvulkan_headers libbacktrace_headers
44bf215546Sopenharmony_ciMESON_GEN_PKGCONFIGS := backtrace cutils expat hardware libdrm:$(LIBDRM_VERSION) nativewindow sync zlib:1.2.11 libelf
45bf215546Sopenharmony_ciLOCAL_CFLAGS += $(BOARD_MESA3D_CFLAGS)
46bf215546Sopenharmony_ci
47bf215546Sopenharmony_ciifneq ($(filter swrast,$(BOARD_MESA3D_GALLIUM_DRIVERS) $(BOARD_MESA3D_VULKAN_DRIVERS)),)
48bf215546Sopenharmony_ciifeq ($(BOARD_MESA3D_FORCE_SOFTPIPE),)
49bf215546Sopenharmony_ciMESON_GEN_LLVM_STUB := true
50bf215546Sopenharmony_ciendif
51bf215546Sopenharmony_ciendif
52bf215546Sopenharmony_ci
53bf215546Sopenharmony_ciifneq ($(filter zink,$(BOARD_MESA3D_GALLIUM_DRIVERS)),)
54bf215546Sopenharmony_ciLOCAL_SHARED_LIBRARIES += libvulkan
55bf215546Sopenharmony_ciMESON_GEN_PKGCONFIGS += vulkan
56bf215546Sopenharmony_ciendif
57bf215546Sopenharmony_ci
58bf215546Sopenharmony_ciifneq ($(filter iris,$(BOARD_MESA3D_GALLIUM_DRIVERS)),)
59bf215546Sopenharmony_ciLOCAL_SHARED_LIBRARIES += libdrm_intel
60bf215546Sopenharmony_ciMESON_GEN_PKGCONFIGS += libdrm_intel:$(LIBDRM_VERSION)
61bf215546Sopenharmony_ciendif
62bf215546Sopenharmony_ci
63bf215546Sopenharmony_ciifneq ($(filter radeonsi amd,$(BOARD_MESA3D_GALLIUM_DRIVERS) $(BOARD_MESA3D_VULKAN_DRIVERS)),)
64bf215546Sopenharmony_ciMESON_GEN_LLVM_STUB := true
65bf215546Sopenharmony_ciLOCAL_CFLAGS += -DFORCE_BUILD_AMDGPU   # instructs LLVM to declare LLVMInitializeAMDGPU* functions
66bf215546Sopenharmony_ciLOCAL_SHARED_LIBRARIES += libdrm_amdgpu
67bf215546Sopenharmony_ciMESON_GEN_PKGCONFIGS += libdrm_amdgpu:$(LIBDRM_VERSION)
68bf215546Sopenharmony_ciendif
69bf215546Sopenharmony_ci
70bf215546Sopenharmony_ciifneq ($(filter radeonsi r300 r600,$(BOARD_MESA3D_GALLIUM_DRIVERS)),)
71bf215546Sopenharmony_ciLOCAL_SHARED_LIBRARIES += libdrm_radeon
72bf215546Sopenharmony_ciMESON_GEN_PKGCONFIGS += libdrm_radeon:$(LIBDRM_VERSION)
73bf215546Sopenharmony_ciendif
74bf215546Sopenharmony_ci
75bf215546Sopenharmony_ciifneq ($(filter nouveau,$(BOARD_MESA3D_GALLIUM_DRIVERS)),)
76bf215546Sopenharmony_ciLOCAL_SHARED_LIBRARIES += libdrm_nouveau
77bf215546Sopenharmony_ciMESON_GEN_PKGCONFIGS += libdrm_nouveau:$(LIBDRM_VERSION)
78bf215546Sopenharmony_ciendif
79bf215546Sopenharmony_ci
80bf215546Sopenharmony_ciifneq ($(filter d3d12,$(BOARD_MESA3D_GALLIUM_DRIVERS)),)
81bf215546Sopenharmony_ciLOCAL_HEADER_LIBRARIES += DirectX-Headers
82bf215546Sopenharmony_ciLOCAL_STATIC_LIBRARIES += DirectX-Guids
83bf215546Sopenharmony_ciMESON_GEN_PKGCONFIGS += DirectX-Headers
84bf215546Sopenharmony_ciendif
85bf215546Sopenharmony_ci
86bf215546Sopenharmony_ciifneq ($(MESON_GEN_LLVM_STUB),)
87bf215546Sopenharmony_ciMESON_LLVM_VERSION := 12.0.0
88bf215546Sopenharmony_ciLOCAL_SHARED_LIBRARIES += libLLVM12
89bf215546Sopenharmony_ciendif
90bf215546Sopenharmony_ci
91bf215546Sopenharmony_ciifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 30; echo $$?), 0)
92bf215546Sopenharmony_ciLOCAL_SHARED_LIBRARIES += \
93bf215546Sopenharmony_ci    android.hardware.graphics.mapper@4.0 \
94bf215546Sopenharmony_ci    libgralloctypes \
95bf215546Sopenharmony_ci    libhidlbase \
96bf215546Sopenharmony_ci    libutils
97bf215546Sopenharmony_ci
98bf215546Sopenharmony_ciMESON_GEN_PKGCONFIGS += android.hardware.graphics.mapper:4.0
99bf215546Sopenharmony_ciendif
100bf215546Sopenharmony_ci
101bf215546Sopenharmony_ci__MY_SHARED_LIBRARIES := $(LOCAL_SHARED_LIBRARIES)
102bf215546Sopenharmony_ci
103bf215546Sopenharmony_ciifeq ($(TARGET_IS_64_BIT),true)
104bf215546Sopenharmony_ciLOCAL_MULTILIB := 64
105bf215546Sopenharmony_cielse
106bf215546Sopenharmony_ciLOCAL_MULTILIB := 32
107bf215546Sopenharmony_ciendif
108bf215546Sopenharmony_ciinclude $(LOCAL_PATH)/mesa3d_cross.mk
109bf215546Sopenharmony_ci
110bf215546Sopenharmony_ciifdef TARGET_2ND_ARCH
111bf215546Sopenharmony_ciLOCAL_MULTILIB := 32
112bf215546Sopenharmony_ciinclude $(LOCAL_PATH)/mesa3d_cross.mk
113bf215546Sopenharmony_ciendif
114bf215546Sopenharmony_ci
115bf215546Sopenharmony_ci#-------------------------------------------------------------------------------
116bf215546Sopenharmony_ci
117bf215546Sopenharmony_ci# $1: name
118bf215546Sopenharmony_ci# $2: symlink suffix
119bf215546Sopenharmony_ci# $3: subdir
120bf215546Sopenharmony_ci# $4: source prebuilt
121bf215546Sopenharmony_ci# $5: export headers
122bf215546Sopenharmony_cidefine mesa3d-lib
123bf215546Sopenharmony_ciinclude $(CLEAR_VARS)
124bf215546Sopenharmony_ciLOCAL_MODULE_CLASS := SHARED_LIBRARIES
125bf215546Sopenharmony_ciLOCAL_MODULE := $1
126bf215546Sopenharmony_ciLOCAL_VENDOR_MODULE := true
127bf215546Sopenharmony_ciLOCAL_MODULE_RELATIVE_PATH := $3
128bf215546Sopenharmony_ciLOCAL_PREBUILT_MODULE_FILE := $($4)
129bf215546Sopenharmony_ciLOCAL_MULTILIB := first
130bf215546Sopenharmony_ciLOCAL_CHECK_ELF_FILES := false
131bf215546Sopenharmony_ciLOCAL_MODULE_SUFFIX := .so
132bf215546Sopenharmony_ciLOCAL_MODULE_SYMLINKS := $1$2
133bf215546Sopenharmony_ciLOCAL_SHARED_LIBRARIES := $(__MY_SHARED_LIBRARIES)
134bf215546Sopenharmony_ciLOCAL_EXPORT_C_INCLUDE_DIRS := $5
135bf215546Sopenharmony_ciinclude $(BUILD_PREBUILT)
136bf215546Sopenharmony_ci
137bf215546Sopenharmony_ciifdef TARGET_2ND_ARCH
138bf215546Sopenharmony_ciinclude $(CLEAR_VARS)
139bf215546Sopenharmony_ciLOCAL_MODULE_CLASS := SHARED_LIBRARIES
140bf215546Sopenharmony_ciLOCAL_MODULE := $1
141bf215546Sopenharmony_ciLOCAL_VENDOR_MODULE := true
142bf215546Sopenharmony_ciLOCAL_MODULE_RELATIVE_PATH := $3
143bf215546Sopenharmony_ciLOCAL_PREBUILT_MODULE_FILE := $(2ND_$4)
144bf215546Sopenharmony_ciLOCAL_MULTILIB := 32
145bf215546Sopenharmony_ciLOCAL_CHECK_ELF_FILES := false
146bf215546Sopenharmony_ciLOCAL_MODULE_SUFFIX := .so
147bf215546Sopenharmony_ciLOCAL_MODULE_SYMLINKS := $1$2
148bf215546Sopenharmony_ciLOCAL_SHARED_LIBRARIES := $(__MY_SHARED_LIBRARIES)
149bf215546Sopenharmony_ciLOCAL_EXPORT_C_INCLUDE_DIRS := $5
150bf215546Sopenharmony_ciinclude $(BUILD_PREBUILT)
151bf215546Sopenharmony_ciendif
152bf215546Sopenharmony_ciendef
153bf215546Sopenharmony_ci
154bf215546Sopenharmony_ci# Module 'libgallium_dri', produces '/vendor/lib{64}/dri/libgallium_dri.so'
155bf215546Sopenharmony_ci# This module also trigger DRI symlinks creation process
156bf215546Sopenharmony_ci$(eval $(call mesa3d-lib,libgallium_dri,.so.0,dri,MESA3D_GALLIUM_DRI_BIN))
157bf215546Sopenharmony_ci# Module 'libglapi', produces '/vendor/lib{64}/libglapi.so'
158bf215546Sopenharmony_ci$(eval $(call mesa3d-lib,libglapi,.so.0,,MESA3D_LIBGLAPI_BIN))
159bf215546Sopenharmony_ci
160bf215546Sopenharmony_ci# Module 'libEGL_mesa', produces '/vendor/lib{64}/egl/libEGL_mesa.so'
161bf215546Sopenharmony_ci$(eval $(call mesa3d-lib,libEGL_mesa,.so.1,egl,MESA3D_LIBEGL_BIN))
162bf215546Sopenharmony_ci# Module 'libGLESv1_CM_mesa', produces '/vendor/lib{64}/egl/libGLESv1_CM_mesa.so'
163bf215546Sopenharmony_ci$(eval $(call mesa3d-lib,libGLESv1_CM_mesa,.so.1,egl,MESA3D_LIBGLESV1_BIN))
164bf215546Sopenharmony_ci# Module 'libGLESv2_mesa', produces '/vendor/lib{64}/egl/libGLESv2_mesa.so'
165bf215546Sopenharmony_ci$(eval $(call mesa3d-lib,libGLESv2_mesa,.so.2,egl,MESA3D_LIBGLESV2_BIN))
166bf215546Sopenharmony_ci
167bf215546Sopenharmony_ci# Modules 'vulkan.{driver_name}', produces '/vendor/lib{64}/hw/vulkan.{driver_name}.so' HAL
168bf215546Sopenharmony_ci$(foreach driver,$(BOARD_MESA3D_VULKAN_DRIVERS), \
169bf215546Sopenharmony_ci    $(eval $(call mesa3d-lib,vulkan.$(MESA_VK_LIB_SUFFIX_$(driver)),.so.0,hw,MESA3D_VULKAN_$(driver)_BIN)))
170bf215546Sopenharmony_ci
171bf215546Sopenharmony_ciifneq ($(filter true, $(BOARD_MESA3D_BUILD_LIBGBM)),)
172bf215546Sopenharmony_ci# Modules 'libgbm', produces '/vendor/lib{64}/libgbm.so'
173bf215546Sopenharmony_ci$(eval $(call mesa3d-lib,libgbm,.so.1,,MESA3D_LIBGBM_BIN,$(MESA3D_TOP)/src/gbm/main))
174bf215546Sopenharmony_ciendif
175bf215546Sopenharmony_ci
176bf215546Sopenharmony_ci#-------------------------------------------------------------------------------
177bf215546Sopenharmony_ci
178bf215546Sopenharmony_ciendif
179