diff options
-rw-r--r-- | Makefile | 87 | ||||
-rw-r--r-- | kernel/Makefile | 129 | ||||
-rw-r--r-- | usr/Makefile | 18 |
3 files changed, 177 insertions, 57 deletions
@@ -2,9 +2,30 @@ # Makefile for the Open-iSCSI Initiator # +# if you are packaging open-iscsi, set this variable to the location +# that you want everything installed into. +DESTDIR ?= + +prefix = /usr +exec_prefix = $(prefix) +sbindir = $(exec_prefix)/sbin +bindir = $(exec_prefix)/bin +mandir = $(prefix)/share/man +etcdir = /etc +initddir = $(etcdir)/init.d + +MANPAGES = doc/iscsid.8 doc/iscsiadm.8 +PROGRAMS = usr/iscsid usr/iscsiadm +INSTALL = install +ETCFILES = etc/iscsid.conf + +# Random comments: +# using '$(MAKE)' instead of just 'make' allows make to run in parallel +# over multiple makefile. + all: - make -C usr - make -C kernel + $(MAKE) -C usr + $(MAKE) -C kernel @echo @echo "Compilation complete Output file" @echo "----------------------------------- ----------------" @@ -16,17 +37,59 @@ all: @echo Read README file for detailed information. clean: - make -C usr clean - make -C kernel clean + $(MAKE) -C usr clean + $(MAKE) -C kernel clean + +# this is for safety +# now -jXXX will still be safe +# note that make may still execute the blocks in parallel +.NOTPARALLEL: install_usr install_programs install_initd \ + install_initd_suse install_initd_redhat install_initd_debian \ + install_etc install_doc install_kernel + +install: install_kernel install_programs install_doc install_etc \ + install_initd + +install_programs: $(PROGRAMS) + $(INSTALL) -d $(DESTDIR)$(sbindir) + $(INSTALL) -m 755 $^ $(DESTDIR)$(sbindir) -install: kernel/iscsi_tcp.ko kernel/scsi_transport_iscsi.ko usr/iscsid usr/iscsiadm - @install -vD usr/iscsid /usr/sbin/iscsid - @install -vD usr/iscsiadm /usr/sbin/iscsiadm +# ugh, auto-detection is evil +# Gentoo maintains their own init.d stuff +install_initd: if [ -f /etc/debian_version ]; then \ - install -vD -m 755 etc/initd/initd.debian /etc/init.d/open-iscsi; \ + $(MAKE) install_initd_debian ; \ elif [ -f /etc/redhat-release ]; then \ - install -vD -m 755 etc/initd/initd.redhat /etc/init.d/open-iscsi; \ + $(MAKE) install_initd_redhat ; \ + elif [ -f /etc/SuSE-release ]; then \ + $(MAKE) install_initd_suse ; \ fi - install -vD kernel/iscsi_tcp.ko /lib/modules/`uname -r`/kernel/drivers/scsi/iscsi_tcp.ko - install -vD kernel/scsi_transport_iscsi.ko /lib/modules/`uname -r`/kernel/drivers/scsi/scsi_transport_iscsi.ko - -depmod -aq + +# these are external targets to allow bypassing distribution detection +install_initd_suse: + $(INSTALL) -d $(DESTDIR)$(initddir) + $(INSTALL) -m 755 etc/initd/initd.suse \ + $(DESTDIR)$(initddir)/open-iscsi + +install_initd_redhat: + $(INSTALL) -d $(DESTDIR)$(initddir) + $(INSTALL) -m 755 etc/initd/initd.redhat \ + $(DESTDIR)$(initddir)/open-iscsi + +install_initd_debian: + $(INSTALL) -d $(DESTDIR)$(initddir) + $(INSTALL) -m 755 etc/initd/initd.debian \ + $(DESTDIR)$(initddir)/open-iscsi + +install_etc: $(ETCFILES) + $(INSTALL) -d $(DESTDIR)$(etcdir) + $(INSTALL) $^ $(DESTDIR)$(etcdir) + +install_doc: $(MANPAGES) + $(INSTALL) -d $(DESTDIR)$(mandir)/man8 + $(INSTALL) -m 644 $^ $(DESTDIR)$(mandir)/man8 + +install_kernel: + $(MAKE) -C kernel install_kernel + +# vim: ft=make tw=72 sw=4 ts=4: diff --git a/kernel/Makefile b/kernel/Makefile index baa04b1..3da8d4f 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -1,69 +1,120 @@ # # Makefile for the Linux Kernel iSCSI Initiator # +# This Makefile invokes KBuild from outside the kernel directory when +# used from the main open-iscsi package. It also contains all of the +# KBuild stuff needed to build the the modules. +# +# Kbuild stuff, the following is the only part of this file that KBuild +# actually uses itself. EXTRA_CFLAGS += -I$(obj) -I$(obj)/../include obj-m += scsi_transport_iscsi.o obj-m += iscsi_tcp.o -KSRC ?= /lib/modules/`uname -r`/build +# Everything beyond this point is used to call KBuild or handle support +# for multiple kernel versions. + +# Kbuild verbosity +V ?= 0 + +# allow users to override these +# eg to compile for a kernel that you aren't currently running +KERNELRELEASE ?= $(shell uname -r) +KSRC ?= /lib/modules/$(KERNELRELEASE)/build -KVER = $(shell cat $(KSRC)/Makefile | awk -F= '/^SUBLEVEL =/ {print $$2}' | \ +# this is the basic Kbuild invocation, just append your make target +KBUILD_BASE = +$(MAKE) -C $(KSRC) M=`pwd` $(KARCH) V=$(V) + +# fun stuff for maintaining multiple versions +KSUBLEVEL = $(shell cat $(KSRC)/Makefile | awk -F= '/^SUBLEVEL =/ {print $$2}' | \ sed 's/^[ \t]*//;s/[ \t]*$$//') -ifeq ($(KVER), 11) +ifeq ($(KSUBLEVEL), 11) EXTRA_CFLAGS += -DNETLINK_ISCSI=12 else -ifeq ($(KVER), 12) +ifeq ($(KSUBLEVEL), 12) EXTRA_CFLAGS += -DNETLINK_ISCSI=12 endif endif -#TODO: learn how to program Makefiles! -all: -ifeq ($(KVER),11) - @if ! cat scsi_transport_iscsi.c | \ - grep iscsi_compat > /dev/null; then \ - echo "kernel check... FAILED"; \ - echo "Apply the 2.6.11-compat.patch first!"; exit 1; fi - @echo "kernel check... OK" +all: kernel_check + $(KBUILD_BASE) modules + +# ====== BEGIN code for kernel_check + + +# generic make function +# syntax: +# @$(call generic_check_command, CHECKING-COMMAND, PATCHNAME) +generic_check_command = if $(1) ; then \ + echo "kernel check... FAILED"; \ + echo "Apply the $(2) first!"; exit 1; fi ; \ + echo "kernel check... OK" + +# this variable defines how we check for iscsi_compat +check_iscsi_compat_command = ! grep iscsi_compat scsi_transport_iscsi.c >/dev/null +# this variable is the actual make function +check_iscsi_compat = $(call generic_check_command, $(check_iscsi_compat_command), $(1)) +# syntax: +# @$(call check_iscsi_compat, PATCHNAME) + +# this if-else ladder is horrible +# but I don't know any quick way to clean it up +# since Make doesn't support a switch construct +.NOTPARALLEL: kernel_check +kernel_check: +ifeq ($(KSUBLEVEL),11) + @$(call check_iscsi_compat, 2.6.11-compat.patch) else -ifeq ($(KVER),12) - @if ! cat scsi_transport_iscsi.c | \ - grep iscsi_compat > /dev/null; then \ - echo "kernel check... FAILED"; \ - echo "Apply the 2.6.12-compat.patch first!"; exit 1; fi - @echo "kernel check... OK" +ifeq ($(KSUBLEVEL),12) + @$(call check_iscsi_compat, 2.6.12-compat.patch) else -ifeq ($(KVER),13) - @if ! cat scsi_transport_iscsi.c | \ - grep iscsi_compat > /dev/null; then \ - echo "kernel check... FAILED"; \ - echo "Apply the 2.6.13-compat.patch first!"; exit 1; fi - @echo "kernel check... OK" +ifeq ($(KSUBLEVEL),13) + @$(call check_iscsi_compat, 2.6.13-compat.patch) else -ifeq ($(KVER),14) - @if ! cat scsi_transport_iscsi.c | \ - grep iscsi_compat > /dev/null; then \ - echo "kernel check... FAILED"; \ - echo "Apply the 2.6.14-and-2.6.15-compat.patch first!"; exit 1; fi - @echo "kernel check... OK" +ifeq ($(KSUBLEVEL),14) + @$(call check_iscsi_compat, 2.6.14-and-2.6.15-compat.patch) else -ifeq ($(KVER),15) - @if ! cat scsi_transport_iscsi.c | \ - grep iscsi_compat > /dev/null; then \ - echo "kernel check... FAILED"; \ - echo "Apply the 2.6.14-and-2.6.15-compat.patch first!"; exit 1; fi - @echo "kernel check... OK" +ifeq ($(KSUBLEVEL),15) + @$(call check_iscsi_compat, 2.6.14-and-2.6.15-compat.patch) else - @echo "kernel check... OK" + @echo "kernel check... OTHER KERNEL DETECTED" endif endif endif endif endif - make -C $(KSRC) SUBDIRS=`pwd` $(KARCH) + +# ====== END code for kernel_check clean: - rm -f -r *.mod.c .*cmd *.o *.ko .tmp_versions + $(KBUILD_BASE) clean +#echo rm -f -r *.mod.c .*cmd *.o *.ko .tmp_versions + +# the following is only for convienience +# do not submit to Linus +# it's also called from the toplevel makefile + +# INSTALL_MOD_DIR is set so that the drivers go into the correct location using Kbuild +# it defaults to 'extra' otherwise +INSTALL_MOD_DIR ?= kernel/drivers/scsi + +# this allows packaging of modules +ifdef DESTDIR +INSTALL_MOD_PATH=$(DESTDIR) +else +INSTALL_MOD_PATH= +endif + +# this evil rule ensures that the modules get build if you specify $(ko) +# as a dependancy. +ko = $(patsubst %.o,%.ko,$(obj-m)) +$(ko): all + +# now the actual command +install_kernel: $(ko) + $(KBUILD_BASE) modules_install INSTALL_MOD_DIR=$(INSTALL_MOD_DIR) INSTALL_MOD_PATH=$(INSTALL_MOD_PATH) + +# vim: ft=make tw=72 sw=4 ts=4: diff --git a/usr/Makefile b/usr/Makefile index 013bf56..dfa4e0e 100644 --- a/usr/Makefile +++ b/usr/Makefile @@ -1,15 +1,20 @@ # This Makefile will work only with GNU make. OSNAME=$(shell uname -s) -KSRC=/lib/modules/`uname -r`/build -KVER=$(shell cat $(KSRC)/Makefile | awk -F= '/^SUBLEVEL =/ {print $$2}' | \ + +# allow users to override these +# eg to compile for a kernel that you aren't currently running +KERNELRELEASE ?= $(shell uname -r) +KSRC ?= /lib/modules/$(KERNELRELEASE)/build + +KSUBLEVEL=$(shell cat $(KSRC)/Makefile | awk -F= '/^SUBLEVEL =/ {print $$2}' | \ sed 's/^[ \t]*//;s/[ \t]*$$//') ifeq ($(OSNAME),Linux) - ifeq ($(KVER),11) + ifeq ($(KSUBLEVEL),11) IPC_CFLAGS=-DNETLINK_ISCSI=12 else - ifeq ($(KVER),12) + ifeq ($(KSUBLEVEL),12) IPC_CFLAGS=-DNETLINK_ISCSI=12 else IPC_CFLAGS=-DNETLINK_ISCSI=8 @@ -25,8 +30,9 @@ DBM_LIB= endif endif -CFLAGS += -O2 -fno-inline -Wall -Wstrict-prototypes -g -I../include \ - -D$(OSNAME) $(IPC_CFLAGS) +OPTFLAGS ?= -O2 -fno-inline -g +WARNFLAGS ?= -Wall -Wstrict-prototypes +CFLAGS += $(OPTFLAGS) $(WARNFLAGS) -I../include -D$(OSNAME) $(IPC_CFLAGS) PROGRAMS = iscsid iscsiadm # sources shared between iscsid and iscsiadm |