Building Wine on NetBSD 8.0 beta with pkgsrc current

For personal purposes I needed to build wine on my VT310-DP board using current pkgsrc package manager. I initially  tried to build and install emulators/wine package for this purpose as an “obvious” choice. It contains a build for wine-1.6.2. I face two compilation issues during the build. First build issue was complaining about undefined yywrap variable in tools/wrc/parser.yy.c file.   I “fixed” it by commenting out //#undef yywrap.

--- tools/wrc/parser.yy.c 2017-08-19 15:29:22.954733511 +0300
+++ tools/wrc/parser.yy.c 2017-08-19 15:30:39.061280133 +0300
@@ -837,7 +837,7 @@
 #include "newstruc.h"
 
 #include "parser.tab.h"
-#undef yywrap
+//#undef yywrap
 
 /* Always update the current character position within a line */
 #define YY_USER_ACTION char_number+=yyleng; wanted_id = want_id; want_id = 0;

Another one was server/ptrace.c issue. There were two code blocks using dbregs.drX variables (X is a number from 0-7), for example  context->debug.i386_regs.dr0 = dbregs.dr0. Compiler was complaining that non of drX variables were defined in the struct. From the code I realized that it was using dbreg struct. Then I checked system’s /usr/include/machine/reg.h file, dbreg struct was defined like this:

/*
 * Debug Registers
 *
 * DR0-DR3 Debug Address Registers
 * DR4-DR5 Reserved
 * DR6 Debug Status Register
 * DR7 Debug Control Register
 */
struct dbreg {
 int dr[8];
};

It is visible that that dbreg struct has one dr variable which is an array of int. So I replaced all the dbregs.drX lines with array indexes instead dbregs.dr[X] line. It helped and wine was build. Unfortunately running any executable was failing with an error message: “wine: failed to create the process heap”. I tried to investigate error online but it was usually pointing to some old wine bug and workaround to build a manual Linux kernel which I wasn’t sure how to apply on NetBSD. One thing that caught my eye was that NetBSD has a newer wine package called wine-devel. It builds wine-1.9.18. During wine-devel compilation I didn’t face parser.yy.c issue anymore but ptrace.c one was still the same. I made this modification to the file:

--- ptrace.c 2017-08-19 15:14:09.316982274 +0300
+++ ptrace.c 2017-08-19 15:16:07.746233823 +0300
@@ -675,12 +675,12 @@
 context->debug.i386_regs.dr6 = DBREG_DRX((&dbregs), 6);
 context->debug.i386_regs.dr7 = DBREG_DRX((&dbregs), 7);
 #else
- context->debug.i386_regs.dr0 = dbregs.dr0;
- context->debug.i386_regs.dr1 = dbregs.dr1;
- context->debug.i386_regs.dr2 = dbregs.dr2;
- context->debug.i386_regs.dr3 = dbregs.dr3;
- context->debug.i386_regs.dr6 = dbregs.dr6;
- context->debug.i386_regs.dr7 = dbregs.dr7;
+ context->debug.i386_regs.dr0 = dbregs.dr[0];
+ context->debug.i386_regs.dr1 = dbregs.dr[1];
+ context->debug.i386_regs.dr2 = dbregs.dr[2];
+ context->debug.i386_regs.dr3 = dbregs.dr[3];
+ context->debug.i386_regs.dr6 = dbregs.dr[6];
+ context->debug.i386_regs.dr7 = dbregs.dr[7];
 #endif
 context->flags |= SERVER_CTX_DEBUG_REGISTERS;
 }
@@ -709,14 +709,14 @@
 DBREG_DRX((&dbregs), 6) = context->debug.i386_regs.dr6;
 DBREG_DRX((&dbregs), 7) = context->debug.i386_regs.dr7;
 #else
- dbregs.dr0= context->debug.i386_regs.dr0;
- dbregs.dr1 = context->debug.i386_regs.dr1;
- dbregs.dr2 = context->debug.i386_regs.dr2;
- dbregs.dr3 = context->debug.i386_regs.dr3;
- dbregs.dr4 = 0;
- dbregs.dr5 = 0;
- dbregs.dr6 = context->debug.i386_regs.dr6;
- dbregs.dr7 = context->debug.i386_regs.dr7;
+ dbregs.dr[0] = context->debug.i386_regs.dr0;
+ dbregs.dr[1] = context->debug.i386_regs.dr1;
+ dbregs.dr[2] = context->debug.i386_regs.dr2;
+ dbregs.dr[3] = context->debug.i386_regs.dr3;
+ dbregs.dr[4] = 0;
+ dbregs.dr[5] = 0;
+ dbregs.dr[6] = context->debug.i386_regs.dr6;
+ dbregs.dr[7] = context->debug.i386_regs.dr7;
 #endif
 if (ptrace( PTRACE_SETDBREGS, pid, (caddr_t) &dbregs, 0 ) == -1) file_set_error();
 else if (thread->context)

Applying this patch fixed the build and I had a newer version of wine ready. Trying it out proved to be successful for some small Windows executable files I was planning to use. Old wine bug didn’t reoccur. So if you want to build wine on NetBSD 8.0 beta and current pkgsrc I recommend using wine-devel package and apply the patch above if build fails.