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

MODULE=internet
all: makeMakedeps ../../../modules/internet.dll ../../../modules/internet2.dll

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

CPPFLAGS=-I../../include -I../../extra/graphapp -DHAVE_CONFIG_H
CFLAGS=$(OPTFLAGS)

WSOCK=-lws2_32

../../../modules/internet.dll: internet.o nanoftp.o nanohttp.o sockconn.o Rsock.o sock.o dllversion.o
	$(MKDIR) -p ../../../modules
	@$(ECHO) "EXPORTS" > internet.def
	@$(ECHO) " R_init_internet" >> internet.def
	$(DLL) -shared  -o $@ $^ internet.def -L../../../$(IMPDIR) -lR $(GRAPHAPP_LIB) $(WSOCK)
	@$(RM) internet.def

../../../modules/internet2.dll: internet2.o sockconn.o Rsock.o sock.o dllversion.o
	$(MKDIR) -p ../../../modules
	@$(ECHO) "EXPORTS" > internet2.def
	@$(ECHO) " R_init_internet2" >> internet2.def
	$(DLL) -shared  -o $@ $^ internet2.def -L../../../$(IMPDIR) -lR $(GRAPHAPP_LIB) -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) $(DEPARG) $(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
