1# SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note 2# 3# (C) COPYRIGHT 2021-2022 ARM Limited. All rights reserved. 4# 5# This program is free software and is provided to you under the terms of the 6# GNU General Public License version 2 as published by the Free Software 7# Foundation, and any use by you of this program is subject to the terms 8# of such GNU license. 9# 10# This program is distributed in the hope that it will be useful, 11# but WITHOUT ANY WARRANTY; without even the implied warranty of 12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13# GNU General Public License for more details. 14# 15# You should have received a copy of the GNU General Public License 16# along with this program; if not, you can access it online at 17# http://www.gnu.org/licenses/gpl-2.0.html. 18# 19# 20 21# 22# Paths 23# 24KERNEL_SRC ?= /lib/modules/$(shell uname -r)/build 25KDIR ?= $(KERNEL_SRC) 26 27ifeq ($(KDIR),) 28 $(error Must specify KDIR to point to the kernel to target)) 29endif 30 31vars := 32# 33# Default configuration values 34# 35CONFIG_MALI_BASE_MODULES ?= n 36 37ifeq ($(CONFIG_MALI_BASE_MODULES),y) 38 CONFIG_MALI_CSF_SUPPORT ?= n 39 40 ifneq ($(CONFIG_DMA_SHARED_BUFFER),n) 41 CONFIG_DMA_SHARED_BUFFER_TEST_EXPORTER ?= y 42 else 43 # Prevent misuse when CONFIG_DMA_SHARED_BUFFER=n 44 CONFIG_DMA_SHARED_BUFFER_TEST_EXPORTER = n 45 endif 46 47 CONFIG_MALI_MEMORY_GROUP_MANAGER ?= y 48 49 ifneq ($(CONFIG_MALI_CSF_SUPPORT), n) 50 CONFIG_MALI_PROTECTED_MEMORY_ALLOCATOR ?= y 51 endif 52 53else 54 # Prevent misuse when CONFIG_MALI_BASE_MODULES=n 55 CONFIG_DMA_SHARED_BUFFER_TEST_EXPORTER = n 56 CONFIG_MALI_MEMORY_GROUP_MANAGER = n 57 CONFIG_MALI_PROTECTED_MEMORY_ALLOCATOR = n 58 59endif 60 61CONFIGS := \ 62 CONFIG_MALI_BASE_MODULES \ 63 CONFIG_MALI_CSF_SUPPORT \ 64 CONFIG_DMA_SHARED_BUFFER_TEST_EXPORTER \ 65 CONFIG_MALI_MEMORY_GROUP_MANAGER \ 66 CONFIG_MALI_PROTECTED_MEMORY_ALLOCATOR \ 67 68 69# 70# MAKE_ARGS to pass the custom CONFIGs on out-of-tree build 71# 72# Generate the list of CONFIGs and values. 73# $(value config) is the name of the CONFIG option. 74# $(value $(value config)) is its value (y, m). 75# When the CONFIG is not set to y or m, it defaults to n. 76MAKE_ARGS := $(foreach config,$(CONFIGS), \ 77 $(if $(filter y m,$(value $(value config))), \ 78 $(value config)=$(value $(value config)), \ 79 $(value config)=n)) 80 81# 82# EXTRA_CFLAGS to define the custom CONFIGs on out-of-tree build 83# 84# Generate the list of CONFIGs defines with values from CONFIGS. 85# $(value config) is the name of the CONFIG option. 86# When set to y or m, the CONFIG gets defined to 1. 87EXTRA_CFLAGS := $(foreach config,$(CONFIGS), \ 88 $(if $(filter y m,$(value $(value config))), \ 89 -D$(value config)=1)) 90 91KBUILD_CFLAGS += -Wall -Werror 92 93ifeq ($(CONFIG_GCOV_KERNEL), y) 94 KBUILD_CFLAGS += $(call cc-option, -ftest-coverage) 95 KBUILD_CFLAGS += $(call cc-option, -fprofile-arcs) 96 EXTRA_CFLAGS += -DGCOV_PROFILE=1 97endif 98 99ifeq ($(CONFIG_MALI_KCOV),y) 100 KBUILD_CFLAGS += $(call cc-option, -fsanitize-coverage=trace-cmp) 101 EXTRA_CFLAGS += -DKCOV=1 102 EXTRA_CFLAGS += -DKCOV_ENABLE_COMPARISONS=1 103endif 104 105# The following were added to align with W=1 in scripts/Makefile.extrawarn 106# from the Linux source tree (v5.18.14) 107KBUILD_CFLAGS += -Wextra -Wunused -Wno-unused-parameter 108KBUILD_CFLAGS += -Wmissing-declarations 109KBUILD_CFLAGS += -Wmissing-format-attribute 110KBUILD_CFLAGS += -Wmissing-prototypes 111KBUILD_CFLAGS += -Wold-style-definition 112# The -Wmissing-include-dirs cannot be enabled as the path to some of the 113# included directories change depending on whether it is an in-tree or 114# out-of-tree build. 115KBUILD_CFLAGS += $(call cc-option, -Wunused-but-set-variable) 116KBUILD_CFLAGS += $(call cc-option, -Wunused-const-variable) 117KBUILD_CFLAGS += $(call cc-option, -Wpacked-not-aligned) 118KBUILD_CFLAGS += $(call cc-option, -Wstringop-truncation) 119# The following turn off the warnings enabled by -Wextra 120KBUILD_CFLAGS += -Wno-sign-compare 121KBUILD_CFLAGS += -Wno-shift-negative-value 122# This flag is needed to avoid build errors on older kernels 123KBUILD_CFLAGS += $(call cc-option, -Wno-cast-function-type) 124 125KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN1 126 127# The following were added to align with W=2 in scripts/Makefile.extrawarn 128# from the Linux source tree (v5.18.14) 129KBUILD_CFLAGS += -Wdisabled-optimization 130# The -Wshadow flag cannot be enabled unless upstream kernels are 131# patched to fix redefinitions of certain built-in functions and 132# global variables. 133KBUILD_CFLAGS += $(call cc-option, -Wlogical-op) 134KBUILD_CFLAGS += -Wmissing-field-initializers 135# -Wtype-limits must be disabled due to build failures on kernel 5.x 136KBUILD_CFLAGS += -Wno-type-limit 137KBUILD_CFLAGS += $(call cc-option, -Wmaybe-uninitialized) 138KBUILD_CFLAGS += $(call cc-option, -Wunused-macros) 139 140KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN2 141 142# This warning is disabled to avoid build failures in some kernel versions 143KBUILD_CFLAGS += -Wno-ignored-qualifiers 144 145all: 146 $(MAKE) -C $(KDIR) M=$(CURDIR) $(MAKE_ARGS) EXTRA_CFLAGS="$(EXTRA_CFLAGS)" KBUILD_EXTRA_SYMBOLS="$(EXTRA_SYMBOLS)" modules 147 148modules_install: 149 $(MAKE) -C $(KDIR) M=$(CURDIR) $(MAKE_ARGS) modules_install 150 151clean: 152 $(MAKE) -C $(KDIR) M=$(CURDIR) $(MAKE_ARGS) clean 153