# Makefile for Services.
#
# IRC Services is copyright (c) 1996-2007 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=.

default: config-check all

###########################################################################
########################## 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.  ("icc" below is the Intel
# C compiler for Linux, which doesn't understand GCC's -W/-f options.)

ifeq ($(CC),icc)
MORE_CFLAGS = -g
else
MORE_CFLAGS = -g -Wall -Wmissing-prototypes -fno-builtin-log
endif

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


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

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


OBJS =	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 \
	suspinfo.o timeout.o users.o $(VSNPRINTF_O)

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

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

.PHONY: default config-check all myall myclean clean spotless distclean \
	install instbin instmod insttools modules languages tools

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

config-check:
	@if ./configure -check ; then : ; else \
		echo 'Either you have not yet run the "configure" script, or the script has been' ; \
		echo 'updated since you last ran it.  Please run "./configure" before running' ; \
		echo '"$(MAKE)".' ; \
		exit 1 ; \
	fi

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 -rf config.cache config.h* configure.log conf-tmp 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 version.o
	$(CC) $(LFLAGS) $(OBJS) version.o $(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
suspinfo.o:	suspinfo.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: $(OBJS) modules/.stamp
	sh version.sh
modules/.stamp: modules

language.h: langstrs.h
	-touch $@

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

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

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

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


syntax highlighted by Code2HTML, v. 0.9.1