# Makefile
# This file holds the make rules for the Telephony Engine clients

# override DESTDIR at install time to prefix the install directory
DESTDIR :=

# override DEBUG at compile time to enable full debug or remove it all
DEBUG :=

CXX := @CXX@ -Wall
SED := sed
DEFS :=
MOC := @QT4_MOC@
QT4_INC := @QT4_INC@
QT4_LIB := @QT4_LIB@
QT4_INC_NET := @QT4_INC_NET@
QT4_LIB_NET := @QT4_LIB_NET@
QT4_CLIENT_DEPS := ../libyateqt4.so
QT4_CLIENT_LIBS := -lyateqt4
LIBTHR:= @THREAD_LIB@
INCLUDES := -I.. -I@top_srcdir@
CFLAGS := @CFLAGS@ @MODULE_CPPFLAGS@ @INLINE_FLAGS@
LDFLAGS:= @LDFLAGS@
YATELIBS := -L.. -lyate @LIBS@
INCFILES := @top_srcdir@/yatengine.h @top_srcdir@/yatephone.h ../yateversn.h

MKDEPS  := ../config.status
SUBDIRS :=
PROGS :=
LIBS :=
MENUFILES :=
DESKFILES :=

ifneq (@HAVE_QT4@,no)
SUBDIRS := $(SUBDIRS) qt4
PROGS := $(PROGS) yate-qt4
MENUFILES := $(MENUFILES) yate-qt4.menu
DESKFILES := $(DESKFILES) yate-qt4.desktop
ICONFILES := $(ICONFILES) null_team-16.png null_team-32.png null_team-48.png

ifneq (@QT4_STATIC_MODULES@,no)
ifeq (@QT4_STATIC_MODULES@,yes)
QT4_CLIENT_LIBS := customtable customtext customtree widgetlist clientarchive
else
QT4_CLIENT_LIBS := $(strip @QT4_STATIC_MODULES@)
endif
QT4_CLIENT_LIBS := $(foreach mod,$(QT4_CLIENT_LIBS),../modules/qt4/$(mod).o) qt4/qt4client.a
QT4_CLIENT_DEPS := $(QT4_CLIENT_LIBS)
endif

endif

LOCALFLAGS =
LOCALLIBS =
COMPILE = $(CXX) $(DEFS) $(DEBUG) $(INCLUDES) $(CFLAGS)
LINK = $(CXX) $(LDFLAGS)

ifneq (x@QT4_VER@,x)
DEFS := $(DEFS) -DQT4_VER=@QT4_VER@
endif

prefix = @prefix@
exec_prefix = @exec_prefix@
datarootdir = @datarootdir@
datadir = @datadir@

bindir = @bindir@
menudir= $(prefix)/lib/menu
shrdir = $(datadir)/yate
deskdir= $(datadir)/applications
icondir= $(datadir)/pixmaps

# include optional local make rules
-include YateLocal.mak

.PHONY: all
all: do-all $(LIBS) $(PROGS)

.PHONY: strip
strip: all do-strip
	strip --strip-debug --discard-locals $(PROGS)

.PHONY: clean
clean: do-clean
	@-$(RM) $(PROGS) $(LIBS) *.o core 2>/dev/null

.PHONY: install
install: all do-install
	@mkdir -p "$(DESTDIR)$(bindir)/" && \
	test -z "$(PROGS)" || \
	install $(PROGS) "$(DESTDIR)$(bindir)/"
	$(if $(MENUFILES),\
	@mkdir -p "$(DESTDIR)$(menudir)/" && \
	for i in $(MENUFILES) ; do \
	    @INSTALL_D@ -m 0644 "@srcdir@/$$i" "$(DESTDIR)$(menudir)/$$i" ; \
	done \
	)
	$(if $(ICONFILES),\
	@mkdir -p "$(DESTDIR)$(icondir)/" && \
	for i in $(ICONFILES) ; do \
	    @INSTALL_D@ -m 0644 "@srcdir@/$$i" "$(DESTDIR)$(icondir)/$$i" ; \
	done \
	)
	$(if $(DESKFILES),\
	@mkdir -p "$(DESTDIR)$(deskdir)/" && \
	for i in $(DESKFILES) ; do \
	    @INSTALL_D@ -m 0644 "@srcdir@/$$i" "$(DESTDIR)$(deskdir)/$$i" ; \
	done \
	)

.PHONY: uninstall
uninstall: do-uninstall
	@-for i in $(PROGS) ; do \
	    rm "$(DESTDIR)$(bindir)/$$i" ; \
	done
	@-rmdir "$(DESTDIR)$(bindir)"
	$(if $(MENUFILES),\
	@-for i in $(MENUFILES) ; do \
	    rm "$(DESTDIR)$(menudir)/$$i" ; \
	done ; \
	rmdir "$(DESTDIR)$(menudir)" \
	)
	$(if $(DESKFILES),\
	@-for i in $(DESKFILES) ; do \
	    rm "$(DESTDIR)$(deskdir)/$$i" ; \
	done ; \
	rmdir "$(DESTDIR)$(deskdir)" \
	)
	$(if $(ICONFILES),\
	@-for i in $(ICONFILES) ; do \
	    rm "$(DESTDIR)$(icondir)/$$i" ; \
	done ; \
	rmdir "$(DESTDIR)$(icondir)" \
	)

../modules/qt4/%.o: @top_srcdir@/modules/qt4/%.cpp
	$(MAKE) -C ../modules qt4/$(notdir $@)

%.o: @srcdir@/%.cpp $(MKDEPS) $(INCFILES)
	$(COMPILE) -c $<

%.moc.o: %.moc $(INCFILES)
	$(COMPILE) $(QT4_INC) -o $@ -c -x c++ $<

%.moc: @srcdir@/%.h
	$(MOC) $(DEFS) $(INCLUDES) $(QT4_INC) -o $@ $<

do-all do-strip do-clean do-install do-uninstall:
	$(if $(SUBDIRS),\
	@target=`echo $@ | $(SED) -e 's/^do-//'`; \
	for i in $(SUBDIRS) ; do \
	    if test -f ./$$i/Makefile ; then \
		$(MAKE) -C ./$$i $${target} || exit 1;\
	    fi; \
	done \
	)

Makefile: @srcdir@/Makefile.in $(MKDEPS)
	cd .. && ./config.status

yate-qt4: $(QT4_CLIENT_DEPS)
yate-qt4: LOCALFLAGS = $(QT4_INC)
yate-qt4: LOCALLIBS = $(QT4_CLIENT_LIBS) $(QT4_LIB)

qt4/qt4client.a: @srcdir@/qt4/qt4client.h @srcdir@/qt4/qt4client.cpp
	$(MAKE) -C qt4 $(notdir $@)

yate-%: @srcdir@/main-%.cpp $(MKDEPS) ../libyate.so $(INCFILES)
	$(COMPILE) -o $@ $(LOCALFLAGS) $< $(LDFLAGS) $(LIBTHR) $(LOCALLIBS) $(YATELIBS)
