#############################################################
#
# directfb
#
#############################################################
DIRECTFB_VERSION_MAJOR:=1.2
DIRECTFB_VERSION=$(strip $(subst ",, $(BR2_DIRECTFB_VERSION)))
ifeq "$(DIRECTFB_VERSION)" "1.0.0"
DIRECTFB_SOURCE:=DirectFB-$(DIRECTFB_VERSION)_nxp.tar.gz
DIRECTFB_DIR:=$(BUILD_DIR)/DirectFB-$(DIRECTFB_VERSION)_nxp
FUSION_VERSION:=3.2.6
else
DIRECTFB_SOURCE:=DirectFB-$(DIRECTFB_VERSION).tar.gz
FUSION_VERSION:=8.1.1
endif
DIRECTFB_SITE:=http://www.directfb.org/downloads/Core
DIRECTFB_AUTORECONF = NO
DIRECTFB_LIBTOOL_PATCH = YES
DIRECTFB_INSTALL_STAGING = YES
DIRECTFB_INSTALL_TARGET = YES
DIRECTFB_USE_CONFIG_CACHE = NO

ifeq ($(BR2_PACKAGE_DIRECTFB_MULTI),y)
DIRECTFB_MULTI:=--enable-multi --enable-fusion
else
DIRECTFB_MULTI:=
DIRECTFB_FUSION:=
endif
ifeq ($(BR2_PACKAGE_XSERVER),y)
DIRECTFB_X:=--enable-x11
else
DIRECTFB_X:=--disable-x11
endif

#If we have enabled freetype then build with support for it.
ifeq ($(BR2_PACKAGE_FREETYPE),y)
DIRECTFB_FREETYPE:=--enable-freetype
DIRECTFB_DEP+= freetype
else
DIRECTFB_FREETYPE:=
endif

#If we have enabled sysfs then build with support for it
ifeq ($(BR2_PACKAGE_LIBSYSFS),y)
DIRECTFB_SYSFS:=--enable-sysfs
DIRECTFB_DEP+= libsysfs
else
DIRECTFB_SYSFS:=
endif

#If we have enabled zlib then build with support for it
ifeq ($(BR2_PACKAGE_ZLIB),y)
DIRECTFB_ZLIB:=--enable-zlib
DIRECTFB_DEP+= zlib
else
DIRECTFB_ZLIB:=
endif

ifeq ($(BR2_PACKAGE_DIRECTFB_UNIQUE),y)
DIRECTFB_UNIQUE:=--enable-unique
else
DIRECTFB_UNIQUE:=--disable-unique
endif

DIRECTFB_GFX:=
ifeq ($(BR2_PACKAGE_DIRECTFB_ATI128),y)
DIRECTFB_GFX+= ati128
endif
ifeq ($(BR2_PACKAGE_DIRECTFB_CLE266),y)
DIRECTFB_GFX+= cle266
endif
ifeq ($(BR2_PACKAGE_DIRECTFB_CYBER5K),y)
DIRECTFB_GFX+= cyber5k
endif
ifeq ($(BR2_PACKAGE_DIRECTFB_MATROX),y)
DIRECTFB_GFX+= matrox
endif
ifeq ($(BR2_PACKAGE_DIRECTFB_UNICHROME),y)
DIRECTFB_GFX+= unichrome
endif
ifeq ($(DIRECTFB_GFX),)
DIRECTFB_GFX:=none
else
DIRECTFB_GFX:=$(subst $(space),$(comma),$(strip $(DIRECTFB_GFX)))
endif

DIRECTFB_INPUT:=
ifeq ($(BR2_PACKAGE_DIRECTFB_LINUXINPUT),y)
DIRECTFB_INPUT+= linuxinput
endif
ifeq ($(BR2_PACKAGE_DIRECTFB_KEYBOARD),y)
DIRECTFB_INPUT+= keyboard
endif
ifeq ($(BR2_PACKAGE_DIRECTFB_PS2MOUSE),y)
DIRECTFB_INPUT+= ps2mouse
endif
ifeq ($(BR2_PACKAGE_DIRECTFB_SERIALMOUSE),y)
DIRECTFB_INPUT+= serialmouse
endif
ifeq ($(BR2_PACKAGE_DIRECTFB_TSLIB),y)
DIRECTFB_INPUT+= tslib
DIRECTFB_DEP+= tslib
endif
ifeq ($(DIRECTFB_INPUT),)
DIRECTFB_INPUT:=none
else
DIRECTFB_INPUT:=$(subst $(space),$(comma),$(strip $(DIRECTFB_INPUT)))
endif

# The following ensure dependencies are correct but we still use our own video provider.
ifeq ($(BR2_PACKAGE_DIRECTFB_GIF),y)
DIRECTFB_DEP+= libungif
endif

ifeq ($(BR2_PACKAGE_DIRECTFB_PNG),y)
DIRECTFB_DEP+= libpng
endif

ifeq ($(BR2_PACKAGE_DIRECTFB_JPEG),y)
DIRECTFB_DEP+= jpeg
endif

# For DirectFB 1.0 use our image providers.
ifeq "$(DIRECTFB_VERSION)" "1.0.0"
DIRECTFB_IMAGEPROVIDERS = \
 	--disable-jpeg \
	--disable-png \
	--disable-gif
else
# For DirectFB 1.2.x we also use our own Image Provider.
DIRECTFB_IMAGEPROVIDERS = \
 	--disable-jpeg \
	--disable-png \
	--disable-gif
endif

#For DirectFB 1.0.X we use fbdev for 1.2.X we use devmem
ifeq "$(DIRECTFB_VERSION)" "1.0.0"
DIRECTFB_SYSTEM= \
	--enable-devmem=no \
	--enable-fbdev=yes
else
DIRECTFB_SYSTEM= \
	--enable-devmem=yes \
	--enable-fbdev=no
endif

#If we have enabled debug then build with support for it.
ifeq ($(BR2_PACKAGE_DIRECTFB_DEBUG),y)
DIRECTFB_DEBUG:=--enable-debug --enable-trace
else
DIRECTFB_DEBUG:=--disable-debug
endif

DIRECTFB_CONF_OPT = \
	--localstatedir=/var \
	--with-gfxdrivers=$(DIRECTFB_GFX) \
	--with-inputdrivers=$(DIRECTFB_INPUT) \
    --with-smooth-scaling \
	--enable-shared \
	--disable-explicit-deps \
	$(DIRECTFB_MULTI) \
	$(DIRECTFB_DEBUG) \
	$(DIRECTFB_X) \
	$(DIRECTFB_IMAGEPROVIDERS) \
	$(DIRECTFB_UNIQUE) \
	--enable-linux-input \
	$(DIRECTFB_ZLIB) \
	$(DIRECTFB_FREETYPE) \
	$(DIRECTFB_SYSTEM) \
	$(DIRECTFB_SYSFS) \
	--disable-sdl \
	--disable-vnc \
	--disable-video4linux \
	--disable-video4linux2

DIRECTFB_DEPENDENCIES = uclibc $(DIRECTFB_DEP)

$(eval $(call AUTOTARGETS,package,directfb))

$(DIRECTFB_HOOK_POST_EXTRACT):
ifeq ($(BR2_PACKAGE_LINUX_FUSION),y)
	mkdir -p $(STAGINGDIR)/usr/include/linux
	tar zxfO $(DL_DIR)/linux-fusion-$(FUSION_VERSION).tar.gz \
		linux-fusion-$(FUSION_VERSION)/linux/include/linux/fusion.h > $(STAGINGDIR)/usr/include/linux/fusion.h
endif
	cp -R package/directfb/overlay$(DIRECTFB_VERSION)/* $(DIRECTFB_DIR)
	touch $@
