# Makefile for Services.
#
# 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.


include Makefile.inc
TOPDIR=.


###########################################################################
########################## Configuration section ##########################

# NOTE: Compilation options (CLEAN_COMPILE, etc.) are now all controlled by
#       the configure script.

# Add any extra flags you want here.  The default line below enables
# warnings and debugging symbols on GCC.  If you have a non-GCC compiler,
# you may want to comment it out or change it.

MORE_CFLAGS = -Wall -Wmissing-prototypes -g


######################## End configuration section ########################
###########################################################################


ifneq ($(STATIC_MODULES),)
CDEFS += -DSTATIC_MODULES
MODLIB = modules/modules.a
endif

CFLAGS = $(CDEFS) $(BASE_CFLAGS) $(MORE_CFLAGS)


OBJS =	version.o \
	actions.o channels.o commands.o compat.o conffile.o encrypt.o \
	ignore.o init.o language.o log.o main.o memory.o messages.o misc.o \
	modes.o modules.o process.o send.o servers.o signals.o sockets.o \
	timeout.o users.o $(VSNPRINTF_O)
SRCS = $(OBJS:.o=.c)

.c.o:
	$(CC) $(CFLAGS) -c $< -o $@

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

.PHONY: all myall myclean clean spotless distclean install instbin instmod \
	insttools modules languages tools version.c

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

all: myall
	@echo Now run \"$(MAKE) install\" to install Services.

myall: $(PROGRAM) languages tools

myclean:
	rm -f *.o $(PROGRAM) version.c.old

clean: myclean
	$(MAKE) -C lang clean
	$(MAKE) -C modules clean
	$(MAKE) -C tools clean

spotless distclean: myclean
	$(MAKE) -C lang spotless
	$(MAKE) -C modules spotless
	$(MAKE) -C tools spotless
	rm -f config.cache config.h* configure.log Makefile.inc* \
		langstrs.h version.c

install: myall myinstall
	@echo ""
	@echo "Don't forget to create/update your ircservices.conf and modules.conf files!"
	@echo "See the README for details."
	@echo ""

myinstall: instbin instmod insttools
	$(MAKE) -C lang install
	$(MAKE) -C data install

instbin:
	$(INSTALL_EXE) $(PROGRAM)$(EXE_SUFFIX) $(BINDEST)/$(PROGRAM)$(EXE_SUFFIX)

ifneq ($(STATIC_MODULES),)
instmod:
else
instmod:
	@$(MAKE) -C modules install
endif

insttools:
	@$(MAKE) -C tools install

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

$(PROGRAM): $(OBJS) modules
	$(CC) $(LFLAGS) $(OBJS) $(MODLIB) $(LIBS) -o $@

ifneq ($(STATIC_MODULES),)
modules:
	@$(MAKE) -C modules all-static CFLAGS="$(CFLAGS)"
else
modules:
	@$(MAKE) -C modules all-dynamic CFLAGS="$(CFLAGS)"
endif

languages:
	@$(MAKE) -C lang CFLAGS="$(CFLAGS)"

tools: services.h
	@$(MAKE) -C tools CFLAGS="$(CFLAGS)"


# Catch any changes in compilation options at the top of this file or the
# configure output
$(OBJS): Makefile Makefile.inc

$(OBJS): services.h

actions.o:	actions.c	language.h modules.h timeout.h
channels.o:	channels.c	modules.h hash.h
commands.o:	commands.c	modules.h commands.h language.h
compat.o:	compat.c
conffile.o:	conffile.c	conffile.h
encrypt.o:	encrypt.c	encrypt.h
ignore.o:	ignore.c	ignore.h
init.o:		init.c		conffile.h messages.h modules.h language.h version.h
language.o:	language.c	language.h modules/nickserv/nickserv.h
log.o:		log.c
main.o:		main.c		modules.h timeout.h
memory.o:	memory.c
messages.o:	messages.c	messages.h language.h modules.h ignore.h version.h
misc.o:		misc.c
modes.o:	modes.c
modules.o:	modules.c	modules.h conffile.h
process.o:	process.c	modules.h messages.h ignore.h
send.o:		send.c		modules.h language.h
servers.o:	servers.c	modules.h hash.h
signals.o:	signals.c
sockets.o:	sockets.c
timeout.o:	timeout.c	timeout.h
users.o:	users.c		modules.h hash.h
vsnprintf.o:	vsnprintf.c


services.h: config.h defs.h list-array.h memory.h sockets.h \
            modes.h users.h channels.h servers.h extern.h
	-touch $@

version.c:
	sh version.sh

language.h: langstrs.h
	-touch $@

langstrs.h: lang/langstrs.h
	cp -p lang/langstrs.h .

lang/langstrs.h: lang/Makefile lang/en_us.l
	$(MAKE) -C lang langstrs.h

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