#-*- Makefile -*-
include ../../gnuwin32/MkRules

MODULE = internet
ifdef USE_LIBCURL
all: makeMakedeps ../../../modules$(R_ARCH)/internet.dll
else
all:
	@echo "*** libcurl is required ***" && exit 1
endif

CSOURCES = internet.c libcurl.c  sockconn.c Rsock.c sock.c Rhttpd.c

CPPFLAGS = -I../../include -I../../extra/graphapp -DHAVE_CONFIG_H

EXTRA_LIBS = -lwininet -lws2_32

ifdef USE_LIBCURL
  libcurl-CPPFLAGS += -DHAVE_CURL_CURL_H -DHAVE_LIBCURL
  ifndef USE_PKG_CONFIG
    libcurl-CPPFLAGS += -DCURL_STATICLIB -I"$(CURL_PATH)"/include
    EXTRA_LIBS += -L"$(CURL_PATH)"/lib$(R_ARCH) $(CURL_LIBS)
  else
    libcurl-CPPFLAGS += $(shell $(PKG_CONFIG) --cflags libcurl)
    EXTRA_LIBS += $(shell $(PKG_CONFIG) --libs libcurl)
  endif
endif


../../../modules$(R_ARCH)/internet.dll: internet.o libcurl.o sockconn.o Rhttpd.o Rsock.o sock.o dllversion.o
	@$(MKDIR) -p ../../../modules$(R_ARCH)
	@$(ECHO) "EXPORTS" > internet.def
	@$(ECHO) " R_init_internet" >> internet.def
	$(DLL) -shared  -o $@ $^ internet.def -L../../../$(IMPDIR) -lR -lRgraphapp $(EXTRA_LIBS)
	@$(RM) internet.def

clean:
	@$(RM) Makedeps *.d *.o *.def *.dll

# Dependencies
dllversion.o: ../../include/Rversion.h
DEPS = $(CSOURCES:.c=.d)


makeMakedeps: $(DEPS)
	@$(RM) Makedeps
	@cat $(DEPS) >> Makedeps

-include Makedeps
