.PHONY: all clean install

ifndef BUILDDIR
BUILDDIR := $(realpath ..)
endif

include $(BUILDDIR)/common.mk

KERNEL := $(build_kernel_version)
ifneq ($(MAKECMDGOALS),clean)
ifndef PRODUCT
$(error PRODUCT is not defined!)
endif
else
ifneq ($(PRODUCT),px2)
KERNEL := linux-kernel-2.4
else
KERNEL := linux-kernel-rtl-2.4
endif
endif

ifeq ($(KERNEL),)
$(error build_kernel_version is not defined!)
endif

all:
	rm -f $(KERNEL)/.config
	cp -f $(PRODUCT_KERNEL_CFG) $(KERNEL)/.config
	make -C $(KERNEL) oldconfig
	make -C $(KERNEL) depend
	make -C $(KERNEL) vmlinux
	cp $(KERNEL)/vmlinux $(KERNEL)/vmlinux.notstripped
	make -C $(KERNEL) bzImage
	make -C $(KERNEL) modules

install: all
	INSTALL_MOD_PATH=${build_install_directory} make -C $(KERNEL) modules_install

clean:
	rm -f $(KERNEL)/vmlinux.notstripped
	make -C $(KERNEL) clean || echo "Ignoring errors!"

