# Makefile for applications/3pp/libunigf-4.1.0


### Requires these modules

#REQUIRES += link/3pp/gtk+
#REQUIRES += 3pp/libjpeg-v6b


### Component specification

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


### Tar archive

tar_archive = $(CURDIR)/libungif-4.1.0.tar.gz
src_dir     = $(CURDIR)/$(TARGET)/libungif-4.1.0
obj_dir     = $(CURDIR)/$(TARGET)/build


### Targets

BIN_TARGETS  = $(obj_dir)/imlib-config

LIB_TARGETS += $(obj_dir)/lib/.libs/libungif.so.4.1.0
LIB_TARGETS += $(obj_dir)/lib/.libs/libungif.so.4
LIB_TARGETS += $(obj_dir)/lib/.libs/libungif.so

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

INTERFACE_HEADERS += $(src_dir)/lib/gif_lib.h

INTERFACE_OMIT_SOURCE_DIR = yes

#INTERFACE_LIBS = ungif

DOC_TARGETS = $(src_dir)/COPYING
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


### 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)/ltmain.patch
	@touch $@

$(obj_dir)/Makefile: $(src_dir)/configure
	@rm -rf $(obj_dir)
	@mkdir $(obj_dir)
	@cd $(obj_dir) && \
	  $(BSG_DEVSETUP) $(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) \
	    --disable-gtktest
#ifeq ($(TARGET),$(TARGET_NAME_VIP1500))
#	@cd $(obj_dir) && patch -p1 < $(CURDIR)/libtool.patch
#	@cd $(obj_dir) && patch -p1 < $(CURDIR)/mipsel.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
