MAKE_DIRS=@MAKE_DIRS2@

all .DEFAULT:
	# "cd baselib" and "cd encodefilter" must be enclosed by () because it may not return
	# to the $(top_builddir) at the next line.
	if [ -f baselib/Makefile ]; then (cd baselib ; $(MAKE) $@) ; fi
	if [ -f encodefilter/Makefile ]; then (cd encodefilter ; $(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 baselib/Makefile ]; then (cd baselib ; $(MAKE) install-la) ; fi
	if [ -f encodefilter/Makefile ]; then (cd encodefilter ; $(MAKE) install-la) ; fi
	for dir in $(MAKE_DIRS) ; do (cd $${dir} ; $(MAKE) $@) || exit $? ; done

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

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

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

vte:
	(cd gtk; $(MAKE))

install-vte:
	(cd gtk; $(MAKE) install)

clean-vte:
	(cd gtk; $(MAKE) clean)

vterm:
	(cd libvterm; $(MAKE))

install-vterm:
	(cd libvterm; $(MAKE) install)

clean-vterm:
	(cd libvterm; $(MAKE) clean)

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

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

test:
