From bf9dcd92c7b73da6d2e134e4feda3cbff8204fc0 Mon Sep 17 00:00:00 2001
From: Dongsheng Song <dongsheng.song@gmail.com>
Date: Wed, 17 Nov 2010 17:35:42 +0800
Subject: [PATCH 2/2] Bring up to date windows build environment

---
 NMakefile              |    5 ++---
 src/NMakefile          |   11 +++++++----
 src/keepalive.c        |    2 +-
 src/libssh2_priv.h     |   21 ---------------------
 win32/config.mk        |   16 +++++++---------
 win32/libssh2.rc       |    2 +-
 win32/libssh2_config.h |    8 +++++++-
 win32/rules.mk         |    3 ++-
 8 files changed, 27 insertions(+), 41 deletions(-)

diff --git a/NMakefile b/NMakefile
index 51948cc..0254d53 100644
--- a/NMakefile
+++ b/NMakefile
@@ -11,9 +11,8 @@ clean:
 
 real-clean: clean
 	-del libssh2.dll
+	-del libssh2.dll.manifest
 	-del libssh2.exp
 	-del libssh2.ilk
 	-del libssh2.lib
-	-del *.pdb
-
-
+	-del libssh2.pdb
diff --git a/src/NMakefile b/src/NMakefile
index aabceab..b54541a 100644
--- a/src/NMakefile
+++ b/src/NMakefile
@@ -3,6 +3,7 @@
 CFLAGS=$(CFLAGS)
 
 OBJECTS = \
+	$(INTDIR)\agent.obj \
 	$(INTDIR)\channel.obj \
 	$(INTDIR)\comp.obj \
 	$(INTDIR)\crypt.obj \
@@ -10,6 +11,8 @@ OBJECTS = \
 	$(INTDIR)\hostkey.obj \
 	$(INTDIR)\keepalive.obj \
 	$(INTDIR)\kex.obj \
+	$(INTDIR)\knownhost.obj \
+	$(INTDIR)\libgcrypt.obj \
 	$(INTDIR)\mac.obj \
 	$(INTDIR)\misc.obj \
 	$(INTDIR)\openssl.obj \
@@ -20,14 +23,14 @@ OBJECTS = \
 	$(INTDIR)\session.obj \
 	$(INTDIR)\sftp.obj \
 	$(INTDIR)\transport.obj \
-	$(INTDIR)\userauth.obj
+	$(INTDIR)\userauth.obj \
+	$(INTDIR)\version.obj
 
 DLL=libssh2$(SUFFIX).dll
 
-$(DLL): $(OBJECTS)
-	$(CC) -o $(DLL) $(DLLFLAGS) $(OBJECTS) $(LIBS)
+$(DLL): $(OBJECTS) $(INTDIR)\libssh2.res
+	$(CC) -Fe"$(DLL)" $(DLLFLAGS) $(OBJECTS) $(INTDIR)\libssh2.res $(LIBS)
 
 all: $(DLL)
 
 !include "win32/rules.mk"
-
diff --git a/src/keepalive.c b/src/keepalive.c
index 260206a..160c80e 100644
--- a/src/keepalive.c
+++ b/src/keepalive.c
@@ -91,7 +91,7 @@ libssh2_keepalive_send (LIBSSH2_SESSION *session,
             *seconds_to_next = session->keepalive_interval;
     } else if (seconds_to_next) {
         *seconds_to_next = (int) session->keepalive_last_sent
-            + session->keepalive_interval - now;
+            + session->keepalive_interval - (int) now;
     }
 
     return 0;
diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h
index d281c11..b912111 100644
--- a/src/libssh2_priv.h
+++ b/src/libssh2_priv.h
@@ -43,14 +43,6 @@
 #define LIBSSH2_LIBRARY
 #include "libssh2_config.h"
 
-#ifdef HAVE_WINDOWS_H
-#include <windows.h>
-#endif
-
-#ifdef HAVE_WS2TCPIP_H
-#include <ws2tcpip.h>
-#endif
-
 #include <stdio.h>
 #include <time.h>
 
@@ -132,19 +124,6 @@ static inline int writev(int sock, struct iovec *iov, int nvecs)
 #include "openssl.h"
 #endif
 
