MAKE_DIRS=@MAKE_DIRS@

all .DEFAULT:
	# "cd kiklib" and "cd mkf" must be enclosed by () because it may not return
	# to the $(top_builddir) at the next line.
	if [ -f kiklib/Makefile ]; then (cd kiklib ; $(MAKE) $@) ; fi
	if [ -f mkf/Makefile ]; then (cd mkf ; $(MAKE) $@) ; fi
	(for dir in $(MAKE_DIRS) ; do (cd $${dir} ; $(MAKE) $@) || exit $? ; done) && \
	if test "$@" != "clean" ; then touch BUILD_SUCCESS ; else rm -f BUILD_SUCCESS ; fi

BUILD_SUCCESS: Makefile
	$(MAKE) all

install: BUILD_SUCCESS
	if [ -f kiklib/Makefile ]; then (cd kiklib ; $(MAKE) install-la) ; fi
	if [ -f mkf/Makefile ]; then (cd mkf ; $(MAKE) install-la) ; fi
	for dir in $(MAKE_DIRS) ; do (cd $${dir} ; $(MAKE) $@) || exit $? ; done

install-fb: BUILD_SUCCESS
	for dir in main `find inputmethod -name Makefile|sed 's/\/Makefile//'` ; \
		do (cd $${dir} ; $(MAKE) install) || exit $? ; done

distclean:
	if [ -f kiklib/Makefile ]; then (cd kiklib ; $(MAKE) $@) ; fi
	if [ -f mkf/Makefile ]; then (cd mkf ; $(MAKE) $@) ; fi
	if [ -f gtk/Makefile ]; then (cd gtk ; $(MAKE) $@) ; fi
	for dir in $(MAKE_DIRS) java ; do (cd $${dir} ; $(MAKE) $@) || exit $? ; done
	rm -f config.log config.cache config.status libtool Makefile \
		common/c_config.h common/stamp-h1

tags:
	find . -name "*.[ch]" | xargs etags
