1*49cdfc7eSAndroid Build Coastguard Worker# Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved. 2*49cdfc7eSAndroid Build Coastguard Worker# 3*49cdfc7eSAndroid Build Coastguard Worker# This program is free software; you can redistribute it and/or 4*49cdfc7eSAndroid Build Coastguard Worker# modify it under the terms of the GNU General Public License as 5*49cdfc7eSAndroid Build Coastguard Worker# published by the Free Software Foundation; either version 2 of 6*49cdfc7eSAndroid Build Coastguard Worker# the License, or (at your option) any later version. 7*49cdfc7eSAndroid Build Coastguard Worker# 8*49cdfc7eSAndroid Build Coastguard Worker# This program is distributed in the hope that it would be useful, 9*49cdfc7eSAndroid Build Coastguard Worker# but WITHOUT ANY WARRANTY; without even the implied warranty of 10*49cdfc7eSAndroid Build Coastguard Worker# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11*49cdfc7eSAndroid Build Coastguard Worker# GNU General Public License for more details. 12*49cdfc7eSAndroid Build Coastguard Worker# 13*49cdfc7eSAndroid Build Coastguard Worker# You should have received a copy of the GNU General Public License 14*49cdfc7eSAndroid Build Coastguard Worker# along with this program; if not, write the Free Software Foundation, 15*49cdfc7eSAndroid Build Coastguard Worker# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16*49cdfc7eSAndroid Build Coastguard Worker# 17*49cdfc7eSAndroid Build Coastguard Worker# Author: Alexey Kodanev <[email protected]> 18*49cdfc7eSAndroid Build Coastguard Worker# 19*49cdfc7eSAndroid Build Coastguard Worker# Include it to build kernel modules. 20*49cdfc7eSAndroid Build Coastguard Worker# REQ_VERSION_MAJOR and REQ_VERSION_PATCH must be defined beforehand. 21*49cdfc7eSAndroid Build Coastguard Worker# 22*49cdfc7eSAndroid Build Coastguard Worker 23*49cdfc7eSAndroid Build Coastguard Worker$(if $(REQ_VERSION_MAJOR),,$(error You must define REQ_VERSION_MAJOR)) 24*49cdfc7eSAndroid Build Coastguard Worker$(if $(REQ_VERSION_PATCH),,$(error You must define REQ_VERSION_MINOR)) 25*49cdfc7eSAndroid Build Coastguard Worker 26*49cdfc7eSAndroid Build Coastguard Workerifeq ($(WITH_MODULES),no) 27*49cdfc7eSAndroid Build Coastguard WorkerSKIP := 1 28*49cdfc7eSAndroid Build Coastguard Workerelse 29*49cdfc7eSAndroid Build Coastguard Workerifeq ($(LINUX_VERSION_MAJOR)$(LINUX_VERSION_PATCH),) 30*49cdfc7eSAndroid Build Coastguard WorkerSKIP := 1 31*49cdfc7eSAndroid Build Coastguard Workerelse 32*49cdfc7eSAndroid Build Coastguard WorkerSKIP ?= $(shell \ 33*49cdfc7eSAndroid Build Coastguard Worker [ "$(LINUX_VERSION_MAJOR)" -gt "$(REQ_VERSION_MAJOR)" ] || \ 34*49cdfc7eSAndroid Build Coastguard Worker [ "$(LINUX_VERSION_MAJOR)" -eq "$(REQ_VERSION_MAJOR)" -a \ 35*49cdfc7eSAndroid Build Coastguard Worker "$(LINUX_VERSION_PATCH)" -ge "$(REQ_VERSION_PATCH)" ]; echo $$?) 36*49cdfc7eSAndroid Build Coastguard Workerendif 37*49cdfc7eSAndroid Build Coastguard Workerendif 38*49cdfc7eSAndroid Build Coastguard Worker 39*49cdfc7eSAndroid Build Coastguard Workerifneq ($(SKIP),0) 40*49cdfc7eSAndroid Build Coastguard WorkerMAKE_TARGETS := $(filter-out %.ko, $(MAKE_TARGETS)) 41*49cdfc7eSAndroid Build Coastguard Workerendif 42*49cdfc7eSAndroid Build Coastguard Worker 43*49cdfc7eSAndroid Build Coastguard Workerifneq ($(filter install clean,$(MAKECMDGOALS)),) 44*49cdfc7eSAndroid Build Coastguard WorkerMAKE_TARGETS := $(filter-out %.ko, $(MAKE_TARGETS)) 45*49cdfc7eSAndroid Build Coastguard WorkerMAKE_TARGETS += $(sort $(wildcard *.ko)) 46*49cdfc7eSAndroid Build Coastguard Workerendif 47*49cdfc7eSAndroid Build Coastguard Worker 48*49cdfc7eSAndroid Build Coastguard WorkerCLEAN_TARGETS += .dep_modules *.mod built-in.a 49*49cdfc7eSAndroid Build Coastguard Worker 50*49cdfc7eSAndroid Build Coastguard WorkerCHECK_TARGETS := $(filter-out %.ko, $(CHECK_TARGETS)) 51*49cdfc7eSAndroid Build Coastguard Worker 52*49cdfc7eSAndroid Build Coastguard WorkerMODULE_SOURCES := $(patsubst %.ko,%.c,$(filter %.ko, $(MAKE_TARGETS))) 53*49cdfc7eSAndroid Build Coastguard Worker 54*49cdfc7eSAndroid Build Coastguard Worker# Ignoring the exit status of commands is done to be forward compatible with 55*49cdfc7eSAndroid Build Coastguard Worker# kernel internal API changes. The user-space test will return TCONF, if it 56*49cdfc7eSAndroid Build Coastguard Worker# doesn't find the module (i.e. it wasn't built either due to kernel-devel 57*49cdfc7eSAndroid Build Coastguard Worker# missing or module build failure). 58*49cdfc7eSAndroid Build Coastguard Worker%.ko: %.c .dep_modules ; 59*49cdfc7eSAndroid Build Coastguard Worker 60*49cdfc7eSAndroid Build Coastguard Worker.dep_modules: $(MODULE_SOURCES) 61*49cdfc7eSAndroid Build Coastguard Worker @echo "Building modules: $(MODULE_SOURCES)" 62*49cdfc7eSAndroid Build Coastguard Worker -$(MAKE) -C $(LINUX_DIR) M=$(abs_srcdir) 63*49cdfc7eSAndroid Build Coastguard Worker rm -rf *.mod.c *.o *.ko.unsigned modules.order .tmp* .*.ko .*.cmd Module.symvers 64*49cdfc7eSAndroid Build Coastguard Worker @touch .dep_modules 65