include Makefile.conf

SUBDIRS=stoolkit swindow mytool swidget uniconv uniprint gui addon

SUBDIRS_all:=$(foreach dir, $(SUBDIRS), $(dir)_all)
SUBDIRS_clean:=$(foreach dir, $(SUBDIRS), $(dir)_clean)

.PHONY: all $(SUBDIRS_all) $(SUBDIRS_clean)

all: $(SUBDIRS_all)
	@echo "M----------------------------------------------------"
	@echo "Everything is made. You can type 'make install' now."
	@echo "M----------------------------------------------------"

gui_all: swidget_all swindow_all stoolkit_all addon_all

uniprint_all: swidget_all swindow_all stoolkit_all

uniconv_all: stoolkit_all

mytool_all: swindow_all stoolkit_all

$(SUBDIRS_all):
	$(MAKE) -C $(patsubst %_all,%,$@) all

$(SUBDIRS_clean):
	$(MAKE) -C $(patsubst %_clean,%,$@) clean

clean: $(SUBDIRS_clean)
	rm -f core */core */*/core
	rm -rf SunWS_cache */SunWS_cache */*/SunWS_cache
	rm -f *.pdb */*.pdb */*/*.pdb
	rm -f *.ilk */*.ilk */*/*.ilk
	rm -f *.opt */*.opt */*/*.opt
	rm -f */*.lib */*/*.lib


veryclean: clean
	rm -f */.depend  
	rm -f config.cache config.log config.status
	rm -rf autom4te.cache
	rm -f Makefile  
	rm -rf target  
	rm -rf ./macos/Yudit.app

distclean: veryclean
	$(MAKE) -C addon distclean

depend:
	@for i in $(SUBDIRS); do \
		cd $$i ; $(MAKE) depend; \
		if [ $$? != 0 ]; then \
			cd ..; \
			exit 1; \
		fi;  \
		cd ..; \
	done