-#ifdef HAVE_WINSOCK2_H
-
-#include <winsock2.h>
-#include <mswsock.h>
-#include <ws2tcpip.h>
-
-#ifdef _MSC_VER
-/* "inline" keyword is valid only with C++ engine! */
-#define inline __inline
-#endif
-
-#endif
-
 /* RFC4253 section 6.1 Maximum Packet Length says:
  *
  * "All implementations MUST be able to process packets with
diff --git a/win32/config.mk b/win32/config.mk
index 74627a4..15a7b8a 100644
--- a/win32/config.mk
+++ b/win32/config.mk
@@ -1,10 +1,10 @@
 
 # Tweak these for your system
-OPENSSLINC=..\openssl-0.9.8o\inc32
-OPENSSLLIB=..\openssl-0.9.8o\out32dll
+OPENSSLINC=..\thirdparty\openssl\inc32
+OPENSSLLIB=..\thirdparty\openssl\out32dll
 
-ZLIBINC=-DLIBSSH2_HAVE_ZLIB=1 /I..\zlib-1.2.5
-ZLIBLIB=..\zlib-1.2.5
+ZLIBINC=-DLIBSSH2_HAVE_ZLIB=1 /I..\thirdparty\zlib
+ZLIBLIB=..\thirdparty\zlib
 
 !if "$(TARGET)" == ""
 TARGET=Release
@@ -15,15 +15,13 @@ SUFFIX=_debug
 CPPFLAGS=/Od /MDd
 DLLFLAGS=/DEBUG /LDd
 !else
-CPPFLAGS=/Og /Oi /O2 /Oy /GF /Y- /MD /DNDEBUG
+CPPFLAGS=/MD /O2 /Oy- /Zi /D"_WIN32_WINNT=0x0502" /DNDEBUG
 DLLFLAGS=/DEBUG /LD
 !endif
 
-CPPFLAGS=/nologo /GL /Zi /EHsc $(CPPFLAGS) /Iwin32 /Iinclude /I$(OPENSSLINC) $(ZLIBINC) -DLIBSSH2_WIN32
+CPPFLAGS=/nologo /W3 /GL /EHsc /Fdlibssh2.pdb $(CPPFLAGS) /DWIN32_LEAN_AND_MEAN /DNOCRYPT /Iwin32 /Iinclude /I$(OPENSSLINC) $(ZLIBINC) -DLIBSSH2_WIN32
 CFLAGS=$(CPPFLAGS)
 DLLFLAGS=$(CFLAGS) $(DLLFLAGS)
-LIBS=$(OPENSSLLIB)\libeay32.lib $(OPENSSLLIB)\ssleay32.lib ws2_32.lib $(ZLIBLIB)\zlib.lib
+LIBS=ws2_32.lib user32.lib $(OPENSSLLIB)\libeay32.lib $(OPENSSLLIB)\ssleay32.lib $(ZLIBLIB)\zdll.lib
 
 INTDIR=$(TARGET)\$(SUBDIR)
-
-
diff --git a/win32/libssh2.rc b/win32/libssh2.rc
index 1fdd46c..1d8b56f 100644
--- a/win32/libssh2.rc
+++ b/win32/libssh2.rc
@@ -33,7 +33,7 @@ BEGIN
       VALUE "OriginalFilename", "libssh2.dll\0"
       VALUE "ProductName",      "The libssh2 library\0"
       VALUE "ProductVersion",   LIBSSH2_VERSION "\0"
-      VALUE "LegalCopyright",   "© " LIBSSH2_COPYRIGHT "\0"
+      VALUE "LegalCopyright",   "Copyright (c) " LIBSSH2_COPYRIGHT "\0"
       VALUE "License",          "http://www.libssh2.org/license.html\0"
     END
   END
diff --git a/win32/libssh2_config.h b/win32/libssh2_config.h
index 56c64a6..32524ce 100644
--- a/win32/libssh2_config.h
+++ b/win32/libssh2_config.h
@@ -4,11 +4,12 @@
 #ifndef WIN32
 #define WIN32
 #endif
+
 #ifndef _CRT_SECURE_NO_DEPRECATE
 #define _CRT_SECURE_NO_DEPRECATE 1
 #endif /* _CRT_SECURE_NO_DEPRECATE */
+
 #include <winsock2.h>
-#include <mswsock.h>
 #include <ws2tcpip.h>
 
 #ifdef __MINGW32__
@@ -22,7 +23,12 @@
 #define HAVE_SELECT
 
 #ifdef _MSC_VER
+/* "inline" keyword is valid only with C++ engine! */
+#define inline __inline
 #define snprintf _snprintf
+#if _MSC_VER <= 1200
+typedef int socklen_t;
+#endif
 #if _MSC_VER < 1500
 #define vsnprintf _vsnprintf
 #endif
diff --git a/win32/rules.mk b/win32/rules.mk
index bfb7784..49a21ed 100644
--- a/win32/rules.mk
+++ b/win32/rules.mk
@@ -12,4 +12,5 @@ $(INTDIR):
 {$(SUBDIR)}.c{$(INTDIR)}.obj::
 	$(CC) -c $(CFLAGS) /Fo"$(INTDIR)\\" $<
 
-
+$(INTDIR)\libssh2.res: win32\libssh2.rc
+	$(RC) /Fo"$@" $?
\ No newline at end of file
-- 
1.7.2.3

