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

MODULE=internet
all: makeMakedeps ../../../modules$(R_ARCH)/internet.dll ../../../modules$(R_ARCH)/internet2.dll

CSOURCES=internet.c nanoftp.c nanohttp.c sockconn.c Rsock.c sock.c Rhttpd.c

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

WSOCK=-lws2_32

../../../modules$(R_ARCH)/internet.dll: internet.o nanoftp.o nanohttp.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 $(WSOCK)
	@$(RM) internet.def

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

internet2.o: internet.c
	@$(CC) $(CPPFLAGS) $(CFLAGS) -DUSE_WININET -c $< -o $@

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

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

internet2.d: internet.c
	@echo "making $@ from $<"
	@$(CC) -MM $(CPPFLAGS) -DUSE_WININET -c $< -o foo
	@sed -e 's/internet.o/internet2.o/' foo > internet2.d
	@rm foo


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

-include Makedeps
