#
# $Id: Makefile,v 1.26 2006/06/08 14:02:24 evertonm Exp $
#

# If the following aren't defined, nepim
# defines some internal types as work-arounds.
# It's always safer to have them defined, if
# the environment supports them.
# 
#   HAVE_IP_MREQN
#   HAVE_IPV6_MREQ
#   HAVE_SIGHANDLER_T
#   HAVE_SUSECONDS_T
# 
# The following are for portable definitions
# of uint8_t/uint16_t/uint32_t:
# 
#   HAVE_STDINT   -- for systems with <stdint.h>         
#   HAVE_INTTYPES -- for systems with <inttypes.h>
# 
# The following is specific for Solaris,
# which seems to demand a "uchar" argument
# for setsockopt(IP_MULTICAST_TTL):
# 
#   HAVE_UCHAR_MCAST_TTL
# 
# Systems with dlopen(3) support should have
# ENABLE_DLOPEN defined as -DHAVE_DLOPEN.
# Otherwise, tcpwrapper support is disabled.

OOP_BASE = /usr/local/oop
OOP_INC  = $(OOP_BASE)/include
OOP_LIB  = $(OOP_BASE)/lib

ENABLE_DLOPEN = -DHAVE_DLOPEN

CC      = gcc
WARN    = -Wall
REENT   = -D_REENTRANT
CFLAGS  = $(WARN) $(REENT) -g -ggdb -I$(OOP_INC) $(ENABLE_DLOPEN) \
	 -DHAVE_IPV6_MREQ
LDFLAGS += -L$(OOP_LIB) -loop

PLATFORM=$(shell uname)

ifeq ($(PLATFORM),SunOS)
SPARC64 = -m64 -mcpu=v9
CFLAGS += -DHAVE_SUSECONDS_T -DHAVE_UCHAR_MCAST_TTL -DHAVE_INTTYPES \
	$(SPARC64)
LDFLAGS += $(SPARC64) -R$(OOP_LIB)
LDFLAGS += -lsocket -lnsl
ifdef ENABLE_DLOPEN
LDFLAGS += -ldl
endif
endif

ifeq ($(PLATFORM),Linux)
CFLAGS += -DHAVE_STDINT -DHAVE_SUSECONDS_T \
	-DHAVE_SIGHANDLER_T -DHAVE_IP_MREQN
ifdef ENABLE_DLOPEN
LDFLAGS += -ldl
endif
endif

ifeq ($(PLATFORM),NetBSD)
CFLAGS += -DHAVE_INTTYPES -DHAVE_UCHAR_MCAST_TTL
endif

ifeq ($(PLATFORM),OpenBSD)
CFLAGS += -DHAVE_INTTYPES -DHAVE_UCHAR_MCAST_TTL
endif

ifeq ($(PLATFORM),FreeBSD)
CFLAGS += -DHAVE_INTTYPES
endif

OBJ    = main.o conf.o sock.o session.o pipe.o \
	common.o client.o server.o slot.o \
	udp_server.o udp_client.o greet.o \
	array.o usock.o str.o udp_header.o int.o \
	tcpwrap.o

TARGET = nepim

.PHONY: default
default: $(TARGET)

.PHONY: clean
clean:
	rm -f *.o *~ $(TARGET)

.PHONY: build
build: clean default

$(TARGET): $(OBJ)
	$(CC) $(LDFLAGS) -o $@ $^
