CP		= @CP@
MV		= @MV@
RM		= @RM@
RMF		= @RM@ -f
MKDIR		= @MKDIR@

subdirs		= lib asimagelib doc src/afterstep src/Animate src/Audio \
		  src/Auto src/Banner src/Cascade src/Clean src/Form src/Ident \
		  src/Pager src/Save src/Scroll src/Sound src/Tile src/Wharf \
		  src/WinList src/Zharf @SCRIPT_DIR@

all:
	@for I in ${subdirs}; do (cd $$I; ${MAKE} $@ || exit 1); done

install: install.bin install.man install.all
 
install.bin:
	@for I in ${subdirs}; do (cd $$I; ${MAKE} install || exit 1); done

install.man:
	@for I in ${subdirs}; do (cd $$I; ${MAKE} install.man || exit 1); done

install.all:
	if [ -d @datadir@/afterstep ] ; then \
	$(RMF) -r @datadir@/afterstep_old ; \
	$(MV) @datadir@/afterstep @datadir@/afterstep_old ; fi ;\
	$(MKDIR) -p @datadir@/afterstep ; \
	$(CP) -R afterstep @datadir@/afterstep/../ ; \
	$(RMF) @datadir@/afterstep/*.in ; \
	$(RMF) @datadir@/afterstep/non-configurable/*.in ; \
	$(RMF) @datadir@/afterstep/*.orig ; \
	(cd doc ; $(MAKE) install.all || exit 1)

uninstall:
	@for I in ${subdirs}; do (cd $$I; ${MAKE} uninstall || exit 1); done
	$(RMF) -r @datadir@/afterstep
	if [ -d @datadir@/afterstep_old ] ; then $(MV) @datadir@/afterstep_old @datadir@/afterstep ; fi

clean:
	@for I in ${subdirs}; do (cd $$I; ${MAKE} clean || exit 1); done

distclean:
	@for I in ${subdirs}; do (cd $$I; ${MAKE} distclean || exit 1); done
	$(RMF) config.cache config.log config.status Makefile.bak Makefile config.h configure.h *.o *~ *% *.bak \#* core

indent:
	for i in ${subdirs}; do ${MAKE} -C $$i indent; done
	HEADERS=`echo "include/*.h"`; \
	for i in $$HEADERS; do \
	  if (indent < $$i > /tmp/$$i); then \
	    mv /tmp/$$i $$i; \
	  fi; \
	done

config:
	autoconf --localdir=autoconf autoconf/configure.in > \
	configure ; chmod 755 configure
	autoheader --localdir=autoconf autoconf/configure.in > \
	autoconf/config.h.in ; chmod 644 autoconf/config.h.in
