Skip to content

Commit

Permalink
Add guide and scripts for Windows for IoT compatible building of qpid…
Browse files Browse the repository at this point in the history
…-proton 0.8 and openssl 1.0.2-beta3
  • Loading branch information
ivanignatiev committed Jan 22, 2015
1 parent 93eb102 commit 400326c
Show file tree
Hide file tree
Showing 7 changed files with 303 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Devices/IntelGalileo/ConnectTheDotsGalileo/Docs/Build Libraries.md
@@ -0,0 +1,25 @@
##Requirements for OpenSSL
* Install Git (chose option to add Git to the system PATH during installation) - http://git-scm.com/download/win
* Install Perl (chose option to add Git to the system PATH during installation) - https://www.perl.org/get.html
* Install Visual Studio 2013

##OpenSSL
* Create solder `C:\Source`
* Copy `openssl-debug.bat`, `openssl-release.bat`, `windowsiot.patch`, and `windowsiot_dbg.patch` to `C:\Source`
* Launch `openssl-release.bat` or `openssl-debug.bat` (depend on your needs)
* Find build of `openssl-1.0.2-beta3` in `C:\Source\openssl\builds` (or `C:\Source\openssl\builds_dbg` if Debug configuration was built)

##Requirements for Apache Qpid Proton C
* Build OpenSSL
* Install Cmake (chose option to add Git to the system PATH during installation) - http://www.cmake.org/download/
* Install Python 2.7 (chose option to add Git to the system PATH during installation) - https://www.python.org/downloads/windows/

##Apache Qpid Proton C
* Copy `proton-release.bat` and `proton-debug.bat` to `C:\Source`
* Launch `proton-release.bat` or `proton-debug.bat` (depends on your needs)
* Find build of `qpid-proton 0.8` in `C:\Source\proton\builds` (or `C:\Source\proton\builds_dbg` if Debug configuration was built)

##References
To understand better, please, read following articles:
* http://pjdecarlo.com/2015/01/porting-open-source-libraries-to-windows-for-iot-mincore.html
* https://code.msdn.microsoft.com/windowsazure/Using-Apache-Qpid-Proton-C-afd76504
15 changes: 15 additions & 0 deletions Devices/IntelGalileo/ConnectTheDotsGalileo/Docs/openssl-debug.bat
@@ -0,0 +1,15 @@
:: set up the Visual Studio environment
call "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\vcvars32.bat"
:: clone library's sources
git clone -b OpenSSL_1_0_2-beta3 https://github.com/openssl/openssl.git openssl
cd openssl
:: generate makefiles for nmake
perl Configure debug-VC-WIN32 no-asm --prefix="C:\Source\openssl\builds_dbg"
call "ms\do_ms.bat"
:: apply the patch to sources and the makefile to make Windows for IoT compatible
git apply ..\windowsiot_dbg.patch
:: compile sources
nmake -f ms\ntdll.mak
:: install binaries to the builds\ folder
nmake -i -f ms\ntdll.mak install
cd ..
@@ -0,0 +1,15 @@
:: set up the Visual Studio environment
call "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\vcvars32.bat"
:: clone library's sources
git clone -b OpenSSL_1_0_2-beta3 https://github.com/openssl/openssl.git openssl
cd openssl
:: generate makefiles for nmake
perl Configure VC-WIN32 no-asm --prefix="C:\Source\openssl\builds"
call "ms\do_ms.bat"
:: apply the patch to sources and the makefile to make Windows for IoT compatible
git apply ..\windowsiot.patch
:: compile sources
nmake -f ms\ntdll.mak
:: install binaries to the builds\ folder
nmake -i -f ms\ntdll.mak install
cd ..
18 changes: 18 additions & 0 deletions Devices/IntelGalileo/ConnectTheDotsGalileo/Docs/proton-debug.bat
@@ -0,0 +1,18 @@
:: set up the Visual Studio environment
call "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\vcvars32.bat"
:: clone library's sources
git clone -b 0.8 https://github.com/apache/qpid-proton.git proton
cd proton
:: generate solutions and projects files
set OPENSSL_ROOT_DIR=C:\Source\openssl\builds_dbg
cmake -DCMAKE_CXX_STANDARD_LIBRARIES:STRING=mincore.lib ^
-DCMAKE_CXX_FLAGS:STRING=" /arch:IA32 /DWIN32 /D_WINDOWS /W3 /GR /EHsc " ^
-DCMAKE_C_FLAGS:STRING=" /arch:IA32 /DWIN32 /D_WINDOWS /W3 " ^
-DCMAKE_C_STANDARD_LIBRARIES:STRING=mincore.lib ^
-DCMAKE_INSTALL_PREFIX:PATH="C:\Source\proton\builds_dbg" ^
-DCMAKE_EXE_LINKER_FLAGS:STRING=" /machine:X86 /NODEFAULTLIB:kernel32.lib /NODEFAULTLIB:ws2_32.lib /NODEFAULTLIB:gdi32.lib /NODEFAULTLIB:advapi32.lib /NODEFAULTLIB:crypt32.lib /NODEFAULTLIB:user32.lib "
:: compile sources
msbuild Proton.sln /property:Configuration=Debug
:: install binaries to the builds\ folder
msbuild INSTALL.vcxproj /property:Configuration=Debug
cd ..
18 changes: 18 additions & 0 deletions Devices/IntelGalileo/ConnectTheDotsGalileo/Docs/proton-release.bat
@@ -0,0 +1,18 @@
:: set up the Visual Studio environment
call "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\vcvars32.bat"
:: clone library's sources
git clone -b 0.8 https://github.com/apache/qpid-proton.git proton
cd proton
set OPENSSL_ROOT_DIR=C:\Source\openssl\builds
:: generate solutions and projects files
cmake -DCMAKE_CXX_STANDARD_LIBRARIES:STRING=mincore.lib ^
-DCMAKE_CXX_FLAGS:STRING=" /arch:IA32 /DWIN32 /D_WINDOWS /W3 /GR /EHsc " ^
-DCMAKE_C_FLAGS:STRING=" /arch:IA32 /DWIN32 /D_WINDOWS /W3 " ^
-DCMAKE_C_STANDARD_LIBRARIES:STRING=mincore.lib ^
-DCMAKE_INSTALL_PREFIX:PATH="C:\Source\proton\builds" ^
-DCMAKE_EXE_LINKER_FLAGS:STRING=" /machine:X86 /NODEFAULTLIB:kernel32.lib /NODEFAULTLIB:ws2_32.lib /NODEFAULTLIB:gdi32.lib /NODEFAULTLIB:advapi32.lib /NODEFAULTLIB:crypt32.lib /NODEFAULTLIB:user32.lib "
:: compile sources
msbuild Proton.sln /property:Configuration=Release
:: install binaries to the builds\ folder
msbuild INSTALL.vcxproj /property:Configuration=Release
cd ..
106 changes: 106 additions & 0 deletions Devices/IntelGalileo/ConnectTheDotsGalileo/Docs/windowsiot.patch
@@ -0,0 +1,106 @@
From 3542df4a36ce83086ab86ff0132bbaf5678babcb Mon Sep 17 00:00:00 2001
From: ivanignatiev <ignatiev.ivan@gmail.com>
Date: Tue, 20 Jan 2015 18:02:58 +0100
Subject: [PATCH] Enable Windows for IoT build

---
apps/apps.c | 9 ++++++++-
crypto/cryptlib.c | 4 ++--
crypto/rand/rand_win.c | 2 +-
ms/ntdll.mak | 10 +++++-----
4 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/apps/apps.c b/apps/apps.c
index 235ede4..71ae318 100644
--- a/apps/apps.c
+++ b/apps/apps.c
@@ -3084,12 +3084,19 @@ static int WIN32_rename(const char *from, const char *to)
#endif
for (i=0;i<tlen;i++) tto[i] =(TCHAR)to[i];
}
-
+#if !defined(_WIN32_WCE) || _WIN32_WCE>=101
+ if (MoveFileExW((WCHAR *)tfrom,(WCHAR *)tto,MOVEFILE_REPLACE_EXISTING)) goto ok;
+#else
if (MoveFile(tfrom,tto)) goto ok;
+#endif
err=GetLastError();
if (err==ERROR_ALREADY_EXISTS || err==ERROR_FILE_EXISTS)
{
+#if !defined(_WIN32_WCE) || _WIN32_WCE>=101
+ if (DeleteFile(tto) && MoveFileExW((WCHAR *)tfrom,(WCHAR *)tto,MOVEFILE_REPLACE_EXISTING))
+#else
if (DeleteFile(tto) && MoveFile(tfrom,tto))
+#endif
goto ok;
err=GetLastError();
}
diff --git a/crypto/cryptlib.c b/crypto/cryptlib.c
index be61a9d..98575ab 100644
--- a/crypto/cryptlib.c
+++ b/crypto/cryptlib.c
@@ -784,7 +784,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason,
}
#endif

