#
#                             IPSTB Project
#                   ---------------------------------
#
# Copyright (C) 2007 NXP B.V.,
# All Rights Reserved.
#
# Filename: phStbDFB/directfb_libinstall.mk
#
#
# Rev Date       Author      Comments
#-------------------------------------------------------------------------------
#   1 20070118   batelaan    Initial
#   2 20070118   batelaan    Don't add install as dependency to all, it's too early.
#   3 20070502   burningh    Update for DirectFB 1.0
#   4 20070903   batelaan    Only determine DIRECTFB_MODULEDIR if needed
#                            (prevent unneccessary error on cleaning).
#                            Clean target should rm installed shared object file.
#   5 20070921   batelaan    Rename install to install_lib target
#   6 20080528   laird       Move to /usr/ not /usr/local.
#   7 20080709   batelaan    Don't re-install files.

# TODO: should use pkg-config program for this:
DIRECTFB_INTERNAL_PC_FILE = $(STAGINGDIR)/usr/lib/pkgconfig/directfb-internal.pc
DIRECTFB_MODULEDIR := $(shell perl -n -e 'print if s/^moduledirname=//;' $(DIRECTFB_INTERNAL_PC_FILE) /dev/null)

_SDE_NO_DEFAULT_INSTALL=true

SO_INSTALL_DIR := $(ROOTFS)/usr/lib/$(DIRECTFB_MODULEDIR)/$(DIRECTFB_INSTALL_SUBDIR)
STAGING_SO_INSTALL_DIR := $(STAGINGDIR)/usr/lib/$(DIRECTFB_MODULEDIR)/$(DIRECTFB_INSTALL_SUBDIR)

ifneq "$(MAKECMDGOALS)" "clean"
  ifeq "$(wildcard $(DIRECTFB_INTERNAL_PC_FILE))" ""
    $(error Cannot determine directfb moduledirname (no such file: $(DIRECTFB_INTERNAL_PC_FILE)))
  endif
  ifeq "$(DIRECTFB_MODULEDIR)" ""
    $(error Cannot determine directfb moduledirname (moduledirname missing in $(DIRECTFB_INTERNAL_PC_FILE)))
  endif
endif

install: install_lib_dll
INSTALLED_DLL = $(SO_INSTALL_DIR)/$(_SDE_DLLTARGETNAME)
install_lib_dll:
	$(if $(shell cmp $(_SDE_THISDLL_ACTUAL) $(INSTALLED_DLL) 2>&1),\
		$(eval _sde_dll_needs_install:=true)\
		$(eval _sde_dll_version_used:=$(if $(filter $(_SDE_THISDLL),$(_SDE_THISDLL_ACTUAL)),built,pre-built)))
	$(if $(_sde_dll_needs_install),@echo '  INSTALL ($(_sde_dll_version_used)) $(notdir $(_SDE_THISDLL_ACTUAL)) -> $(INSTALLED_DLL)')
	$(if $(_sde_dll_needs_install),$(_SDE_ECHO)mkdir -p $(dir $(INSTALLED_DLL)))
	$(if $(_sde_dll_needs_install),$(_SDE_ECHO)cp -Lf $(_SDE_THISDLL_ACTUAL) $(INSTALLED_DLL))
	$(if $(_sde_dll_needs_install),$(_SDE_ECHO)chmod 0755 $(INSTALLED_DLL))
.PHONY: install_lib_dll

# We want to install the library in staging too so that the debugger can find the unstripped version even 
# when we've stripped the one in rootfs. MAC 2010/03/02
install : install_staging_lib_dll
STAGING_INSTALLED_DLL = $(STAGING_SO_INSTALL_DIR)/$(_SDE_DLLTARGETNAME)
install_staging_lib_dll:
	$(if $(shell cmp $(_SDE_THISDLL_ACTUAL) $(STAGING_INSTALLED_DLL) 2>&1),\
		$(eval _sde_staging_dll_needs_install:=true)\
		$(eval _sde_staging_dll_version_used:=$(if $(filter $(_SDE_THISDLL),$(_SDE_THISDLL_ACTUAL)),built,pre-built)))
	$(if $(_sde_staging_dll_needs_install),@echo '  INSTALL ($(_sde_staging_dll_version_used)) $(notdir $(_SDE_THISDLL_ACTUAL)) -> $(STAGING_INSTALLED_DLL)')
	$(if $(_sde_staging_dll_needs_install),$(_SDE_ECHO)mkdir -p $(dir $(STAGING_INSTALLED_DLL)))
	$(if $(_sde_staging_dll_needs_install),$(_SDE_ECHO)cp -Lf $(_SDE_THISDLL_ACTUAL) $(STAGING_INSTALLED_DLL))
	$(if $(_sde_dll_needs_install),$(_SDE_ECHO)chmod 0755 $(STAGING_INSTALLED_DLL))
.PHONY: install_staging_lib_dll
clean::
	$(_SDE_ECHO)rm -f $(INSTALLED_DLL)
