
DEFINE_KERNEL_SOURCE	= yes
include			../../Makefile.top

LV			:= $(shell test -f $(KERNEL_SOURCE)/Rules.make && echo 24 || echo 26)
MP			:= $(shell test -f $(KERNEL_SOURCE)/Rules.make && echo "o" || echo "ko")
MOD_DEST		= $(top_srcdir)/mollib/modules/`cat build/.kuname`

KILL_WARNING_26		= 2>&1 | sed -e '/\*\*\*.*SUBDIRS/ d' \
				     -e '/\*\*\*.*inconsistencies/ d' \
				     -e '/scripts\/Makefile.*complain if/ d' 1>&2

setup-tree-common:
	@test -d build || mkdir build
	@ln -sf ../kuname.c ../sheep.c build
	@ln -sf ../Makefile.$(LV) build/Makefile

setup-tree-26: setup-tree-common
	@for x in tun.c ethertap.c ; do \
		ln -sf $(KERNEL_SOURCE)/drivers/net/$$x build/ || exit 1 ; \
	done

setup-tree-24: setup-tree-common
	@for x in tun.c ethertap.c if_tun.h ; do \
		ln -sf ../$$x build/ || exit 1 ; \
	done

# The ethertap and tun driver is 2.4 only. Unfortunately, it is difficult to 
# do a conditional build based upon the kuname result since kuname
# is dynamically generated. We hack around this by building empty
# modules and by deleting them in the all-local target.

all-local: setup-tree-$(LV)
	@$(MAKE) --no-print-directory -C $(KERNEL_SOURCE) "SUBDIRS=$$PWD/build" \
		BUILD_SHEEP=$(CONFIG_SHEEP:y=m) BUILD_TAP=$(CONFIG_TAP:y=m) \
		BUILD_TUN=$(CONFIG_TUN:y=m) \
		modules $(KILL_WARNING_$(LV))
	@for x in tun ethertap sheep ; do \
		[ -f build/$$x.$(MP) ] || continue ; \
		$(NM) build/$$x.$(MP) | grep -q init_module || continue ; \
		ln -f build/$$x.$(MP) $(MOD_DEST)/ || exit 1 ; \
	done

#@$(STRIP) -g $(MOD_DEST)/$$x.$(MP)


clean-local:
	@rm -rf build

include		$(top_srcdir)/Rules.make
