cava icon indicating copy to clipboard operation
cava copied to clipboard

build cava using the MinGW compiler

Open karlstav opened this issue 1 year ago • 10 comments

          I made some changes to build cava using the MinGW compiler (basically the commands mentioned in the linux section of Readme): 
diff --git a/Makefile.am b/Makefile.am
index f133e95..b6cb4de 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -3,13 +3,19 @@ AUTOMAKE_OPTIONS = foreign
 ACLOCAL_AMFLAGS = -I m4
 
 bin_PROGRAMS = cava
-cava_SOURCES = cava.c cavacore.c config.c input/common.c input/fifo.c input/shmem.c \
+cava_SOURCES = cava.c cavacore.c config.c input/common.c \
                output/terminal_noncurses.c output/raw.c output/noritake.c
 cava_CPPFLAGS = -DPACKAGE=\"$(PACKAGE)\" -DVERSION=\"$(VERSION)\" \
            -D_POSIX_SOURCE -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE_EXTENDED \
 	   -DFONTDIR=\"@FONT_DIR@\"
 cava_CFLAGS = -std=c99 -Wall -Wextra -Wno-unused-result -Wno-unknown-warning-option -Wno-maybe-uninitialized -Wno-vla-parameter
 
+if WINDOWS
+    cava_SOURCES += input/winscap.c
+    cava_CFLAGS += -lkernel32 -lole32
+else
+    cava_SOURCES += input/fifo.c
+    cava_SOURCES += input/shmem.c
 if OSX
     cava_CFLAGS += -DNORT
     cava_LDADD =
@@ -18,6 +24,7 @@ else
     cava_font_dir = @FONT_DIR@
     cava_font__DATA = cava.psf
 endif
+endif
 
 if ALSA
     cava_SOURCES += input/alsa.c
diff --git a/cava.c b/cava.c
index c146682..a73fd8e 100644
--- a/cava.c
+++ b/cava.c
@@ -97,7 +97,7 @@ int should_quit = 0;
 // these variables are used only in main, but making them global
 // will allow us to not free them on exit without ASan complaining
 struct config_params p;
-
+#undef SDL
 // general: cleanup
 void cleanup(void) {
     if (output_mode == OUTPUT_NCURSES) {
diff --git a/config.c b/config.c
index a978264..e160936 100644
--- a/config.c
+++ b/config.c
@@ -19,6 +19,7 @@
 #define NUMBER_OF_SHADERS 2
 
 #ifdef _MSC_VER
+#define mkdir(A, B) mkdir(A)
 #include "Windows.h"
 #define PATH_MAX 260
 #define PACKAGE "cava"
diff --git a/configure.ac b/configure.ac
index 9a8b0e7..fe49d55 100644
--- a/configure.ac
+++ b/configure.ac
@@ -212,7 +212,7 @@ AC_CHECK_LIB(SDL2,SDL_Init, have_sdl=yes, have_sdl=no)
           [do not include support for output with sdl_glsl])
       )
       AS_IF([test "x$enable_output_sdl_glsl" != "xno"], [
-      AX_CHECK_GL(have_opengl=yes, have_opengl=no)
+      have_opengl=yes
       if [[ $have_opengl = "yes" ]] ; then
         LIBS="$LIBS $GL_LIBS"
         CPPFLAGS="$CPPFLAGS -DSDL_GLSL $GL_CFLAGS"
@@ -321,6 +321,11 @@ case "${host_os}" in
         AC_MSG_NOTICE([OSX detected])
         build_mac=yes
         ;;
+    mingw*)
+        AC_MSG_NOTICE([Windows detected])
+        AC_DEFINE([_MSC_VER])
+        build_windows=yes
+        ;;
     freebsd*)
         AC_MSG_NOTICE([FreeBSD detected])
         build_linux=yes
@@ -332,6 +337,7 @@ esac
 
 # Pass the conditionals to automake
 AM_CONDITIONAL([LINUX], [test "$build_linux" = "yes"])
+AM_CONDITIONAL([WINDOWS], [test "$build_windows" = "yes"])
 AM_CONDITIONAL([OSX], [test "$build_mac" = "yes"])
 
 
diff --git a/input/winscap.c b/input/winscap.c
index 8738ec9..1c79e06 100644
--- a/input/winscap.c
+++ b/input/winscap.c
@@ -18,6 +18,15 @@
 #define REFTIMES_PER_SEC 10000000
 #define REFTIMES_PER_MILLISEC 10000
 
+#ifndef PKEY_Device_FriendlyName
+
+#undef DEFINE_PROPERTYKEY
+#define DEFINE_PROPERTYKEY(id, a, b, c, d, e, f, g, h, i, j, k, l) \
+	const PROPERTYKEY id = { { a, b, c, { d, e, f, g, h, i, j, k, } }, l };
+
+DEFINE_PROPERTYKEY(PKEY_Device_FriendlyName, 0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, 14);
+#endif
+
 // the device change funcitonality is disabled until I figure out how
 // or if to rewrite it to c
 /*
diff --git a/output/terminal_ncurses.c b/output/terminal_ncurses.c
index 7058714..8b50b96 100644
--- a/output/terminal_ncurses.c
+++ b/output/terminal_ncurses.c
@@ -6,6 +6,9 @@
 #include <wchar.h>
 
 #include "util.h"
+#ifdef _MSC_VER
+#include <windows.h>
+#endif
 
 int gradient_size = 64;
 
@@ -310,6 +313,17 @@ int draw_terminal_ncurses(int is_tty, int dimension_value, int dimension_bar, in
 
 // general: cleanup
 void cleanup_terminal_ncurses(void) {
+#ifdef _MSC_VER
+    setecho(1, 1);
+    HANDLE hStdOut = NULL;
+    CONSOLE_CURSOR_INFO curInfo;
+
+    hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
+    GetConsoleCursorInfo(hStdOut, &curInfo);
+    curInfo.bVisible = TRUE;
+    SetConsoleCursorInfo(hStdOut, &curInfo);
+    system("cls");
+#else
     echo();
     system("setfont  >/dev/null 2>&1");
     system("setfont /usr/share/consolefonts/Lat2-Fixed16.psf.gz  >/dev/null 2>&1");
@@ -326,4 +340,5 @@ void cleanup_terminal_ncurses(void) {
     standend();
     endwin();
     system("clear");
+#endif
 }

But I face a huge wall of errors when running make. I don't think they're syntax/semantic errors, they're just redefinition errors: image

How should I fix this?

Originally posted by @rashil2000 in https://github.com/karlstav/cava/issues/479#issuecomment-1416691295

karlstav avatar Feb 04 '23 09:02 karlstav