#### Makefile for SquirrelMail IMAP Proxy
#### Contributed by Gary Mills <mills@cc.UManitoba.CA>

# Fixed to work with configure script
# by Devrim SERAL <devrim@gazi.edu.tr>

# Cleaned up by Ken Murchison, Brad Smith

## Tuneables

# Paths
SHELL = /bin/sh
VPATH = @srcdir@

top_srcdir = @top_srcdir@
srcdir = @srcdir@
prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = $(exec_prefix)/bin
sbindir = $(exec_prefix)/sbin
infodir = $(prefix)/info
libdir = $(prefix)/lib/gnudl
mandir = $(prefix)/man/man3

CC = @CC@
CPPFLAGS = @CPPFLAGS@
CFLAGS = @CFLAGS@
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
DEFINES = @DEFINES@
FLAGS = -I. -I./include

INSTALL = @INSTALL@
EBIN = $(sbindir)
MAN =  $(mandir)
ETC =  /etc
# ETC =  @sysconfdir@


## Nothing to change after this point

# Libraries

XYD_LIB = $(LIBS)
TAT_LIB = @LIB_CURSES@

# Object files

XYD_OBJ = ./src/icc.o ./src/main.o ./src/imapcommon.o ./src/request.o \
	  ./src/hash.o ./src/becomenonroot.o ./src/config.o ./src/logging.o \
	  ./src/threads.o \
          ./src/select.o
TAT_OBJ = ./src/pimpstat.o ./src/config.o

# Final targets

XYD_BIN = ./bin/in.imapproxyd
TAT_BIN = ./bin/pimpstat

# Rules

all: $(XYD_BIN) $(TAT_BIN)

$(XYD_OBJ) $(TAT_OBJ): $(MAKEFILE) ./include/common.h ./include/imapproxy.h

.c.o:
	$(CC) $(CFLAGS) $(FLAGS) $(CPPFLAGS) -c -o $@ $<

$(XYD_BIN): $(XYD_OBJ)
	$(CC) -o $@ $(XYD_OBJ) $(LDFLAGS) $(XYD_LIB)

$(TAT_BIN): $(TAT_OBJ)
	$(CC) -o $@ $(TAT_OBJ) $(LDFLAGS) $(TAT_LIB)

clean:
	rm -f ./src/core  $(XYD_OBJ) $(TAT_OBJ) $(XYD_BIN) $(TAT_BIN)

distclean: clean
	rm -f config.cache config.log config.h Makefile

install: $(XYD_BIN) $(TAT_BIN)
	mkdir -p $(DESTDIR)$(EBIN)
	$(INSTALL) -o bin -g bin -m 0755 $(XYD_BIN) $(DESTDIR)$(EBIN)
	$(INSTALL) -o bin -g bin -m 0755 $(TAT_BIN) $(DESTDIR)$(EBIN)

install-init-linux:
	$(INSTALL) -o root -g sys -m 0755 ./scripts/imapproxy-linux.init $(DESTDIR)$(ETC)/init.d/imapproxy
	ln -s ../init.d/imapproxy $(DESTDIR)/etc/rc2.d/S99imapproxy
	ln -s ../init.d/imapproxy $(DESTDIR)/etc/rc0.d/K10imapproxy

install-init-systemd:
	$(INSTALL) -o root -g root -m 0644 ./scripts/imap_proxy.service $(DESTDIR)/lib/systemd/system

install-conf:
	$(INSTALL) -o root -g bin -m 0644 ./scripts/imapproxy.conf $(DESTDIR)$(ETC)

rpm-install: install
	$(INSTALL) -o root -g sys -m 0644 ./scripts/imapproxy.conf $(DESTDIR)/etc
	$(INSTALL) -o root -g sys -m 0755 ./scripts/imapproxy-linux.init $(DESTDIR)/etc/init.d/imapproxy

pkg:
	pkgmk -o -r .
####