-#if defined(_WIN32) && !defined(__CYGWIN__)
+#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(BUILD_FOR_WINIOT)
#include <tchar.h>
#include <signal.h>
#ifdef __WATCOMC__
@@ -935,7 +935,7 @@ void OpenSSLDie(const char *file,int line,const char *assertion)
OPENSSL_showfatal(
"%s(%d): OpenSSL internal error, assertion failed: %s\n",
file,line,assertion);
-#if !defined(_WIN32) || defined(__CYGWIN__)
+#if !defined(_WIN32) || defined(__CYGWIN__) || defined(BUILD_FOR_WINIOT)
abort();
#else
/* Win32 abort() customarily shows a dialog, but we just did that... */
diff --git a/crypto/rand/rand_win.c b/crypto/rand/rand_win.c
index 324e395..c64f162 100644
--- a/crypto/rand/rand_win.c
+++ b/crypto/rand/rand_win.c
@@ -737,7 +737,7 @@ static void readtimer(void)

static void readscreen(void)
{
-#if !defined(OPENSSL_SYS_WINCE) && !defined(OPENSSL_SYS_WIN32_CYGWIN)
+#if !defined(OPENSSL_SYS_WINCE) && !defined(OPENSSL_SYS_WIN32_CYGWIN) && !defined(BUILD_FOR_WINIOT)
HDC hScrDC; /* screen DC */
HBITMAP hBitmap; /* handle for our bitmap */
BITMAP bm; /* bitmap properties */
diff --git a/ms/ntdll.mak b/ms/ntdll.mak
index 853060f..8fd3925 100644
--- a/ms/ntdll.mak
+++ b/ms/ntdll.mak
@@ -18,21 +18,21 @@ OPENSSLDIR=C:\Source\openssl\builds\ssl
# Set your compiler options
PLATFORM=VC-WIN32
CC=cl
-CFLAG= /MD /Ox /O2 /Ob2 -DOPENSSL_THREADS -DDSO_WIN32 -W3 -Gs0 -GF -Gy -nologo -DOPENSSL_SYSNAME_WIN32 -DWIN32_LEAN_AND_MEAN -DL_ENDIAN -D_CRT_SECURE_NO_DEPRECATE -DOPENSSL_USE_APPLINK -I. -DOPENSSL_NO_RC5 -DOPENSSL_NO_MD2 -DOPENSSL_NO_KRB5 -DOPENSSL_NO_JPAKE -DOPENSSL_NO_STATIC_ENGINE
-APP_CFLAG= /Zi /Fd$(TMP_D)/app
-LIB_CFLAG= /Zi /Fd$(TMP_D)/lib -D_WINDLL
+CFLAG= /arch:IA32 /MD /Ox /O2 /Ob2 -DOPENSSL_THREADS -DBUILD_FOR_WINIOT -DOPENSSL_NO_CAPIENG -DDSO_WIN32 -W3 -Gs0 -GF -Gy -nologo -DOPENSSL_SYSNAME_WIN32 -DWIN32_LEAN_AND_MEAN -DL_ENDIAN -D_CRT_SECURE_NO_DEPRECATE -DOPENSSL_USE_APPLINK -I. -DOPENSSL_NO_RC5 -DOPENSSL_NO_MD2 -DOPENSSL_NO_KRB5 -DOPENSSL_NO_JPAKE -DOPENSSL_NO_STATIC_ENGINE
+APP_CFLAG= /arch:IA32 /Zi /Fd$(TMP_D)/app
+LIB_CFLAG= /arch:IA32 /Zi /Fd$(TMP_D)/lib -D_WINDLL
SHLIB_CFLAG=
APP_EX_OBJ=setargv.obj $(OBJ_D)\applink.obj /implib:$(TMP_D)\junk.lib
SHLIB_EX_OBJ=
# add extra libraries to this define, for solaris -lsocket -lnsl would
# be added
-EX_LIBS=ws2_32.lib gdi32.lib advapi32.lib crypt32.lib user32.lib
+EX_LIBS=mincore.lib

# The OpenSSL directory
SRC_D=.

LINK=link
-LFLAGS=/nologo /subsystem:console /opt:ref /debug
+LFLAGS= /NODEFAULTLIB:kernel32.lib /NODEFAULTLIB:ws2_32.lib /NODEFAULTLIB:gdi32.lib /NODEFAULTLIB:advapi32.lib /NODEFAULTLIB:crypt32.lib /NODEFAULTLIB:user32.lib /nologo /subsystem:console /opt:ref /debug
RSC=rc

# The output directory for everything interesting
--
1.9.5.msysgit.0

106 changes: 106 additions & 0 deletions Devices/IntelGalileo/ConnectTheDotsGalileo/Docs/windowsiot_dbg.patch
@@ -0,0 +1,106 @@
From a3faa52ef886df647cc83eed7199965f4192c5e1 Mon Sep 17 00:00:00 2001
From: ivanignatiev <ignatiev.ivan@gmail.com>
Date: Tue, 20 Jan 2015 18:54:48 +0100
Subject: [PATCH] Enable debug build of OpenSLL for Windows for IoT

---
apps/apps.c | 9 +-
crypto/cryptlib.c | 4 +-
crypto/rand/rand_win.c | 2 +-
ms/ntdll.mak | 486 ++++++++++++++++++++++++-------------------------
4 files changed, 254 insertions(+), 247 deletions(-)

diff --git a/apps/apps.c b/apps/apps.c
index 235ede4..71ae318 100644
--- a/apps/apps.c
+++ b/apps/apps.c
@@ -3084,12 +3084,19 @@ static int WIN32_rename(const char *from, const char *to)
#endif
for (i=0;i<tlen;i++) tto[i] =(TCHAR)to[i];
}
-
+#if !defined(_WIN32_WCE) || _WIN32_WCE>=101
+ if (MoveFileExW((WCHAR *)tfrom,(WCHAR *)tto,MOVEFILE_REPLACE_EXISTING)) goto ok;
+#else
if (MoveFile(tfrom,tto)) goto ok;
+#endif
err=GetLastError();
if (err==ERROR_ALREADY_EXISTS || err==ERROR_FILE_EXISTS)
{
+#if !defined(_WIN32_WCE) || _WIN32_WCE>=101
+ if (DeleteFile(tto) && MoveFileExW((WCHAR *)tfrom,(WCHAR *)tto,MOVEFILE_REPLACE_EXISTING))
+#else
if (DeleteFile(tto) && MoveFile(tfrom,tto))
+#endif
goto ok;
err=GetLastError();
}
diff --git a/crypto/cryptlib.c b/crypto/cryptlib.c
index be61a9d..98575ab 100644
--- a/crypto/cryptlib.c
+++ b/crypto/cryptlib.c
@@ -784,7 +784,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason,
}
#endif

