# Master makefile for modules.
#
# IRC Services is copyright (c) 1996-2002 Andrew Church.
#     E-mail: <achurch@achurch.org>
# Parts written by Andrew Kempe and others.
# This program is free but copyrighted software; see the file COPYING for
# details.

TOPDIR=../
include ../Makefile.inc

###########################################################################

SUBDIRS = chanserv database encryption httpd mail memoserv misc nickserv \
	  operserv protocol statserv

###########################################################################

all-dynamic:
	@set -e ; for i in $(SUBDIRS) ; do \
		$(MAKE) -C $$i $@ DIRNAME="$$i" CFLAGS="$(CFLAGS)" ; \
	done

all-static:
	@rm -f modext.h modsyms.c modlist.c
	@echo '#include "../config.h"' >>modlist.c
	@echo '#include "modext.h"' >>modlist.c
	@echo '#include "modsyms.c"' >>modlist.c
	@echo 'struct {const char *name; void *symlist;} modlist[] = {' >>modlist.c
	@set -e ; for i in $(SUBDIRS) ; do \
		$(MAKE) -C $$i $@ DIRNAME="$$i" CFLAGS="$(CFLAGS)" ; \
		cat $$i/.modext-*.h >>modext.h ; \
		cat $$i/.modsyms-*.c >>modsyms.c ; \
		cat $$i/.modlist-*.c >>modlist.c ; \
	done
	@echo '{0}};' >>modlist.c
	$(CC) -c modlist.c -o modlist.o
	ar r modules.a modlist.o

install:
	@set -e ; for i in $(SUBDIRS) ; do \
		$(MAKE) -C $$i $@ DIRNAME="$$i" ; \
	done

clean spotless:
	@set -e ; for i in $(SUBDIRS) ; do \
		$(MAKE) -C $$i $@ DIRNAME="$$i" ; \
	done
	rm -f modext.h modsyms.c modlist.c *.[oa]

# Remove modules.a (for recompilation) if the top-level Makefile changed
modules.a: ../Makefile ../Makefile.inc
	rm -f $@

$(DATDEST)/modules:
	$(MKDIR) $@
