#CROSS_COMPILE	:= $(ARM_TOOLCHAIN_PREFIX)-
#ARCH		:= arm

INSTALL_PATH		:= $(MAKETOP)/boot
INSTALL_MOD_PATH	:= $(MAKETOP)
INSTALL_HDR_PATH	:= $(MAKETOP)/usr
INSTALL_MOD_STRIP	:="--strip-unneeded -R .GCC-command-line"

MKIMAGE			:= $(PLATFORM)/tools/bin/mkuboot.sh

ifeq ($(MAKETOP), )
maketop_err = $(error Please set MAKETOP)
$(call maketop_err)
endif

MFLAGS		+= ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) INSTALL_PATH=$(INSTALL_PATH) INSTALL_MOD_PATH=$(INSTALL_MOD_PATH) INSTALL_MOD_STRIP=$(INSTALL_MOD_STRIP) INSTALL_HDR_PATH=$(INSTALL_HDR_PATH)
ifneq (, $(wildcard $(MKIMAGE)))
MFLAGS		+= MKIMAGE=$(MKIMAGE)
endif

.PHONY: _all
_all:
#	$(MAKE) -f Makefile $(MFLAGS) uImage
	$(MAKE) -f Makefile $(MFLAGS) all HOST_EXTRACFLAGS=-DKBUILD_NO_NLS
	$(MAKE) -f Makefile $(MFLAGS) modules_install
	$(MAKE) -f Makefile $(MFLAGS) headers_install ARCH=arm
	install -c -m 0755 -d $(INSTALL_PATH)
	install -c -m 0755 arch/$(ARCH)/boot/Image $(INSTALL_PATH)/vmlinux
	install -c -m 0755 arch/$(ARCH)/boot/Image $(INSTALL_PATH)/Image
	install -c -m 0755 arch/$(ARCH)/boot/Image.gz $(INSTALL_PATH)/Image.gz
	install -c -m 0755 arch/$(ARCH)/boot/dts/socionext/uniphier-pxs3-ref.dtb $(INSTALL_PATH)/uniphier-pxs3-ref.dtb
#	install -c -m 0755 arch/$(ARCH)/boot/zImage $(INSTALL_PATH)/vmlinuz
#	install -c -m 0755 arch/$(ARCH)/boot/uImage $(INSTALL_PATH)/uImage

.config: arch/$(ARCH)/configs/defconfig
	$(MAKE) -f Makefile $(MFLAGS) defconfig

install: .config
#	$(MAKE) -f Makefile $(MFLAGS) uinstall
	$(MAKE) -f Makefile $(MFLAGS) all
	install -c -m 0755 -d $(INSTALL_PATH)
	install -c -m 0755 arch/$(ARCH)/boot/Image $(INSTALL_PATH)/vmlinux
	install -c -m 0755 arch/$(ARCH)/boot/Image $(INSTALL_PATH)/Image
	install -c -m 0755 arch/$(ARCH)/boot/Image.gz $(INSTALL_PATH)/Image.gz
	install -c -m 0755 arch/$(ARCH)/boot/dts/socionext/uniphier-pxs3-ref.dtb $(INSTALL_PATH)/uniphier-pxs3-ref.dtb
	$(MAKE) -f Makefile $(MFLAGS) modules
	$(MAKE) -f Makefile $(MFLAGS) modules_install
	$(MAKE) -f Makefile $(MFLAGS) headers_install ARCH=arm


install32: .config
#	$(MAKE) -f Makefile $(MFLAGS) headers_install
#	install -c -m 0644 -D ./include/generated/autoconf.h ${MAKETOP}/usr/include/generated/autoconf.h
#	install -c -m 0644 -D ./include/linux/autoconf.h ${MAKETOP}/usr/include/linux/autoconf.h
#	install -c -m 0755 -d $(INSTALL_PATH)
#	install -c -m 0644 -D .config $(INSTALL_PATH)/kernelconfig

install_headers: .config
	$(MAKE) -f Makefile $(MFLAGS) headers_install

GNUmakefile: ;

%:: FORCE
	$(MAKE) -f Makefile $(MFLAGS) $@

FORCE:
