Set debugging option based on NO_TRACE_MSGS define. Only output 32-bit
relay stubs if debugging is on.

diff --git a/relay32/relay386.c b/relay32/relay386.c
index dc8b65d..33ba0e6 100644
--- a/relay32/relay386.c
+++ b/relay32/relay386.c
@@ -418,6 +418,7 @@
         int on = 1;
 
         if (!debug->call) continue;  /* not a normal function */
+        if (debug->call != 0xe8 && debug->call != 0xe9) break; /* not a debug thunk at all */
 
         if ((name = find_exported_name( module, exports, i + exports->Base )))
         {
diff --git a/tools/winebuild/main.c b/tools/winebuild/main.c
index da75bdc..b64049b 100644
--- a/tools/winebuild/main.c
+++ b/tools/winebuild/main.c
@@ -28,10 +28,16 @@
 int UsePIC = 0;
 int nb_entry_points = 0;
 int nb_names = 0;
-int debugging = 1;
 int nb_debug_channels = 0;
 int nb_lib_paths = 0;
 
+/* we only support relay debugging on i386 */
+#if defined(__i386__) && !defined(NO_TRACE_MSGS)
+int debugging = 1;
+#else
+int debugging = 0;
+#endif
+
 char DLLName[80];
 char DLLFileName[80];
 char DLLInitFunc[80];
diff --git a/tools/winebuild/spec32.c b/tools/winebuild/spec32.c
index 4e57217..782ef20 100644
--- a/tools/winebuild/spec32.c
+++ b/tools/winebuild/spec32.c
@@ -136,16 +136,17 @@
     }
     fprintf( outfile, "  } exp;\n" );
 
-#ifdef __i386__
-    fprintf( outfile, "  struct {\n" );
-    fprintf( outfile, "    unsigned char  jmp;\n" );
-    fprintf( outfile, "    unsigned char  addr[4];\n" );
-    fprintf( outfile, "    unsigned char  ret;\n" );
-    fprintf( outfile, "    unsigned short args;\n" );
-    fprintf( outfile, "    func_ptr       orig;\n" );
-    fprintf( outfile, "    unsigned int   argtypes;\n" );
-    fprintf( outfile, "  } relay[%d];\n", nr_exports );
-#endif  /* __i386__ */
+    if (debugging)
+    {
+        fprintf( outfile, "  struct {\n" );
+        fprintf( outfile, "    unsigned char  jmp;\n" );
+        fprintf( outfile, "    unsigned char  addr[4];\n" );
+        fprintf( outfile, "    unsigned char  ret;\n" );
+        fprintf( outfile, "    unsigned short args;\n" );
+        fprintf( outfile, "    func_ptr       orig;\n" );
+        fprintf( outfile, "    unsigned int   argtypes;\n" );
+        fprintf( outfile, "  } relay[%d];\n", nr_exports );
+    }
 
     fprintf( outfile, "} exports = {\n  {\n" );
     fprintf( outfile, "    0,\n" );                 /* Characteristics */
@@ -248,57 +249,58 @@
 
     /* output relays */
 
-#ifdef __i386__
-    fprintf( outfile, "  },\n  {\n" );
-    for (i = Base; i <= Limit; i++)
+    if (debugging)
     {
-        ORDDEF *odp = Ordinals[i];
-        unsigned int j, mask = 0;
-
-        /* skip non-existent entry points */
-        if (!odp) goto ignore;
-        /* skip non-functions */
-        if ((odp->type != TYPE_STDCALL) &&
-            (odp->type != TYPE_CDECL) &&
-            (odp->type != TYPE_REGISTER)) goto ignore;
-        /* skip norelay entry points */
-        if (odp->flags & FLAG_NORELAY) goto ignore;
-
-        for (j = 0; odp->u.func.arg_types[j]; j++)
+        fprintf( outfile, "  },\n  {\n" );
+        for (i = Base; i <= Limit; i++)
         {
-            if (odp->u.func.arg_types[j] == 't') mask |= 1<< (j*2);
-            if (odp->u.func.arg_types[j] == 'W') mask |= 2<< (j*2);
-        }
-        if ((odp->flags & FLAG_RET64) && (j < 16)) mask |= 0x80000000;
+            ORDDEF *odp = Ordinals[i];
+            unsigned int j, mask = 0;
 
-        switch(odp->type)
-        {
-        case TYPE_STDCALL:
-            fprintf( outfile, "    { 0xe9, { 0,0,0,0 }, 0xc2, 0x%04x, %s, 0x%08x }",
-                     strlen(odp->u.func.arg_types) * sizeof(int),
-                     odp->u.func.link_name, mask );
-            break;
-        case TYPE_CDECL:
-            fprintf( outfile, "    { 0xe9, { 0,0,0,0 }, 0xc3, 0x%04x, %s, 0x%08x }",
-                     strlen(odp->u.func.arg_types) * sizeof(int),
-                     odp->u.func.link_name, mask );
-            break;
-        case TYPE_REGISTER:
-            fprintf( outfile, "    { 0xe9, { 0,0,0,0 }, 0xc3, 0x%04x, %s, 0x%08x }",
-                     0x8000 | (strlen(odp->u.func.arg_types) * sizeof(int)),
-                     make_internal_name( odp, "regs" ), mask );
-            break;
-        default:
-            assert(0);
-        }
-        goto done;
+            /* skip non-existent entry points */
+            if (!odp) goto ignore;
+            /* skip non-functions */
+            if ((odp->type != TYPE_STDCALL) &&
+                (odp->type != TYPE_CDECL) &&
+                (odp->type != TYPE_REGISTER)) goto ignore;
+            /* skip norelay entry points */
+            if (odp->flags & FLAG_NORELAY) goto ignore;
 
-    ignore:
-        fprintf( outfile, "    { 0, { 0,0,0,0 }, 0, 0, 0, 0 }" );
-    done:
-        if (i < Limit) fprintf( outfile, ",\n" );
+            for (j = 0; odp->u.func.arg_types[j]; j++)
+            {
+                if (odp->u.func.arg_types[j] == 't') mask |= 1<< (j*2);
+                if (odp->u.func.arg_types[j] == 'W') mask |= 2<< (j*2);
+            }
+            if ((odp->flags & FLAG_RET64) && (j < 16)) mask |= 0x80000000;
+
+            switch(odp->type)
+            {
+            case TYPE_STDCALL:
+                fprintf( outfile, "    { 0xe9, { 0,0,0,0 }, 0xc2, 0x%04x, %s, 0x%08x }",
+                         strlen(odp->u.func.arg_types) * sizeof(int),
+                         odp->u.func.link_name, mask );
+                break;
+            case TYPE_CDECL:
+                fprintf( outfile, "    { 0xe9, { 0,0,0,0 }, 0xc3, 0x%04x, %s, 0x%08x }",
+                         strlen(odp->u.func.arg_types) * sizeof(int),
+                         odp->u.func.link_name, mask );
+                break;
+            case TYPE_REGISTER:
+                fprintf( outfile, "    { 0xe9, { 0,0,0,0 }, 0xc3, 0x%04x, %s, 0x%08x }",
+                         0x8000 | (strlen(odp->u.func.arg_types) * sizeof(int)),
+                         make_internal_name( odp, "regs" ), mask );
+                break;
+            default:
+                assert(0);
+            }
+            goto done;
+
+        ignore:
+            fprintf( outfile, "    { 0, { 0,0,0,0 }, 0, 0, 0, 0 }" );
+        done:
+            if (i < Limit) fprintf( outfile, ",\n" );
+        }
     }
-#endif  /* __i386__ */
 
     fprintf( outfile, "  }\n};\n\n" );