# $Cambridge: hermes/src/prayer/utils/Makefile,v 1.9 2009/03/19 17:30:03 dpc22 Exp $
# Prayer - a Webmail Interface
#
# Copyright (c) University of Cambridge 2000 - 2008
# 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 -I../shared -I../session

# Default list of things to build
BIN = prayer-ssl-prune prayer-cyclog prayer-sem-prune

# Enable SYSV mutex
ifeq ($(strip $(MUTEX_SEMAPHORE)), true)
  MUTEX_DEF = -DMUTEX_SEMAPHORE
endif

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

# Enable on the fly compression
ifeq ($(strip $(GZIP_ENABLE)), true)
  BASE_LIBS  += $(Z_LIBS)
endif

# Add PAM if backend needs pam
ifeq ($(strip $(CCLIENT_PAM_ENABLE)), true)
  BASECFLAGS   += $(PAM_INCLUDE)
endif

# Add Kerberos if backend needs Kerberos
ifeq ($(strip $(CCLIENT_KERB_ENABLE)), true)
  BASECFLAGS   += $(KERB_INCLUDE)
endif

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

MYCFLAGS  = $(BASECFLAGS) $(SSL_INCLUDE) $(CCLIENT_INCLUDE)
MYLDFLAGS = $(BASELDFLAGS)

PRUNE_OBJS = ssl_prune_main.o ../shared/shared.a
PRUNE_LIBS = $(BASE_LIBS)

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

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

all:	$(BIN)

clean:
	-rm -f $(BIN) core *.o *.flc *~ \#*\#

install: all
	$(INSTALL) -o $(RO_USER) -g $(RO_GROUP) -m $(PUBLIC_DIR) -d \
	  $(BROOT)$(BIN_DIR)
	$(INSTALL) -o $(RO_USER) -g $(RO_GROUP) -m $(PUBLIC_EXEC) \
	  prayer-ssl-prune $(BROOT)$(BIN_DIR)
	$(INSTALL) -o $(RO_USER) -g $(RO_GROUP) -m $(PUBLIC_EXEC) \
	  prayer-sem-prune $(BROOT)$(BIN_DIR)
	$(INSTALL) -o $(RO_USER) -g $(RO_GROUP) -m $(PUBLIC_EXEC) \
	  prayer-db-prune $(BROOT)$(BIN_DIR)
	$(INSTALL) -o $(RO_USER) -g $(RO_GROUP) -m $(PUBLIC_EXEC) \
	  prayer-cyclog    $(BROOT)$(BIN_DIR)

prayer-ssl-prune: $(PRUNE_OBJS)
	$(CC) $(MYLDFLAGS) -o prayer-ssl-prune $(PRUNE_OBJS) $(PRUNE_LIBS)

prayer-cyclog: prayer-cyclog.SRC
	perl -pe "s&__PREFIX__&${PREFIX}&; s&__VAR_PREFIX__&${VAR_PREFIX}&; s&__BIN_DIR__&${BIN_DIR}&;" < prayer-cyclog.SRC > prayer-cyclog

ssl_prune_main.o: ssl_prune_main.c Makefile
	$(CC) $(MYCFLAGS) -c \
	  -DPRAYER_CONFIG_FILE=\"$(PRAYER_CONFIG_FILE)\" $<

prayer-sem-prune: prayer-sem-prune.o
	$(CC) $(MYLDFLAGS) -o prayer-sem-prune prayer-sem-prune.o

prayer-sem-prune.o: prayer-sem-prune.c
	$(CC) $(MYCFLAGS) $(MUTEX_DEF) -c $<

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

