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