####################################################################
#   Copyright (c)
#
#   You may copy, distribute, and modify it freely as long as you  #
#   preserve this copyright and permission notice.                 #
#                                                                  #
#
####################################################################

#
#  Makefile for Adlib
#

SHELL   = @CONFIGSHELL@

VERSION = @VERSION@

srcdir      = @srcdir@
top_srcdir  = @top_srcdir@

TESTDIR = test
MANDIR  = man
SRCDIR  = src

SUBDIR  = ${SRCDIR} 

VPATH = .:${srcdir}

all: ${srcdir}/configure config.status Makefile
	@for i in ${SUBDIR}; \
	do (cd $$i; $(MAKE) "MAKE=$(MAKE)"); done

Makefile: ${srcdir}/Makefile.in
	@echo
	@echo Please configure the package to generate new makefile ...
	@exit

check:
	@echo "Recursively checking testsuite dir"
	@for i in ${TESTDIR}; \
	do (cd $$i; $(MAKE) "MAKE=$(MAKE)" -i check); done

clean:
	@for i in ${SUBDIR}; \
	do (cd $$i; $(MAKE) "MAKE=$(MAKE)" clean); done
	@rm -r -f Templates.DB

distclean:  
	@for i in ${SUBDIR} $(TESTDIR) $(MANDIR); \
	do (cd $$i; $(MAKE) "MAKE=$(MAKE)" distclean); done
	@rm -r -f Templates.DB
	@echo Deleting installed stuff if prefix is current dir ...;
	if [ -d bin ] ; then rm -r -f bin ; fi
	if [ -d include ] ; then rm -r -f include ; fi
	if [ -d lib ] ; then rm -r -f lib; fi
#	@echo Deleting testing results ...
#	@for i in ${TESTDIR}; \
#	do (cd $$i; $(MAKE) "MAKE=$(MAKE)" distclean); done
	@echo Deleting generated configure files ...
	rm -f config.cache config.status config.log
	rm -f ./src/include/config.h 
	@echo Deleting generated Makefiles ...
	rm -f Makefile

install:
	@for i in ${SRCDIR} ${MANDIR}; \
	do (cd $$i; $(MAKE) "MAKE=$(MAKE)" install); done

uninstall:
	@for i in ${SRCDIR} ${MANDIR}; \
	do (cd $$i; $(MAKE) "MAKE=$(MAKE)" uninstall); done


#
# For generating configure script
#

${srcdir}/configure: ${srcdir}/configure.in ${srcdir}/acconfig.h
	cd ${srcdir}/ && autoconf
	autoheader

config.status: ${srcdir}/configure
	@echo
	@echo Please configure the package first ...
	@exit
