# Makefile for Services

include Makefile.inc

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


# Destination mode, user, and group.
DESTMODE = 710
DESTUSER = root
DESTGROUP= espernet

# Command to copy a program to the installation directory.
INSTALL  = /usr/bin/install -s -m $(DESTMODE) -o $(DESTUSER) -g $(DESTGROUP)

# Command to copy a directory tree.
CP_ALL   = cp -pr


# Runtime group and umask we should use (note that umask requires leading 0).
# If you're not root, comment out RUNGROUP.  UMASK can be set or not set
# depending on your system; if it's not set, it remains at the default umask
# of the user running Services.

RUNGROUP = espernet
UMASK    = 0007


# Compilation options:
#	-DSKELETON	Compile a "skeleton" version of Services, with only
#			    OperServ enabled
#	-DREADONLY	Compile a normal version of Services, but with
#			    database modification disabled ("backup" Services)
# Note that SKELETON and READONLY are mutually exclusive.

CDEFS =


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


OBJS =	channels.o chanserv.o helpserv.o main.o memoserv.o misc.o \
	nickserv.o operserv.o process.o send.o sockutil.o users.o
SRCS =	channels.c chanserv.c helpserv.c main.c memoserv.c misc.c \
	nickserv.c operserv.c process.c send.c sockutil.c users.c


ifdef RUNGROUP
ifdef UMASK
CFLAGS = $(CDEFS) -DRUNGROUP=\"$(RUNGROUP)\" -DDEFUMASK=$(UMASK) $(EXTRA_CFLAGS)
else
CFLAGS = $(CDEFS) -DRUNGROUP=\"$(RUNGROUP)\" $(EXTRA_CFLAGS)
endif
else
ifdef UMASK
CFLAGS = $(CDEFS) -DDEFUMASK=$(UMASK) $(EXTRA_CFLAGS)
else
CFLAGS = $(CDEFS) $(EXTRA_CFLAGS)
endif
endif

all: services listnicks listchans

test: services do-test

do-test:
	cd test ; make test-services DATA_DIR=`pwd`/test/data
	test/test-services 0 ./services

tar:
	rm -f services.tar.gz
	tar cvf - `find . -path ./backup -prune -o \! -perm +0100 \! -name \*.o \! -print` | gzip -9 > services.tar.gz

services: version.h $(OBJS)
	$(CC) $(OBJS) -o $@
	strip $@

listnicks: services
	rm -f $@
	ln services $@

listchans: services
	rm -f $@
	ln services $@

clean:
	rm -f *.o


install: all
	$(INSTALL) services listnicks listchans $(BINDEST)
	$(CP_ALL) data $(DATDEST)

########

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

channels.o: channels.c services.h
chanserv.o: chanserv.c cs-help.c services.h
helpserv.o: helpserv.c services.h
main.o: main.c services.h
memoserv.o: memoserv.c ms-help.c services.h
misc.o: misc.c services.h
nickserv.o: nickserv.c ns-help.c services.h
operserv.o: operserv.c os-help.c services.h
process.o: process.c services.h version.h
send.o: send.c services.h
sockutil.o: sockutil.c services.h
users.o: users.c services.h

services.h: config.h extern.h
	touch $@

version.h: services.h $(SRCS)
	sh version.sh
	
########

convert: convert.o misc.o
	$(CC) convert.o misc.o -o $@
	strip $@

covnert.o: convert.c services.h
