diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 000000000..9812ceb1f
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1 @@
+*.patch text eol=lf
diff --git a/ports/antlr4/crt_mt.patch b/ports/antlr4/crt_mt.patch
index d2e8a28da..22d91efc3 100644
--- a/ports/antlr4/crt_mt.patch
+++ b/ports/antlr4/crt_mt.patch
@@ -1,36 +1,36 @@
-diff --git a/runtime/antlr4cpp-vs2015.vcxproj b/runtime/antlr4cpp-vs2015.vcxproj
-index 85fa3da..540f031 100644
---- a/runtime/antlr4cpp-vs2015.vcxproj
-+++ b/runtime/antlr4cpp-vs2015.vcxproj
-@@ -201,6 +201,7 @@
- 4251
- true
- false
-+ MultiThreadedDebug
-
-
- Windows
-@@ -239,6 +240,7 @@
- 4251
- true
- false
-+ MultiThreadedDebug
-
-
- Windows
-@@ -281,6 +283,7 @@
-
- 4251
- true
-+ MultiThreaded
-
-
- Windows
-@@ -325,6 +328,7 @@
-
- 4251
- true
-+ MultiThreaded
-
-
- Windows
+diff --git a/runtime/antlr4cpp-vs2015.vcxproj b/runtime/antlr4cpp-vs2015.vcxproj
+index 85fa3da..540f031 100644
+--- a/runtime/antlr4cpp-vs2015.vcxproj
++++ b/runtime/antlr4cpp-vs2015.vcxproj
+@@ -201,6 +201,7 @@
+ 4251
+ true
+ false
++ MultiThreadedDebug
+
+
+ Windows
+@@ -239,6 +240,7 @@
+ 4251
+ true
+ false
++ MultiThreadedDebug
+
+
+ Windows
+@@ -281,6 +283,7 @@
+
+ 4251
+ true
++ MultiThreaded
+
+
+ Windows
+@@ -325,6 +328,7 @@
+
+ 4251
+ true
++ MultiThreaded
+
+
+ Windows
diff --git a/ports/bzip2/auto-define-import-macro.patch b/ports/bzip2/auto-define-import-macro.patch
index 81492d3a5..b0eae0796 100644
--- a/ports/bzip2/auto-define-import-macro.patch
+++ b/ports/bzip2/auto-define-import-macro.patch
@@ -1,13 +1,13 @@
-diff --git a/bzlib.h b/bzlib.h
-index e3ba1d6..d3bed44 100644
---- a/bzlib.h
-+++ b/bzlib.h
-@@ -26,6 +26,8 @@
- extern "C" {
- #endif
-
-+#define BZ_IMPORT
-+
- #define BZ_RUN 0
- #define BZ_FLUSH 1
- #define BZ_FINISH 2
+diff --git a/bzlib.h b/bzlib.h
+index e3ba1d6..d3bed44 100644
+--- a/bzlib.h
++++ b/bzlib.h
+@@ -26,6 +26,8 @@
+ extern "C" {
+ #endif
+
++#define BZ_IMPORT
++
+ #define BZ_RUN 0
+ #define BZ_FLUSH 1
+ #define BZ_FINISH 2
diff --git a/ports/bzip2/fix-import-export-macros.patch b/ports/bzip2/fix-import-export-macros.patch
index e3ee8494b..fc67887da 100644
--- a/ports/bzip2/fix-import-export-macros.patch
+++ b/ports/bzip2/fix-import-export-macros.patch
@@ -1,40 +1,40 @@
-diff --git a/bzlib.h b/bzlib.h
-index 8277123..84fbd0a 100644
---- a/bzlib.h
-+++ b/bzlib.h
-@@ -65,29 +65,23 @@ typedef
- }
- bz_stream;
-
--
--#ifndef BZ_IMPORT
--#define BZ_EXPORT
--#endif
--
- #ifndef BZ_NO_STDIO
- /* Need a definitition for FILE */
- #include
- #endif
-
- #ifdef _WIN32
--# include
- # ifdef small
- /* windows.h define small to char */
- # undef small
- # endif
--# ifdef BZ_EXPORT
--# define BZ_API(func) WINAPI func
--# define BZ_EXTERN extern
-+# define BZ_API(func) func
-+# if defined(BZ_BUILD_DLL)
-+# define BZ_EXTERN __declspec(dllexport)
-+# elif defined(BZ_IMPORT)
-+# define BZ_EXTERN __declspec(dllimport)
- # else
-- /* import windows dll dynamically */
--# define BZ_API(func) (WINAPI * func)
--# define BZ_EXTERN
-+# define BZ_EXTERN
- # endif
- #else
- # define BZ_API(func) func
+diff --git a/bzlib.h b/bzlib.h
+index 8277123..84fbd0a 100644
+--- a/bzlib.h
++++ b/bzlib.h
+@@ -65,29 +65,23 @@ typedef
+ }
+ bz_stream;
+
+-
+-#ifndef BZ_IMPORT
+-#define BZ_EXPORT
+-#endif
+-
+ #ifndef BZ_NO_STDIO
+ /* Need a definitition for FILE */
+ #include
+ #endif
+
+ #ifdef _WIN32
+-# include
+ # ifdef small
+ /* windows.h define small to char */
+ # undef small
+ # endif
+-# ifdef BZ_EXPORT
+-# define BZ_API(func) WINAPI func
+-# define BZ_EXTERN extern
++# define BZ_API(func) func
++# if defined(BZ_BUILD_DLL)
++# define BZ_EXTERN __declspec(dllexport)
++# elif defined(BZ_IMPORT)
++# define BZ_EXTERN __declspec(dllimport)
+ # else
+- /* import windows dll dynamically */
+-# define BZ_API(func) (WINAPI * func)
+-# define BZ_EXTERN
++# define BZ_EXTERN
+ # endif
+ #else
+ # define BZ_API(func) func
diff --git a/ports/liblzma/auto-define-lzma-api-static.patch b/ports/liblzma/auto-define-lzma-api-static.patch
index b2643fe6a..d897e2457 100644
--- a/ports/liblzma/auto-define-lzma-api-static.patch
+++ b/ports/liblzma/auto-define-lzma-api-static.patch
@@ -1,14 +1,14 @@
-diff --git a/lzma.h b/lzma.h
-index ce675a7..ac0fc98 100644
---- a/lzma.h
-+++ b/lzma.h
-@@ -187,6 +187,9 @@
- * need to worry about LZMA_API_STATIC. Also the calling convention is
- * omitted on Cygwin but not on MinGW.
- */
-+
-+#define LZMA_API_STATIC
-+
- #ifndef LZMA_API_IMPORT
- # if !defined(LZMA_API_STATIC) && defined(_WIN32) && !defined(__GNUC__)
- # define LZMA_API_IMPORT __declspec(dllimport)
+diff --git a/lzma.h b/lzma.h
+index ce675a7..ac0fc98 100644
+--- a/lzma.h
++++ b/lzma.h
+@@ -187,6 +187,9 @@
+ * need to worry about LZMA_API_STATIC. Also the calling convention is
+ * omitted on Cygwin but not on MinGW.
+ */
++
++#define LZMA_API_STATIC
++
+ #ifndef LZMA_API_IMPORT
+ # if !defined(LZMA_API_STATIC) && defined(_WIN32) && !defined(__GNUC__)
+ # define LZMA_API_IMPORT __declspec(dllimport)
diff --git a/ports/libmodplug/automagically-define-modplug-static.patch b/ports/libmodplug/automagically-define-modplug-static.patch
index b7982b2d3..eaa7e6ca6 100644
--- a/ports/libmodplug/automagically-define-modplug-static.patch
+++ b/ports/libmodplug/automagically-define-modplug-static.patch
@@ -1,13 +1,13 @@
-diff --git a/libmodplug/modplug.h b/libmodplug/modplug.h
-index 3ffbf9d..fd19ae5 100644
---- a/libmodplug/modplug.h
-+++ b/libmodplug/modplug.h
-@@ -11,6 +11,8 @@
- extern "C" {
- #endif
-
-+#define MODPLUG_STATIC
-+
- #if defined(_WIN32) || defined(__CYGWIN__)
- # if defined(MODPLUG_BUILD) && defined(DLL_EXPORT) /* building libmodplug as a dll for windows */
- # define MODPLUG_EXPORT __declspec(dllexport)
+diff --git a/libmodplug/modplug.h b/libmodplug/modplug.h
+index 3ffbf9d..fd19ae5 100644
+--- a/libmodplug/modplug.h
++++ b/libmodplug/modplug.h
+@@ -11,6 +11,8 @@
+ extern "C" {
+ #endif
+
++#define MODPLUG_STATIC
++
+ #if defined(_WIN32) || defined(__CYGWIN__)
+ # if defined(MODPLUG_BUILD) && defined(DLL_EXPORT) /* building libmodplug as a dll for windows */
+ # define MODPLUG_EXPORT __declspec(dllexport)
diff --git a/ports/lz4/auto-define-import-macro.patch b/ports/lz4/auto-define-import-macro.patch
index 48b4585ea..314c228db 100644
--- a/ports/lz4/auto-define-import-macro.patch
+++ b/ports/lz4/auto-define-import-macro.patch
@@ -1,28 +1,28 @@
-diff --git a/lz4.h b/lz4.h
-index 7420ad8..c1c3e56 100644
---- a/lz4.h
-+++ b/lz4.h
-@@ -73,6 +73,9 @@ extern "C" {
- * LZ4_DLL_EXPORT :
- * Enable exporting of functions when building a Windows DLL
- */
-+
-+#define LZ4_DLL_IMPORT 1
-+
- #if defined(LZ4_DLL_EXPORT) && (LZ4_DLL_EXPORT==1)
- # define LZ4LIB_API __declspec(dllexport)
- #elif defined(LZ4_DLL_IMPORT) && (LZ4_DLL_IMPORT==1)
-diff --git a/lz4frame.h b/lz4frame.h
-index 3104d2e..4442461 100644
---- a/lz4frame.h
-+++ b/lz4frame.h
-@@ -55,6 +55,9 @@ extern "C" {
- * LZ4_DLL_EXPORT :
- * Enable exporting of functions when building a Windows DLL
- */
-+
-+#define LZ4_DLL_IMPORT 1
-+
- #if defined(LZ4_DLL_EXPORT) && (LZ4_DLL_EXPORT==1)
- # define LZ4FLIB_API __declspec(dllexport)
- #elif defined(LZ4_DLL_IMPORT) && (LZ4_DLL_IMPORT==1)
+diff --git a/lz4.h b/lz4.h
+index 7420ad8..c1c3e56 100644
+--- a/lz4.h
++++ b/lz4.h
+@@ -73,6 +73,9 @@ extern "C" {
+ * LZ4_DLL_EXPORT :
+ * Enable exporting of functions when building a Windows DLL
+ */
++
++#define LZ4_DLL_IMPORT 1
++
+ #if defined(LZ4_DLL_EXPORT) && (LZ4_DLL_EXPORT==1)
+ # define LZ4LIB_API __declspec(dllexport)
+ #elif defined(LZ4_DLL_IMPORT) && (LZ4_DLL_IMPORT==1)
+diff --git a/lz4frame.h b/lz4frame.h
+index 3104d2e..4442461 100644
+--- a/lz4frame.h
++++ b/lz4frame.h
+@@ -55,6 +55,9 @@ extern "C" {
+ * LZ4_DLL_EXPORT :
+ * Enable exporting of functions when building a Windows DLL
+ */
++
++#define LZ4_DLL_IMPORT 1
++
+ #if defined(LZ4_DLL_EXPORT) && (LZ4_DLL_EXPORT==1)
+ # define LZ4FLIB_API __declspec(dllexport)
+ #elif defined(LZ4_DLL_IMPORT) && (LZ4_DLL_IMPORT==1)
diff --git a/ports/nana/fix-linking.patch b/ports/nana/fix-linking.patch
index a687e228b..f897ed228 100644
--- a/ports/nana/fix-linking.patch
+++ b/ports/nana/fix-linking.patch
@@ -1,51 +1,51 @@
-diff --git a/CMakeLists.txt b/CMakeLists.txt
-index 5c9c9c9..ae35185 100644
---- a/CMakeLists.txt
-+++ b/CMakeLists.txt
-@@ -149,26 +149,20 @@ endif ()
- # Find PNG
- if(NANA_CMAKE_ENABLE_PNG)
- add_definitions(-DNANA_ENABLE_PNG)
-- set(NANA_LINKS "${NANA_LINKS} -lpng")
- if(NANA_CMAKE_LIBPNG_FROM_OS)
-- find_package(PNG)
-- if (PNG_FOUND)
-- include_directories( ${PNG_INCLUDE_DIRS})
-- add_definitions(-DUSE_LIBPNG_FROM_OS)
-- endif(PNG_FOUND)
-+ find_package(PNG REQUIRED)
-+ include_directories(${PNG_INCLUDE_DIRS})
-+ add_definitions(-DUSE_LIBPNG_FROM_OS)
- endif(NANA_CMAKE_LIBPNG_FROM_OS)
- endif(NANA_CMAKE_ENABLE_PNG)
-
- # Find JPEG
- if(NANA_CMAKE_ENABLE_JPEG)
- add_definitions(-DNANA_ENABLE_JPEG)
-- set(NANA_LINKS "${NANA_LINKS} -ljpeg")
- if(NANA_CMAKE_LIBJPEG_FROM_OS)
-- find_package(JPEG)
-- if (JPEG_FOUND)
-- include_directories( ${JPEG_INCLUDE_DIRS})
-- add_definitions(-DUSE_LIBJPEG_FROM_OS)
-- endif(JPEG_FOUND)
-+ find_package(JPEG REQUIRED)
-+ include_directories(${JPEG_INCLUDE_DIRS})
-+ add_definitions(-DUSE_LIBJPEG_FROM_OS)
- endif(NANA_CMAKE_LIBJPEG_FROM_OS)
- endif(NANA_CMAKE_ENABLE_JPEG)
-
-@@ -253,7 +247,12 @@ endforeach(subdir ${NANA_SOURCE_SUBDIRS})
-
- include_directories(${NANA_INCLUDE_DIR})
- add_library(${PROJECT_NAME} ${sources} )
--target_link_libraries(${PROJECT_NAME} ${NANA_LINKS})
-+if(NANA_CMAKE_ENABLE_JPEG AND NANA_CMAKE_LIBJPEG_FROM_OS)
-+ target_link_libraries(${PROJECT_NAME} ${JPEG_LIBRARIES})
-+endif()
-+if(NANA_CMAKE_ENABLE_PNG AND NANA_CMAKE_LIBPNG_FROM_OS)
-+ target_link_libraries(${PROJECT_NAME} ${PNG_LIBRARIES})
-+endif()
-
- # Headers: use INCLUDE_DIRECTORIES
- # Libraries: use FIND_LIBRARY and link with the result of it (try to avoid LINK_DIRECTORIES)
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index 5c9c9c9..ae35185 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -149,26 +149,20 @@ endif ()
+ # Find PNG
+ if(NANA_CMAKE_ENABLE_PNG)
+ add_definitions(-DNANA_ENABLE_PNG)
+- set(NANA_LINKS "${NANA_LINKS} -lpng")
+ if(NANA_CMAKE_LIBPNG_FROM_OS)
+- find_package(PNG)
+- if (PNG_FOUND)
+- include_directories( ${PNG_INCLUDE_DIRS})
+- add_definitions(-DUSE_LIBPNG_FROM_OS)
+- endif(PNG_FOUND)
++ find_package(PNG REQUIRED)
++ include_directories(${PNG_INCLUDE_DIRS})
++ add_definitions(-DUSE_LIBPNG_FROM_OS)
+ endif(NANA_CMAKE_LIBPNG_FROM_OS)
+ endif(NANA_CMAKE_ENABLE_PNG)
+
+ # Find JPEG
+ if(NANA_CMAKE_ENABLE_JPEG)
+ add_definitions(-DNANA_ENABLE_JPEG)
+- set(NANA_LINKS "${NANA_LINKS} -ljpeg")
+ if(NANA_CMAKE_LIBJPEG_FROM_OS)
+- find_package(JPEG)
+- if (JPEG_FOUND)
+- include_directories( ${JPEG_INCLUDE_DIRS})
+- add_definitions(-DUSE_LIBJPEG_FROM_OS)
+- endif(JPEG_FOUND)
++ find_package(JPEG REQUIRED)
++ include_directories(${JPEG_INCLUDE_DIRS})
++ add_definitions(-DUSE_LIBJPEG_FROM_OS)
+ endif(NANA_CMAKE_LIBJPEG_FROM_OS)
+ endif(NANA_CMAKE_ENABLE_JPEG)
+
+@@ -253,7 +247,12 @@ endforeach(subdir ${NANA_SOURCE_SUBDIRS})
+
+ include_directories(${NANA_INCLUDE_DIR})
+ add_library(${PROJECT_NAME} ${sources} )
+-target_link_libraries(${PROJECT_NAME} ${NANA_LINKS})
++if(NANA_CMAKE_ENABLE_JPEG AND NANA_CMAKE_LIBJPEG_FROM_OS)
++ target_link_libraries(${PROJECT_NAME} ${JPEG_LIBRARIES})
++endif()
++if(NANA_CMAKE_ENABLE_PNG AND NANA_CMAKE_LIBPNG_FROM_OS)
++ target_link_libraries(${PROJECT_NAME} ${PNG_LIBRARIES})
++endif()
+
+ # Headers: use INCLUDE_DIRECTORIES
+ # Libraries: use FIND_LIBRARY and link with the result of it (try to avoid LINK_DIRECTORIES)
diff --git a/ports/smpeg2/correct-sdl-headers-dir.patch b/ports/smpeg2/correct-sdl-headers-dir.patch
index 601b6c8a8..6cbcb6b9b 100644
--- a/ports/smpeg2/correct-sdl-headers-dir.patch
+++ b/ports/smpeg2/correct-sdl-headers-dir.patch
@@ -1,17 +1,17 @@
-diff --git a/smpeg.h b/smpeg.h
-index 6bc2dbd..d12c8f8 100644
---- a/smpeg.h
-+++ b/smpeg.h
-@@ -22,9 +22,9 @@
- #ifndef _SMPEG_H_
- #define _SMPEG_H_
-
--#include "SDL.h"
--#include "SDL_mutex.h"
--#include "SDL_audio.h"
-+#include "SDL2/SDL.h"
-+#include "SDL2/SDL_mutex.h"
-+#include "SDL2/SDL_audio.h"
- #include "MPEGframe.h"
-
- #ifdef __cplusplus
+diff --git a/smpeg.h b/smpeg.h
+index 6bc2dbd..d12c8f8 100644
+--- a/smpeg.h
++++ b/smpeg.h
+@@ -22,9 +22,9 @@
+ #ifndef _SMPEG_H_
+ #define _SMPEG_H_
+
+-#include "SDL.h"
+-#include "SDL_mutex.h"
+-#include "SDL_audio.h"
++#include "SDL2/SDL.h"
++#include "SDL2/SDL_mutex.h"
++#include "SDL2/SDL_audio.h"
+ #include "MPEGframe.h"
+
+ #ifdef __cplusplus