# $Cambridge: hermes/src/prayer/lib/Makefile,v 1.8 2008/06/03 10:04:15 dpc22 Exp $ 

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

ifeq ($(strip $(SSL_ENABLE)), true)
  SSL_DEFS       = -DSSL_ENABLE
  ifeq ($(strip $(SESSION_CACHE_ENABLE)), true)
    # Berkeley DB required for SSL session cache.
    SSL_DEFS    += -DSESSION_CACHE_ENABLE
    DB_DEFS      = -DDB_ENABLE
  endif
  TARGETS=lib_withssl.a lib_nossl.a
else
  TARGETS=lib_nossl.a
endif

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

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

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

ifeq ($(strip $(ACCOUNTD_ENABLE)), true)
  ifeq ($(strip $(ACCOUNTD_USE_BSD_PTY)), true)
    OS_DEFS = -DUSE_BSD_PTY
  endif
endif

OBJS= \
  pool.o assoc.o list.o buffer.o str.o memblock.o mystring.o iostream.o \
  misc.o ipaddr.o os.o process.o utf8.o html.o \
  mymutex.o setproctitle.o cdb.o template.o template_parse.o \
  template_compile.o template_expand.o template_vals.o

WITHSSL_OBJS = ssl.o mydb_db3.o mydb.o

NOSSL_OBJS = no_ssl.o

all: $(TARGETS)

lib_withssl.a: $(OBJS) $(WITHSSL_OBJS)
	rm -f lib_withssl.a
	ar q lib_withssl.a $(OBJS) $(WITHSSL_OBJS)

lib_nossl.a: $(OBJS) $(NOSSL_OBJS)
	rm -f lib_nossl.a
	ar q lib_nossl.a $(OBJS) $(NOSSL_OBJS)

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

os.o: os.c os_bsd.c os_linux.c os_solaris.c
	$(CC) $(CFLAGS) -c $(OS_DEFS) $<

ssl.o: ssl.c *.h Makefile
	$(CC) $(CFLAGS) $(SSL_INCLUDE) $(SSL_DEFS) -c $<

# mydb_db3.o: need to add DB_DEFS
mydb_db3.o: mydb_db3.c *.h Makefile
	$(CC) $(CFLAGS) $(DB_INCLUDE) $(DB_DEFS) -c $<

mymutex.o:  mymutex.c mymutex_sem.c mymutex_file.c
	$(CC) $(CFLAGS) $(MUTEX_DEF) -c $<

clean:
	rm -f lib.o $(OBJS) $(WITHSSL_OBJS) $(NOSSL_OBJS) *~ \#*\#

install: all
	cp template_expand template_compile ../bin
