#************************************************************************
#*   IRC - Internet Relay Chat, ircd/Makefile
#*   Copyright (C) 1990 Jarkko Oikarinen
#*
#*   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 1, 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., 675 Mass Ave, Cambridge, MA 02139, USA.
#*/

CC=gcc -traditional
RM=/bin/rm
CP=/bin/cp
TOUCH=touch
SHELL=/bin/sh

# IRCDMODE given in top level Makefile, but added here to make sure
# compilation works if started in ircd subdirectory

IRCDMODE=711
INCLUDEDIR=../include

#
LINTFLAGS=-hba
#
RES=res_init.o res_comp.o res_mkquery.o

COMMONOBJS=../common/bsd.o ../common/dbuf.o ../common/packet.o \
           ../common/send.o ../common/match.o ../common/parse.o \
           ../common/support.o ../common/inet_addr.o

OBJS=channel.o class.o hash.o ircd.o list.o res.o s_auth.o s_bsd.o s_conf.o \
	s_debug.o s_err.o s_misc.o s_numeric.o s_serv.o s_service.o s_user.o \
	whowas.o note.o $(RES) $(COMMONOBJS)

SRC=$(OBJS:%.o=%.c)

COMMONSRC=$(COMMONOBJS:%.o=%.c)

MAKE = make 'CFLAGS=${CFLAGS}' 'CC=${CC}' 'IRCDLIBS=${IRCDLIBS}' \
	    'LDFLAGS=${LDFLAGS}' 'IRCDMODE=${IRCDMODE}'


all:
	(cd ..; make server)

build: ircd chkconf

ircd: $(OBJS) ../include/patchlevel.h
	$(SHELL) version.c.SH
	$(CC) $(CFLAGS) -c version.c
	$(CC) $(CFLAGS) $(OBJS) version.o $(LDFLAGS) $(IRCDLIBS) -o ircd -lm
	chmod $(IRCDMODE) ircd

chkconf: ../include/struct.h ../include/config.h ../include/sys.h \
	 ../include/common.h chkconf.c
	$(CC) $(CFLAGS) -DDPATH=$(IRCDDIR) chkconf.c ../common/match.o \
	$(LDFLAGS) $(IRCDLIBS) -o chkconf

saber: $(SRC)
	#load -I../include $(SRC) $(COMMONSRC) version.c $(IRCDLIBS)

lint:
	lint $(LINTFLAGS) -I../include $(SRC) | egrep -v 'sendto_|debug'

../common/parse.o: ../common/parse.c ../include/msg.h ../include/config.h\
		   ../include/struct.h ../include/sys.h ../include/numeric.h
	(cd ../common; $(MAKE) build);
../common/bsd.o: ../common/bsd.c ../include/config.h ../include/common.h\
		 ../include/struct.h ../include/sys.h
	(cd ../common; $(MAKE) build);
../common/dbuf.o: ../common/dbuf.c ../include/config.h ../include/common.h\
		  ../include/struct.h ../include/dbuf.h
	(cd ../common; $(MAKE) build);
../common/packet.o: ../common/packet.c ../include/config.h ../include/common.h\
		    ../include/struct.h ../include/msg.h
	(cd ../common; $(MAKE) build);
../common/send.o: ../common/send.c ../include/config.h ../include/common.h\
		  ../include/struct.h ../include/sys.h
	(cd ../common; $(MAKE) build);
../common/match.o: ../common/match.c ../include/config.h ../include/common.h\
		   ../include/sys.h
	(cd ../common; $(MAKE) build);
../common/support.o: ../common/support.c ../include/config.h ../include/sys.h\
		     ../include/common.h
	(cd ../common; $(MAKE) build);
../common/inet_addr.o: ../common/inet_addr.c ../include/sys.h
	(cd ../common; $(MAKE) build);

install: all
	-if [ ! -d ${IRCDDIR} -a ! -f ${IRCDDIR} ] ; then \
		-mkdir ${IRCDDIR}; \
	fi
	../install -c -s -m ${IRCDMODE} ircd ${BINDIR}
	../install -c -s -m 700 chkconf ${BINDIR}
	$(CP) ../doc/example.conf ${IRCDDIR}
	$(TOUCH) ${IRCDDIR}/ircd.motd
	$(RM) -f ${IRCDDIR}/ircd.m4
	$(TOUCH) ${IRCDDIR}/ircd.m4
	chmod +x buildm4
	./buildm4 ${IRCDDIR}

clean:
	$(RM) -f *.o *~ core ircd version.c \#* *.bak chkconf

depend:
	makedepend -I${INCLUDEDIR} ${SRC}

channel.o: ../include/struct.h ../include/config.h ../include/dbuf.h \
	   ../include/numeric.h ../include/channel.h ../include/sys.h \
	   ../include/common.h
	$(CC) $(CFLAGS) -c channel.c

class.o: ../include/struct.h ../include/class.h ../include/numeric.h \
	 ../include/common.h ../include/config.h ../include/sys.h \
	 ../include/common.h
	$(CC) $(CFLAGS) -c class.c

ircd.o: ircd.c ../include/struct.h ../include/config.h ../include/sys.h \
	../include/dbuf.h ../include/numeric.h ../include/common.h
	$(CC) $(CFLAGS) -DDPATH=$(IRCDDIR) -c ircd.c

list.o: list.c ../include/struct.h ../include/config.h ../include/dbuf.h \
	../include/sys.h ../include/common.h
	$(CC) $(CFLAGS) -c list.c

res.o: res.c ../include/struct.h ../include/config.h ../include/res.h \
	   ../include/sys.h ../include/common.h
	$(CC) $(CFLAGS) -c res.c

