# $Cambridge: hermes/src/prayer/accountd/Makefile,v 1.6 2008/06/02 15:07:10 dpc22 Exp $
# Prayer - a Webmail Interface
#
# Copyright (c) University of Cambridge 2000 - 2002
# See the file NOTICE for conditions of use and distribution.

ifeq ($(strip $(RPM_BUILD)), true)
include ../Config-RPM
else
include ../Config
endif

BASECFLAGS += -I../lib

# Enable Electric Fence
ifeq ($(strip $(FENCE_ENABLE)), true)
  BASECFLAGS += $(FENCE_INCLUDE)
  BASE_LIBS  += $(FENCE_LIBS)
endif

# Add PAM if backend needs pam
ifeq ($(strip $(ACCOUNTD_PAM_ENABLE)), true)
  BASE_INCLUDE      += $(PAM_INCLUDE)
  BASE_LIBS         += $(PAM_LIBS)
  ACCOUNTD_PAM_DEFS  = -DACCOUNTD_PAM_ENABLE=1
endif

ifeq ($(strip $(ACCOUNTD_USE_BSD_PTY)), true)
  BASE_LIBS += -lutil
endif

CFLAGS  = $(BASECFLAGS)
LDFLAGS = $(BASELDFLAGS) 
LIBS    = $(BASE_LIBS)

ifeq ($(strip $(ACCOUNTD_SSL_ENABLE)), true)
  LIB  = ../lib/lib_withssl.a
  LIBS += $(SSL_LIBS)
  ifeq ($(strip $(SESSION_CACHE_ENABLE)), true)
    # Berkeley DB required for SSL session cache.
    LIBS    += $(DB_LIBS)
  endif
else
  LIB  = ../lib/lib_nossl.a
endif


all: prayer-accountd

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

OBJS = config.o log.o \
       password.o fullname.o quota.o file.o mail.o \
       filter.o checksum.o authenticate.o $(LIB)

prayer-accountd: $(OBJS) accountd.o
	$(CC) $(LDFLAGS) -o prayer-accountd accountd.o $(OBJS) $(LIBS)

test: test.o $(OBJS)
	$(CC) $(LDFLAGS) -o test test.o $(OBJS) $(LIBS)

# Default build rule
%.o: %.c *.h Makefile
	$(CC) $(CFLAGS) -c $<

accountd.o: accountd.c *.h Makefile
	$(CC) $(CFLAGS) -c \
	  -DACCOUNTD_CONFIG_FILE=\"$(ACCOUNTD_CONFIG_FILE)\" $<

authenticate.o: authenticate.c *.h Makefile
	$(CC) $(CFLAGS) -c $(ACCOUNTD_PAM_DEFS) $<

clean:
	-rm -f prayer-accountd test core *.o *~ \#*\# 

install:
	$(INSTALL) -m 755 -o ${RO_USER} -g ${RW_GROUP} \
	prayer-accountd ${BROOT}${BIN_DIR}

