rendered paste body# checkKenerlOS.mk
# Dennis Yang
# Include this for checking the OS distribution
# Support RedHat, RHEL_AS_30, RHEL_AS_40, SUSE, SUEL_9
# This .mk will parapre these parameters
# $(RUNKVER) $(KERSRC) $(KSRCSYMLINK)
# $(OSDIST) $(KER_INCLUDES) $(VERSION_H) $(CONFIG_H) $(MODPOST)
# Start: 2005/05/12
# Update: 2006/01/26
RUNKVER := $(shell uname -r)
KSRCPATH := /lib/modules/$(RUNKVER)/source /lib/modules/$(RUNKVER)/build /usr/src/linux-$(RUNKVER) /usr/src/linux-$(shell echo $(RUNKVER) | sed 's/-.*//') /usr/src/linux-$(shel$
KERSRC := $(shell for i in $(KSRCPATH) ; do if [ -e $${i}/include/linux ] ; then echo $${i} ; break ; fi ; done)
ifeq ($(KERSRC),)
$(error Can not find linux kernel source!)
endif
KSRCSYMLINK := $(shell ls -la $(KERSRC)|grep "\->"|sed -e 's/..*-> //')
OSDIST := NONE
GENKSYMS := genksyms
KER_INCLUDES := -I$(KERSRC)/include
VERSION_H := $(KERSRC)/include/linux/version.h
CONFIG_H := $(KERSRC)/include/linux/config.h
ifneq ($(wildcard /etc/redhat-release),)
#RedHat
ISRHEL := $(shell cat /etc/redhat-release|grep "Enterprise Linux")
ifneq ($(ISRHEL),)
ifneq ($(wildcard $(KERSRC)/include/linux/rhconfig.h),)
OSDIST := RHEL_AS_30
endif
ifeq ($(OSDIST),NONE)
ISRHELAS4 := $(shell cat $(KERSRC)/include/linux/compile.h|grep "LINUX_COMPILE_DOMAIN"|grep ".redhat.com")
ifneq ($(ISRHELAS4),)
OSDIST := RHEL_AS_40
endif
endif
else
ifneq ($(wildcard $(KERSRC)/include/linux/rhconfig.h),)
OSDIST := REDHAT
endif
endif
else
ifneq ($(wildcard /etc/SuSE-release),)
OSDIST := SUSE
ISSUEL9 := $(shell cat /etc/SuSE-release|grep "SUSE LINUX Enterprise Server 9")
ifneq ($(ISSUEL9),)
OSDIST := SUEL_9
endif
endif
endif
#verify OS
ifeq ($(OSDIST),NONE)
$(error Can not find OS distribution)
endif
# Check CPU section
#ifeq ($(CPU),INTEL)
# CPU_ARCH = INTEL
#endif
#ifeq ($(CPU),AMD)
# CPU_ARCH = AMD
#endif
ifneq ($(CPU_ARCH),)
FORCE_ARCH = 1
else
# For RedHat
ifeq ($(OSDIST),REDHAT)
#UP
ifeq ($(KERNEL_CONFIG),1)
KDEF_EXT = -D__BOOT_KERNEL_UP=1 -D__BOOT_KERNEL_SMP=0 -D__BOOT_KERNEL_BIGMEM=0 -D__BOOT_KERNEL_ENTERPRISE=0
endif
#SMP
ifeq ($(KERNEL_CONFIG),2)
KDEF_EXT = -D__BOOT_KERNEL_UP=0 -D__BOOT_KERNEL_SMP=1 -D__BOOT_KERNEL_BIGMEM=0 -D__BOOT_KERNEL_ENTERPRISE=0
endif
#Bigmem
ifeq ($(KERNEL_CONFIG),3)
KDEF_EXT = -D__BOOT_KERNEL_UP=0 -D__BOOT_KERNEL_SMP=0 -D__BOOT_KERNEL_BIGMEM=1 -D__BOOT_KERNEL_ENTERPRISE=0
endif
KER_INCLUDES := -I$(KERSRC)/include
VERSION_H := $(KERSRC)/include/linux/version.h
CONFIG_H := $(KERSRC)/include/linux/config.h
endif
#For RHEL AS 30
ifeq ($(OSDIST),RHEL_AS_30)
KER_INCLUDES := -I$(KERSRC)/include
VERSION_H := $(KERSRC)/include/linux/version.h
CONFIG_H := $(KERSRC)/include/linux/config.h
X64BIT := $(shell $(CC) -v 2>&1 | grep "host=x86_64-redhat-linux" )
ifneq ($(X64BIT),)
X64 = 1
else
X64 = 0
endif
ifeq ($(CPU_ARCH),INTEL)
ifeq ($(X64),1)
KDEF_EXT_CPU = -D__MODULE_KERNEL_ia32e=1 -D__MODULE_KERNEL_x86_64=0
else
KDEF_EXT_CPU = -D__MODULE_KERNEL_athlon=0 -D__MODULE_KERNEL_i686=1
endif
endif
ifeq ($(CPU_ARCH),AMD)
ifeq ($(X64),1)
KDEF_EXT_CPU = -D__MODULE_KERNEL_ia32e=0 -D__MODULE_KERNEL_x86_64=1
else
KDEF_EXT_CPU = -D__MODULE_KERNEL_athlon=1 -D__MODULE_KERNEL_i686=0
endif
endif
#UP
ifeq ($(KERNEL_CONFIG),1)
KDEF_EXT = $(KDEF_EXT_CPU) -D__BOOT_KERNEL_UP=1 -D__BOOT_KERNEL_SMP=0 -D__BOOT_KERNEL_BIGMEM=0 -D__BOOT_KERNEL_ENTERPRISE=0 -D__BOOT_KERNEL_HUGEMEM=0
endif
#SMP
ifeq ($(KERNEL_CONFIG),2)
KDEF_EXT = $(KDEF_EXT_CPU) -D__BOOT_KERNEL_UP=0 -D__BOOT_KERNEL_SMP=1 -D__BOOT_KERNEL_BIGMEM=0 -D__BOOT_KERNEL_ENTERPRISE=0 -D__BOOT_KERNEL_HUGEMEM=0
endif
#Bigmem
ifeq ($(KERNEL_CONFIG),3)
ifneq ($(X64),1)
KDEF_EXT = $(KDEF_EXT_CPU) -D__BOOT_KERNEL_UP=0 -D__BOOT_KERNEL_SMP=0 -D__BOOT_KERNEL_BIGMEM=1 -D__BOOT_KERNEL_ENTERPRISE=0 -D__BOOT_KERNEL_HUGEMEM=1
else
KDEF_EXT = $(KDEF_EXT_CPU) -D__BOOT_KERNEL_UP=0 -D__BOOT_KERNEL_SMP=1 -D__BOOT_KERNEL_BIGMEM=0 -D__BOOT_KERNEL_ENTERPRISE=0 -D__BOOT_KERNEL_HUGEMEM=0
endif
endif
ifeq ($(FORCE_ARCH),1)
KDEF_EXT += $(KDEF_EXT_CPU)
endif
endif
#For RHEL AS 40
ifeq ($(OSDIST),RHEL_AS_40)
X64BIT := $(shell $(CC) -v 2>&1 | grep "host=x86_64-redhat-linux" )
ifneq ($(X64BIT),)
X64 = 1
else
X64 = 0
endif
#UP
KVBASE=$(shell echo $(RUNKVER)|sed -e 's/hugemem//'|sed -e 's/smp//')
ifeq ($(KERNEL_CONFIG),1)
KERSRC := /lib/modules/$(KVBASE)/build
endif
#SMP
ifeq ($(KERNEL_CONFIG),2)
KERSRC := /lib/modules/$(KVBASE)smp/build
endif
#Hugemem
ifeq ($(KERNEL_CONFIG),3)
ifeq ($(X64),0)
KERSRC := /lib/modules/$(KVBASE)hugemem/build
else
KERSRC := /lib/modules/$(KVBASE)smp/build
endif
endif
KER_INCLUDES := -I$(KERSRC)/include
VERSION_H := $(KERSRC)/include/linux/version.h
CONFIG_H := $(KERSRC)/include/linux/config.h
MODPOST := $(KERSRC)/scripts/mod/modpost
GENKSYMS := $(KERSRC)/scripts/genksyms/genksyms
endif
#check SuSE
ifeq ($(OSDIST),SUSE)
CONFIG_H := $(KERSRC)/include/linux/config.h
ifneq ($(wildcard $(CONFIG_H)),)
suse := $(shell $(CC) -E -dM -I$(KERSRC)/include $(CONFIG_H) | grep CONFIG_SUSE_KERNEL | cut -f3 -d' ')
else
$(error missing $(CONFIG_H))
endif
ifeq ($(suse),1)
ifneq ($(KERNEL_CONFIG),0)
#get suse config path
VERSION_H := $(KERSRC)/include/linux/version.h
ifeq ($(wildcard $(VERSION_H)),)
$(error missing $(VERSION_H))
endif
KVER := $(SHELL $(CC) -E -dM $(VERSION_H) | grep UTS_RELEASE | awk '{ print $$3 }' | sed 's/\"//g')
KMAJORVER := $(shell echo "$(KVER)"|cut -f1 -d'-')
ifeq ($(KERNEL_CONFIG),1)
SUSECFG_PATH := $(SUSECFGPATH)/$(KMAJORVER)-4GB
endif
ifeq ($(KERNEL_CONFIG),2)
SUSECFG_PATH := $(SUSECFGPATH)/$(KMAJORVER)-4GB-SMP
endif
ifeq ($(KERNEL_CONFIG),3)
SUSECFG_PATH := $(SUSECFGPATH)/$(KMAJORVER)-64GB-SMP
endif
#set up header
VERSION_H := $(SUSECFG_PATH)/vmlinuz.version.h
CONFIG_H := $(SUSECFG_PATH)/vmlinuz.autoconf.h
tmp := $(shell rm -rf ./include; mkdir -p include/linux; cp -af $(VERSION_H) include/linux/version.h; cp -af $(CONFIG_H) include/linux/autoconf.h)
KER_INCLUDES := -I./include -I$(KERSRC)/include
else
VERSION_H := /boot/vmlinuz.version.h
CONFIG_H := /boot/vmlinuz.autoconf.h
ifneq ($(wildcard $(VERSION_H)),)
ifneq ($(wildcard $(CONFIG_H)),)
KVER := $(shell $(CC) -E -dM $(VERSION_H) | grep UTS_RELEASE | awk '{ print $$3 }' | sed 's/\"//g')
ifeq ($(KVER),$(RUNKVER))
tmp := $(shell rm -rf ./include; mkdir -p include/linux; cp -af $(VERSION_H) include/linux/version.h; cp -af $(CONFIG_H) include/$
KER_INCLUDES := -I./include -I$(KERSRC)/include
$(warning $(VERSION_H) and $(CONFIG_H) matched the running kernel, use them as default)
endif
endif
endif
endif
else
$(error This kernel source is not SuSE released!)
endif
endif
ifeq ($(OSDIST),SUEL_9)
CONFIG_H := $(KERSRC)/include/linux/autoconf.h
ifneq ($(wildcard $(CONFIG_H)),)
suse := $(shell $(CC) -E -dM -I$(KERSRC)/include $(CONFIG_H) | grep CONFIG_SUSE_KERNEL | cut -f3 -d' ')
else
$(error missing $(CONFIG_H), need suse kernel source!)
endif
KERBUILD := /lib/modules/$(RUNKVER)/build
ifeq ($(suse),1)
ifneq ($(KERNEL_CONFIG),0)
ifeq ($(KERNEL_CONFIG),1)
KERBUILD := /usr/src/linux-obj/i386/default
endif
ifeq ($(KERNEL_CONFIG),2)
KERBUILD := /usr/src/linux-obj/i386/smp
endif
ifeq ($(KERNEL_CONFIG),3)
KERBUILD := /usr/src/linux-obj/i386/bigsmp
endif
#set up header
VERSION_H := $(KERBUILD)/include/linux/version.h
CONFIG_H := $(KERBUILD)/include/linux/autoconf.h
KER_INCLUDES := -I$(KERBUILD)/include -I$(KERSRC)/include
else
VERSION_H := $(KERBUILD)/include/linux/version.h
CONFIG_H := $(KERBUILD)/include/linux/autoconf.h
KER_INCLUDES :=
ifneq ($(wildcard $(VERSION_H)),)
ifneq ($(wildcard $(CONFIG_H)),)
KVER := $(shell $(CC) -E -dM $(VERSION_H) | grep UTS_RELEASE | awk '{ print $$3 }' | sed 's/\"//g')
ifeq ($(KVER),$(RUNKVER))
KER_INCLUDES := -I$(KERBUILD)/include -I$(KERSRC)/include
$(warning $(VERSION_H) and $(CONFIG_H) matched the running kernel, use them as default)
endif
endif
endif
ifeq ($(KER_INCLUDES),)
$(error Can not find the kernel include directory for current kernel!)
endif
endif
MODPOST := $(KERBUILD)/scripts/modpost
GENKSYMS := $(KERBUILD)/scripts/genksyms/genksyms
else
$(error This kernel source is not SuSE released!)
endif
endif
ifneq ($(wildcard $(MINCLUDEPATH)/cpuarch.mk),)
include $(MINCLUDEPATH)/cpuarch.mk
else
CPU_ARCH = INTEL
endif
endif
endif
ifeq ($(OSDIST),SUEL_9)
CONFIG_H := $(KERSRC)/include/linux/autoconf.h
ifneq ($(wildcard $(CONFIG_H)),)
suse := $(shell $(CC) -E -dM -I$(KERSRC)/include $(CONFIG_H) | grep CONFIG_SUSE_KERNEL | cut -f3 -d' ')
else
$(error missing $(CONFIG_H), need suse kernel source!)
endif
KERBUILD := /lib/modules/$(RUNKVER)/build
ifeq ($(suse),1)
ifneq ($(KERNEL_CONFIG),0)
ifeq ($(KERNEL_CONFIG),1)
KERBUILD := /usr/src/linux-obj/i386/default
endif
ifeq ($(KERNEL_CONFIG),2)
KERBUILD := /usr/src/linux-obj/i386/smp
endif
ifeq ($(KERNEL_CONFIG),3)
KERBUILD := /usr/src/linux-obj/i386/bigsmp
endif
#set up header
VERSION_H := $(KERBUILD)/include/linux/version.h
CONFIG_H := $(KERBUILD)/include/linux/autoconf.h
KER_INCLUDES := -I$(KERBUILD)/include -I$(KERSRC)/include
else
VERSION_H := $(KERBUILD)/include/linux/version.h
CONFIG_H := $(KERBUILD)/include/linux/autoconf.h
KER_INCLUDES :=
ifneq ($(wildcard $(VERSION_H)),)
ifneq ($(wildcard $(CONFIG_H)),)
KVER := $(shell $(CC) -E -dM $(VERSION_H) | grep UTS_RELEASE | awk '{ print $$3 }' | sed 's/\"//g')
ifeq ($(KVER),$(RUNKVER))
KER_INCLUDES := -I$(KERBUILD)/include -I$(KERSRC)/include
$(warning $(VERSION_H) and $(CONFIG_H) matched the running kernel, use them as default)
endif
endif
endif
ifeq ($(KER_INCLUDES),)
$(error Can not find the kernel include directory for current kernel!)
endif
endif
MODPOST := $(KERBUILD)/scripts/modpost
GENKSYMS := $(KERBUILD)/scripts/genksyms/genksyms
else
$(error This kernel source is not SuSE released!)
endif
endif
# Test file existence
ifeq ($(wildcard $(CONFIG_H)),)
$(error missing $(CONFIG_H))
endif
ifeq ($(wildcard $(VERSION_H)),)
$(error missing $(VERSION_H))
endif
ifneq ($(MODPOST),)
ifeq ($(wildcard $(MODPOST)),)
$(error missing $(MODPOST))
endif
endif
#EOF