#
# c-ares Makefile for djgpp/gcc/Watt-32.
#   By Gisle Vanem <giva@bgnett.no> 2004.
#
# $Id$

TOPDIR = ..

include ../packages/DOS/common.dj

include Makefile.inc

CFLAGS += -DWATT32 -DHAVE_AF_INET6 -DHAVE_PF_INET6 -DHAVE_IOCTLSOCKET \
          -DHAVE_IOCTLSOCKET_FIONBIO -DHAVE_STRUCT_IN6_ADDR \
          -DHAVE_SOCKADDR_IN6_SIN6_SCOPE_ID -DHAVE_SYS_TIME_H \
          -DHAVE_STRUCT_SOCKADDR_IN6 -DHAVE_STRUCT_ADDRINFO \
          -DHAVE_ARPA_NAMESER_H -DHAVE_ARPA_INET_H -DHAVE_SYS_SOCKET_H \
          -DHAVE_SYS_UIO_H -DHAVE_NETINET_IN_H -DHAVE_NETINET_TCP_H \
          -DNS_INADDRSZ=4 -DHAVE_RECV -DHAVE_SEND -DHAVE_GETTIMEOFDAY \
          -DSEND_TYPE_ARG1='int'   -DSEND_QUAL_ARG2='const' \
          -DSEND_TYPE_ARG2='void*' -DSEND_TYPE_ARG3='int' \
          -DSEND_TYPE_ARG4='int'   -DSEND_TYPE_RETV='int' \
          -DRECV_TYPE_ARG1='int'   -DRECV_TYPE_ARG2='void*' \
          -DRECV_TYPE_ARG3='int'   -DRECV_TYPE_ARG4='int' \
          -DRECV_TYPE_RETV='int'   -DHAVE_STRUCT_TIMEVAL \
          -Dselect=select_s        -Dsocklen_t=int -UHAVE_CONFIG_H \
          -DRECVFROM_TYPE_ARG1='int' -DRECVFROM_TYPE_ARG2='void' \
          -DRECVFROM_TYPE_ARG3='int' -DRECVFROM_TYPE_ARG4='int' \
          -DRECVFROM_TYPE_ARG6='int' -DRECVFROM_TYPE_RETV='int' \
          -DRECVFROM_TYPE_ARG5='struct sockaddr' -DHAVE_RECVFROM \
          -DRECVFROM_TYPE_ARG2_IS_VOID -DHAVE_STRDUP -DHAVE_NETDB_H \
          -DHAVE_STRCASECMP -DHAVE_STRNCASECMP -DHAVE_GETHOSTNAME

LDFLAGS = -s

ifeq ($(USE_DEBUG),1)
  EX_LIBS  = ../lib/libcurl.a
  OBJ_HACK = $(OBJECTS)
else
  OBJ_HACK = libcares.a
endif

ifeq ($(USE_SSL),1)
  EX_LIBS += $(OPENSSL_ROOT)/lib/libssl.a $(OPENSSL_ROOT)/lib/libcrypt.a
endif

ifeq ($(USE_ZLIB),1)
  EX_LIBS += $(ZLIB_ROOT)/libz.a
endif

ifeq ($(USE_IDNA),1)
  EX_LIBS += $(LIBIDN_ROOT)/lib/dj_obj/libidn.a -liconv
endif

EX_LIBS += $(WATT32_ROOT)/lib/libwatt.a

OBJECTS = $(addprefix $(OBJ_DIR)/, $(CSOURCES:.c=.o))

all: $(OBJ_DIR) libcares.a ahost.exe adig.exe acountry.exe
	@echo Welcome to c-ares.

libcares.a: $(OBJECTS)
	ar rs $@ $?

ahost.exe: ahost.c $(OBJ_DIR)/ares_getopt.o $(OBJ_HACK)
	$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $^ $(EX_LIBS)

adig.exe: adig.c $(OBJ_DIR)/ares_getopt.o $(OBJ_HACK)
	$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $^ $(EX_LIBS)

acountry.exe: acountry.c $(OBJ_DIR)/ares_getopt.o $(OBJ_HACK)
	$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $^ $(EX_LIBS)

clean:
	rm -f $(OBJECTS) libcares.a

vclean realclean: clean
	rm -f ahost.exe adig.exe acountry.exe depend.dj
	- rmdir $(OBJ_DIR)

-include depend.dj

