From 79b8ce942edc20cd253f47124bd58e63e20086fa Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Fri, 14 Feb 2014 15:52:10 +0000 Subject: [PATCH] Makefiles: calculate KVER properly When deriving the kernel version (KVER) from KDIR, the file $(KDIR)/include/config/kernel.release should be preferred over 'make kernelversion'. For example, the Ubuntu 3.2.0-23-generic kernel has a kernel.release file containing '3.2.0-23-generic', but 'make kernelversion' returns 3.2.14. Since the modules are stored under /lib/modules/3.2.0-23-generic, the value in kernel.release is the correct one to use. Also: - Evaluate KVER only once - All depmod commands must include KVER Signed-off-by: Steven J. Magnani [bvanassche: Split long lines / removed trailing whitespace] git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@5286 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- Makefile | 14 +++++++----- fcst/Makefile | 38 +++++++++++++++++++------------- ibmvstgt/Makefile | 14 ++++++++---- iscsi-scst/Makefile | 14 ++++++++---- mpt/Makefile | 16 ++++++++++++-- mvsas_tgt/Makefile | 20 +++++++++++++++-- qla2x00t/Makefile | 10 ++++++++- qla2x00t/qla2x00-target/Makefile | 24 ++++++++++++++------ scst/src/Makefile | 14 +++++++----- scst/src/dev_handlers/Makefile | 22 ++++++++++++------ scst_local/Makefile | 25 ++++++++++++++------- srpt/Makefile | 14 ++++++++---- 12 files changed, 160 insertions(+), 65 deletions(-) diff --git a/Makefile b/Makefile index 01742ad63..05511f086 100644 --- a/Makefile +++ b/Makefile @@ -20,18 +20,20 @@ SHELL = /bin/bash # Define the location to the kernel src. Can be defined here or on # the command line during the build process. If KDIR is defined, -# we will set an appropriate value for KVER by running "make -# kernelversion" in the kernel source tree. KVER can still be -# overrode by the user via the command line or by defining it in -# this Makefile. If KDIR and KVER are not defined by the user, -# the current running kernel version is used to define KVER. +# we will determine an appropriate value for KVER from the kernel +# source tree. KVER can still be overridden by the user via the +# command line or by defining it in this Makefile. If KDIR and KVER +# are not defined by the user, the current running kernel version is +# used to define KVER. #export KDIR=/usr/src/linux-2.6 #export KVER=2.6.x ifdef KDIR ifndef KVER - export KVER = $(strip $(shell make -s -C $(KDIR) kernelversion)) + export KVER = $(strip $(shell \ + cat $(KDIR)/include/config/kernel.release 2>/dev/null || \ + make -s -C $(KDIR) kernelversion)) endif endif diff --git a/fcst/Makefile b/fcst/Makefile index b5bdab718..db2a888ff 100644 --- a/fcst/Makefile +++ b/fcst/Makefile @@ -26,19 +26,6 @@ # - install and uninstall must be made as root # -ifndef PREFIX - PREFIX=/usr/local -endif - -ifeq ($(KVER),) - ifeq ($(KDIR),) - KVER = $(shell uname -r) - KDIR := /lib/modules/$(KVER)/build - endif -else - KDIR := /lib/modules/$(KVER)/build -endif - export PWD := $(shell pwd) export CONFIG_FCST := m @@ -55,11 +42,30 @@ EXTRA_CFLAGS += -I$(SCST_INC_DIR) $(FCSTFLAGS$(BUILDMODE)) MODULE_NAME = fcst -INSTALL_DIR := /lib/modules/$(KVER)/extra - ifneq ($(KERNELRELEASE),) include $(SUBDIRS)/Makefile_in-tree else +######### BEGIN OUT-OF-TREE RULES ######### + +ifndef PREFIX + PREFIX=/usr/local +endif + +ifeq ($(KVER),) + ifeq ($(KDIR),) + KVER := $(shell uname -r) + KDIR := /lib/modules/$(KVER)/build + else + KVER := $(strip $(shell \ + cat $(KDIR)/include/config/kernel.release 2>/dev/null || \ + make -s -C $(KDIR) kernelversion)) + endif +else + KDIR := /lib/modules/$(KVER)/build +endif + +INSTALL_DIR := /lib/modules/$(KVER)/extra + SCST_INC_DIR := $(shell if [ -e "$$PWD/../scst" ]; \ then echo "$$PWD/../scst/include"; \ else echo "$(PREFIX)/include/scst"; fi) @@ -102,6 +108,8 @@ endif uninstall: rm -f $(INSTALL_DIR)/$(MODULE_NAME).ko -/sbin/depmod -a $(KVER) + +########## END OUT-OF-TREE RULES ########## endif clean: diff --git a/ibmvstgt/Makefile b/ibmvstgt/Makefile index cfa1f6015..6eaf7933e 100644 --- a/ibmvstgt/Makefile +++ b/ibmvstgt/Makefile @@ -7,13 +7,19 @@ SUBDIRS := $(shell pwd) ifeq ($(KVER),) ifeq ($(KDIR),) - KVER = $(shell uname -r) - KDIR ?= /lib/modules/$(KVER)/build + KVER := $(shell uname -r) + KDIR := /lib/modules/$(KVER)/build else - KVER = $$KERNELRELEASE + ifeq ($(KERNELRELEASE),) + KVER := $(strip $(shell \ + cat $(KDIR)/include/config/kernel.release 2>/dev/null || \ + make -s -C $(KDIR) kernelversion)) + else + KVER := $(KERNELRELEASE) + endif endif else - KDIR ?= /lib/modules/$(KVER)/build + KDIR := /lib/modules/$(KVER)/build endif # The file Modules.symvers has been renamed in the 2.6.18 kernel to diff --git a/iscsi-scst/Makefile b/iscsi-scst/Makefile index 2bd21646c..e14e46402 100644 --- a/iscsi-scst/Makefile +++ b/iscsi-scst/Makefile @@ -27,13 +27,19 @@ INCDIR := $(shell pwd)/include ifeq ($(KVER),) ifeq ($(KDIR),) - KVER = $(shell uname -r) - KDIR ?= /lib/modules/$(KVER)/build + KVER := $(shell uname -r) + KDIR := /lib/modules/$(KVER)/build else - KVER = $$KERNELRELEASE + ifeq ($(KERNELRELEASE),) + KVER := $(strip $(shell \ + cat $(KDIR)/include/config/kernel.release 2>/dev/null || \ + make -s -C $(KDIR) kernelversion)) + else + KVER := $(KERNELRELEASE) + endif endif else - KDIR ?= /lib/modules/$(KVER)/build + KDIR := /lib/modules/$(KVER)/build endif all: include/iscsi_scst_itf_ver.h progs mods diff --git a/mpt/Makefile b/mpt/Makefile index 2c19fa9b8..0e32736e5 100644 --- a/mpt/Makefile +++ b/mpt/Makefile @@ -38,7 +38,16 @@ EXTRA_CFLAGS += -DCONFIG_SCST_DEBUG ifeq ($(KVER),) ifeq ($(KDIR),) - KDIR := /lib/modules/$(shell uname -r)/build + KVER := $(shell uname -r) + KDIR := /lib/modules/$(KVER)/build + else + ifeq ($(KERNELRELEASE),) + KVER := $(strip $(shell \ + cat $(KDIR)/include/config/kernel.release 2>/dev/null || \ + make -s -C $(KDIR) kernelversion)) + else + KVER := $(KERNELRELEASE) + endif endif else KDIR := /lib/modules/$(KVER)/build @@ -50,6 +59,7 @@ EXTRA_CFLAGS += -I$(LSI_INC_DIR) ifneq ($(PATCHLEVEL),) obj-m += mpt_scst.o else +######### BEGIN OUT-OF-TREE RULES ######### all: Modules.symvers Module.symvers $(MAKE) -C $(KDIR) SUBDIRS=$(shell pwd) BUILD_INI=m @@ -80,7 +90,9 @@ endif uninstall: rm -f $(INSTALL_DIR)/mpt_scst.ko - -/sbin/depmod -a + -/sbin/depmod -a $(KVER) + +########## END OUT-OF-TREE RULES ########## endif clean: diff --git a/mvsas_tgt/Makefile b/mvsas_tgt/Makefile index c0a4d8732..4149e899c 100644 --- a/mvsas_tgt/Makefile +++ b/mvsas_tgt/Makefile @@ -31,13 +31,25 @@ endif ifeq ($(KVER),) ifeq ($(KDIR),) - KVER = $(shell uname -r) + KVER := $(shell uname -r) KDIR := /lib/modules/$(KVER)/build + else + ifeq ($(KERNELRELEASE),) + KVER := $(strip $(shell \ + cat $(KDIR)/include/config/kernel.release 2>/dev/null || \ + make -s -C $(KDIR) kernelversion)) + else + KVER := $(KERNELRELEASE) + endif endif else KDIR := /lib/modules/$(KVER)/build endif +ifeq ($(INSTALL_MOD_PATH),) + export INSTALL_MOD_PATH := $(DESTDIR) +endif + export PWD := $(shell pwd) export LIBSAS := m @@ -53,7 +65,7 @@ MODULE_NAME = mvsas_tgt EXTRA_CFLAGS += -DMV_DEBUG -INSTALL_DIR := /lib/modules/$(shell uname -r)/extra +INSTALL_DIR := $(INSTALL_MOD_PATH)/lib/modules/$(KVER)/extra #EXTRA_CFLAGS += -DCONFIG_SCST_TRACING #EXTRA_CFLAGS += -DDEBUG_WORK_IN_THREAD @@ -68,6 +80,8 @@ mvsas-y := mv_init.o \ mv_94xx.o \ mv_spi.o else +######### BEGIN OUT-OF-TREE RULES ######### + all: Modules.symvers Module.symvers $(MAKE) -C $(KDIR) SUBDIRS=$(shell pwd) BUILD_INI=m @@ -102,6 +116,8 @@ endif uninstall: rm -f $(INSTALL_DIR)/$(MODULE_NAME).ko -/sbin/depmod -a $(KVER) + +########## END OUT-OF-TREE RULES ########## endif clean: diff --git a/qla2x00t/Makefile b/qla2x00t/Makefile index 0b9494b12..145063c19 100644 --- a/qla2x00t/Makefile +++ b/qla2x00t/Makefile @@ -16,6 +16,7 @@ extraclean: clean .PHONY: clean extraclean else +######### BEGIN OUT-OF-TREE RULES ######### SHELL=/bin/bash @@ -32,7 +33,12 @@ endif ifeq ($(KVER),) ifeq ($(KDIR),) - KDIR := /lib/modules/$(shell uname -r)/build + KVER := $(shell uname -r) + KDIR := /lib/modules/$(KVER)/build + else + KVER := $(strip $(shell \ + cat $(KDIR)/include/config/kernel.release 2>/dev/null || \ + make -s -C $(KDIR) kernelversion)) endif else KDIR := /lib/modules/$(KVER)/build @@ -54,6 +60,8 @@ install: all uninstall: rm -f $(INSTALL_DIR)/qla2xxxt.ko -/sbin/depmod -a $(KVER) + +########## END OUT-OF-TREE RULES ########## endif clean: diff --git a/qla2x00t/qla2x00-target/Makefile b/qla2x00t/qla2x00-target/Makefile index 2868cae24..710e1273e 100644 --- a/qla2x00t/qla2x00-target/Makefile +++ b/qla2x00t/qla2x00-target/Makefile @@ -27,16 +27,10 @@ # - install and uninstall must be made as root # -ifndef PREFIX - PREFIX=/usr/local -endif - SHELL=/bin/bash EXTRA_CFLAGS += -I$(SCST_INC_DIR) -INSTALL_DIR := /lib/modules/$(shell uname -r)/extra - EXTRA_CFLAGS += -W -Wno-unused-parameter -Wno-missing-field-initializers EXTRA_CFLAGS += -DCONFIG_SCST_EXTRACHECKS @@ -47,8 +41,16 @@ EXTRA_CFLAGS += -DCONFIG_SCST_DEBUG -g -fno-inline -fno-inline-functions ifeq ($(KVER),) ifeq ($(KDIR),) - KVER = $(shell uname -r) + KVER := $(shell uname -r) KDIR := /lib/modules/$(KVER)/build + else + ifeq ($(KERNELRELEASE),) + KVER := $(strip $(shell \ + cat $(KDIR)/include/config/kernel.release 2>/dev/null || \ + make -s -C $(KDIR) kernelversion)) + else + KVER := $(KERNELRELEASE) + endif endif else KDIR := /lib/modules/$(KVER)/build @@ -69,6 +71,13 @@ ifneq ($(PATCHLEVEL),) obj-m := qla2x00tgt.o qla2x00tgt-objs := qla2x00t.o else +######### BEGIN OUT-OF-TREE RULES ######### + +ifndef PREFIX + PREFIX=/usr/local +endif + +INSTALL_DIR := /lib/modules/$(KVER)/extra SCST_INC_DIR := $(shell if [ -e "$$PWD/../../scst" ]; \ then echo "$$PWD/../../scst/include"; \ @@ -130,6 +139,7 @@ else .PHONY: Module.symvers endif +########## END OUT-OF-TREE RULES ########## endif clean: diff --git a/scst/src/Makefile b/scst/src/Makefile index 9b6a55862..84a707774 100644 --- a/scst/src/Makefile +++ b/scst/src/Makefile @@ -54,10 +54,16 @@ obj-$(CONFIG_SCST) += scst.o dev_handlers/ obj-$(BUILD_DEV) += $(DEV_HANDLERS_DIR)/ else +######### BEGIN OUT-OF-TREE RULES ######### + ifeq ($(KVER),) ifeq ($(KDIR),) - KVER = $(shell uname -r) + KVER := $(shell uname -r) KDIR := /lib/modules/$(KVER)/build + else + KVER := $(strip $(shell \ + cat $(KDIR)/include/config/kernel.release 2>/dev/null || \ + make -s -C $(KDIR) kernelversion)) endif else KDIR := /lib/modules/$(KVER)/build @@ -118,13 +124,11 @@ uninstall: -rmdir $(INSTALL_DIR) 2>/dev/null -/sbin/depmod -a $(KVER) rm -rf $(INSTALL_DIR_H) + +########## END OUT-OF-TREE RULES ########## endif -ifeq ($(KVER),) -INSTALL_DIR := $(DESTDIR)/lib/modules/$(shell uname -r)/extra -else INSTALL_DIR := $(DESTDIR)/lib/modules/$(KVER)/extra -endif INSTALL_DIR_H := $(DESTDIR)$(PREFIX)/include/scst enable-Wextra = $(shell uname_r="$$(uname -r)"; if [ "$${uname_r%.el5}" = "$${uname_r}" ]; then echo "$(1)"; fi) diff --git a/scst/src/dev_handlers/Makefile b/scst/src/dev_handlers/Makefile index 56f66e20b..286482aaa 100644 --- a/scst/src/dev_handlers/Makefile +++ b/scst/src/dev_handlers/Makefile @@ -46,11 +46,23 @@ obj-$(CONFIG_SCST_VDISK) += scst_vdisk.o obj-$(CONFIG_SCST_USER) += scst_user.o else -ifeq ($(KDIR),) - KVER = $(shell uname -r) +######### BEGIN OUT-OF-TREE RULES ######### + +ifeq ($(KVER),) + ifeq ($(KDIR),) + KVER := $(shell uname -r) + KDIR := /lib/modules/$(KVER)/build + else + KVER := $(strip $(shell \ + cat $(KDIR)/include/config/kernel.release 2>/dev/null || \ + make -s -C $(KDIR) kernelversion)) + endif +else KDIR := /lib/modules/$(KVER)/build endif +INSTALL_DIR := /lib/modules/$(KVER)/extra + all: $(MAKE) -C $(KDIR) SUBDIRS=$(shell pwd) @@ -60,12 +72,8 @@ install: all uninstall: rm -f $(INSTALL_DIR)/dev_handlers/scst_*.ko -endif -ifeq ($(KVER),) -INSTALL_DIR := /lib/modules/$(shell uname -r)/extra -else -INSTALL_DIR := /lib/modules/$(KVER)/extra +########## END OUT-OF-TREE RULES ########## endif enable-Wextra = $(shell uname_r="$$(uname -r)"; if [ "$${uname_r%.el5}" = "$${uname_r}" ]; then echo "$(1)"; fi) diff --git a/scst_local/Makefile b/scst_local/Makefile index ab0495822..04f3b3081 100644 --- a/scst_local/Makefile +++ b/scst_local/Makefile @@ -2,10 +2,6 @@ # A Makefile for the scst-local ... # -ifndef PREFIX - PREFIX=/usr/local -endif - SHELL=/bin/bash KMOD := $(shell pwd)/kernel @@ -24,17 +20,28 @@ EXTRA_CFLAGS += -DCONFIG_SCST_EXTRACHECKS EXTRA_CFLAGS += -DCONFIG_SCST_DEBUG -g -fno-inline -fno-inline-functions +ifneq ($(PATCHLEVEL),) +obj-m := scst_local.o +else +######### BEGIN OUT-OF-TREE RULES ######### + +ifndef PREFIX + PREFIX=/usr/local +endif + ifeq ($(KVER),) ifeq ($(KDIR),) - KDIR := /lib/modules/$(shell uname -r)/build + KVER := $(shell uname -r) + KDIR := /lib/modules/$(KVER)/build + else + KVER := $(strip $(shell \ + cat $(KDIR)/include/config/kernel.release 2>/dev/null || \ + make -s -C $(KDIR) kernelversion)) endif else KDIR := /lib/modules/$(KVER)/build endif -ifneq ($(PATCHLEVEL),) -obj-m := scst_local.o -else SCST_INC_DIR := $(shell if [ -e "$$PWD/../scst" ]; \ then echo "$$PWD/../scst/include"; \ @@ -71,6 +78,8 @@ endif uninstall: rm -f $(INSTALL_DIR)/scst_local.ko -/sbin/depmod -a $(KVER) + +########## END OUT-OF-TREE RULES ########## endif clean: diff --git a/srpt/Makefile b/srpt/Makefile index 12a0ddebf..bceb631a4 100644 --- a/srpt/Makefile +++ b/srpt/Makefile @@ -15,13 +15,19 @@ SUBDIRS := $(shell pwd) ifeq ($(KVER),) ifeq ($(KDIR),) - KVER = $(shell uname -r) - KDIR ?= /lib/modules/$(KVER)/build + KVER := $(shell uname -r) + KDIR := /lib/modules/$(KVER)/build else - KVER = $$KERNELRELEASE + ifeq ($(KERNELRELEASE),) + KVER := $(strip $(shell \ + cat $(KDIR)/include/config/kernel.release 2>/dev/null || \ + make -s -C $(KDIR) kernelversion)) + else + KVER := $(KERNELRELEASE) + endif endif else - KDIR ?= /lib/modules/$(KVER)/build + KDIR := /lib/modules/$(KVER)/build endif # Set variable $(2) to value $(3) in file $(1).