# $Cambridge: hermes/src/prayer/servers/Makefile,v 1.19 2010/07/01 12:08:54 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 prayer-session prayer-chroot

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

# Enable LDAP
ifeq ($(strip $(LDAP_ENABLE)), true)
  BASE_LIBS  += $(LDAP_LIBS)
endif

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

# Enable libtidy
ifeq ($(strip $(TIDY_ENABLE)), true)
  BASECFLAGS += $(TIDY_INCLUDE)
  BASE_LIBS  += $(TIDY_LIBS)
endif

ifeq ($(strip $(SSL_ENABLE)), true)
  ifeq ($(strip $(RAVEN_ENABLE)), true)
    RAVEN_ENABLE_DEFS     = -DRAVEN_ENABLE
  endif
  SERVER_SSL_DEFS       = -DSSL_ENABLE
  SERVER_SSL_INCLUDE    = $(SSL_INCLUDE)
  SERVER_SSL_LIBS       = $(SSL_LIBS)
  ifeq ($(strip $(SESSION_CACHE_ENABLE)), true)
    # Berkeley DB required for SSL session cache.
    SERVER_SSL_DEFS    += -DSESSION_CACHE_ENABLE
    SERVER_SSL_LIBS    += $(DB_LIBS)
  endif
  LIB=../lib/lib_withssl.a
else
  LIB=../lib/lib_nossl.a
endif

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

PRAYER_LIBS   = $(BASE_LIBS) $(SERVER_SSL_LIBS)
SESSION_LIBS  = $(BASE_LIBS) $(CCLIENT_LIBS)

# Add SSL if c-client needs SSL
ifeq ($(strip $(CCLIENT_SSL_ENABLE)), true)
  SESSION_LIBS += $(SSL_LIBS)
endif

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

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

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

TEMPLATES= ../templates/index.o \
 ../templates/old/templates.a \
 ../templates/cam/templates.a \

TEMPLATES_FRONTEND= ../templates/index.o \
 ../templates/old/templates_frontend.a \
 ../templates/cam/templates_frontend.a

PRAYER_OBJS= prayer.o prayer_login.o prayer_server.o portlist.o \
  ../shared/shared.a $(LIB) $(TEMPLATES_FRONTEND)

SESSION_OBJS= \
   session_config.o session_exchange.o session_unix.o session_server.o \
   session_main.o portlist.o ../cmd/cmd.a ../session/session.a \
   ../shared/shared.a ../lib/lib_nossl.a

SESSION_OBJS += $(TEMPLATES)

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

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           $(BROOT)$(BIN_DIR)
	$(INSTALL) -o $(RO_USER) -g $(RO_GROUP) -m $(PUBLIC_EXEC) \
	  prayer-chroot           $(BROOT)$(BIN_DIR)
	$(INSTALL) -o $(RO_USER) -g $(RO_GROUP) -m $(PUBLIC_EXEC) \
	  prayer-session   $(BROOT)$(BIN_DIR)

prayer: $(PRAYER_OBJS) prayer_main.o
	$(CC) $(MYLDFLAGS) -o prayer prayer_main.o $(PRAYER_OBJS) $(PRAYER_LIBS)

prayer-chroot: $(PRAYER_OBJS) prayer_chroot.o
	$(CC) $(MYLDFLAGS) -o prayer-chroot prayer_chroot.o $(PRAYER_OBJS) $(PRAYER_LIBS)

prayer-session: $(SESSION_OBJS)
	$(CC) $(MYLDFLAGS) -o prayer-session \
		$(SESSION_OBJS) $(SESSION_LIBS)

prayer_login.o: prayer_login.c *.h Makefile
	$(CC) $(MYCFLAGS) -c $(RAVEN_ENABLE_DEFS) $<

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

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

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

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

