##################################################################
#   Copyright  2004, Sebastian Heutling. All rights reserved.
#   $Id: Makefile,v 1.13 2004/11/05 23:07:51 basti Exp $
#
#   Descr. : Makefile for the daemon
#   Authors: Sebastian Heutling, sheutlin@gmx.de
##################################################################
TOP     :=../..
include $(TOP)/config/make.tmpl
include ../config/make.cfg
LD=$(CXX)
FILES   := \
	main \
	KeymanServer \
	ComPort \
	MsgPorts \
	misc \
	PluginThread \
	ServerKeyHandle \


EXE      := keymanserver
OBJECTS  :=$(foreach f, $(FILES), .$(f).o)
DEPENDS  := $(foreach f, $(FILES), .$(f).d)
cleanobjects=$(OBJECTS) $(DEPENDS) $(EXE) ComPort.* MsgPorts.*

INCLUDES := -I$(TOP)/server/include -I. -I$(XERCESINCLUDES)
DEFINES  := -DPLUGINDIR=\"$(PLUGINDIR)\" -DDATADIR=\"$(datadir)\"
CXXFLAGS += $(INCLUDES) $(DEFINES)
LDLIBS   := -L$(XERCESLIBS) -ldl -lstdc++ -lpthread -lxerces-c
LDFLAGS  := $(LDLIBS)
subdirs  := locale

.PHONY: all

all: $(EXE)
	@$(call multimake,$(subdirs))

#WARNINGWARNINGWARNINGWARNINGWARNINGWARNINGWARNINGWARNINGWARNING
# remove this if GNU's make is finally fixed!
#$(EXE): $(OBJECTS)
#WARNINGWARNINGWARNINGWARNINGWARNINGWARNINGWARNINGWARNINGWARNING
$(eval $(call link,$(EXE),$(OBJECTS),$(LDFLAGS)))
$(eval $(call compile_source,cpp,Makefile,$(CXXFLAGS)))
$(eval $(call build_depends,cpp,Makefile,$(CXXFLAGS)))
$(eval $(call clean,$(subdirs),$(cleanobjects)))
$(eval $(call distclean,$(subdirs),$(cleanobjects)))

############################################
$(eval $(call link_source,MsgPorts,$(TOP)/shared))
$(eval $(call link_source,ComPort,$(TOP)/shared))
############################################

install:
	@$(INSTALL) -d $(DESTDIR)$(bindir)
	@$(INSTALL) -d $(DESTDIR)/etc/keyman
	@$(INSTALL_BIN) $(EXE) $(DESTDIR)$(bindir)
	@$(INSTALL_DATA) .server $(DESTDIR)/etc/keyman/server
	@$(call multimake,$(subdirs),install)

ifeq (,$(filter clean distclean depend install,$(MAKECMDGOALS)))
-include $(DEPENDS)
endif

