# Copyright (C) 2005 by MusIRCd Development.
# $Id: Makefile.in,v 1.61 2005/07/15 03:50:48 musirc Exp $

RM	= @RM@
INSTALL	= @INSTALL@
INSTALL_DATA	= @INSTALL_DATA@

# Default make flags - you may want to uncomment this on a multicpu machine
MFLAGS = -j2
BUILD_DIRS  = modules src
INSTALL_DIRS = ${BUILD_DIRS} etc messages
@SET_MAKE@

prefix          = $(DESTDIR)@prefix@
helpdir         = ${prefix}/help

all:	build

build: include/setup.h depend
	@for i in $(BUILD_DIRS); do \
		cd $$i && ${MAKE} ${MFLAGS} build || exit; cd ..;\
	done

clean:
	@for i in $(BUILD_DIRS); do \
		cd $$i && ${MAKE} ${MFLAGS} clean || exit; cd ..;\
	done

distclean:
	${RM} -f Makefile *~ *core config.* *.cache
	cd include; ${RM} -f setup.h *~; cd ..
	cd help; ${RM} -f *~; cd ..
	@for i in $(INSTALL_DIRS); do \
		cd $$i && ${MAKE} ${MFLAGS} distclean || exit; cd ..; \
	done

depend:
	@for i in $(BUILD_DIRS); do \
		cd $$i && ${MAKE} ${MFLAGS} .depend || exit; cd .. ; \
	done

index:
	@echo building index files
	@for help in help/*; do \
		if [ -f $$help ]; then \
			echo $$help >> help/index.tmp; \
	fi \
	done
	echo 'Help topics available:' > help/index
	echo '' >> help/index
	cat help/index.tmp \
		| sort -u \
		| sed -e 's|^help/||' \
		| tr a-z A-Z \
		| expand \
		>> help/index
	rm -f help/index.tmp

install: all index
	@for i in $(INSTALL_DIRS); do \
		cd $$i && ${MAKE} ${MFLAGS} install || exit; cd ..; \
	done

	mkdir -p $(helpdir)
	@for help in help/*; do \
		if [ -f $$help ]; then \
			${INSTALL_DATA} $$help $(helpdir); \
	fi \
	done

include/setup.h:
	@sh configure

dep: depend
