steve-m/rtltcpaccess — pull request #1 by ackalker (2014-07-18 00:26:42+00:00)
Title: Build using winegcc, no MinGW needed :-)

First off, thanks for this clever hack! :-)
Thanks to this, I've discovered that there are a few very nice DAB+ broadcasts in my area.

From fiddling a bit (that's an understatement...) with winemaker and reading a bit (that's a big understatement) about Wine 'built-in' DLLs , I've discovered that it is possible to build your dll entirely using winegcc, so no MinGW tools needed, just a sufficiently recent Wine (I guess).

Here's what to do, feel free to integrate it into your build:

Renamed `main.c` to `rtl283xaccess.c`.
Created a file `rtl283xaccess.def` with the following contents:
```
LIBRARY RTL283XACCESS
EXPORTS
RTK_BDAFilterInit
RTK_BDAFilterRelease
RTK_Demod_Byte_Read
RTK_Demod_Byte_Write
RTK_DeviceUpdate
RTK_GetData
RTK_Get_TunerType
RTK_ReleaseDABEventHandle
RTK_SYS_Byte_Read
RTK_SYS_Byte_Write
RTK_SetDABEventHandle
RTK_Set_Bandwidth
RTK_Set_Frequency
```
Used `winemaker --interactive .` to setup a build infrastructure, specifying `rtl283xaccess.dll` as the target to build, with global project options: `--nodlls -iws2_32`.

Winemaker applied the following patch to `rtl283xaccess.c` (which was `main.c`):
```
--- rtl283xaccess.c.bak 2014-07-17 20:44:49.790515475 +0200
+++ rtl283xaccess.c 2014-07-18 00:51:19.989767623 +0200
@@ -42,12 +42,14 @@
static int enable_testmode = FALSE;
static SOCKET sock;

-#pragma pack(push, 1)
+/* winemaker: #pragma pack(push, 1) */
+#include
struct command {
unsigned char cmd;
unsigned int param;
}__attribute__((packed));
-#pragma pack(pop)
+/* winemaker: #pragma pack(pop) */
+#include

static int is_error(int perr)
{
```
Finally, after patching the Makefile to use `CC = winegcc -m32` (I'm using an x86_64 multiarch system), I was able to build the DLL as a Wine 'built-in' shared library by running `make`. The commands executed are:
```
winegcc -m32 -c -mno-cygwin -o rtl283xaccess.o rtl283xaccess.c
winegcc -m32 -shared rtl283xaccess.def -mno-cygwin -o rtl283xaccess.dll.so rtl283xaccess.o -lws2_32
```
This produced the file `rtl283xaccess.dll.so`, which I then copied to `${HOME}/.wine/drive_c/Program Files (x86)/NOXON Media/NOXON DAB MediaPlayer/RTL283XACCESS.dll` (note: no `.so` suffix!), overwriting your native Windows DLL.
Started the player, verified that everything works well.

I hope this will be useful in some way.