#
#                             IPSTB Project
#                   ---------------------------------
#
# Copyright (C) 2009 NXP B.V.,
# All Rights Reserved.
#
# Filename: linux-fusion/Makefile
#
#
# Rev Date        Author      Comments
#-------------------------------------------------------------------------------
#   1 12072005    laird       Initial Version
#   2 20050718    batelaan    Rename untarsrc->untar and installsrc to install
#   3 20050721    batelaan    Ensure dirs exists before cp'ing to them.
#   4 20051010    charrett    Solve dependency issue
#   5 20051027    laird       Changed to linux-fusion
#   6 20060525    laird       Changed to the new version (3.0)
#   7 20061101    neill       Changed fusion major number to 255
#   8 20070110    steel       updated for linux_VARIANT support
#   9 20070523    batelaan    Update version to 3.2.3 to be consistent with buildroot 1.0 directfb.
#  10 20071220    laird       Add support for DirectFB version switching.
#  11 20080214    batelaan    Improve dependencies for linux-fusion.install
#  12 20080305    batelaan    Don't run find on non-existent directory.
#  13 20080310    laird       Upgrade version to 3.2.4
#  14 20080310    laird       Revert to 3.2.3
#  15 20080311    laird       Dont build by default (still available if people want it).
#  16 20080717    laird       Use CONFIG_DIRECTFB_VERSION_1_2_X variable instead of directfb_VERSION.
#  17 20090420    laird       Bounce versions.
#  xx 20091015    amccurdy    Force KERNEL_VERSION when calling linux-fusion Makefile
#  xx 20091016    amccurdy    Enable building if CONFIG_DIRECTFB_MULTIAPP option is set
#  xx 20091028    amccurdy    Remove udev rules, mkdir $(STAGINGDIR)/usr/include before copying fusion.h

# File: linux-fusion/Makefile
# Makefile to control building of fusion (multi application core for Direct FB package).

# Always needed at the start:
include $(PRJROOT)/etc/first.mk

# Skip build if CONFIG_DIRECTFB_MULTIAPP is not set
linux-fusion_SKIPBUILD = $(if $(CONFIG_DIRECTFB_MULTIAPP),,true)

$(eval $(PKG_START))

# Define what the package and version is:
PKG=linux-fusion
ifeq "$(CONFIG_DIRECTFB_VERSION_1_2_X)" "y"
linux-fusion_VERSION=8.1.1
else
linux-fusion_VERSION=3.2.6
endif

$(eval $(PKG_SETUP_VARS))
make_PREDECESSOR = patch

$(call PKG_DEFINE_TARGETS,help clean untar patch make)
make_PREDECESSOR = $(make_STDPREDECESSOR)

$(call OBJ_TARGET_OTHER_DEPS, linux-fusion.make, $(MODULE_INSTALLDIR))

$(MODULE_INSTALLDIR):
	mkdir -p $@

# Define: linux-fusion_KERNEL_VERSION
# e.g. 2.6.24.7_nxp
#
linux-fusion_KERNEL_VERSION = $(shell echo "$${KSRC\#\#*/linux-}")

# Define: linux-fusion.install_CMDS
#
# Fixme: mkdir of $(STAGINGDIR)/usr/include before copying header file is
#        a temporary hack. Better solution would be to fix dependencies so
#        that the dir is always created before before install_CMDS is run.
#
define linux-fusion.install_CMDS
	@echo '  INSTALL fusion module -> $(MODULE_INSTALLDIR)'
	$(Q)mkdir -p $(MODULE_INSTALLDIR)
	$(Q)cp -f $(linux-fusion_BUILDDIR)/linux/drivers/char/fusion/fusion.ko $(MODULE_INSTALLDIR)/
	@echo '  INSTALL fusion include files'
	mkdir -p $(STAGINGDIR)/usr/include
	rsync -ra $(linux-fusion_BUILDDIR)/linux/include/ $(STAGINGDIR)/usr/include
endef

$(call PKG_TARGET, linux-fusion.install, linux-fusion.$(install_PREDECESSOR))

ifneq "$(wildcard $(linux-fusion_BUILDDIR)/linux/include)" ""
  $(call OBJ_TARGET_OTHER_DEPS, linux-fusion.install, \
    $(shell find $(linux-fusion_BUILDDIR)/linux/include/))
endif

linux-fusion_DEFMAKEOPTS = \
	$(linux_DEFMAKEOPTS) \
	KERNEL_VERSION=$(linux-fusion_KERNEL_VERSION) \
	KERNEL_MODLIB=$(MODULE_INSTALLDIR) \
	KERNEL_SOURCE=$(KSRC) \
	KERNEL_BUILD=$(KSRC) \
	"CPPFLAGS+=-DFUSION_MAJOR=255"

linux-fusion_DEFINSTALLOPTS = \
	KERNEL_VERSION=$(linux-fusion_KERNEL_VERSION) \
	KERNEL_MODLIB=$(MODULE_INSTALLDIR) \
	KERNEL_SOURCE=$(KSRC) \
	KERNEL_BUILD=$(KSRC)

# When the Linux kernel is patched, $(KSRC) contents changes,
# so we trigger linux-fusion.make again:
$(call OBJ_TARGET_DEPS, linux-fusion.make, linux.patch)

# # We need some kind of dependency here... but buildroot.install isn't it...
# $(call OBJ_TARGET_DEPS, linux-fusion.make, buildroot.install)

# Always needed at the end:
$(eval $(PKG_END))
include $(PRJROOT)/etc/last.mk

