adplug / adplay-unix

AdPlug's UNIX console-based frontend
GNU General Public License v2.0
12 stars 15 forks source link

Compiling with mingw32 and SDL 1.2 as console application #22

Closed dmitrysmagin closed 8 months ago

dmitrysmagin commented 1 year ago

Hi. It's possible to compile a console application with mingw32, though you need some manual config

0) I needed to create a ./m4 subfolder and put pkg.m4 inside in order to configure properly. I used this https://github.com/pkgconf/pkgconf/blob/master/pkg.m4 and changed Makefile.am and configure.ac accordingly:

diff --git a/Makefile.am b/Makefile.am
index dd9a7fc..66ea5e4 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -3,3 +3,5 @@ SUBDIRS = src doc
 EXTRA_DIST = adplay.spec adplay.qpg

 AUTOMAKE_OPTIONS = dist-bzip2
+
+ACLOCAL_AMFLAGS = -I m4
diff --git a/configure.ac b/configure.ac
index 565acb2..cdb8938 100644
--- a/configure.ac
+++ b/configure.ac
@@ -15,6 +15,8 @@ AC_PROG_CXX
 AC_PROG_CPP
 AC_PROG_CXXCPP

+AC_CONFIG_MACRO_DIRS([m4])
+
 # Nothing works without these libraries...
 AC_CHECK_LIB(stdc++,main,,AC_MSG_ERROR([libstdc++ not installed]))
 PKG_CHECK_MODULES([adplug], [adplug >= 2.0],,[

Only after that the command autoreconf --install finished successfully

1) After that I was able to execute ./configure --prefix=/mingw CXXFLAGS=-fpermissive. But before configuring it's better to fix SDL (below)

2) SDL config problem. By default sdl-config script forces your application to be a windows app, not console, and it intercepts output to sderr and stdout and redirects it into files. I've found if you edit sdl-config the configure will fail (sdl won't be found) so I had to edit the resulting Makefile in the following way: removed -Dmain=SDL_main and -lSDLmain and changed -mwindows into -mconsole Another important thing: insert #undef main in the adplug.cc right before the main().

3) sdl.h header problem. As noted in another issue, windows fs is not case-sensitive, so #include <SDL.h> and #include "sdl.h" are misinterpreted as 'include local sdl.h` by the compiler. To overcome this, better rename ./src/sdl.h into ./src/sdlx.h and change all #includes accordingly

4) Strange typecast is needed in adplug.cc:

diff --git a/src/adplay.cc b/src/adplay.cc
index d93d16f..2973ca0 100644
--- a/src/adplay.cc
+++ b/src/adplay.cc
@@ -239,7 +239,7 @@ static int decode_switches(int argc, char **argv)
     {NULL, 0, NULL, 0}                         // end of options
   };

-  while ((c = getopt_long(argc, argv, "8f:b:d:irms:ol:hVe:O:D:qv",
+  while ((c = getopt_long(argc, (char* const** (*)())argv, "8f:b:d:irms:ol:hVe:O:D:qv",
                          long_options, (int *)0)) != EOF) {
       switch (c) {
       case '8': cfg.bits = 8; break;

After all above the make will succeed and the resulting adplay.exe will show output in the console

https://github.com/dmitrysmagin/adplay-unix/commit/3f1135a2048c311a0afc819ee17ac3634930e4c9

mywave82 commented 1 year ago

Can you please create some PRs?

Add support for SDL2.0 and fallback to SDL1.2. For audio I believe the API is identical, and perhaps fixes a couple of the issues.

dmitrysmagin commented 1 year ago

Created PR: https://github.com/adplug/adplay-unix/pull/23