-#if defined(_WIN32) && !defined(__CYGWIN__)
+#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(BUILD_FOR_WINIOT)
#include <tchar.h>
#include <signal.h>
#ifdef __WATCOMC__
@@ -935,7 +935,7 @@ void OpenSSLDie(const char *file,int line,const char *assertion)
OPENSSL_showfatal(
"%s(%d): OpenSSL internal error, assertion failed: %s\n",
file,line,assertion);
-#if !defined(_WIN32) || defined(__CYGWIN__)
+#if !defined(_WIN32) || defined(__CYGWIN__) || defined(BUILD_FOR_WINIOT)
abort();
#else
/* Win32 abort() customarily shows a dialog, but we just did that... */
diff --git a/crypto/rand/rand_win.c b/crypto/rand/rand_win.c
index 324e395..c64f162 100644
--- a/crypto/rand/rand_win.c
+++ b/crypto/rand/rand_win.c
@@ -737,7 +737,7 @@ static void readtimer(void)

static void readscreen(void)
{
-#if !defined(OPENSSL_SYS_WINCE) && !defined(OPENSSL_SYS_WIN32_CYGWIN)
+#if !defined(OPENSSL_SYS_WINCE) && !defined(OPENSSL_SYS_WIN32_CYGWIN) && !defined(BUILD_FOR_WINIOT)
HDC hScrDC; /* screen DC */
HBITMAP hBitmap; /* handle for our bitmap */
BITMAP bm; /* bitmap properties */
diff --git a/ms/ntdll.mak b/ms/ntdll.mak
index 0b659fe..cee51fb 100644
--- a/ms/ntdll.mak
+++ b/ms/ntdll.mak
@@ -18,21 +18,21 @@ OPENSSLDIR=C:\Source\openssl\builds_dbg\ssl
# Set your compiler options
PLATFORM=VC-WIN32
CC=cl
-CFLAG= /MDd /Od -DDEBUG -D_DEBUG -DOPENSSL_THREADS -DDSO_WIN32 -W3 -Gs0 -GF -Gy -Zi -nologo -DOPENSSL_SYSNAME_WIN32 -DWIN32_LEAN_AND_MEAN -DL_ENDIAN -D_CRT_SECURE_NO_DEPRECATE -DOPENSSL_USE_APPLINK -I. -DOPENSSL_NO_RC5 -DOPENSSL_NO_MD2 -DOPENSSL_NO_KRB5 -DOPENSSL_NO_JPAKE -DOPENSSL_NO_STATIC_ENGINE
-APP_CFLAG= /Zi /Fd$(TMP_D)/app
-LIB_CFLAG= /Zi /Fd$(TMP_D)/lib -D_WINDLL
+CFLAG= /arch:IA32 /MDd /Od -DDEBUG -D_DEBUG -DOPENSSL_THREADS -DBUILD_FOR_WINIOT -DOPENSSL_NO_CAPIENG -DDSO_WIN32 -W3 -Gs0 -GF -Gy -Zi -nologo -DOPENSSL_SYSNAME_WIN32 -DWIN32_LEAN_AND_MEAN -DL_ENDIAN -D_CRT_SECURE_NO_DEPRECATE -DOPENSSL_USE_APPLINK -I. -DOPENSSL_NO_RC5 -DOPENSSL_NO_MD2 -DOPENSSL_NO_KRB5 -DOPENSSL_NO_JPAKE -DOPENSSL_NO_STATIC_ENGINE
+APP_CFLAG= /arch:IA32 /Zi /Fd$(TMP_D)/app
+LIB_CFLAG= /arch:IA32 /Zi /Fd$(TMP_D)/lib -D_WINDLL
SHLIB_CFLAG=
APP_EX_OBJ=setargv.obj $(OBJ_D)\applink.obj /implib:$(TMP_D)\junk.lib
SHLIB_EX_OBJ=
# add extra libraries to this define, for solaris -lsocket -lnsl would
# be added
-EX_LIBS=ws2_32.lib gdi32.lib advapi32.lib crypt32.lib user32.lib
+EX_LIBS=mincore.lib

# The OpenSSL directory
SRC_D=.

LINK=link
-LFLAGS=/nologo /subsystem:console /opt:ref /debug
+LFLAGS= /NODEFAULTLIB:kernel32.lib /NODEFAULTLIB:ws2_32.lib /NODEFAULTLIB:gdi32.lib /NODEFAULTLIB:advapi32.lib /NODEFAULTLIB:crypt32.lib /NODEFAULTLIB:user32.lib /nologo /subsystem:console /opt:ref /debug
RSC=rc

# The output directory for everything interesting
--
1.9.5.msysgit.0

0 comments on commit 400326c

Please sign in to comment.