# Makefile.in for sawfish
# Copyright (C) 1998 - 2008 John Harper
#               2008 - 2010 Sawfish Community
#
# This file is part of sawfish.
#
# sawmfish is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# sawfish is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with sawfish; see the file COPYING.  If not, write to
# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.

include ./Makedefs

top_builddir=.
top_srcdir=@top_srcdir@
srcdir=@srcdir@

SUBDIRS = @SUBDIRS@

all : build.h DOC
	for dir in $(SUBDIRS); do \
	  [ -d $$dir ] && ( cd $$dir && $(MAKE) $@ ) || exit 1; \
	done

# this depends on config.status so it's rebuilt if configure is re-run
build.h : build-info config.status
	$(SHELL) $< $(version)$(subversion) '$(sawfishdir)' \
		'$(lispdir)' '$(sawfishexecdir)' '$(localedir)'

install : all installdirs
	for dir in $(SUBDIRS); do \
	  ( cd $$dir && $(MAKE) $@ ) || exit 1; \
	done
	for f in ./DOC*; do \
	  $(INSTALL_DATA) $$f $(DESTDIR)$(sawfishexecdir); \
	done
	$(INSTALL_DATA) $(srcdir)/data/sawfish.desktop $(DESTDIR)$(datadir)/applications/
	$(INSTALL_DATA) $(srcdir)/data/sawfish-config.desktop $(DESTDIR)$(datadir)/applications/
	$(INSTALL_DATA) $(top_srcdir)/data/sawfish.pc $(DESTDIR)$(libdir)/pkgconfig/
	# needed for GNOME2 to recognize Sawfish, GConf-Key /desktop/gnome/session/required-components/windowmanager 
	# need to be set to 'sawfish' aswell
	$(INSTALL_DATA) $(top_srcdir)/data/sawfish.desktop $(DESTDIR)$(datadir)/xsessions/sawfish.desktop;\
	if test $(GNOME2_SESSION) = "yes"; then \
		$(INSTALL_DATA) $(srcdir)/data/sawfish.desktop $(DESTDIR)$(GNOMEDIR)/share/gnome/wm-properties/sawfish-wm.desktop; \
	fi
	if test $(KDE4_SESSION) = "yes"; then \
		$(INSTALL_DATA) $(top_srcdir)/data/sawfish-ksm.desktop $(DESTDIR)$(KDE4DIR)/ksmserver/windowmanagers/sawfish.desktop; \
		$(INSTALL_DATA) $(top_srcdir)/data/sawfish-kde4.desktop $(DESTDIR)$(datadir)/xsessions/sawfish-kde4.desktop; \
		$(INSTALL_SCRIPT) $(top_srcdir)/data/sawfish-kde4-session $(DESTDIR)$(bindir)/sawfish-kde4-session; \
	fi
	if test $(KDE5_SESSION) = "yes"; then \
		$(INSTALL_DATA) $(top_srcdir)/data/sawfish-ksm.desktop $(DESTDIR)$(KDE5DIR)/ksmserver/windowmanagers/sawfish.desktop; \
		$(INSTALL_DATA) $(top_srcdir)/data/sawfish-kde5.desktop $(DESTDIR)$(datadir)/xsessions/sawfish-kde5.desktop; \
		$(INSTALL_SCRIPT) $(top_srcdir)/data/sawfish-kde5-session $(DESTDIR)$(bindir)/sawfish-kde5-session; \
	fi
	if test $(XFCE_SESSION) = "yes"; then \
		$(INSTALL_DATA) $(top_srcdir)/data/sawfish-xfce.desktop $(DESTDIR)$(datadir)/xsessions/sawfish-xfce.desktop; \
		$(INSTALL_SCRIPT) $(top_srcdir)/data/sawfish-xfce-session $(DESTDIR)$(bindir)/sawfish-xfce-session; \
	fi
	if test $(MATE_SESSION) = "yes"; then \
		$(INSTALL_DATA) $(top_srcdir)/data/sawfish-mate.desktop $(DESTDIR)$(datadir)/xsessions/sawfish-mate.desktop; \
		$(INSTALL_SCRIPT) $(top_srcdir)/data/sawfish-mate-session $(DESTDIR)$(bindir)/sawfish-mate-session; \
	fi
	if test $(LUMINA_SESSION) = "yes"; then \
		$(INSTALL_DATA) $(top_srcdir)/data/sawfish-lumina.desktop $(DESTDIR)$(datadir)/xsessions/sawfish-lumina.desktop; \
		$(INSTALL_SCRIPT) $(top_srcdir)/data/sawfish-lumina-session $(DESTDIR)$(bindir)/sawfish-lumina-session; \
	fi

