diff --git a/src/tools/Makefile.am b/src/tools/Makefile.am
index 4c29f1a..cc25476 100644
--- a/src/tools/Makefile.am
+++ b/src/tools/Makefile.am
@@ -12,7 +12,10 @@ unmunch_SOURCES=unmunch.cxx unmunch.h
 example_SOURCES=example.cxx
 example_LDADD = ../hunspell/libhunspell-1.7.la
 
-hunspell_SOURCES=hunspell.cxx
+hunspell_CXXFLAGS = \
+  -DBINDIR=\""$(bindir)"\" \
+  -DDATA_DIR=\""$(datadir)"\"
+hunspell_SOURCES=hunspell.cxx pathtools.cxx pathtools.h
 nodist_hunspell_SOURCES= ../../config.h
 hunspell_LDADD = @LIBINTL@ @LIBICONV@ ../parsers/libparsers.a \
 	../hunspell/libhunspell-1.7.la @CURSESLIB@ @READLINELIB@
--- hunspell-1.7.2/src/tools/hunspell.cxx.orig	2022-12-29 21:10:49.000000000 +0100
+++ hunspell-1.7.2/src/tools/hunspell.cxx	2023-07-20 07:59:29.376921500 +0200
@@ -51,6 +51,7 @@
 #include "../hunspell/hunspell.hxx"
 #include "../hunspell/csutil.hxx"
 #include "../hunspell/hunzip.hxx"
+#include "pathtools.h"
 
 #define HUNSPELL_VERSION VERSION
 #define INPUTLEN 50
@@ -70,6 +71,16 @@
 
 #ifdef WIN32
 
+#ifdef __MINGW32__
+#define LIBDIR \
+    DATA_DIR "/hunspell:" \
+    DATA_DIR "/myspell:" \
+    DATA_DIR "/myspell/dicts:"
+#define OOODIR \
+    DATA_DIR "/dict/ooo"
+#define USEROOODIR {"/Application Data/OpenOffice.org 2/user/wordbook"}
+#define HOME "%USERPROFILE%"
+#else
 #define LIBDIR "C:\\Hunspell\\"
 #define USEROOODIR { "Application Data\\OpenOffice.org 2\\user\\wordbook" }
 #define OOODIR                                                 \
@@ -79,10 +90,16 @@
   "C:\\Program files\\OpenOffice.org 2.1\\share\\dict\\ooo\\;" \
   "C:\\Program files\\OpenOffice.org 2.0\\share\\dict\\ooo\\"
 #define HOME "%USERPROFILE%\\"
+#endif
 #define DICBASENAME "hunspell_"
 #define LOGFILE "C:\\Hunspell\\log"
+#ifdef __MINGW32__
+#define DIRSEPCH '/'
+#define DIRSEP "/"
+#else
 #define DIRSEPCH '\\'
 #define DIRSEP "\\"
+#endif
 #define PATHSEP ";"
 
 #ifdef __MINGW32__
@@ -2054,11 +2071,24 @@
   {
     std::string path_std_str = ".";
     path_std_str.append(PATHSEP); // <- check path in local directory
+#ifndef __MINGW32__
     path_std_str.append(PATHSEP); // <- check path in root directory
+#else
+    char* reloc_path = single_path_relocation(BINDIR, BINDIR);
+    path_std_str.append(reloc_path).append(PATHSEP);
+    free(reloc_path);
+#endif    
     if (getenv("DICPATH")) {
       path_std_str.append(getenv("DICPATH")).append(PATHSEP);
     }
+#ifndef __MINGW32__
     path_std_str.append(LIBDIR).append(PATHSEP);
+#else
+  char* reloc_pathlist = get_relocated_path_list(BINDIR, LIBDIR);
+  path_std_str.append(reloc_pathlist).append(PATHSEP);
+  free(reloc_pathlist);
+#endif
+
     if (HOME) {
       const char * userooodir[] = USEROOODIR;
       for(size_t i = 0; i < sizeof(userooodir)/sizeof(userooodir[0]); ++i) {
@@ -2068,7 +2098,13 @@
 #endif
         path_std_str.append(userooodir[i]).append(PATHSEP);
       }
+#ifndef __MINGW32__
       path_std_str.append(OOODIR);
+#else
+      char* reloc_path = single_path_relocation(BINDIR, OOODIR);
+      path_std_str.append(reloc_path).append(PATHSEP);
+      free(reloc_path);
+#endif 
     }
     path = mystrdup(path_std_str.c_str());
   }
@@ -2168,6 +2204,7 @@
   }
 
   if (arg_files == -1) {
+    fflush(stderr);
     pipe_interface(pMS, format, stdin, NULL);
   } else if (filter_mode != NORMAL) {
     for (int i = arg_files; i < argc; i++) {
