##
#
# Makefile
#   IIRC src Makefile
#
# $Id: Makefile.in,v 1.1.1.1 2002/01/24 20:19:34 sembera Exp $
#
##
#
# IIRC - IIRC Is a Real Client (Modular IRC Client)
# Copyright (C) 2001,2002  Jan Sembera <fis@ji.cz>
# Copyright (C) 2001,2002  Petr Baudis <pasky@ji.cz>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#

###
# Dirs

prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
sysconfdir = @sysconfdir@
libdir = @libdir@
datadir = @datadir@
includedir = @includedir@
install = @INSTALL@
VERSION = @VERSION@

###
# Commons
CC = @CC@
MAKE = @MAKE@
CFLAGS = @CFLAGS@
LDFLAGS = @LDFLAGS@
DEFS = @DEFS@
LIBS = @LIBS@

MODULES = core back front libiirc libmod libaio

RECURSIVES = $(MODULES)
RECURSIVES_CLEAN = $(foreach tget, $(RECURSIVES), $(tget)-clean)
RECURSIVES_DISTCLEAN = $(foreach tget, $(RECURSIVES), $(tget)-distclean)
RECURSIVES_INSTALL = $(foreach tget, $(RECURSIVES), $(tget)-install)

LIBRARIES = $(foreach tget, $(MODULES), $(tget).a)

###
# And targets

#
##### BUILD
#

all:	recursive iirc
everything: all

recursive: $(RECURSIVES)
	@echo "Recursive targets done..."

.PHONY:	$(RECURSIVES)
$(RECURSIVES):
	@dir=`echo $@`; \
	r=`pwd`; export r; \
	if [ -f ./$${dir}/Makefile ] ; then \
	  s=`cd $(srcdir); pwd`; export s; \
	  (cd $${dir}; $(MAKE) all); \
	else \
	  echo "Warning, directory $${dir} skipped."; \
	  true; \
	fi

iirc:	$(LIBRARIES)
	$(CC) $(CFLAGS) $(LDFLAGS) $(LIBS) -o ../iirc $^ 

$(LIBRARIES):	$(RECURSIVES)
	
#
##### CLEAN
#

.PHONY:	clean
clean:	recursive-clean src-clean

recursive-clean: $(RECURSIVES_CLEAN) src-clean
	@echo "Recursive targets cleaned..."

.PHONY:	$(RECURSIVES_CLEAN)
$(RECURSIVES_CLEAN):
	@dir=`echo $@ | sed s/-clean$$//`; \
	r=`pwd`; export r; \
	if [ -f ./$${dir}/Makefile ] ; then \
	  s=`cd $(srcdir); pwd`; export s; \
	  (cd $${dir}; $(MAKE) clean); \
	else \
	  echo "Warning, directory $${dir} skipped."; \
	  true; \
	fi

src-clean:
	rm -f *.a

#
##### DISTCLEAN
#

.PHONY: distclean
distclean: recursive-distclean src-distclean

recursive-distclean: $(RECURSIVES_DISTCLEAN) src-distclean
	@echo "Recursive targets dist-cleaned..."

.PHONY: $(RECURSIVES_DISTCLEAN)
$(RECURSIVES_DISTCLEAN):
	@dir=`echo $@ | sed s/-distclean$$//`; \
         r=`pwd`; export r; \
         if [ -f ./$${dir}/Makefile ] ; then \
           s=`cd $(srcdir); pwd`; export s; \
           (cd $${dir}; $(MAKE) distclean); \
         else \
           echo "Warning, directory $${dir} skipped."; \
           true; \
         fi
												
src-distclean:
	rm -f *.a Makefile

#
##### install
#

.PHONY: install
install: src-install

.PHONY: src-install
src-install:
	if [ -f $(bindir)/iirc ]; then rm -f $(bindir)/iirc; fi
	$(install) -m 755 iirc $(bindir)
	if [ -f $(libdir)/mod_iirc-$(VERSION)_irc_be.so ]; then rm -f $(libdir)/mod_iirc-$(VERSION)_backend.so; fi
	$(install) -m 644 mod_iirc-$(VERSION)_irc_be.so $(libdir)
	if [ -f $(libdir)/mod_iirc-$(VERSION)_dummy_fe.so ]; then rm -f $(libdir)/mod_iirc-$(VERSION)_dummy_fe.so; fi
	$install -m 644 mod_iirc-$(VERSION)_irc_be.so $(libdir)

