--- /tmp/Makefile.orig	Tue Nov 20 16:33:36 2001
+++ Makefile	Tue Nov 20 17:10:30 2001
@@ -1,9 +1,39 @@
 LOCALSUBDIRS=esm
-KERNEL_SUB_DIRS= $(shell uname -r | sed "s/[a-z].*//")
+KERNEL_SUB_DIRS= $(shell uname -r)
 ia64 = $(shell grep "define __MODULE_KERNEL_ia64" /boot/kernel.h |  awk '{print $$3}')
 
+kernel_i686 =       $(shell grep "define __MODULE_KERNEL_i686" /boot/kernel.h |  awk '{print $$3}')
+kernel_enterprise = $(shell grep "define __BOOT_KERNEL_ENTERPRISE" /boot/kernel.h |  awk '{print $$3}')
+kernel_smp =        $(shell grep "define __BOOT_KERNEL_SMP" /boot/kernel.h |  awk '{print $$3}')
+kernel_up =         $(shell grep "define __BOOT_KERNEL_UP" /boot/kernel.h |  awk '{print $$3}')
+
+
+ifeq ("$(kernel_i686)", "1")
+ifeq ("$(kernel_up)", "1")
+	config_file = $${KDIR}/kernel-$${KVER}-i686.config
+endif
+ifeq ("$(kernel_smp)", "1")
+	config_file = $${KDIR}/kernel-$${KVER}-i686-smp.config
+endif
+ifeq ("$(kernel_enterprise)", "1")
+	config_file = $${KDIR}/kernel-$${KVER}-i686-enterprise.config
+endif
+endif
+
+ifeq ("$(ia64)", "1")
+ifeq ("$(kernel_up)", "1")
+	config_file = $${KDIR}/kernel-$${KVER}-ia64.config
+endif
+ifeq ("$(kernel_smp)", "1")
+	config_file = $${KDIR}/kernel-$${KVER}-ia64-smp.config
+endif
+endif
+
 all: $(patsubst %, _mod_%, $(KERNEL_SUB_DIRS)) 
 
+
+
+
 $(patsubst %, _mod_%, $(KERNEL_SUB_DIRS)):
 ifeq ("$(ia64)", "1")
 
@@ -18,8 +48,9 @@
 		for i in ${LOCALSUBDIRS}; do \
 			ln -s ../$$i $${KDIR}/$$i ; \
 		done; \
-		cp $${KDIR}/kernel-$${KVER}-ia64.config $${KDIR}/.config; \
-		cp $${KDIR}/kernel-$${KVER}-ia64-smp.config $${KDIR}/.config; \
+		if [ ! -e $${KDIR}/.config ]; then  \
+			cp ${config_file} $${KDIR}/.config; \
+		fi; \
 		make -C $${KDIR} SUBDIRS="${LOCALSUBDIRS}" COMPILE_VERSION="-DSYSTEM_TYPE_LINUX" EXTRAVERSION=-$${BVER} INSTALL_MOD_PATH=`pwd`/$${KDIR} modules; \
 		make -C $${KDIR} SUBDIRS="${LOCALSUBDIRS}" COMPILE_VERSION="-DSYSTEM_TYPE_LINUX" EXTRAVERSION=-$${BVER} INSTALL_MOD_PATH=`pwd`/$${KDIR} modules_install; \
 		for i in ${LOCALSUBDIRS}; do \
@@ -42,16 +73,14 @@
 		for i in ${LOCALSUBDIRS}; do \
 			ln -s ../$$i $${KDIR}/$$i ; \
 		done; \
-		cp $${KDIR}/kernel-$${KVER}-i386-BOOT.config $${KDIR}/.config; \
-		cp $${KDIR}/kernel-$${KVER}-i386.config $${KDIR}/.config; \
-		cp $${KDIR}/kernel-$${KVER}-i386-smp.config $${KDIR}/.config; \
-		cp $${KDIR}/kernel-$${KVER}-i686-enterprise.config $${KDIR}/.config; \
+		if [ ! -e $${KDIR}/.config ]; then  \
+			cp ${config_file} $${KDIR}/.config; \
+		fi; \
 		make -C $${KDIR} SUBDIRS="${LOCALSUBDIRS}" COMPILE_VERSION="-DSYSTEM_TYPE_LINUX" EXTRAVERSION=-$${BVER} INSTALL_MOD_PATH=`pwd`/$${KDIR} modules; \
 		make -C $${KDIR} SUBDIRS="${LOCALSUBDIRS}" COMPILE_VERSION="-DSYSTEM_TYPE_LINUX" EXTRAVERSION=-$${BVER} INSTALL_MOD_PATH=`pwd`/$${KDIR} modules_install; \
 		for i in ${LOCALSUBDIRS}; do \
 			rm $${KDIR}/$$i ; \
 		done; \
-		rm $${KDIR}/.config; \
 		rm $${KDIR}/modules/*; \
 		rmdir $${KDIR}/modules; \
 
