### Path settings
datarootdir = @datarootdir@
srcdir = @srcdir@
top_srcdir = @top_srcdir@
prefix = @prefix@
exec_prefix = @exec_prefix@
sbindir = @sbindir@
sysconfdir = @sysconfdir@
mandir = @mandir@
datadir = @datadir@
libdir = @libdir@
pkglibdir = $(libdir)/conserver
exampledir = $(datadir)/examples/conserver

### Installation programs and flags
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@ -s
LN_S = @LN_S@
MKDIR = @MKDIR@

### Compiler and link options
CC	= @CC@
CFLAGS	= @CFLAGS@
DEFS	= @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)\"
CPPFLAGS = -I.. -I$(top_srcdir) -I$(srcdir) $(DEFS) @CPPFLAGS@ @CONSCPPFLAGS@
LDFLAGS	= @LDFLAGS@ @CONSLDFLAGS@
LIBS	= @LIBS@ @CONSLIBS@
@SET_MAKE@


### Makefile rules - no user-servicable parts below

CONSERVER_OBJS = access.o client.o consent.o group.o main.o master.o \
		 readcfg.o fallback.o cutil.o
CONSERVER_HDRS = ../config.h $(top_srcdir)/compat.h $(srcdir)/access.h \
		 $(srcdir)/client.h $(srcdir)/consent.h $(srcdir)/cutil.h \
		 $(srcdir)/group.h $(srcdir)/main.h $(srcdir)/master.h \
		 $(srcdir)/readcfg.h $(srcdir)/version.h

ALL = conserver convert


all: $(ALL)

$(CONSERVER_OBJS): $(CONSERVER_HDRS)

conserver: $(CONSERVER_OBJS)
	$(CC) $(CFLAGS) $(LDFLAGS) -o conserver $(CONSERVER_OBJS) $(LIBS)

convert: convert.o cutil.o
	$(CC) $(CFLAGS) $(LDFLAGS) -o convert convert.o cutil.o $(LIBS)

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

clean:
	rm -f *~ *.o $(ALL) core

distclean: clean
	rm -f Makefile conserver.rc

install: conserver
	$(MKDIR) $(DESTDIR)$(sbindir)
	$(INSTALL_PROGRAM) conserver $(DESTDIR)$(sbindir)
	$(MKDIR) $(DESTDIR)$(mandir)/man8
	$(INSTALL) -m 0644 conserver.man $(DESTDIR)$(mandir)/man8/conserver.8
	$(MKDIR) $(DESTDIR)$(exampledir)
	$(INSTALL) conserver.rc $(DESTDIR)$(exampledir)
	$(MKDIR) $(DESTDIR)$(pkglibdir)
	$(INSTALL) convert $(DESTDIR)$(pkglibdir)/convert

.PHONY: clean distclean install
