###############################
# Makefile for NDO
#
# Last Modified: 10-02-2007
###############################


# Source code directories
CORE_INCLUDE=../../../include
SRC_INCLUDE=../include

prefix=@prefix@
exec_prefix=@exec_prefix@
LOGDIR=@localstatedir@
CFGDIR=@sysconfdir@
BINDIR=@bindir@
LIBEXECDIR=@libexecdir@
CGIDIR=@sbindir@
INSTALL=@INSTALL@
INSTALL_OPTS=@INSTALL_OPTS@

CC=@CC@

CFLAGS=@CFLAGS@ @DEFS@ 

# We don't like ANSI because ANSI doesn't like us! phhht!
#CFLAGS=-g -Wall -ansi -pedantic -DHAVE_CONFIG_H

# Compiler flags for use with Valgrind
#CFLAGS=-O0 -g -DHAVE_CONFIG_H

MOD_CFLAGS=@MOD_CFLAGS@
LDFLAGS=@LDFLAGS@
MOD_LDFLAGS=@MOD_LDFLAGS@
LIBS=@LIBS@
SOCKETLIBS=@SOCKETLIBS@
#DBCFLAGS=@DBCFLAGS@ 
#DBLDFLAGS=@DBLDFLAGS@
DBLIBS=@DBLIBS@
MATHLIBS=-lm
OTHERLIBS=@OTHERLIBS@

COMMON_INC=$(CORE_INCLUDE)/config.h $(SRC_INCLUDE)/common.h $(SRC_INCLUDE)/io.h $(SRC_INCLUDE)/protoapi.h $(SRC_INCLUDE)/utils.h
COMMON_SRC=io.c utils.c
COMMON_OBJS=io.o utils.o

NDO_INC=$(SRC_INCLUDE)/ido2db.h $(SRC_INCLUDE)/db.h
NDO_SRC=db.c
NDO_OBJS=db.o

CP=@CP@


all: file2sock log2ndo ido2db idomod.o sockdebug

file2sock: file2sock.c $(COMMON_INC) $(COMMON_OBJS)
	$(CC) $(CFLAGS) -o $@ file2sock.c $(COMMON_OBJS) $(LDFLAGS) $(LIBS) $(MATHLIBS) $(SOCKETLIBS) $(OTHERLIBS)

log2ndo: log2ndo.c $(COMMON_INC) $(COMMON_OBJS)
	$(CC) $(CFLAGS) -o $@ log2ndo.c $(COMMON_OBJS) $(LDFLAGS) $(LIBS) $(MATHLIBS) $(SOCKETLIBS) $(OTHERLIBS)

ido2db: ido2db.c $(NDO_INC) $(NDO_OBJS) $(COMMON_INC) $(COMMON_OBJS) dbhandlers.o
	$(CC) $(CFLAGS) $(DBCFLAGS) -o ido2db ido2db.c dbhandlers.o $(COMMON_OBJS) $(NDO_OBJS) $(LDFLAGS) $(DBLDFLAGS) $(LIBS) $(SOCKETLIBS) $(DBLIBS) $(MATHLIBS) $(OTHERLIBS)

idomod.o: idomod.c $(COMMON_INC) $(COMMON_OBJS)
	$(CC) $(MOD_CFLAGS) $(CFLAGS) -o idomod.o idomod.c $(COMMON_OBJS) $(MOD_LDFLAGS) $(LDFLAGS) $(LIBS) $(SOCKETLIBS) $(OTHERLIBS)

sockdebug: sockdebug.c $(COMMON_INC) $(COMMON_OBJS)
	$(CC) $(CFLAGS) -o $@ sockdebug.c $(COMMON_OBJS) $(LDFLAGS) $(LIBS) $(MATHLIBS) $(SOCKETLIBS) $(OTHERLIBS)

io.o: io.c $(SRC_INCLUDE)/io.h
	$(CC) $(MOD_CFLAGS) $(CFLAGS) -c -o $@ io.c

utils.o: utils.c $(SRC_INCLUDE)/utils.h
	$(CC) $(MOD_CFLAGS) $(CFLAGS) -c -o $@ utils.c

db.o: db.c $(SRC_INCLUDE)/db.h
	$(CC) $(CFLAGS) -c -o $@ db.c

dbhandlers.o: dbhandlers.c $(SRC_INCLUDE)/dbhandlers.h
	$(CC) $(CFLAGS) -c -o $@ dbhandlers.c

clean:
	rm -f core file2sock log2ndo ido2db sockdebug *.o
	rm -f *~ */*~

distclean: clean
	rm -f Makefile

devclean: distclean

install:
	$(INSTALL) -m 775 $(INSTALL_OPTS) -d $(DESTDIR)$(BINDIR)
	$(INSTALL) -m 774 $(INSTALL_OPTS) ido2db $(DESTDIR)$(BINDIR)
	$(INSTALL) -m 774 $(INSTALL_OPTS) idomod.o $(DESTDIR)$(BINDIR)

