# Makefile for applications/3pp/imlib-1.9.14


### Requires these modules

REQUIRES += link/3pp/gtk+
REQUIRES += applications/3pp/libpng-1.2.8
REQUIRES += hal/3pp/libjpeg-v6b
REQUIRES += applications/3pp/libungif-4.1.0


### Component specification

COMPONENT_TARGETS = $(TARGET_NAME_VIP)
COMPONENT_IS_3PP = true
NEEDS_ABS_PATHS = true


### Tar archive

tar_archive = $(CURDIR)/imlib-1.9.14.tar.gz
src_dir     = $(CURDIR)/$(TARGET)/imlib-1.9.14
obj_dir     = $(TARGET)/build


### Targets

BIN_TARGETS  = $(obj_dir)/imlib-config

LIB_TARGETS += $(obj_dir)/gdk_imlib/.libs/libgdk_imlib.so.1.9.14
LIB_TARGETS += $(obj_dir)/gdk_imlib/.libs/libgdk_imlib.so.1
LIB_TARGETS += $(obj_dir)/gdk_imlib/.libs/libgdk_imlib.so

# library files for specific image formats
LIB_TARGETS += $(obj_dir)/gdk_imlib/.libs/libimlib-png.so

INTERFACE_HEADERS += $(src_dir)/gdk_imlib/gdk_imlib.h
INTERFACE_HEADERS += $(src_dir)/gdk_imlib/gdk_imlib_types.h

INTERFACE_OMIT_SOURCE_DIR = yes

INTERFACE_LIBS = gdk_imlib

DOC_TARGETS = $(src_dir)/COPYING
DOC_TARGETS += $(src_dir)/COPYING.LIB
DOC_TARGETS += $(src_dir)/AUTHORS
DOC_OMIT_SOURCE_DIR = yes
DOC_PATH = ../../doc/doc


### Extra cleanup

CLEANUP_FILES += $(src_dir) $(obj_dir)


### Common.mk

include ../../../makesystem/common.mk

# Needs to find the dist:ed glib-config, not the host version.
ifneq ($(TARGET),)
PATH := $(PATH):$(TARGET_3PP_DIST_DIR)/bin
endif


### Dependencies

# A few words of wisdom: 
# The configure script creates a libtool script. However, there seems to be a
# bug in the configure script, since the file is created in the output dir,
# and is then read from the src dir. This is fixed by a small sed hack.
#
# Don't change this unless you know what you're doing, and beware that
# the lib will still be built without errors even when the path is set
# wrong (except for a quiet "no such file or directory" error during
# run of configure. You have to look closely to even see it...  The
# error then only occurs in runtime when GTK applications try to load
# images.
$(src_dir)/configure: $(tar_archive)
	@echo "Expanding $<"
	@mkdir -p $(TARGET)
	@cd $(TARGET) && tar xfz $<
	@sed -e "s/\$$srcdir\/libtool/libtool/" $(src_dir)/configure > \
		$(src_dir)/configure_new
	@mv -f $(src_dir)/configure_new $(src_dir)/configure
	@chmod a+x $(src_dir)/configure
	@cd $(src_dir) && patch -p1 < $(CURDIR)/configure.patch
	@cd $(src_dir) && patch -p1 < $(CURDIR)/no_tiff.patch
	@touch $@

$(obj_dir)/Makefile: $(src_dir)/configure
	@rm -rf $(obj_dir)
	@mkdir $(obj_dir)
	@cd $(obj_dir) && \
	  $(BSG_DEVSETUP) GDK_IMLIB="libgdk.so" $(src_dir)/configure \
	    --prefix=/usr \
	    --build=$(ARCH_BUILD) \
	    --host=$(ARCH_BUILD) \
	    --target=$(TARGET_ARCH) \
	    --x-includes=$(TARGET_3PP_DIST_DIR)/include \
	    --x-libraries=$(TARGET_3PP_DIST_DIR)/lib \
	    --with-gnu-ld \
	    --with-gtk-prefix=$(TARGET_3PP_DIST_DIR) \
	    --with-gtk-exec-prefix=$(TARGET_3PP_DIST_DIR) \
	    --disable-gtktest
ifneq ($(TARGET),$(TARGET_NAME_VIP500))
	@cd $(obj_dir) && patch -p1 < $(CURDIR)/libtool.patch
endif
	@touch $(obj_dir)/Makefile

$(LIB_TARGETS): $(obj_dir)/Makefile
	$(BSG_DEVSETUP) $(MAKE) -C $(obj_dir)

$(INTERFACE_HEADERS): $(LIB_TARGETS)

$(BIN_TARGETS): $(LIB_TARGETS)
	@touch $(obj_dir)/imlib-config
