# Makefile for cyrus library
# 
# @configure_input@
# 
#        Copyright 1998 by Carnegie Mellon University
#
#                      All Rights Reserved
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose and without fee is hereby granted,
# provided that the above copyright notice appear in all copies and that
# both that copyright notice and this permission notice appear in
# supporting documentation, and that the name of CMU not be
# used in advertising or publicity pertaining to distribution of the
# software without specific, written prior permission.
#
# CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
# CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
# ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
# ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
# SOFTWARE.

# Authorization namespace.
AUTH=auth_@WITH_AUTH@.o

# ACL interpretation.  Only one choice for now:
ACL=acl_afs.o

srcdir = @srcdir@
VPATH = @srcdir@

CC = @CC@

INSTALL = @INSTALL@
RANLIB = @RANLIB@

DEFS = @DEFS@
CPPFLAGS = @CPPFLAGS@ @SASLFLAGS@
LIBS = @LIBS@

CFLAGS = @CFLAGS@
LDFLAGS = @LDFLAGS@

SHELL = /bin/sh
MAKEDEPEND = @MAKEDEPEND@

prefix = @prefix@
exec_prefix = @exec_prefix@
cyrus_prefix = @cyrus_prefix@

HDRS = $(srcdir)/acl.h $(srcdir)/assert.h $(srcdir)/auth.h \
	$(srcdir)/bsearch.h $(srcdir)/charset.h $(srcdir)/glob.h \
	$(srcdir)/gmtoff.h $(srcdir)/imclient.h $(srcdir)/imparse.h \
	$(srcdir)/lock.h $(srcdir)/map.h $(srcdir)/mkgmtime.h \
	$(srcdir)/nonblock.h $(srcdir)/parseaddr.h $(srcdir)/prot.h \
	$(srcdir)/retry.h $(srcdir)/sysexits.h \
	$(srcdir)/util.h $(srcdir)/xmalloc.h

OBJS = acl.o assert.o bsearch.o charset.o glob.o retry.o util.o \
	mkgmtime.o prot.o parseaddr.o imclient.o imparse.o xmalloc.o \
	chartable.o nonblock_@WITH_NONBLOCK@.o lock_@WITH_LOCK@.o \
	gmtoff_@WITH_GMTOFF@.o map_@WITH_MAP@.o $(ACL) $(AUTH) \
	@LIBOBJS@

all: libcyrus.a

install:
	$(INSTALL) -m 644 libcyrus.a $(DESTDIR)$(exec_prefix)/lib
	$(RANLIB) $(DESTDIR)$(exec_prefix)/lib/libcyrus.a
	for file in $(HDRS); \
	do \
		$(INSTALL) -m 644 $$file $(DESTDIR)$(prefix)/include/cyrus || exit 1; \
	done

.c.o:
	$(CC) -c $(CPPFLAGS) $(DEFS) -I$(srcdir) -I. $(CFLAGS) \
	$<

libcyrus.a: $(OBJS)
	rm -f libcyrus.a
	ar cr libcyrus.a $(OBJS)
	$(RANLIB) libcyrus.a

chartable.c: mkchartable 
	@echo "### Building chartables..."
	rm -f chartable.c
	./mkchartable \
	 -m $(srcdir)/charset/unifix.txt	\
	 -m $(srcdir)/charset/unidata2.txt \
	 $(srcdir)/charset/*.t \
	 > chartable.c \
	 || (rm -f chartable.c && exit 1)
	@echo "### Done building chartables."
#	./mkchartable -m $(srcdir)/charset/unicode.map $(srcdir)/charset/*.t >x-chartables.h
#	mv x-chartables.h chartables.h

mkchartable: mkchartable.o xmalloc.o assert.o
	$(CC) $(LDFLAGS) -o mkchartable mkchartable.o xmalloc.o assert.o

clean:
	rm -f *.o *.a chartable.c Makefile.bak mkchartable makedepend.log

distclean: clean
	rm -f Makefile

depend:
	${MAKEDEPEND} $(CPPFLAGS) $(DEFS) -I$(srcdir) $(CFLAGS) *.c $(srcdir)/*.c 1>makedepend.log 2>&1

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