installdirs : mkinstalldirs
	$(SHELL) $< $(DESTDIR)$(sawfishdir) \
	  $(DESTDIR)$(bindir) $(DESTDIR)$(sawfishexecdir) \
	  $(DESTDIR)$(GNOMEDIR)/share/gnome/wm-properties \
	  $(DESTDIR)$(datadir)/applications/ \
	  $(DESTDIR)$(libdir)/pkgconfig/ \
	  $(DESTDIR)$(datadir)/xsessions/ \
	  $(DESTDIR)$(KDE4DIR)/ksmserver/windowmanagers/ \
	  $(DESTDIR)$(KDE5DIR)/ksmserver/windowmanagers/

uninstall :
	for dir in $(SUBDIRS); do \
	  ( cd $$dir && $(MAKE) $@ ) || exit 1; \
	done
	rm -rf $(DESTDIR)$(sawfishdir)
	rm -f $(DESTDIR)$(libdir)/pkgconfig/sawfish.pc
	rm -f $(DESTDIR)$(datadir)/xsessions/sawfish.desktop
	rm -f $(DESTDIR)$(datadir)/xsessions/sawfish-kde4.desktop
	rm -f $(DESTDIR)$(datadir)/xsessions/sawfish-kde5.desktop
	rm -f $(DESTDIR)$(datadir)/xsessions/sawfish-mate.desktop
	rm -f $(DESTDIR)$(datadir)/xsessions/sawfish-lumina.desktop
	rm -f $(DESTDIR)$(datadir)/applications/sawfish.desktop
	rm -f $(DESTDIR)$(GNOMEDIR)/share/gnome/wm-properties/sawfish-wm.desktop
	rm -f $(DESTDIR)$(KDE5DIR)/ksmserver/windowmanagers/sawfish.desktop
	rm -f $(DESTDIR)$(KDE4DIR)/ksmserver/windowmanagers/sawfish.desktop
	rm -f $(DESTDIR)$(bindir)/sawfish-*-session

# At this stage, DOC file omits some docstrings. (Only small portion,
# though.) Byte compilation makes it complete.
DOC :
	repdoc DOC `find $(srcdir) \( -name '*.c' -o -name '*.jl' \) -print`

changelog :
	$(srcdir)/scripts/make-changelog

clean :
	-for dir in $(SUBDIRS); do \
	  [ -d $$dir ] && ( cd $$dir && $(MAKE) $@ ) || exit 1; \
	done
	rm -f *~ DOC* TAGS build.h

distclean :
	-for dir in $(SUBDIRS); do \
	  [ -d $$dir ] && ( cd $$dir && $(MAKE) $@ ) || exit 1; \
	done
	rm -f config.cache config.h config.log config.status Makedefs Makefile
	rm -f *~ DOC* TAGS build.h data/sawfish.pc
	rm -rf autom4te.cache m4/ aclocal.m4

gitclean : distclean
	-fakeroot debian/rules clean
	rm -f configure libtool ltmain.sh config.h.in
	rm -f sawfish.spec sawfish*.ebuild

tarball :
	git checkout-index --prefix="$$HOME/sawfish-$(version)/" -a

TAGS :
	etags --language=c `find $(srcdir) -name '*.[ch]' -print` \
	      --language=lisp `find $(srcdir) -name '*.jl' -print`

.PHONY: install uninstall tar clean debclean gitclean distclean tarball TAGS
