CC		= @CC@
RM		= @RM@
MV		= @MV@
CP		= @CP@
INSTALL		= @INSTALL@
prefix		= @prefix@
exec_prefix	= @exec_prefix@
datarootdir	= @datarootdir@
bindir		= @sbindir@
datadir		= @datadir@
sysconfdir	= @sysconfdir@
libdir		= @libdir@
sbindir		= @sbindir@
localstatedir	= @localstatedir@
DOCDIR		= @DOCDIR@
MODDIR		= @MODDIR@
DATADIR		= @DATADIR@
RUNDIR		= @RUNDIR@
LOGDIR		= @LOGDIR@
SHAREDIR	= @SHAREDIR@
BIN		= dsyslog@EXEEXT@
MKDEP		= @MKDEP@
CFLAGS		= @CFLAGS@ -I../include -DBINDIR=\"$(bindir)\"

VERSION		= @PACKAGE_VERSION@

LIBS		= @LIBS@
LDFLAGS		= @LDFLAGS@ @LTLIBINTL@
RPATH		= @RPATH@
CPPFLAGS	= @CPPFLAGS@

# Want absolute paths?
SRCDIR		= .
@ABSPATHS@SRCDIR= @SRCDIR@/src

BUILDDIR	= @BUILDDIR@

default: all

SRCS = \
	dsyslog_cond.c \
	dsyslog_config.c \
	dsyslog_confparse.c \
	dsyslog_event.c \
	dsyslog_filter.c \
	dsyslog_main.c \
	dsyslog_module.c \
	dsyslog_output.c \
	dsyslog_severity.c \
	dsyslog_source.c

OBJS = ${SRCS:.c=.o}

all: dsyslog 

build: all

dsyslog: $(OBJS)
	${CC} ${CFLAGS} ${LDFLAGS} -o $@ ${OBJS} ${LIBS} ${RPATH}

install: build
	$(INSTALL) -m 755 -d $(DESTDIR)$(prefix)
	$(INSTALL) -m 755 -d $(DESTDIR)$(bindir)
	$(INSTALL) -m 755 -d $(DESTDIR)$(sysconfdir)
	$(INSTALL) -m 755 -d $(DESTDIR)$(localstatedir)
	$(INSTALL) -m 755 -d $(DESTDIR)$(DOCDIR)
	$(INSTALL) -m 755 -d $(DESTDIR)$(LOGDIR)
	$(INSTALL) -m 755 -d $(DESTDIR)$(RUNDIR)
	$(INSTALL) -m 755 -d $(DESTDIR)$(DATADIR)
	$(INSTALL) -m 755 -d $(DESTDIR)$(SHAREDIR)/www
	$(INSTALL) -m 755 -c $(BIN) $(DESTDIR)$(bindir)
	(cd ../doc; for i in *; do \
		[ -f $$i ] && $(INSTALL) -m 644 $$i $(DESTDIR)$(DOCDIR); \
		if [ -d $$i ]; then \
			cd $$i; \
			$(INSTALL) -m 755 -d $(DESTDIR)$(DOCDIR)/$$i; \
			for j in *; do \
				[ -f $$j ] && $(INSTALL) -m 644 $$j $(DESTDIR)$(DOCDIR)/$$i; \
			done; \
			cd ..; \
		fi; \
	done)
	(cd ../www; for i in *; do \
		[ -f $$i ] && $(INSTALL) -m 644 $$i $(DESTDIR)$(SHAREDIR)/www; \
		if [ -d $$i ]; then \
			cd $$i; \
			$(INSTALL) -m 755 -d $(DESTDIR)$(SHAREDIR)/www/$$i; \
			for j in *; do \
				[ -f $$j ] && $(INSTALL) -m 644 $$j $(DESTDIR)$(SHAREDIR)/www/$$i; \
			done; \
			cd ..; \
		fi; \
	done)

.c.o:
	${CC} ${CPPFLAGS} ${CFLAGS} -c $< -o $@

.PHONY: depend clean distclean
# This sed command sucks but I don't know a better way -- jilles
depend:
	${MKDEP} ${PICFLAGS} ${CPPFLAGS} ${CFLAGS} ${SRCS} | sed -e 's|\([^.]*\.o\):|$(SRCDIR)/\1:|' > .depend

clean:
	${RM} -f *.o *.exe *~ dsyslog.core core dsyslog

distclean: clean
	${RM} -f Makefile .depend

include .depend