s_bsd.o: s_bsd.c ../include/struct.h ../include/config.h ../include/dbuf.h \
	 ../include/sys.h ../include/common.h
	$(CC) $(CFLAGS) -c s_bsd.c

s_auth.o: s_auth.c ../include/struct.h ../include/config.h ../include/dbuf.h \
	  ../include/sys.h ../include/common.h
	$(CC) $(CFLAGS) -c s_auth.c

s_conf.o: s_conf.c ../include/struct.h ../include/config.h ../include/sys.h \
	  ../include/common.h ../include/numeric.h  ../include/dbuf.h
	$(CC) $(CFLAGS) -c s_conf.c

s_debug.o: ../include/config.h ../include/struct.h ../include/common.h \
	  ../include/sys.h s_debug.c
	$(CC) $(CFLAGS) -c s_debug.c

s_misc.o: s_misc.c ../include/struct.h ../include/config.h ../include/dbuf.h \
	  ../include/common.h ../include/sys.h ../include/numeric.h
	$(CC) $(CFLAGS) -c s_misc.c

s_user.o: s_user.c ../include/struct.h ../include/config.h ../include/sys.h \
	  ../include/common.h ../include/dbuf.h ../include/channel.h \
	  ../include/msg.h ../include/numeric.h ../include/whowas.h
	$(CC) $(CFLAGS) -c s_user.c

s_serv.o: s_serv.c ../include/struct.h ../include/config.h ../include/sys.h \
	  ../include/common.h ../include/dbuf.h ../include/channel.h \
	  ../include/msg.h ../include/numeric.h ../include/whowas.h
	$(CC) $(CFLAGS) -c s_serv.c

s_service.o: s_service.c ../include/struct.h ../include/config.h \
	  ../include/service.h ../include/sys.h \
	  ../include/common.h ../include/dbuf.h ../include/channel.h \
	  ../include/msg.h ../include/numeric.h ../include/whowas.h
	$(CC) $(CFLAGS) -c s_service.c

s_numeric.o: s_numeric.c ../include/config.h ../include/sys.h \
	  ../include/common.h ../include/struct.h ../include/dbuf.h \
	  ../include/numeric.h
	$(CC) $(CFLAGS) -c s_numeric.c

whowas.o: ../include/struct.h ../include/config.h ../include/sys.h \
	  ../include/common.h ../include/dbuf.h ../include/numeric.h \
	  ../include/whowas.h whowas.c
	$(CC) $(CFLAGS) -c whowas.c

hash.o: ../include/struct.h ../include/sys.h ../include/hash.h hash.c \
	../include/common.h ../include/config.h s_bsd.c s_serv.c s_user.c \
	channel.c s_misc.c
	@$(SHELL) crypt/sums
	$(CC) $(CFLAGS) -c hash.c
	@/bin/rm -f hash.c
	@/bin/mv -f hash.c.old hash.c
	@touch hash.o

# DO NOT DELETE THIS LINE -- make depend depends on it.

channel.o: ../include/struct.h ../include/config.h ../include/dbuf.h
channel.o: ../include/numeric.h ../include/channel.h channel.c
s_misc.o: ../include/struct.h ../include/config.h ../include/dbuf.h s_misc.c
ircd.o: ../include/struct.h ../include/config.h
ircd.o: ../include/dbuf.h ../include/numeric.h ircd.c
list.o: ../include/struct.h ../include/config.h ../include/dbuf.h
list.o: ../include/sys.h list.c
res.o: ../include/struct.h ../include/config.h ../include/res.h res.c
s_bsd.o: ../include/struct.h ../include/config.h ../include/dbuf.h
s_bsd.o: ../include/sys.h s_bsd.c
s_auth.o: ../include/struct.h ../include/config.h ../include/dbuf.h
s_auth.o: ../include/sys.h s_auth.c
s_debug.o: ../include/config.h ../include/struct.h ../include/common.h
s_debug.o: ../include/sys.h s_debug.c
s_debug.o: ../include/struct.h ../include/common.h ../include/sys.h
s_conf.o: ../include/struct.h ../include/config.h ../include/numeric.h
s_conf.o: ../include/dbuf.h ../include/sys.h s_conf.c
s_user.o: ../include/struct.h ../include/config.h
s_user.o: ../include/dbuf.h ../include/sys.h ../include/channel.h
s_user.o: ../include/msg.h ../include/numeric.h ../include/whowas.h s_user.c
s_serv.o: ../include/struct.h ../include/config.h
s_serv.o: ../include/dbuf.h ../include/sys.h ../include/channel.h
s_serv.o: ../include/msg.h ../include/numeric.h ../include/whowas.h s_serv.c
s_service.o: s_service.c ../include/struct.h ../include/config.h 
s_service.o: ../include/service.h ../include/sys.h ../include/msg.h
s_service.o: ../include/common.h ../include/dbuf.h ../include/channel.h 
s_service.o: ../include/numeric.h ../include/whowas.h
s_numeric.o: ../include/config.h ../include/sys.h ../include/struct.h
s_numeric.o: ../include/dbuf.h ../include/numeric.h s_numeric.c
whowas.o: ../include/struct.h ../include/config.h ../include/dbuf.h
whowas.o: ../include/numeric.h ../include/whowas.h ../include/sys.h whowas.c
class.o: ../include/struct.h ../include/class.h ../include/numeric.h
class.o: ../include/common.h ../include/config.h class.c
hash.o: ../include/config.h ../include/sys.h ../include/hash.h
hash.o: ../include/struct.h ../include/common.h s_serv.c s_user.c
hash.o: channel.c s_misc.c s_bsd.c ircd.c hash.c version.c.SH
version.o: version.c.SH version.c
