--- a/magick/blob.c
+++ b/magick/blob.c
@@ -56,6 +56,7 @@
 #include "magick/semaphore.h"
 #include "magick/tempfile.h"
 #include "magick/utility.h"
+#include "magick/pathtools.h"
 #if defined(HasZLIB) && !defined(DISABLE_COMPRESSED_FILES)
 #  include "zlib.h"
 #endif
@@ -1873,7 +1874,7 @@
 %
 */
 
-#if !defined(UseInstalledMagick) && defined(POSIX)
+#if !defined(UseInstalledMagick) && (defined(POSIX) || defined(__MINGW32__))
 static void ChopPathComponents(char *path,const unsigned long components)
 {
   long
@@ -1987,11 +1988,13 @@
 #if defined(UseInstalledMagick)
 
 # if defined(MagickShareConfigPath)
-  AddConfigurePath(path_map,&path_index,MagickShareConfigPath,exception);
+  char * path_share = single_path_relocation_lib(MagickBinPath, MagickShareConfigPath);
+  AddConfigurePath(path_map,&path_index,path_share,exception);
 # endif /* defined(MagickShareConfigPath) */
 
 # if defined(MagickLibConfigPath)
-  AddConfigurePath(path_map,&path_index,MagickLibConfigPath,exception);
+  char * path_lib = single_path_relocation_lib(MagickBinPath, MagickLibConfigPath);
+  AddConfigurePath(path_map,&path_index,path_lib,exception);
 # endif /* defined(MagickLibConfigPath) */
 
 # if defined(MSWINDOWS) && !(defined(MagickLibConfigPath) || defined(MagickShareConfigPath))
@@ -2056,7 +2059,7 @@
 
   if (*SetClientPath((char *) NULL) != '\0')
     {
-#if defined(POSIX)
+#if defined(POSIX) || defined(__MINGW32__)
       char
         prefix[MaxTextExtent];
 
@@ -2067,10 +2070,12 @@
       ChopPathComponents(prefix,1);
 
       FormatString(path,"%.1024s/lib/%s/",prefix,MagickLibConfigSubDir);
-      AddConfigurePath(path_map,&path_index,path,exception);
+      char * path_sub_lib = single_path_relocation_lib(MagickBinPath, path);
+      AddConfigurePath(path_map,&path_index,path_sub_lib,exception);
 
       FormatString(path,"%.1024s/share/%s/",prefix,MagickShareConfigSubDir);
-      AddConfigurePath(path_map,&path_index,path,exception);
+      char * path_sub_share = single_path_relocation_lib(MagickBinPath, path);
+      AddConfigurePath(path_map,&path_index,path_sub_share,exception);
 #else /* defined(POSIX) */
       FormatString(path,"%.1024s%s",SetClientPath((char *) NULL),
         DirectorySeparator);
--- GraphicsMagick-1.3.42/magick/delegate.c.orig	2022-12-26 17:56:05.000000000 +0100
+++ GraphicsMagick-1.3.42/magick/delegate.c	2023-11-06 09:31:04.483825900 +0100
@@ -45,6 +45,7 @@
 #include "magick/constitute.h"
 #include "magick/delegate.h"
 #include "magick/log.h"
+#include "magick/pathtools.h"
 #if defined(MSWINDOWS) || defined(__CYGWIN__)
 # include "magick/nt_feature.h"
 #endif
@@ -1431,7 +1432,13 @@
 
 # if defined(UseInstalledMagick)
 #  if defined(MagickBinPath)
+#    ifdef __MINGW32__
+                    char *executable_path = single_path_relocation(MagickBinPath, MagickBinPath);
+                    strlcpy(BinPath,executable_path,sizeof(BinPath));
+                    free(executable_path);
+#    else
                     strlcpy(BinPath,MagickBinPath,sizeof(BinPath));
+#    endif
 #  else
                     {
                       char
--- a/magick/Makefile.am
+++ b/magick/Makefile.am
@@ -152,6 +152,8 @@
 	magick/operator.h \
 	magick/paint.c \
 	magick/paint.h \
+	magick/pathtools.c \
+	magick/pathtools.h \
 	magick/pixel_cache.h \
 	magick/pixel_cache.c \
 	magick/pixel_iterator.c \
--- a/magick/module.c
+++ b/magick/module.c
@@ -47,6 +47,7 @@
 #include "magick/map.h"
 #include "magick/module.h"
 #include "magick/utility.h"
+#include "magick/pathtools.h"
 #if defined(HasLTDL)
 #  include "ltdl.h"
    typedef lt_dlhandle ModuleHandle;
@@ -873,7 +874,7 @@
   (*path_index)++;
 }
 
-#if !defined(UseInstalledMagick) && defined(POSIX)
+#if !defined(UseInstalledMagick) && (defined(POSIX) || defined(__MINGW32__))
 static void
 ChopPathComponents(char *path,const unsigned long components)
 {
@@ -1049,10 +1050,10 @@
       {
       case MagickCoderModule:
       default:
-        module_directory=MagickCoderModulesPath;
+        module_directory = single_path_relocation_lib(MagickBinPath, MagickCoderModulesPath);
         break;
       case MagickFilterModule:
-        module_directory=MagickFilterModulesPath;
+        module_directory = single_path_relocation_lib(MagickBinPath, MagickFilterModulesPath);
         break;
       }
 
@@ -1102,7 +1103,7 @@
       /*
         Search MAGICK_HOME.
       */
-# if defined(POSIX)
+# if defined(POSIX) || defined(__MINGW32__)
       char
         *subdir=NULL;
 
@@ -1118,18 +1119,20 @@
         }
 
       FormatString(path,"%.512s/lib/%s/",getenv("MAGICK_HOME"),subdir);
+      char * path_home_dirs = single_path_relocation_lib(MagickBinPath, path);
+      AddModulePath(path_map,&path_index,path_home_dirs,exception);
 # else
       FormatString(path,"%.512s%s",getenv("MAGICK_HOME"),
         DirectorySeparator);
-# endif /* !POSIX */
       AddModulePath(path_map,&path_index,path,exception);
+# endif /* !POSIX */
     }
   if (*SetClientPath((char *) NULL) != '\0')
     {
       /*
         Search based on executable directory if directory is known.
       */
-# if defined(POSIX)
+# if defined(POSIX) || defined(__MINGW32__)
       char
         *module_subdir=NULL,
         prefix[MaxTextExtent];
@@ -1149,11 +1152,13 @@
       ChopPathComponents(prefix,1);
       FormatString(path,"%.512s/lib/%s/modules-Q%d/%s/",prefix,
         MagickLibSubdir,QuantumDepth,module_subdir);
+      char * path_home_modules = single_path_relocation_lib(MagickBinPath, path);
+      AddModulePath(path_map,&path_index,path_home_modules,exception);
 # else /* end defined(POSIX) */
       FormatString(path,"%.512s%s",SetClientPath((char *) NULL),
         DirectorySeparator);
-# endif /* !POSIX */
       AddModulePath(path_map,&path_index,path,exception);
+# endif /* !POSIX */
     }
   if (getenv("HOME") != (char *) NULL)
     {
--- a/magick/studio.h
+++ b/magick/studio.h
@@ -323,7 +323,11 @@
 #endif
 
 #if defined(MSWINDOWS)
-#  define DirectorySeparator  "\\"
+#  if defined (__MINGW32__)
+#    define DirectorySeparator  "/"
+#  else
+#    define DirectorySeparator  "\\"
+#  endif
 #  define DirectoryListSeparator  ';'
 #  define EditorOptions ""
 #  define IsBasenameSeparator(c)  (((c) == '/') || ((c) == '\\'))
--- a/winpath.sh
+++ b/winpath.sh
@@ -20,59 +20,4 @@
 #
 # Written by Bob Friesenhahn <bfriesen@simple.dallas.tx.us> June 2002
 #
-arg="$1"
-escapes='none'
-if test -n "$2"
-then
-  escapes="$2"
-  if test $escapes -gt 3
-  then
-    printf "$0: escape level must in range 0 - 3\n"
-    exit 1
-  fi
-fi
-result=''
-length=0
-max_length=0
-mount | sed -e 's:\\:/:g'  | (
-  IFS="\n"
-  while read mount_entry
-  do
-    win_mount_path=`printf "$mount_entry\n" | sed -e 's: .*::g'`
-    unix_mount_path=`printf "$mount_entry\n" | sed -e 's:.* on ::;s: type .*::'`
-    temp=`printf "$arg" | sed -e "s!^$unix_mount_path!$win_mount_path!"`
-    if test "$temp" != "$arg"
-    then
-      candidate="$temp"
-      length=${#unix_mount_path}
-      if test $length -gt $max_length
-      then
-        result=$candidate
-        max_length=$length
-      fi
-    fi
-  done
-  if test -z "$result"
-  then
-    printf "$0: path \"$arg\" is not mounted\n"
-    exit 1
-  fi
-  case "$escapes" in
-    0)
-     printf "${result}" | sed -e 's:/:\\:g'
-     ;;
-    1)
-     printf "${result}" | sed -e 's:/:\\\\:g'
-     ;;
-    2)
-     printf "${result}" | sed -e 's:/:\\\\\\\\:g'
-     ;;
-    3)
-     printf "${result}" | sed -e 's:/:\\\\\\\\\\\\\\\\:g'
-     ;;
-    *)
-     printf "${result}"
-     ;;
-  esac
-  exit 0;
- )
+echo "$1"
