include ../Makefile.conf


TARGETOBJS=SYudit.o SToolBar.o SMessageBar.o SMessageLabel.o  \
SKMapPanel.o SKMapDialog.o SHighlightD.o

TARGETDIR=
MAINOBJ=Main.o
MAIN=yudit

LOCALES=$(wildcard locale/*)

ifeq ($(SPLATFORM),WINDOWS)
TARGET=gui.lib
OBJS=$(subst .o,.obj,$(TARGETOBJS))
MAINOBJS=$(subst .o,.obj,$(MAINOBJ))
SLIBS=/libpath:../stoolkit stoolkit.lib
SWINLIBS=/libpath:../swindow  swindow.lib
SWIDGETLIBS=/libpath:../swidget swidget.lib
SGUILIBS=/libpath:../gui /subsystem:WINDOWS gui.lib 
MYLIBS=/link /subsystem:WINDOWS $(SGUILIBS) $(SWIDGETLIBS) $(SWINLIBS) $(SLIBS) $(SWINDOW_LIBS) $(ALL_LIBS)
RESOURCE=yudit.res
else
TARGET=libgui.a
OBJS=$(TARGETOBJS)
MAINOBJS=$(MAINOBJ)

SLIBS=-L../stoolkit  -lstoolkit
SWINLIBS=-L../swindow -lswindow 
SWIDGETLIBS=-L../swidget -lswidget 
SGUILIBS=-L../gui -lgui 
MYLIBS=$(SGUILIBS) $(SWIDGETLIBS) $(SWINLIBS) $(SLIBS) $(ALL_LIBS)
RESOURCE=
endif

.PHONY: messages

all: $(TARGET) $(MAIN)

$(MAIN): $(TARGET) $(MAINOBJS) $(RESOURCE)
	$(LD) -o yudit $(MAINOBJS) $(RESOURCE) $(MYLIBS)

#
# This is a windows thing
#
yudit.res:
	rc /Fo $@ yudit.rc 

gui.lib: $(OBJS)
	$(AR)$@ $(subst swin32/,,$(OBJS))

libgui.a: $(OBJS)
	$(AR) $@ $(OBJS)
	$(RANLIB) $@      

%.o:%.cpp
	$(CXX) -c $(CPPFLAGS) $(subst .o,.cpp,$@)

%.obj:%.cpp
	$(CXX) -c $(CPPFLAGS) $(subst .obj,.cpp,$@)

depend:
	$(CXX) -M  $(CPPFLAGS)  $(patsubst %.o,%.cpp,$(OBJS)) > .depend

install: 
	@for i in $(LOCALES); do \
		if test ! -d $(DESTDIR)/$(datadir)/yudit/$$i/LC_MESSAGES; then \
			mkdir -p $(DESTDIR)/$(datadir)/yudit/$$i/LC_MESSAGES; \
		fi ; \
		$(INSTALL_DATA) $$i/LC_MESSAGES/messages.[mp]o \
			$(DESTDIR)/$(datadir)/yudit/$$i/LC_MESSAGES ; \
		echo installing messages for $$i; \
	done
	rm -f $(DESTDIR)/$(bindir)/yudit
	$(INSTALL_PROGRAM) $(MAIN) $(DESTDIR)/$(bindir)

messages:
	@if [ $(MSGMERGE) != ":" ] ; then \
		echo "start translating  messages"; \
		xgettext --c++ --keyword=translate  ../swidget/*.cpp *.cpp; \
		for i in $(LOCALES); do \
			echo $$i/LC_MESSAGES/messages.po ; \
			cd $$i/LC_MESSAGES ; touch messages.po;  \
			$(MSGMERGE) --width=100 --strict \
			  messages.po ../../../messages.po > messages.pod; \
			if [ $$? != 0 ]; then \
				cd ../../..; \
				exit 1; \
			fi;  \
			mv messages.pod messages.po; \
			msgfmt -o messages.mo messages.po;  \
			cd ../../..; \
		done ; \
		echo "end translating  messages" ; \
	fi

clean: 
	rm -f *.o  *.obj *.o *.exe $(TARGET) $(MAIN)

ifeq (.depend, $(wildcard .depend))
include .depend
endif
