Moved __ASM_GLOBAL_FUNC macros and interlocked functions to port.[ch]

diff --git a/dlls/msvcrt/except.c b/dlls/msvcrt/except.c
index 5cf36fc..c26054d 100644
--- a/dlls/msvcrt/except.c
+++ b/dlls/msvcrt/except.c
@@ -24,7 +24,9 @@
  *
  * FIXME: Incomplete support for nested exceptions/try block cleanup.
  */
+
 #include "config.h"
+#include "wine/port.h"
 
 #include "ntddk.h"
 #include "wine/exception.h"
diff --git a/dlls/ntdll/critsection.c b/dlls/ntdll/critsection.c
index 0233ef3..34294c5 100644
--- a/dlls/ntdll/critsection.c
+++ b/dlls/ntdll/critsection.c
@@ -18,6 +18,9 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
+#include "config.h"
+#include "wine/port.h"
+
 #include <assert.h>
 #include <errno.h>
 #include <stdio.h>
@@ -29,108 +32,16 @@
 WINE_DEFAULT_DEBUG_CHANNEL(ntdll);
 WINE_DECLARE_DEBUG_CHANNEL(relay);
 
-/* Define the atomic exchange/inc/dec functions.
- * These are available in kernel32.dll already,
- * but we don't want to import kernel32 from ntdll.
- */
-
-#ifdef __i386__
-
-# ifdef __GNUC__
-
-inline static PVOID interlocked_cmpxchg( PVOID *dest, PVOID xchg, PVOID compare )
-{
-    PVOID ret;
-    __asm__ __volatile__( "lock; cmpxchgl %2,(%1)"
-                          : "=a" (ret) : "r" (dest), "r" (xchg), "0" (compare) : "memory" );
-    return ret;
-}
 inline static LONG interlocked_inc( PLONG dest )
 {
-    LONG ret;
-    __asm__ __volatile__( "lock; xaddl %0,(%1)"
-                          : "=r" (ret) : "r" (dest), "0" (1) : "memory" );
-    return ret + 1;
+    return interlocked_xchg_add( dest, 1 ) + 1;
 }
+
 inline static LONG interlocked_dec( PLONG dest )
 {
-    LONG ret;
-    __asm__ __volatile__( "lock; xaddl %0,(%1)"
-                          : "=r" (ret) : "r" (dest), "0" (-1) : "memory" );
-    return ret - 1;
+    return interlocked_xchg_add( dest, -1 ) - 1;
 }
 
-# else  /* __GNUC__ */
-
-PVOID WINAPI interlocked_cmpxchg( PVOID *dest, PVOID xchg, PVOID compare );
-__ASM_GLOBAL_FUNC(interlocked_cmpxchg,
-                  "movl 12(%esp),%eax\n\t"
-                  "movl 8(%esp),%ecx\n\t"
-                  "movl 4(%esp),%edx\n\t"
-                  "lock; cmpxchgl %ecx,(%edx)\n\t"
-                  "ret $12");
-LONG WINAPI interlocked_inc( PLONG dest );
-__ASM_GLOBAL_FUNC(interlocked_inc,
-                  "movl 4(%esp),%edx\n\t"
-                  "movl $1,%eax\n\t"
-                  "lock; xaddl %eax,(%edx)\n\t"
-                  "incl %eax\n\t"
-                  "ret $4");
-LONG WINAPI interlocked_dec( PLONG dest );
-__ASM_GLOBAL_FUNC(interlocked_dec,
-                  "movl 4(%esp),%edx\n\t"
-                  "movl $-1,%eax\n\t"
-                  "lock; xaddl %eax,(%edx)\n\t"
-                  "decl %eax\n\t"
-                  "ret $4");
-# endif  /* __GNUC__ */
-
-#elif defined(__sparc__) && defined(__sun__)
-/*
- * As the earlier Sparc processors lack necessary atomic instructions,
- * I'm simply falling back to the library-provided _lwp_mutex routines
- * to ensure mutual exclusion in a way appropriate for the current 
- * architecture.  
- *
- * FIXME:  If we have the compare-and-swap instruction (Sparc v9 and above)
- *         we could use this to speed up the Interlocked operations ...
- */
-#include <synch.h>
-static lwp_mutex_t interlocked_mutex = DEFAULTMUTEX;
-
-static PVOID interlocked_cmpxchg( PVOID *dest, PVOID xchg, PVOID compare )
-{
-    _lwp_mutex_lock( &interlocked_mutex );
-    if ( *dest == compare )
-        *dest = xchg;
-    else
-        compare = *dest;
-    _lwp_mutex_unlock( &interlocked_mutex );
-    return compare;
-}
-
-static LONG interlocked_inc( PLONG dest )
-{
-    LONG retv;
-    _lwp_mutex_lock( &interlocked_mutex );
-    retv = ++*dest;
-    _lwp_mutex_unlock( &interlocked_mutex );
-    return retv;
-}
-
-static LONG interlocked_dec( PLONG dest )
-{
-    LONG retv;
-    _lwp_mutex_lock( &interlocked_mutex );
-    retv = --*dest;
-    _lwp_mutex_unlock( &interlocked_mutex );
-    return retv;
-}
-#else
-# error You must implement the interlocked* functions for your CPU
-#endif
-
-
 /***********************************************************************
  *           get_semaphore
  */
