diff -Naur blender-4.5.2/extern/ceres/include/ceres/jet.h blender-4.5.2-patched/extern/ceres/include/ceres/jet.h
--- blender-4.5.2/extern/ceres/include/ceres/jet.h	2025-08-26 12:19:18.021333700 +0300
+++ blender-4.5.2-patched/extern/ceres/include/ceres/jet.h	2025-08-26 12:19:53.432392600 +0300
@@ -867,6 +867,7 @@
                    -x.v * exp(-x.a * x.a) * (T(1) / sqrt(atan(T(1)))));
 }
 
+#ifndef __MINGW32__
 // Bessel functions of the first kind with integer order equal to 0, 1, n.
 //
 // Microsoft has deprecated the j[0,1,n]() POSIX Bessel functions in favour of
@@ -918,6 +919,7 @@
       BesselJn(n, f.a),
       T(0.5) * (BesselJn(n - 1, f.a) - BesselJn(n + 1, f.a)) * f.v);
 }
+#endif
 
 // Classification and comparison functionality referencing only the scalar part
 // of a Jet. To classify the derivatives (e.g., for sanity checks), the dual
diff -Naur blender-4.5.2/extern/glog/src/windows/config.h blender-4.5.2-patched/extern/glog/src/windows/config.h
--- blender-4.5.2/extern/glog/src/windows/config.h	2025-08-26 12:19:18.370903500 +0300
+++ blender-4.5.2-patched/extern/glog/src/windows/config.h	2025-08-26 12:19:53.451473800 +0300
@@ -16,6 +16,10 @@
 #  define HAVE_SNPRINTF
 #endif
 
+#if defined(__MINGW32__)
+#  define HAVE_PTHREAD
+#endif
+
 /* Always the empty-string on non-windows systems. On windows, should be
    "__declspec(dllexport)". This way, when we compile the dll, we export our
    functions/classes. It's safe to define this here because config.h is only
diff -Naur blender-4.5.2/extern/glog/src/windows/port.h blender-4.5.2-patched/extern/glog/src/windows/port.h
--- blender-4.5.2/extern/glog/src/windows/port.h	2025-08-26 12:19:18.373902700 +0300
+++ blender-4.5.2-patched/extern/glog/src/windows/port.h	2025-08-26 12:19:53.454470400 +0300
@@ -62,7 +62,7 @@
  * used by both C and C++ code, so we put all the C++ together.
  */
 
-#ifdef _MSC_VER
+#ifdef _WIN32
 
 /* 4244: otherwise we get problems when substracting two size_t's to an int
  * 4251: it's complaining about a private struct I've chosen not to dllexport
@@ -77,17 +77,19 @@
 #pragma warning(disable:4244 4251 4355 4715 4800 4996 4267 4312 4722)
 
 /* file I/O */
-#define PATH_MAX 1024
 #define access  _access
 #define getcwd  _getcwd
 #define open    _open
 #define read    _read
 #define write   _write
-#define lseek   _lseek
 #define close   _close
 #define popen   _popen
 #define pclose  _pclose
+#ifndef __MINGW32__
+#define lseek   _lseek
+#define PATH_MAX 1024
 #define R_OK    04           /* read-only (for access()) */
+#endif
 #define S_ISDIR(m)  (((m) & _S_IFMT) == _S_IFDIR)
 
 #define O_WRONLY _O_WRONLY
@@ -138,7 +140,9 @@
 #define DEFAULT_TEMPLATE_ROOTDIR  ".."
 
 // ----------------------------------- SYSTEM/PROCESS
+#ifndef __MINGW32__
 typedef int pid_t;
+#endif
 #define getpid  _getpid
 
 #endif  // _MSC_VER
diff -Naur blender-4.5.2/extern/quadriflow/src/dedge.cpp blender-4.5.2-patched/extern/quadriflow/src/dedge.cpp
--- blender-4.5.2/extern/quadriflow/src/dedge.cpp	2025-08-26 12:19:18.721189100 +0300
+++ blender-4.5.2-patched/extern/quadriflow/src/dedge.cpp	2025-08-26 12:19:53.458471500 +0300
@@ -10,6 +10,11 @@
 #ifdef WITH_TBB
 #include "tbb/tbb.h"
 #endif