install:
	@if test ! -d $(DESTDIR)/$(prefix) ;then mkdir -p $(DESTDIR)/$(prefix); fi
	@if test ! -d $(DESTDIR)/$(bindir) ;then mkdir -p $(DESTDIR)/$(bindir); fi
	@if test ! -d $(DESTDIR)/$(mandir); then mkdir -p $(DESTDIR)/$(mandir);fi
	@if test ! -d $(DESTDIR)/$(mandir)/man1; then mkdir -p $(DESTDIR)/$(mandir)/man1;fi
	@if test ! -d $(DESTDIR)/$(datadir) ; then mkdir -p $(DESTDIR)/$(datadir);fi
	@if test ! -d $(DESTDIR)/$(datadir)/yudit ; then mkdir -p $(DESTDIR)/$(datadir)/yudit;fi
	@if test ! -d $(DESTDIR)/$(datadir)/yudit/data ;then mkdir -p $(DESTDIR)/$(datadir)/yudit/data;fi
	@if test ! -d $(DESTDIR)/$(datadir)/yudit/config ;then mkdir -p $(DESTDIR)/$(datadir)/yudit/config;fi
	@if test ! -d $(DESTDIR)/$(datadir)/yudit/fonts ;then mkdir -p $(DESTDIR)/$(datadir)/yudit/fonts;fi
	@if test ! -d $(DESTDIR)/$(datadir)/yudit/syntax ;then mkdir -p $(DESTDIR)/$(datadir)/yudit/syntax;fi
	@if test ! -d $(DESTDIR)/$(datadir)/yudit/locale;then mkdir -p $(DESTDIR)/$(datadir)/yudit/locale;fi
	@if test ! -d $(DESTDIR)/$(datadir)/yudit/src;then mkdir -p $(DESTDIR)/$(datadir)/yudit/src;fi
	@if test ! -d $(DESTDIR)/$(datadir)/yudit/doc;then mkdir -p $(DESTDIR)/$(datadir)/yudit/doc;fi
	@if test ! -d $(DESTDIR)/$(datadir)/yudit/doc/cs;then mkdir -p $(DESTDIR)/$(datadir)/yudit/doc/cs;fi
	@if test ! -d $(DESTDIR)/$(datadir)/yudit/doc/de;then mkdir -p $(DESTDIR)/$(datadir)/yudit/doc/de;fi
	@if test ! -d $(DESTDIR)/$(datadir)/yudit/doc/bg;then mkdir -p $(DESTDIR)/$(datadir)/yudit/doc/bg;fi
	@if test ! -d $(DESTDIR)/$(datadir)/yudit/doc/ja;then mkdir -p $(DESTDIR)/$(datadir)/yudit/doc/ja;fi
	@if test ! -d $(DESTDIR)/$(datadir)/yudit/doc/hu;then mkdir -p $(DESTDIR)/$(datadir)/yudit/doc/hu;fi
	@if test ! -d $(DESTDIR)/$(datadir)/yudit/doc/ko;then mkdir -p $(DESTDIR)/$(datadir)/yudit/doc/ko;fi
	@if test ! -d $(DESTDIR)/$(datadir)/yudit/doc/yi;then mkdir -p $(DESTDIR)/$(datadir)/yudit/doc/yi;fi
	@if test ! -d $(DESTDIR)/$(datadir)/yudit/doc/es;then mkdir -p $(DESTDIR)/$(datadir)/yudit/doc/es;fi
	@if test ! -d $(DESTDIR)/$(datadir)/yudit/doc/fi;then mkdir -p $(DESTDIR)/$(datadir)/yudit/doc/fi;fi
	@if test ! -d $(DESTDIR)/$(datadir)/yudit/doc/vi;then mkdir -p $(DESTDIR)/$(datadir)/yudit/doc/vi;fi
	@if test ! -d $(DESTDIR)/$(datadir)/yudit/doc/zh;then mkdir -p $(DESTDIR)/$(datadir)/yudit/doc/zh;fi
	@for i in $(SUBDIRS); do \
		cd $$i ; $(MAKE) install; \
		if [ $$? != 0 ]; then \
			cd ..; \
			exit 1; \
		fi;  \
		cd ..; \
	done
	$(INSTALL_DATA) gnome-yudit.png $(DESTDIR)/$(datadir)/yudit/data
	$(INSTALL_DATA) yudit.properties $(DESTDIR)/$(datadir)/yudit/config
	$(INSTALL_DATA) doc/FAQ.TXT $(DESTDIR)/$(datadir)/yudit/doc
	$(INSTALL_DATA) doc/cs/COPYING-DOCS $(DESTDIR)/$(datadir)/yudit/doc/cs/COPYING-DOCS
	$(INSTALL_DATA) doc/cs/FAQ.TXT $(DESTDIR)/$(datadir)/yudit/doc/cs/FAQ.TXT
	$(INSTALL_DATA) doc/cs/HOWTO-configure.txt $(DESTDIR)/$(datadir)/yudit/doc/cs/HOWTO-configure.txt
	$(INSTALL_DATA) doc/cs/HOWTO-keymap.txt $(DESTDIR)/$(datadir)/yudit/doc/cs/HOWTO-keymap.txt
	$(INSTALL_DATA) doc/cs/HOWTO-windows.txt $(DESTDIR)/$(datadir)/yudit/doc/cs/HOWTO-windows.txt
	$(INSTALL_DATA) doc/cs/CHANGELOG-DOCS.TXT $(DESTDIR)/$(datadir)/yudit/doc/cs/CHANGELOG-DOCS.TXT
	$(INSTALL_DATA) doc/cs/README-DOCS.TXT $(DESTDIR)/$(datadir)/yudit/doc/cs/README-DOCS.TXT
	$(INSTALL_DATA) doc/cs/TODO-DOCS.TXT $(DESTDIR)/$(datadir)/yudit/doc/cs/TODO-DOCS.TXT
	$(INSTALL_DATA) doc/de/FAQ.TXT $(DESTDIR)/$(datadir)/yudit/doc/de/FAQ.TXT
	$(INSTALL_DATA) doc/ja/FAQ.TXT $(DESTDIR)/$(datadir)/yudit/doc/ja/FAQ.TXT
	$(INSTALL_DATA) doc/hu/FAQ.TXT $(DESTDIR)/$(datadir)/yudit/doc/hu/FAQ.TXT
	$(INSTALL_DATA) doc/ko/FAQ.TXT $(DESTDIR)/$(datadir)/yudit/doc/ko/FAQ.TXT
	$(INSTALL_DATA) doc/yi/FAQ.TXT $(DESTDIR)/$(datadir)/yudit/doc/yi/FAQ.TXT
	$(INSTALL_DATA) doc/es/FAQ.TXT $(DESTDIR)/$(datadir)/yudit/doc/es/FAQ.TXT
	$(INSTALL_DATA) doc/fi/FAQ.TXT $(DESTDIR)/$(datadir)/yudit/doc/fi/FAQ.TXT
	$(INSTALL_DATA) doc/ru/FAQ.TXT $(DESTDIR)/$(datadir)/yudit/doc/ru/FAQ.TXT
	$(INSTALL_DATA) doc/zh/FAQ.TXT $(DESTDIR)/$(datadir)/yudit/doc/zh/FAQ.TXT
	$(INSTALL_DATA) doc/vi/FAQ.TXT $(DESTDIR)/$(datadir)/yudit/doc/vi/FAQ.TXT
	$(INSTALL_DATA) doc/bg/FAQ.TXT $(DESTDIR)/$(datadir)/yudit/doc/bg/FAQ.TXT
	$(INSTALL_DATA) doc/sr/FAQ.TXT $(DESTDIR)/$(datadir)/yudit/doc/sr/FAQ.TXT
	$(INSTALL_DATA) README.TXT $(DESTDIR)/$(datadir)/yudit/doc
	$(INSTALL_DATA) COPYING.TXT $(DESTDIR)/$(datadir)/yudit/doc
	$(INSTALL_DATA) doc/TestPage.txt $(DESTDIR)/$(datadir)/yudit/doc
	$(INSTALL_DATA) doc/my-format.txt $(DESTDIR)/$(datadir)/yudit/doc
	$(INSTALL_DATA) doc/UTF-8-test.txt $(DESTDIR)/$(datadir)/yudit/doc
	$(INSTALL_DATA) doc/UTF-8-demo.txt $(DESTDIR)/$(datadir)/yudit/doc
	$(INSTALL_DATA) doc/UTF-8-demo-README.txt $(DESTDIR)/$(datadir)/yudit/doc
	$(INSTALL_DATA) doc/HOWTO-*.txt $(DESTDIR)/$(datadir)/yudit/doc
ifneq (,$(wildcard  addon/syntax/target/*))
	$(INSTALL_DATA) addon/syntax/target/*.* $(DESTDIR)/$(datadir)/yudit/syntax
endif
ifneq (,$(wildcard  addon/truetype/target/*))
	$(INSTALL_DATA) addon/truetype/target/*.* $(DESTDIR)/$(datadir)/yudit/fonts
endif
	$(INSTALL_DATA) fonts/*.* $(DESTDIR)/$(datadir)/yudit/fonts
	$(INSTALL_DATA) syntax/*.* $(DESTDIR)/$(datadir)/yudit/syntax
	@echo "---------------------------------------------------"
	@echo "Everything is installed. You can use @bindir@/yudit"
	@echo "Have fun!"
	@echo "Gaspar - gaspar@yudit.org."
	@echo "---------------------------------------------------"
