DEBUG := debug EXTRA_CFLAGS+= -g sles_distro := $(wildcard /etc/SuSE-release) rhel_distro := $(wildcard /etc/redhat-release) KVER := $(shell uname -r) INC_DIR := /lib/modules/$(KVER)/build/include # Check for a standard header, say scsi.h, in the usual location. # Lack of which usually means a SLES machine, which does not have # headers like other distros; this way an upstream compile would # work on a SLES machine. ifeq ($(wildcard $(INC_DIR)/scsi/scsi.h),) # very likely SLES _KVER=$(shell echo $(KVER) | cut -d "-" -f1,2) INC_DIR := /usr/src/linux-$(_KVER)/include endif # # set-def:- # $(call set-def,,,) # - returns if pattern is in include file. # # pattern should have word boundaries (-w option) and should not have # embedded space (use \s instead). # define set-def $(shell grep -qsw "$(strip $3)" \ $(INC_DIR)/$(strip $2) && echo "$(strip $1)") endef DEFINES += $(call set-def,DEFINE_FIP_VLAN_DESC,scsi/fc/fc_fip.h,fip_vlan_desc) DEFINES += $(call set-def,DEFINE_FIP_SC_VL_REP,scsi/fc/fc_fip.h,FIP_SC_VL_REP) DEFINES += $(call set-def,ETHER_ADDR_COPY,linux/etherdevice.h,ether_addr_copy) DEFINES += $(call set-def,ETHER_ADDR_EQUAL,linux/etherdevice.h,ether_addr_equal) DEFINES += $(call set-def,ETH_ZERO_ADDR,linux/etherdevice.h,eth_zero_addr) DEFINES += $(call set-def,KMALLOC_ARRAY,linux/slab.h,kmalloc_array) DEFINES += $(call set-def,FC_DISC_CONFIG,scsi/libfc.h,fc_disc_config) DEFINES += $(call set-def,KREF_READ,linux/kref.h,kref_read) DEFINES += $(call set-def,FC_RPORT_LOGIN,scsi/libfc.h,fc_rport_login) DEFINES += $(call set-def,FC_RPORT_LOGOFF,scsi/libfc.h,fc_rport_logoff) DEFINES += $(call set-def,FC_RPORT_CREATE,scsi/libfc.h,fc_rport_create) DEFINES += $(call set-def,FC_RPORT_DESTROY,scsi/libfc.h,fc_rport_destroy) DEFINES += $(call set-def,FC_RPORT_LOOKUP,scsi/libfc.h,fc_rport_lookup) DEFINES += $(call set-def,FC_RPORT_INIT,scsi/libfc.h,fc_rport_init) DEFINES += $(call set-def,KREF_GET_UNLESS_ZERO,linux/kref.h,kref_get_unless_zero) DEFINES += $(call set-def,USE_BLK_MQ,scsi/scsi_host.h,nr_hw_queues) override EXTRA_CFLAGS += $(addprefix -D,$(DEFINES)) # Addition defines via command line, call: make EXTRA_DEFINES=XYZ override EXTRA_CFLAGS += $(addprefix -D,$(EXTRA_DEFINES)) ifneq ($(debug),) $(warning EXTRA_CFLAGS=($(EXTRA_CFLAGS))) endif obj-m := qedf.o qedf-objs = qedf_dbg.o qedf_main.o qedf_io.o qedf_fip.o \ qedf_attr.o qedf_els.o qedf_debugfs.o \ drv_scsi_fw_funcs.o drv_fcoe_fw_funcs.o KVER_DIR=/lib/modules/$(KVER) current_modules := $(shell grep -s ^INITRD_MODULES /etc/sysconfig/kernel | awk -F'"' '$$0=$$2') PREFIX= ifneq ($(rhel_distro),) DISTRO_DRV_DIR := extra else DISTRO_DRV_DIR := updates endif DRV_DIR := $(DISTRO_DRV_DIR)/qlgc-fastlinq ifeq ($(ERROR_INJECT), 1) override EXTRA_CFLAGS += -DERROR_INJECT endif NPROCS:=$(shell grep -c ^processor /proc/cpuinfo) .PHONY: build_pre sparse sparse_endian smatch modcopy modules_install install QED_FILES := Module.symvers qed_if.h qed_fcoe_if.h qed_ll2_if.h qed_chain.h build: build_pre make -C $(KVER_DIR)/build -j$(NPROCS) M=`pwd` modules $(QED_FILES): $(addprefix ../qed-8.33.9.0/src/,$(QED_FILES)) cp -f $^ . build_pre: $(QED_FILES) sparse: build_pre if which sparse 1>/dev/null 2>&1; then\ make -C $(KVER_DIR)/build C=2 M=`pwd` modules;\ fi sparse_endian: build_pre if which sparse 1>/dev/null 2>&1; then\ make -C $(KVER_DIR)/build C=2 CF="-D_CHECK_ENDIAN_" M=`pwd` modules;\ fi smatch: build_pre if which smatch 1>/dev/null 2>&1; then\ make -C $(KVER_DIR)/build CHECK="/root/bin/smatch -p=kernel" C=2 M=`pwd` modules;\ fi clean: rm -f Module.symvers rm -f modules.order rm -f ../storcmn/\.*.cmd ../storcmn/*.o make -C $(KVER_DIR)/build M=`pwd` clean modcopy: build make -C $(KVER_DIR)/build M=`pwd` INSTALL_MOD_PATH=$(PREFIX) INSTALL_MOD_DIR=$(DRV_DIR) modules_install @if [ "$(rhel_distro)" != "" ]; then \ echo "override qedf * $(DRV_DIR)" > qedf.conf ;\ install -m 644 -D qedf.conf $(PREFIX)/etc/depmod.d/qedf.conf ;\ fi @if [ "$(PREFIX)" = "" ] ;\ then /sbin/depmod -a ;\ else echo " *** Run '/sbin/depmod -a' to update the module database." ;\ fi modules_install: modcopy @if [ -f /boot/initramfs-$(KVER).img ]; then\ echo "back up initrd to /boot/initramfs-$(KVER).img.bak" ;\ cp /boot/initramfs-$(KVER).img /boot/initramfs-$(KVER).img.bak ;\ elif [ -f /boot/initrd-$(KVER) ]; then\ echo "back up initrd to /boot/initrd-$(KVER).bak";\ cp /boot/initrd-$(KVER) /boot/initrd-$(KVER).bak;\ elif [ -f /boot/initrd.img-$(KVER) ]; then\ echo "back up initrd to /boot/initrd.img-$(KVER).bak";\ cp /boot/initrd.img-$(KVER) /boot/initrd.img-$(KVER).bak;\ fi @echo "add driver qedf to initrd" @if which dracut 1>/dev/null 2>&1; then\ dracut -f --add-drivers qedf;\ elif [ -f /boot/initrd.img-$(KVER) ] && [ -f /usr/sbin/update-initramfs ]; then\ echo "updating initrd" ;\ update-initramfs -u;\ else\ if [ `echo $(current_modules) | grep -c qedf` -eq 0 ];\ then\ echo "need to add qedf to /sys/config/kernel";\ sed -i "s/^INITRD_MODULES=\"${current_modules}\"/INITRD_MODULES=\"${current_modules} qedf\"/" /etc/sysconfig/kernel;\ fi;\ mkinitrd -m qedf;\ fi install: modules_install