+
+#ifdef _WIN32
+#include <intrin.h>
+#endif
+
 namespace qflow {
 
 inline int dedge_prev(int e, int deg) { return (e % deg == 0u) ? e + (deg - 1) : e - 1; }
diff -Naur blender-4.5.2/intern/clog/clog.cc blender-4.5.2-patched/intern/clog/clog.cc
--- blender-4.5.2/intern/clog/clog.cc	2025-08-26 12:19:16.553608200 +0300
+++ blender-4.5.2-patched/intern/clog/clog.cc	2025-08-26 12:19:53.462471100 +0300
@@ -29,7 +29,7 @@
 #  include <unistd.h>
 #endif
 
-#if defined(_MSC_VER)
+#if defined(_WIN32)
 #  ifndef NOMINMAX
 #    define NOMINMAX
 #  endif
@@ -385,7 +385,7 @@
 static uint64_t clg_timestamp_ticks_get(void)
 {
   uint64_t tick;
-#if defined(_MSC_VER)
+#if defined(_WIN32)
   tick = GetTickCount64();
 #else
   struct timeval tv;
diff -Naur blender-4.5.2/intern/cycles/device/cuda/device.cpp blender-4.5.2-patched/intern/cycles/device/cuda/device.cpp
--- blender-4.5.2/intern/cycles/device/cuda/device.cpp	2025-08-26 12:19:17.082381300 +0300
+++ blender-4.5.2-patched/intern/cycles/device/cuda/device.cpp	2025-08-26 12:19:53.466469900 +0300
@@ -84,7 +84,7 @@
 #ifdef WITH_CUDA
 static CUresult device_cuda_safe_init()
 {
-#  ifdef _WIN32
+#  ifdef _MSC_VER
   __try
   {
     return cuInit(0);
diff -Naur blender-4.5.2/intern/cycles/device/hip/device.cpp blender-4.5.2-patched/intern/cycles/device/hip/device.cpp
--- blender-4.5.2/intern/cycles/device/hip/device.cpp	2025-08-26 12:19:17.092379900 +0300
+++ blender-4.5.2-patched/intern/cycles/device/hip/device.cpp	2025-08-26 12:19:53.470471100 +0300
@@ -104,7 +104,7 @@
 #ifdef WITH_HIP
 static hipError_t device_hip_safe_init()
 {
-#  ifdef _WIN32
+#  ifdef _MSC_VER
   __try
   {
     return hipInit(0);
diff -Naur blender-4.5.2/intern/cycles/util/defines.h blender-4.5.2-patched/intern/cycles/util/defines.h
--- blender-4.5.2/intern/cycles/util/defines.h	2025-08-26 12:19:17.423175600 +0300
+++ blender-4.5.2-patched/intern/cycles/util/defines.h	2025-08-26 12:19:53.484467300 +0300
@@ -50,7 +50,7 @@
 #    define ccl_device_inline_method __attribute__((always_inline))
 #    define ccl_device_template_spec template<> inline __attribute__((always_inline))
 #    define ccl_align(...) __attribute__((aligned(__VA_ARGS__)))
-#    ifndef FREE_WINDOWS64
+#    ifndef __MINGW32__
 #      define __forceinline inline __attribute__((always_inline))
 #    endif
 #    define ccl_try_align(...) __attribute__((aligned(__VA_ARGS__)))
diff -Naur blender-4.5.2/intern/cycles/util/murmurhash.cpp blender-4.5.2-patched/intern/cycles/util/murmurhash.cpp
--- blender-4.5.2/intern/cycles/util/murmurhash.cpp	2025-08-26 12:19:17.438173000 +0300
+++ blender-4.5.2-patched/intern/cycles/util/murmurhash.cpp	2025-08-26 12:19:53.493469700 +0300
@@ -14,7 +14,7 @@
 #include "util/math.h"
 #include "util/murmurhash.h"
 
-#if defined(_MSC_VER)
+#if defined(_WIN32)
 #  define ROTL32(x, y) _rotl(x, y)
 #  define ROTL64(x, y) _rotl64(x, y)
 #  define BIG_CONSTANT(x) (x)
diff -Naur blender-4.5.2/intern/cycles/util/simd.h blender-4.5.2-patched/intern/cycles/util/simd.h
--- blender-4.5.2/intern/cycles/util/simd.h	2025-08-26 12:19:17.466202200 +0300
+++ blender-4.5.2-patched/intern/cycles/util/simd.h	2025-08-26 12:19:53.496466600 +0300
@@ -13,12 +13,8 @@
 /* SSE Intrinsics includes
  *
  * We assume __KERNEL_SSEX__ flags to have been defined at this point.
- *
- * MinGW64 has conflicting declarations for these SSE headers in <windows.h>.
- * Since we can't avoid including <windows.h>, better only include that */
-#if defined(FREE_WINDOWS64)
-#  include "util/windows.h"
-#elif defined(_MSC_VER) && !defined(__KERNEL_NEON__)
+ */
+#if defined(_WIN32) && !defined(__KERNEL_NEON__)
 #  include <intrin.h>
 #elif (defined(__x86_64__) || defined(__i386__))
 #  include <x86intrin.h>
diff -Naur blender-4.5.2/intern/dualcon/intern/Projections.h blender-4.5.2-patched/intern/dualcon/intern/Projections.h
--- blender-4.5.2/intern/dualcon/intern/Projections.h	2025-08-26 12:19:17.471170000 +0300
+++ blender-4.5.2-patched/intern/dualcon/intern/Projections.h	2025-08-26 12:19:53.501467100 +0300
@@ -12,7 +12,7 @@
 #define CONTAINS_INDEX
 #define GRID_DIMENSION 20
 
-#if defined(_WIN32) && !(_MSC_VER >= 1900)
+#if defined(_MSC_VER) && !(_MSC_VER >= 1900)
 #  define isnan(n) _isnan(n)
 #  define LONG __int64
 #  define int64_t __int64
diff -Naur blender-4.5.2/intern/ghost/intern/GHOST_ContextWGL.hh blender-4.5.2-patched/intern/ghost/intern/GHOST_ContextWGL.hh
--- blender-4.5.2/intern/ghost/intern/GHOST_ContextWGL.hh	2025-08-26 12:19:17.509201600 +0300
+++ blender-4.5.2-patched/intern/ghost/intern/GHOST_ContextWGL.hh	2025-08-26 12:19:53.505465800 +0300
@@ -10,6 +10,7 @@
 
 #include "GHOST_Context.hh"
 
+#undef INT
 #include <epoxy/wgl.h>
 
 #ifndef GHOST_OPENGL_WGL_RESET_NOTIFICATION_STRATEGY
diff -Naur blender-4.5.2/intern/libmv/libmv/numeric/numeric.h blender-4.5.2-patched/intern/libmv/libmv/numeric/numeric.h
--- blender-4.5.2/intern/libmv/libmv/numeric/numeric.h	2025-08-26 12:19:15.306889600 +0300
+++ blender-4.5.2-patched/intern/libmv/libmv/numeric/numeric.h	2025-08-26 12:19:53.510465900 +0300
@@ -33,7 +33,7 @@
 #include <Eigen/QR>
 #include <Eigen/SVD>
 
-#if !defined(__MINGW64__)
+#if !defined(__MINGW32__)
 #  if defined(_WIN32) || defined(__APPLE__) || defined(__NetBSD__) ||          \
       defined(__HAIKU__)
 inline void sincos(double x, double* sinx, double* cosx) {
@@ -41,7 +41,7 @@
   *cosx = cos(x);
 }
 #  endif
-#endif  // !__MINGW64__
+#endif  // !__MINGW32__
 
 #if (defined(_WIN32) || defined(_WIN64)) && !defined(__MINGW32__)
 inline long lround(double d) {
@@ -451,7 +451,7 @@
 }
 
 inline bool isnan(double i) {
-#ifdef WIN32
+#ifdef _MSC_VER
   return _isnan(i) > 0;
 #else
   return std::isnan(i);
diff -Naur blender-4.5.2/source/blender/blenlib/BLI_fileops.h blender-4.5.2-patched/source/blender/blenlib/BLI_fileops.h
--- blender-4.5.2/source/blender/blenlib/BLI_fileops.h	2025-08-26 12:19:13.614617700 +0300
+++ blender-4.5.2-patched/source/blender/blenlib/BLI_fileops.h	2025-08-26 12:19:53.518465400 +0300
@@ -118,7 +118,7 @@
 
 /* Keep in sync with the definition of struct `direntry` in `BLI_fileops_types.h`. */
 #ifdef WIN32
-#  if defined(_MSC_VER)
+#  if defined(_MSC_VER) || defined(__MINGW32__)
 typedef struct _stat64 BLI_stat_t;
 #  else
 typedef struct _stat BLI_stat_t;
diff -Naur blender-4.5.2/source/blender/blenlib/BLI_fileops_types.h blender-4.5.2-patched/source/blender/blenlib/BLI_fileops_types.h
--- blender-4.5.2/source/blender/blenlib/BLI_fileops_types.h	2025-08-26 12:19:13.615617500 +0300
+++ blender-4.5.2-patched/source/blender/blenlib/BLI_fileops_types.h	2025-08-26 12:19:53.560521700 +0300
@@ -11,7 +11,7 @@
 
 #include <sys/stat.h>
 
-#if defined(WIN32)
+#if defined(_MSC_VER)
 typedef unsigned int mode_t;
 #endif
 
@@ -26,7 +26,7 @@
   const char *relname;
   const char *path;
 #ifdef WIN32 /* keep in sync with the definition of BLI_stat_t in BLI_fileops.h */
-#  if defined(_MSC_VER)
+#  if defined(_MSC_VER) || defined(__MINGW32__)
   struct _stat64 s;
 #  else
   struct _stat s;
diff -Naur blender-4.5.2/source/blender/blenlib/BLI_winstuff.h blender-4.5.2-patched/source/blender/blenlib/BLI_winstuff.h
--- blender-4.5.2/source/blender/blenlib/BLI_winstuff.h	2025-08-26 12:19:13.698191800 +0300
+++ blender-4.5.2-patched/source/blender/blenlib/BLI_winstuff.h	2025-08-26 12:19:53.570522800 +0300
@@ -55,9 +55,9 @@
 /* Not accepted by `access()` on windows. */
 // #  define X_OK    1
 #  define F_OK 0
-#endif
 
 typedef unsigned int mode_t;
+#endif
 
 /** Directory reading compatibility with UNIX. */
 struct dirent {
diff -Naur blender-4.5.2/source/blender/blenlib/intern/path_utils.cc blender-4.5.2-patched/source/blender/blenlib/intern/path_utils.cc
--- blender-4.5.2/source/blender/blenlib/intern/path_utils.cc	2025-08-26 12:19:13.786189100 +0300
+++ blender-4.5.2-patched/source/blender/blenlib/intern/path_utils.cc	2025-08-26 12:19:53.600518200 +0300
@@ -1344,7 +1344,18 @@
 
 void BLI_setenv(const char *env, const char *val)
 {
-#if (defined(_WIN32) || defined(_WIN64))
+#if defined(__MINGW32__)
+  char *envstr;
+
+  if (val)
+    envstr = BLI_sprintfN("%s=%s", env, val);
+  else
+    envstr = BLI_sprintfN("%s=", env);
+
+  putenv(envstr);
+  MEM_freeN(envstr);
+
+#elif defined(_MSC_VER) /* not free windows */
   /* MS-Windows. */
   uputenv(env, val);
 #else
diff -Naur blender-4.5.2/source/blender/blenlib/intern/storage.cc blender-4.5.2-patched/source/blender/blenlib/intern/storage.cc
--- blender-4.5.2/source/blender/blenlib/intern/storage.cc	2025-08-26 12:19:13.794766600 +0300
+++ blender-4.5.2-patched/source/blender/blenlib/intern/storage.cc	2025-08-26 12:19:53.605518400 +0300
@@ -415,7 +415,7 @@
 #ifdef WIN32
 int BLI_fstat(int fd, BLI_stat_t *buffer)
 {
-#  if defined(_MSC_VER)
+#  if defined(_MSC_VER) || defined(__MINGW32__)
   return _fstat64(fd, buffer);
 #  else
   return _fstat(fd, buffer);
@@ -435,7 +435,7 @@
 
 int BLI_wstat(const wchar_t *path, BLI_stat_t *buffer)
 {
-#  if defined(_MSC_VER)
+#  if defined(_MSC_VER) || defined(__MINGW32__)
   return _wstat64(path, buffer);
 #  else
   return _wstat(path, buffer);
diff -Naur blender-4.5.2/source/blender/blenlib/intern/system.cc blender-4.5.2-patched/source/blender/blenlib/intern/system.cc
--- blender-4.5.2/source/blender/blenlib/intern/system.cc	2025-08-26 12:19:13.700190800 +0300
+++ blender-4.5.2-patched/source/blender/blenlib/intern/system.cc	2025-08-26 12:19:53.626516100 +0300
@@ -59,7 +59,7 @@
 }
 
 /* Windows stack-walk lives in system_win32.cc */
-#if !defined(_MSC_VER)
+#if !defined(_WIN32)
 void BLI_system_backtrace_with_os_info(FILE *fp, const void * /*os_info*/)
 {
   /* ----------------------- */
@@ -106,7 +106,7 @@
 
 /* NOTE: The code for CPU brand string is adopted from Cycles. */
 
-#if !defined(_WIN32) || defined(FREE_WINDOWS)
+#if !defined(_WIN32)
 static void __cpuid(
     /* Cannot be const, because it is modified below.
      * NOLINTNEXTLINE: readability-non-const-parameter. */
diff -Naur blender-4.5.2/source/blender/cpucheck/cpu_check.cc blender-4.5.2-patched/source/blender/cpucheck/cpu_check.cc
--- blender-4.5.2/source/blender/cpucheck/cpu_check.cc	2025-08-26 12:19:11.063237700 +0300
+++ blender-4.5.2-patched/source/blender/cpucheck/cpu_check.cc	2025-08-26 12:19:53.633523500 +0300
@@ -63,7 +63,7 @@
   return nullptr;
 }
 
-#ifdef _MSC_VER
+#ifdef _WIN32
 extern "C" __declspec(dllexport) void cpu_check_win32()
 {
 #  ifdef _M_X64
diff -Naur blender-4.5.2/source/blender/editors/mesh/editmesh_knife.cc blender-4.5.2-patched/source/blender/editors/mesh/editmesh_knife.cc
--- blender-4.5.2/source/blender/editors/mesh/editmesh_knife.cc	2025-08-26 12:19:11.824193900 +0300
+++ blender-4.5.2-patched/source/blender/editors/mesh/editmesh_knife.cc	2025-08-26 12:19:53.639522600 +0300
@@ -8,7 +8,7 @@
  * Interactive editmesh knife tool.
  */
 
-#ifdef _MSC_VER
+#ifdef _WIN32
 #  define _USE_MATH_DEFINES
 #endif
 
diff -Naur blender-4.5.2/source/blender/imbuf/movie/intern/movie_write.hh blender-4.5.2-patched/source/blender/imbuf/movie/intern/movie_write.hh
--- blender-4.5.2/source/blender/imbuf/movie/intern/movie_write.hh	2025-08-26 12:19:12.806875800 +0300
+++ blender-4.5.2-patched/source/blender/imbuf/movie/intern/movie_write.hh	2025-08-26 12:19:53.647823400 +0300
@@ -14,7 +14,7 @@
 /* Note: include cmath before ffmpeg headers, since both of them define
  * M_PI and other macros. This is to avoid warnings about macro redefinition
  * if later including cmath (MSVC 2019). */
-#  if defined(_MSC_VER) && !defined(_USE_MATH_DEFINES)
+#  if defined(_WIN32) && !defined(_USE_MATH_DEFINES)
 #    define _USE_MATH_DEFINES
 #  endif
 #  include <cmath>  // IWYU pragma: keep
