# src/container
#######################
BASEDIR      = $(shell cat ../../.BASEDIR)
include $(BASEDIR)/rules.mk

SUBDIR      = $(shell basename `pwd`)
INCLUDES   += -I..

QT_SRC	=	
SDL_SRC = 
X11_SRC = 
DVDREAD_SRC = DVDContainerFile.cpp
FFMPEG_SRC = ffMP4ContainerFile.cpp

ifeq ($(ENABLE_QT),no)
NOCOMP_SRC += $(QT_SRC)
else
MOC_SRC	=	$(patsubst %.hpp,moc_%.cpp, $(shell grep -l Q_OBJECT *.hpp))
SRC_CPP = $(MOC_SRC)  #if already exists, will be uniq by $(sort)
endif
ifeq ($(ENABLE_SDL),no)
NOCOMP_SRC += $(SDL_SRC)
endif
ifeq ($(ENABLE_X11),no)
NOCOMP_SRC += $(X11_SRC)
endif
ifeq ($(ENABLE_DVDREAD),no)
NOCOMP_SRC += $(DVDREAD_SRC)
endif
ifeq ($(ENABLE_FFMPEG),no)
NOCOMP_SRC += $(FFMPEG_SRC)
endif


HEADERS     = $(wildcard *.hpp) $(wildcard *.h)
SRC_CPP +=  $(filter-out $(NOCOMP_SRC),$(wildcard *.cpp))
OBJECTS_CPP = $(sort $(subst .cpp,.o,$(SRC_CPP))) #remove doubles

SRC_C       = $(wildcard *.c)
OBJECTS_C   = $(subst .c,.o,$(SRC_C))
SRC         = $(SRC_CPP) $(SRC_C)
OBJECTS     = $(OBJECTS_CPP) $(OBJECTS_C)
LIBNAME     = libvitooki-$(SUBDIR).so
LIB	        = ../.libs/$(LIBNAME)



all:  $(LIB)

Makefile: Makefile.dep

dep:    Makefile.dep

Makefile.dep:     $(SRC)
	$(GCC) $(INCLUDES) -M $+ > Makefile.dep

include Makefile.dep

$(LIB): $(OBJECTS) $(UCLLIB)
	$(CPP) $(OBJECTS) $(LDFLAGS) -o $@ -shared


doc:	$(HEADERS) $(SRC)
	kdoc -f html -d ../doc/html/ -n vitooki ../includes/*.hpp -lqt -lSDL
#	kdoc -f html -d ../doc/html/ -n vitooki -lqt -lSDL *.hpp

clean:
	rm -rf .libs *.o *~ Makefile.dep

install:
	@echo "installing ViTooKi-$(SUBDIR) lib"
	cp $(LIB) $(PREFIX)/lib/$(LIBNAME)

uninstall:
	@echo "removing ViTooKi-$(SUBDIR) lib"
	rm -f $(PREFIX)/lib/$(LIBNAME)