@@ -141,8 +52,8 @@
     {
         HANDLE sem;
         if (NtCreateSemaphore( &sem, SEMAPHORE_ALL_ACCESS, NULL, 0, 1 )) return 0;
-        if (!(ret = (HANDLE)interlocked_cmpxchg( (PVOID *)&crit->LockSemaphore,
-                                                 (PVOID)sem, 0 )))
+        if (!(ret = (HANDLE)interlocked_cmpxchg_ptr( (PVOID *)&crit->LockSemaphore,
+                                                     (PVOID)sem, 0 )))
             ret = sem;
         else
             NtClose(sem);  /* somebody beat us to it */
@@ -270,7 +181,7 @@
 BOOL WINAPI RtlTryEnterCriticalSection( RTL_CRITICAL_SECTION *crit )
 {
     BOOL ret = FALSE;
-    if (interlocked_cmpxchg( (PVOID *)&crit->LockCount, (PVOID)0L, (PVOID)-1L ) == (PVOID)-1L)
+    if (interlocked_cmpxchg( &crit->LockCount, 0L, -1 ) == -1)
     {
         crit->OwningThread   = GetCurrentThreadId();
         crit->RecursionCount = 1;
diff --git a/dlls/ntdll/debugtools.c b/dlls/ntdll/debugtools.c
index 35a5f73..013e485 100644
--- a/dlls/ntdll/debugtools.c
+++ b/dlls/ntdll/debugtools.c
@@ -31,7 +31,6 @@
 #include "winbase.h"
 #include "winnt.h"
 #include "ntddk.h"
-#include "wtypes.h"
 #include "msvcrt/excpt.h"
 
 WINE_DECLARE_DEBUG_CHANNEL(tid);
diff --git a/dlls/ntdll/exception.c b/dlls/ntdll/exception.c
index 9e0b455..f936b77 100644
--- a/dlls/ntdll/exception.c
+++ b/dlls/ntdll/exception.c
@@ -20,6 +20,7 @@
  */
 
 #include "config.h"
+#include "wine/port.h"
 
 #include <assert.h>
 #include <signal.h>
diff --git a/dlls/ntdll/signal_i386.c b/dlls/ntdll/signal_i386.c
index dd9bc68..5098b2f 100644
--- a/dlls/ntdll/signal_i386.c
+++ b/dlls/ntdll/signal_i386.c
@@ -21,6 +21,7 @@
 #ifdef __i386__
 
 #include "config.h"
+#include "wine/port.h"
 
 #include <errno.h>
 #include <signal.h>
diff --git a/dlls/winedos/int31.c b/dlls/winedos/int31.c
index c4e1d49..9dcc21f 100644
--- a/dlls/winedos/int31.c
+++ b/dlls/winedos/int31.c
@@ -19,6 +19,7 @@
  */
 
 #include "config.h"
+#include "wine/port.h"
 
 #include "windef.h"
 #include "wine/winbase16.h"
diff --git a/include/wine/port.h b/include/wine/port.h
index b7e0dc0..56d5d26 100644
--- a/include/wine/port.h
+++ b/include/wine/port.h
@@ -200,6 +200,92 @@
 #define RTLD_GLOBAL	0x100
 #endif
 
+/* Interlocked functions */
+
+#if defined(__i386__) && defined(__GNUC__)
+
+inline static long interlocked_cmpxchg( long *dest, long xchg, long compare )
+{
+    long ret;
+    __asm__ __volatile__( "lock; cmpxchgl %2,(%1)"
+                          : "=a" (ret) : "r" (dest), "r" (xchg), "0" (compare) : "memory" );
+    return ret;
+}
+
+inline static void *interlocked_cmpxchg_ptr( void **dest, void *xchg, void *compare )
+{
+    void *ret;
+    __asm__ __volatile__( "lock; cmpxchgl %2,(%1)"
+                          : "=a" (ret) : "r" (dest), "r" (xchg), "0" (compare) : "memory" );
+    return ret;
+}
+
+inline static long interlocked_xchg( long *dest, long val )
+{
+    long ret;
+    __asm__ __volatile__( "lock; xchgl %0,(%1)"
+                          : "=r" (ret) : "r" (dest), "0" (val) : "memory" );
+    return ret;
+}
+
+inline static void *interlocked_xchg_ptr( void **dest, void *val )
+{
+    void *ret;
+    __asm__ __volatile__( "lock; xchgl %0,(%1)"
+                          : "=r" (ret) : "r" (dest), "0" (val) : "memory" );
+    return ret;
+}
+
+inline static long interlocked_xchg_add( long *dest, long incr )
+{
+    long ret;
+    __asm__ __volatile__( "lock; xaddl %0,(%1)"
+                          : "=r" (ret) : "r" (dest), "0" (incr) : "memory" );
+    return ret;
+}
+
+#else  /* __i386___ && __GNUC__ */
+
+extern long interlocked_cmpxchg( long *dest, long xchg, long compare );
+extern void *interlocked_cmpxchg_ptr( void **dest, void *xchg, void *compare );
+extern long interlocked_xchg( long *dest, long val );
+extern void *interlocked_xchg_ptr( void **dest, void *val );
+extern long interlocked_xchg_add( long *dest, long incr );
+
+#endif  /* __i386___ && __GNUC__ */
+
+/* Macros to define assembler functions somewhat portably */
+
+#ifdef NEED_UNDERSCORE_PREFIX
+# define __ASM_NAME(name) "_" name
+#else
+# define __ASM_NAME(name) name
+#endif
+
+#ifdef NEED_TYPE_IN_DEF
+# define __ASM_FUNC(name) ".def " __ASM_NAME(name) "; .scl 2; .type 32; .endef"
+#else
+# define __ASM_FUNC(name) ".type " __ASM_NAME(name) ",@function"
+#endif
+
+#ifdef __GNUC__
+# define __ASM_GLOBAL_FUNC(name,code) \
+      __asm__( ".align 4\n\t" \
+               ".globl " __ASM_NAME(#name) "\n\t" \
+               __ASM_FUNC(#name) "\n" \
+               __ASM_NAME(#name) ":\n\t" \
+               code );
+#else  /* __GNUC__ */
+# define __ASM_GLOBAL_FUNC(name,code) \
+      void __asm_dummy_##name(void) { \
+          asm( ".align 4\n\t" \
+               ".globl " __ASM_NAME(#name) "\n\t" \
+               __ASM_FUNC(#name) "\n" \
+               __ASM_NAME(#name) ":\n\t" \
+               code ); \
+      }
+#endif  /* __GNUC__ */
+
 
 /* Macros to access unaligned or wrong-endian WORDs and DWORDs. */
 
diff --git a/include/winnt.h b/include/winnt.h
index f701d86..481f3dd 100644
--- a/include/winnt.h
+++ b/include/winnt.h
@@ -1120,36 +1120,6 @@
 
 /* Macros to retrieve the current context */
 
-#ifdef NEED_UNDERSCORE_PREFIX
-# define __ASM_NAME(name) "_" name
-#else
-# define __ASM_NAME(name) name
-#endif
-
-#ifdef NEED_TYPE_IN_DEF
-# define __ASM_FUNC(name) ".def " __ASM_NAME(name) "; .scl 2; .type 32; .endef"
-#else
-# define __ASM_FUNC(name) ".type " __ASM_NAME(name) ",@function"
-#endif
-
-#ifdef __GNUC__
-# define __ASM_GLOBAL_FUNC(name,code) \
-      __asm__( ".align 4\n\t" \
-               ".globl " __ASM_NAME(#name) "\n\t" \
-               __ASM_FUNC(#name) "\n" \
-               __ASM_NAME(#name) ":\n\t" \
-               code );
-#else  /* __GNUC__ */
-# define __ASM_GLOBAL_FUNC(name,code) \
-      void __asm_dummy_##name(void) { \
-          asm( ".align 4\n\t" \
-               ".globl " __ASM_NAME(#name) "\n\t" \
-               __ASM_FUNC(#name) "\n" \
-               __ASM_NAME(#name) ":\n\t" \
-               code ); \
-      }
-#endif  /* __GNUC__ */
-
 #ifdef __i386__
 
 #define _DEFINE_REGS_ENTRYPOINT( name, fn, args ) \
diff --git a/library/port.c b/library/port.c
index 9d46554..64f8149 100644
--- a/library/port.c
+++ b/library/port.c
@@ -738,3 +738,103 @@
     return buff;
 }
 #endif /* HAVE_ECVT */
+
+
+/***********************************************************************
+ *		interlocked functions
+ */
+#ifdef __i386__
+
+__ASM_GLOBAL_FUNC(interlocked_cmpxchg,
+                  "movl 12(%esp),%eax\n\t"
+                  "movl 8(%esp),%ecx\n\t"
+                  "movl 4(%esp),%edx\n\t"
+                  "lock; cmpxchgl %ecx,(%edx)\n\t"
+                  "ret");
+__ASM_GLOBAL_FUNC(interlocked_cmpxchg_ptr,
+                  "movl 12(%esp),%eax\n\t"
+                  "movl 8(%esp),%ecx\n\t"
+                  "movl 4(%esp),%edx\n\t"
+                  "lock; cmpxchgl %ecx,(%edx)\n\t"
+                  "ret");
+__ASM_GLOBAL_FUNC(interlocked_xchg,
+                  "movl 8(%esp),%eax\n\t"
+                  "movl 4(%esp),%edx\n\t"
+                  "lock; xchgl %eax,(%edx)\n\t"
+                  "ret");
+__ASM_GLOBAL_FUNC(interlocked_xchg_ptr,
+                  "movl 8(%esp),%eax\n\t"
+                  "movl 4(%esp),%edx\n\t"
+                  "lock; xchgl %eax,(%edx)\n\t"
+                  "ret");
+__ASM_GLOBAL_FUNC(interlocked_xchg_add,
+                  "movl 8(%esp),%eax\n\t"
+                  "movl 4(%esp),%edx\n\t"
+                  "lock; xaddl %eax,(%edx)\n\t"
+                  "ret");
+
+#elif defined(__sparc__) && defined(__sun__)
+
+/*
+ * As the earlier Sparc processors lack necessary atomic instructions,
+ * I'm simply falling back to the library-provided _lwp_mutex routines
+ * to ensure mutual exclusion in a way appropriate for the current 
+ * architecture.  
+ *
+ * FIXME:  If we have the compare-and-swap instruction (Sparc v9 and above)
+ *         we could use this to speed up the Interlocked operations ...
+ */
+#include <synch.h>
+static lwp_mutex_t interlocked_mutex = DEFAULTMUTEX;
+
+long interlocked_cmpxchg( long *dest, long xchg, long compare )
+{
+    _lwp_mutex_lock( &interlocked_mutex );
+    if (*dest == compare) *dest = xchg;
+    else compare = *dest;
+    _lwp_mutex_unlock( &interlocked_mutex );
+    return compare;
+}
+
+void *interlocked_cmpxchg_ptr( void **dest, void *xchg, void *compare )
+{
+    _lwp_mutex_lock( &interlocked_mutex );
+    if (*dest == compare) *dest = xchg;
+    else compare = *dest;
+    _lwp_mutex_unlock( &interlocked_mutex );
+    return compare;
+}
+
+long interlocked_xchg( long *dest, long val )
+{
+    long retv;
+    _lwp_mutex_lock( &interlocked_mutex );
+    retv = *dest;
+    *dest = val;
+    _lwp_mutex_unlock( &interlocked_mutex );
+    return retv;
+}
+
+void *interlocked_xchg_ptr( void **dest, void *val )
+{
+    long retv;
+    _lwp_mutex_lock( &interlocked_mutex );
+    retv = *dest;
+    *dest = val;
+    _lwp_mutex_unlock( &interlocked_mutex );
+    return retv;
+}
+
+long interlocked_xchg_add( long *dest, long incr )
+{
+    long retv;
+    _lwp_mutex_lock( &interlocked_mutex );
+    retv = *dest;
+    *dest += incr;
+    _lwp_mutex_unlock( &interlocked_mutex );
+    return retv;
+}
+
+#else
+# error You must implement the interlocked* functions for your CPU
+#endif
diff --git a/memory/selector.c b/memory/selector.c
index 132ba4c..d52989b 100644
--- a/memory/selector.c
+++ b/memory/selector.c
@@ -19,6 +19,7 @@
  */
 
 #include "config.h"
+#include "wine/port.h"
 
 #include <string.h>
 
diff --git a/relay32/relay386.c b/relay32/relay386.c
index 03f5f28..671061d 100644
--- a/relay32/relay386.c
+++ b/relay32/relay386.c
@@ -18,8 +18,8 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-
 #include "config.h"
+#include "wine/port.h"
 
 #include <assert.h>
 #include <string.h>
diff --git a/relay32/snoop.c b/relay32/snoop.c
index 17aa3eb..d9215b6 100644
--- a/relay32/snoop.c
+++ b/relay32/snoop.c
@@ -19,6 +19,7 @@
  */
 
 #include "config.h"
+#include "wine/port.h"
 
 #include <assert.h>
 #include <stdio.h>
diff --git a/scheduler/critsection.c b/scheduler/critsection.c
index 617e18e..20a17ca 100644
--- a/scheduler/critsection.c
+++ b/scheduler/critsection.c
@@ -19,6 +19,7 @@
  */
 
 #include "config.h"
+#include "wine/port.h"
 
 #include <assert.h>
 #include <errno.h>
@@ -150,35 +151,14 @@
                   "decl %eax\n\t"
                   "ret $4");
 
-#elif defined(__sparc__) && defined(__sun__)
-
-/*
- * As the earlier Sparc processors lack necessary atomic instructions,
- * I'm simply falling back to the library-provided _lwp_mutex routines
- * to ensure mutual exclusion in a way appropriate for the current 
- * architecture.  
- *
- * FIXME:  If we have the compare-and-swap instruction (Sparc v9 and above)
- *         we could use this to speed up the Interlocked operations ...
- */
-
-#include <synch.h>
-static lwp_mutex_t interlocked_mutex = DEFAULTMUTEX;
+#else  /* __i386__ */
 
 /***********************************************************************
  *		InterlockedCompareExchange (KERNEL32.@)
  */
 LONG WINAPI InterlockedCompareExchange( PLONG dest, LONG xchg, LONG compare )
 {
-    _lwp_mutex_lock( &interlocked_mutex );
-
-    if ( *dest == compare )
-        *dest = xchg;
-    else
-        compare = *dest;
-    
-    _lwp_mutex_unlock( &interlocked_mutex );
-    return compare;
+    return interlocked_cmpxchg( dest, xchg, compare );
 }
 
 /***********************************************************************
@@ -186,14 +166,7 @@
  */
 LONG WINAPI InterlockedExchange( PLONG dest, LONG val )
 {
-    LONG retv;
-    _lwp_mutex_lock( &interlocked_mutex );
-
-    retv = *dest;
-    *dest = val;
-
-    _lwp_mutex_unlock( &interlocked_mutex );
-    return retv;
+    return interlocked_xchg( dest, val );
 }
 
 /***********************************************************************
@@ -201,14 +174,7 @@
  */
 LONG WINAPI InterlockedExchangeAdd( PLONG dest, LONG incr )
 {
-    LONG retv;
-    _lwp_mutex_lock( &interlocked_mutex );
-
-    retv = *dest;
-    *dest += incr;
-
-    _lwp_mutex_unlock( &interlocked_mutex );
-    return retv;
+    return interlocked_xchg_add( dest, incr );
 }
 
 /***********************************************************************
@@ -216,13 +182,7 @@
  */
 LONG WINAPI InterlockedIncrement( PLONG dest )
 {
-    LONG retv;
-    _lwp_mutex_lock( &interlocked_mutex );
-
-    retv = ++*dest;
-
-    _lwp_mutex_unlock( &interlocked_mutex );
-    return retv;
+    return interlocked_xchg_add( dest, 1 ) + 1;
 }
 
 /***********************************************************************
@@ -230,15 +190,7 @@
  */
 LONG WINAPI InterlockedDecrement( PLONG dest )
 {
-    LONG retv;
-    _lwp_mutex_lock( &interlocked_mutex );
-
-    retv = --*dest;
-
-    _lwp_mutex_unlock( &interlocked_mutex );
-    return retv;
+    return interlocked_xchg_add( dest, -1 ) - 1;
 }
 
-#else
-#error You must implement the Interlocked* functions for your CPU
-#endif
+#endif  /* __i386__ */
diff --git a/tools/winebuild/build.h b/tools/winebuild/build.h
index 1842b9c..5cce3c9 100644
--- a/tools/winebuild/build.h
+++ b/tools/winebuild/build.h
@@ -23,66 +23,13 @@
 #ifndef __WINE_BUILD_H
 #define __WINE_BUILD_H
 
-#ifndef __WINE_CONFIG_H  
-# error You must include config.h to use this header  
-#endif  
+#ifndef __WINE_CONFIG_H
+# error You must include config.h to use this header
+#endif
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#ifdef HAVE_DIRECT_H
-# include <direct.h>
-#endif
-#ifdef HAVE_IO_H
-# include <io.h>
-#endif
-#ifdef HAVE_UNISTD_H
-# include <unistd.h>
-#endif
-
-#if !defined(HAVE_POPEN) && defined(HAVE__POPEN)
-#define popen _popen
-#endif
-
-#if !defined(HAVE_PCLOSE) && defined(HAVE__PCLOSE)
-#define pclose _pclose
-#endif
-
-#if !defined(HAVE_STRNCASECMP) && defined(HAVE__STRNICMP)
-# define strncasecmp _strnicmp
-#endif
-
-#if !defined(HAVE_STRCASECMP) && defined(HAVE__STRICMP)
-# define strcasecmp _stricmp
-#endif
-
-#define PUT_WORD(ptr, w)  (*(WORD *)(ptr) = (w))
-#define PUT_LE_WORD(ptr, w) \
-        do { ((BYTE *)(ptr))[0] = LOBYTE(w); \
-             ((BYTE *)(ptr))[1] = HIBYTE(w); } while (0)
-#define PUT_BE_WORD(ptr, w) \
-        do { ((BYTE *)(ptr))[1] = LOBYTE(w); \
-             ((BYTE *)(ptr))[0] = HIBYTE(w); } while (0)
-
-#if defined(ALLOW_UNALIGNED_ACCESS)
-#define PUT_UA_WORD(ptr, w)  PUT_WORD(ptr, w)
-#elif defined(WORDS_BIGENDIAN)
-#define PUT_UA_WORD(ptr, w)  PUT_BE_WORD(ptr, w)
-#else
-#define PUT_UA_WORD(ptr, w)  PUT_LE_WORD(ptr, w)
-#endif
-
-#ifdef NEED_UNDERSCORE_PREFIX
-# define __ASM_NAME(name) "_" name
-#else
-# define __ASM_NAME(name) name
-#endif
-
-#ifdef NEED_TYPE_IN_DEF
-# define __ASM_FUNC(name) ".def " __ASM_NAME(name) "; .scl 2; .type 32; .endef"
-#else
-# define __ASM_FUNC(name) ".type " __ASM_NAME(name) ",@function"
-#endif
 
 #ifdef NEED_UNDERSCORE_PREFIX
 # define PREFIX "_"
diff --git a/tools/winebuild/import.c b/tools/winebuild/import.c
index 10ae35e..c16d6f2 100644
--- a/tools/winebuild/import.c
+++ b/tools/winebuild/import.c
@@ -20,6 +20,7 @@
  */
 
 #include "config.h"
+#include "wine/port.h"
 
 #include <fcntl.h>
 #include <stdio.h>
diff --git a/tools/winebuild/main.c b/tools/winebuild/main.c
index 4eb9fb2..01d6319 100644
--- a/tools/winebuild/main.c
+++ b/tools/winebuild/main.c
@@ -23,6 +23,7 @@
  */
 
 #include "config.h"
+#include "wine/port.h"
 
 #include <assert.h>
 #include <stdio.h>
diff --git a/tools/winebuild/parser.c b/tools/winebuild/parser.c
index 78b9bcf..0f9811d 100644
--- a/tools/winebuild/parser.c
+++ b/tools/winebuild/parser.c
@@ -23,6 +23,7 @@
  */
 
 #include "config.h"
+#include "wine/port.h"
 
 #include <assert.h>
 #include <ctype.h>
diff --git a/tools/winebuild/relay.c b/tools/winebuild/relay.c
index 6d4e5e5..6332543 100644
--- a/tools/winebuild/relay.c
+++ b/tools/winebuild/relay.c
@@ -23,6 +23,7 @@
  */
 
 #include "config.h"
+#include "wine/port.h"
 
 #include <ctype.h>
 
diff --git a/tools/winebuild/res16.c b/tools/winebuild/res16.c
index 047cc98..b91ffa3 100644
--- a/tools/winebuild/res16.c
+++ b/tools/winebuild/res16.c
@@ -19,6 +19,7 @@
  */
 
 #include "config.h"
+#include "wine/port.h"
 
 #include <ctype.h>
 #include <stdlib.h>
diff --git a/tools/winebuild/res32.c b/tools/winebuild/res32.c
index a295e6b..ed4a38a 100644
--- a/tools/winebuild/res32.c
+++ b/tools/winebuild/res32.c
@@ -19,6 +19,7 @@
  */
 
 #include "config.h"
+#include "wine/port.h"
 
 #include <ctype.h>
 #include <stdlib.h>
diff --git a/tools/winebuild/spec16.c b/tools/winebuild/spec16.c
index e84150f..23d990f 100644
--- a/tools/winebuild/spec16.c
+++ b/tools/winebuild/spec16.c
@@ -23,6 +23,7 @@
  */
 
 #include "config.h"
+#include "wine/port.h"
 
 #include <assert.h>
 #include <ctype.h>
diff --git a/tools/winebuild/spec32.c b/tools/winebuild/spec32.c
index 5bf55da..7bfd39d 100644
--- a/tools/winebuild/spec32.c
+++ b/tools/winebuild/spec32.c
@@ -23,6 +23,7 @@
  */
 
 #include "config.h"
+#include "wine/port.h"
 
 #include <assert.h>
 #include <ctype.h>
diff --git a/tools/winebuild/utils.c b/tools/winebuild/utils.c
index 5f8cfa6..0d9b6aa 100644
--- a/tools/winebuild/utils.c
+++ b/tools/winebuild/utils.c
@@ -19,6 +19,7 @@
  */
 
 #include "config.h"
+#include "wine/port.h"
 
 #include <ctype.h>
 #include <stdarg.h>
diff --git a/windows/winproc.c b/windows/winproc.c
index fb7a559..3fa6fb0 100644
--- a/windows/winproc.c
+++ b/windows/winproc.c
@@ -20,6 +20,7 @@
  */
 
 #include "config.h"
+#include "wine/port.h"
 
 #include <string.h>