## deprecated in favour of AUTORECONF
#ACLOCAL = aclocal
#AUTOMAKE = automake --add-missing --copy
#LIBTOOLIZE = libtoolize --force --copy
#AUTOHEADER = autoheader
#AUTOCONF = autoconf
#CONFIG_CMD = $(ACLOCAL) -I $${acfilesdir} && \
#             $(LIBTOOLIZE) && \
#             $(AUTOHEADER) && \
#             $(AUTOMAKE) && \
#             $(AUTOCONF)

AUTORECONF = autoreconf
BOOTSTRAP = $(AUTORECONF) --install --force
INTL_CMD = glib-gettextize -f && intltoolize --copy --force --automake

CONFIG_FLAGS = --prefix=/usr --sysconfdir=/etc --localstatedir=/var

INTLDIRS = iiimgcf gnome-im-switcher

BUILDDIRS = lib/CSConv lib/EIMIL lib/iiimp lib/iiimcf \
            iiimsf leif leif/sun_le_korea leif/sch_le_sun leif/tch_le_sun \
            iiimxcf/xiiimp.so iiimxcf/htt_xbe \
            iiimgcf gnome-im-switcher doc

CONFIGDIRS = $(BUILDDIRS) leif/m17n_le leif/thai_le_sun

all: compile

intllize:
	@for dir in $(INTLDIRS); do \
		echo "I18n bootstrapping \"$$dir\"..." ; \
		topdir=`pwd` ; \
		cd $$dir && $(INTL_CMD) && cd $$topdir ; \
	done

bootstrap: intllize
	@for dir in $(CONFIGDIRS); do  \
		echo "Bootstrapping \"$$dir\"..." ; \
		acfilesdir=`pwd` ; \
		acfilesdir="$${acfilesdir}/acfiles" ; \
		topdir=`pwd` ; \
		cd $$dir && $(BOOTSTRAP) && cd $$topdir ; \
	done

reconfig:
	@for dir in $(BUILDDIRS); do  \
		echo "Reconfiguring \"$$dir\"..." ; \
		topdir=`pwd` ; \
		cd $$dir && $(AUTORECONF) && cd $$topdir ; \
	done

build:
	@for dir in $(BUILDDIRS); do  \
		echo "Building \"$$dir\"..." ; \
		topdir=`pwd` ; \
		cd $$dir && \
		if test -x ./configure; then \
		   ./configure $(CONFIG_FLAGS) && $(MAKE) all && cd $$topdir ; \
		elif test -x ./autogen.sh; then \
		   ./autogen.sh $(CONFIG_FLAGS) && $(MAKE) all && cd $$topdir ; \
		fi; \
	done

config:
	@for dir in $(BUILDDIRS); do  \
		echo "Configuring \"$$dir\"..." ; \
		topdir=`pwd` ; \
		cd $$dir && \
		if test -x ./configure; then \
		   ./configure $(CONFIG_FLAGS) && cd $$topdir ; \
		elif test -x ./autogen.sh; then \
		   ./autogen.sh $(CONFIG_FLAGS) && cd $$topdir ; \
		fi; \
	done

compile:
	@for dir in $(BUILDDIRS); do  \
		topdir=`pwd` ; \
		cd $$dir && $(MAKE) all && cd $$topdir ; \
	done

debug:
	@for dir in $(BUILDDIRS); do  \
		echo "Configuring with debug \"$$dir\"..." ; \
		topdir=`pwd` ; \
		cd $$dir && \
		if test -x ./configure; then \
		   ./configure $(CONFIG_FLAGS) --enable-debug && $(MAKE) all && cd $$topdir ; \
		elif test -x ./autogen.sh; then \
		   ./autogen.sh $(CONFIG_FLAGS) --enable-debug && $(MAKE) all && cd $$topdir ; \
		fi; \
	done

install:
	@for dir in $(BUILDDIRS); do  \
		topdir=`pwd` ; \
		cd $$dir && $(MAKE) install && cd $$topdir ; \
	done

clean:
	@for dir in $(BUILDDIRS); do  \
		topdir=`pwd` ; \
		cd $$dir && $(MAKE) clean && cd $$topdir ; \
	done

distclean:
	@for dir in $(BUILDDIRS); do  \
		topdir=`pwd` ; \
		cd $$dir && $(MAKE) distclean && cd $$topdir ; \
	done

dist:
	./make-dist
